From 613aa8c579624ba30b243c1baf809485a500bb81 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 31 Jul 2016 11:06:47 +0000 Subject: [PATCH] Reimplement 6846010 correctly. The bug was actually not in ReadPng*, but in WritePng. --- src/resource.cpp | 6 +++--- src/style.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/resource.cpp b/src/resource.cpp index 107047e3..c7551d9a 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -149,7 +149,7 @@ static std::shared_ptr ReadPngIntoPixmap(png_struct *png_ptr, png_info * pixmap->data = std::vector(pixmap->stride * pixmap->height); uint8_t **rows = png_get_rows(png_ptr, info_ptr); for(size_t y = 0; y < pixmap->height; y++) { - uint8_t *srcRow = flip ? rows[y] : rows[pixmap->height - y - 1]; + uint8_t *srcRow = flip ? rows[pixmap->height - y - 1] : rows[y]; memcpy(&pixmap->data[pixmap->stride * y], srcRow, pixmap->width * pixmap->GetBytesPerPixel()); } @@ -229,9 +229,9 @@ bool Pixmap::WritePng(FILE *f, bool flip) { std::vector rows; for(size_t y = 0; y < height; y++) { if(flip) { - rows.push_back(&data[stride * y]); - } else { rows.push_back(&data[stride * (height - y - 1)]); + } else { + rows.push_back(&data[stride * y]); } } diff --git a/src/style.cpp b/src/style.cpp index 8e0c9b9f..9d8ffaed 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -371,7 +371,7 @@ void TextWindow::ScreenBackgroundImage(int link, uint32_t v) { if(GetOpenFile(&bgImageFile, "", PngFileFilter)) { FILE *f = ssfopen(bgImageFile, "rb"); if(f) { - SS.bgImage.pixmap = Pixmap::ReadPng(f, /*flip=*/true); + SS.bgImage.pixmap = Pixmap::ReadPng(f); SS.bgImage.scale = SS.GW.scale; SS.bgImage.origin = SS.GW.offset.ScaledBy(-1); fclose(f);