From 9ffc717de10758caeeb0d2273665cbe99acd7528 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 30 Apr 2016 19:00:20 -0700 Subject: [PATCH] Properly save 16-bit textures for replacements. --- Common/ColorConv.cpp | 33 +++++++++++++++++++++++++++++++++ Common/ColorConv.h | 4 ++++ Core/TextureReplacer.cpp | 13 +++++++++++++ Core/TextureReplacer.h | 3 +++ GPU/GLES/TextureCache.cpp | 6 +++--- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/Common/ColorConv.cpp b/Common/ColorConv.cpp index a318fedd86..9dcd1876f9 100644 --- a/Common/ColorConv.cpp +++ b/Common/ColorConv.cpp @@ -435,6 +435,39 @@ void ConvertRGBA4444ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) } } +void ConvertABGR565ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert5To8((col >> 11) & 0x1f); + dst[x * 4 + 1] = Convert6To8((col >> 5) & 0x3f); + dst[x * 4 + 2] = Convert5To8((col) & 0x1f); + dst[x * 4 + 3] = 255; + } +} + +void ConvertABGR1555ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert5To8((col >> 11) & 0x1f); + dst[x * 4 + 1] = Convert5To8((col >> 6) & 0x1f); + dst[x * 4 + 2] = Convert5To8((col >> 1) & 0x1f); + dst[x * 4 + 3] = (col & 1) ? 255 : 0; + } +} + +void ConvertABGR4444ToRGBA8888(u32 *dst32, const u16 *src, const u32 numPixels) { + u8 *dst = (u8 *)dst32; + for (u32 x = 0; x < numPixels; x++) { + u16 col = src[x]; + dst[x * 4] = Convert4To8(col >> 12); + dst[x * 4 + 1] = Convert4To8((col >> 8) & 0xf); + dst[x * 4 + 2] = Convert4To8((col >> 4) & 0xf); + dst[x * 4 + 3] = Convert4To8(col & 0xf); + } +} + void ConvertRGBA4444ToBGRA8888(u32 *dst32, const u16 *src, const u32 numPixels) { u8 *dst = (u8 *)dst32; for (u32 x = 0; x < numPixels; x++) { diff --git a/Common/ColorConv.h b/Common/ColorConv.h index 5a3b71fb84..5750922ba2 100644 --- a/Common/ColorConv.h +++ b/Common/ColorConv.h @@ -126,6 +126,10 @@ void ConvertRGBA565ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); void ConvertRGBA5551ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); void ConvertRGBA4444ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertABGR565ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertABGR1555ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); +void ConvertABGR4444ToRGBA8888(u32 *dst, const u16 *src, const u32 numPixels); + void ConvertRGBA4444ToBGRA8888(u32 *dst, const u16 *src, const u32 numPixels); void ConvertRGBA5551ToBGRA8888(u32 *dst, const u16 *src, const u32 numPixels); void ConvertRGB565ToBGRA8888(u32 *dst, const u16 *src, const u32 numPixels); diff --git a/Core/TextureReplacer.cpp b/Core/TextureReplacer.cpp index abb78e279c..8698b0d0f2 100644 --- a/Core/TextureReplacer.cpp +++ b/Core/TextureReplacer.cpp @@ -305,12 +305,25 @@ void TextureReplacer::NotifyTextureDecoded(u64 cachekey, u32 hash, u32 addr, con case ReplacedTextureFormat::F_4444: ConvertRGBA4444ToRGBA8888(saveBuf.data(), (const u16 *)data, (pitch * h) / sizeof(u16)); break; + case ReplacedTextureFormat::F_0565_ABGR: + ConvertABGR565ToRGBA8888(saveBuf.data(), (const u16 *)data, (pitch * h) / sizeof(u16)); + break; + case ReplacedTextureFormat::F_1555_ABGR: + ConvertABGR1555ToRGBA8888(saveBuf.data(), (const u16 *)data, (pitch * h) / sizeof(u16)); + break; + case ReplacedTextureFormat::F_4444_ABGR: + ConvertABGR4444ToRGBA8888(saveBuf.data(), (const u16 *)data, (pitch * h) / sizeof(u16)); + break; case ReplacedTextureFormat::F_8888_BGRA: ConvertBGRA8888ToRGBA8888(saveBuf.data(), (const u32 *)data, (pitch * h) / sizeof(u32)); break; } data = saveBuf.data(); + if (fmt != ReplacedTextureFormat::F_8888_BGRA) { + // We doubled our pitch. + pitch *= 2; + } } png_image png; diff --git a/Core/TextureReplacer.h b/Core/TextureReplacer.h index 806ee6059d..c3fd618267 100644 --- a/Core/TextureReplacer.h +++ b/Core/TextureReplacer.h @@ -32,6 +32,9 @@ enum class ReplacedTextureFormat { F_5551, F_4444, F_8888, + F_0565_ABGR, + F_1555_ABGR, + F_4444_ABGR, F_8888_BGRA, }; diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index 3f695c668c..c55e124e9f 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -997,11 +997,11 @@ ReplacedTextureFormat FromGLESFormat(GLenum fmt, bool useBGRA = false) { // TODO: 16-bit formats are incorrect, since swizzled. switch (fmt) { case GL_UNSIGNED_SHORT_5_6_5: - return ReplacedTextureFormat::F_5650; + return ReplacedTextureFormat::F_0565_ABGR; case GL_UNSIGNED_SHORT_5_5_5_1: - return ReplacedTextureFormat::F_5551; + return ReplacedTextureFormat::F_1555_ABGR; case GL_UNSIGNED_SHORT_4_4_4_4: - return ReplacedTextureFormat::F_4444; + return ReplacedTextureFormat::F_4444_ABGR; case GL_UNSIGNED_BYTE: default: return useBGRA ? ReplacedTextureFormat::F_8888_BGRA : ReplacedTextureFormat::F_8888;