From 47b67a8f6139877595e82b12deb3cd9a0fd5a78b Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 1 May 2016 00:20:58 -0700 Subject: [PATCH] Correct handling of 8 bit and no-alpha PNGs. --- Core/TextureReplacer.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index e06dd6a5e2a7..742f9d1b4942 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -435,19 +435,27 @@ void ReplacedTexture::Load(int level, void *out, int rowPitch) { #else png_image png = {}; png.version = PNG_IMAGE_VERSION; - png.format = PNG_FORMAT_RGBA; FILE *fp = File::OpenCFile(info.file, "rb"); if (!png_image_begin_read_from_stdio(&png, fp)) { ERROR_LOG(G3D, "Could not load texture replacement info: %s - %s", info.file.c_str(), png.message); return; } + + bool checkedAlpha = false; + if ((png.format & PNG_FORMAT_FLAG_ALPHA) == 0) { + // Well, we know for sure it doesn't have alpha. + alphaStatus_ = ReplacedTextureAlpha::FULL; + checkedAlpha = true; + } + png.format = PNG_FORMAT_RGBA; + if (!png_image_finish_read(&png, nullptr, out, rowPitch, nullptr)) { ERROR_LOG(G3D, "Could not load texture replacement: %s - %s", info.file.c_str(), png.message); return; } - if (level == 0) { + if (level == 0 && !checkedAlpha) { // This will only check the hashed bits. CheckAlphaResult res = CheckAlphaRGBA8888Basic((u32 *)out, rowPitch / sizeof(u32), png.width, png.height); alphaStatus_ = ReplacedTextureAlpha(res);