From 3557b454407bc421b812c1624eaf570ce72d7698 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 20 Oct 2015 12:07:30 +0200 Subject: [PATCH] PNG loader now converts RGB to RGBA, because we'd rather treat them the same way when rendering, especially in DirectX --- src/game/Rendering/PNG.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/game/Rendering/PNG.cpp b/src/game/Rendering/PNG.cpp index 75ea402..2779ae0 100644 --- a/src/game/Rendering/PNG.cpp +++ b/src/game/Rendering/PNG.cpp @@ -75,8 +75,6 @@ dd::PNG::PNG(std::string path) } switch (color_type) { case PNG_COLOR_TYPE_RGB: - Format = Image::ImageFormat::RGB; - break; case PNG_COLOR_TYPE_RGBA: Format = Image::ImageFormat::RGBA; break; @@ -84,8 +82,15 @@ dd::PNG::PNG(std::string path) LOG_ERROR("libpng: Unsupported color format \"%i\" of image \"%s\"", color_type, path.c_str()); return; } - unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr); + // Convert RGB to RGBA, since DirectX rather treat them all the same way + if (color_type == PNG_COLOR_TYPE_RGB) { + LOG_DEBUG("Converting RGB to RGBA for \"%s\"", path.c_str()); + png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER); + png_read_update_info(png_ptr, info_ptr); + } + + unsigned int row_bytes = png_get_rowbytes(png_ptr, info_ptr); this->Data = new unsigned char[height * row_bytes]; png_bytep* row_pointers = new png_bytep[height];