Properly save 16-bit textures for replacements.

This commit is contained in:
Unknown W. Brackets 2016-04-30 19:00:20 -07:00
parent 149de4147a
commit 9ffc717de1
5 changed files with 56 additions and 3 deletions

View File

@ -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++) {

View File

@ -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);

View File

@ -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;

View File

@ -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,
};

View File

@ -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;