From 6872ac1b49389057c29fe9327392ad15b2083096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Wed, 16 Apr 2014 14:31:48 -0400 Subject: [PATCH] add flag to allow flipping the png image --- include/llmr/util/image.hpp | 2 +- src/util/image.cpp | 4 ++-- test/headless.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/llmr/util/image.hpp b/include/llmr/util/image.hpp index 5642de986..abc021e03 100644 --- a/include/llmr/util/image.hpp +++ b/include/llmr/util/image.hpp @@ -6,7 +6,7 @@ namespace llmr { namespace util { -std::string compress_png(int width, int height, void *rgba); +std::string compress_png(int width, int height, void *rgba, bool flip = false); } } diff --git a/src/util/image.cpp b/src/util/image.cpp index e7cb22697..3a29a95a2 100644 --- a/src/util/image.cpp +++ b/src/util/image.cpp @@ -2,7 +2,7 @@ #include -std::string llmr::util::compress_png(int width, int height, void *rgba) { +std::string llmr::util::compress_png(int width, int height, void *rgba, bool flip) { png_voidp error_ptr = 0; png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, error_ptr, NULL, NULL); if (!png_ptr) { @@ -39,7 +39,7 @@ std::string llmr::util::compress_png(int width, int height, void *rgba) { } pointers(height); for (int i = 0; i < height; i++) { - pointers.rows[i] = (png_bytep)((png_bytep)rgba + width * 4 * i); + pointers.rows[flip ? height - 1 - i : i] = (png_bytep)((png_bytep)rgba + width * 4 * i); } png_set_rows(png_ptr, info_ptr, pointers.rows); diff --git a/test/headless.cpp b/test/headless.cpp index af9f56acd..d60e634dd 100644 --- a/test/headless.cpp +++ b/test/headless.cpp @@ -127,7 +127,7 @@ TEST(Headless, initialize) { glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); - std::string result = llmr::util::compress_png(width, height, pixels); + std::string result = llmr::util::compress_png(width, height, pixels, true); llmr::util::write_file("out.png", result); delete[] pixels;