From 290e62f179a86328f90aaac3c87d4d640637dec6 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 22 Feb 2022 18:01:39 -0800 Subject: Remove casts to integers for texture and EFB formats The only remaining casts for these types that I know of are in TextureInfo (where format_name is set to the int version of the format, and since that affects filenames and probably would break resource packs, I'm not changing it) and in TextureDecoder_Common's TexDecoder_DrawOverlay, which will be handled separately. --- Source/Core/VideoCommon/TextureDecoder_Common.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'Source/Core/VideoCommon/TextureDecoder_Common.cpp') diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp index 798496ac6d..bc2de947ea 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp @@ -50,8 +50,7 @@ int TexDecoder_GetTexelSizeInNibbles(TextureFormat format) case TextureFormat::XFB: return 4; default: - PanicAlertFmt("Invalid Texture Format ({:#X})! (GetTexelSizeInNibbles)", - static_cast(format)); + PanicAlertFmt("Invalid Texture Format {}! (GetTexelSizeInNibbles)", format); return 1; } } @@ -90,8 +89,7 @@ int TexDecoder_GetBlockWidthInTexels(TextureFormat format) case TextureFormat::XFB: return 16; default: - PanicAlertFmt("Invalid Texture Format ({:#X})! (GetBlockWidthInTexels)", - static_cast(format)); + PanicAlertFmt("Invalid Texture Format {}! (GetBlockWidthInTexels)", format); return 8; } } @@ -125,8 +123,7 @@ int TexDecoder_GetBlockHeightInTexels(TextureFormat format) case TextureFormat::XFB: return 1; default: - PanicAlertFmt("Invalid Texture Format ({:#X})! (GetBlockHeightInTexels)", - static_cast(format)); + PanicAlertFmt("Invalid Texture Format {}! (GetBlockHeightInTexels)", format); return 4; } } @@ -160,8 +157,7 @@ int TexDecoder_GetEFBCopyBlockWidthInTexels(EFBCopyFormat format) case EFBCopyFormat::XFB: return 16; default: - PanicAlertFmt("Invalid EFB Copy Format ({:#X})! (GetEFBCopyBlockWidthInTexels)", - static_cast(format)); + PanicAlertFmt("Invalid EFB Copy Format {}! (GetEFBCopyBlockWidthInTexels)", format); return 8; } } @@ -195,8 +191,7 @@ int TexDecoder_GetEFBCopyBlockHeightInTexels(EFBCopyFormat format) case EFBCopyFormat::XFB: return 1; default: - PanicAlertFmt("Invalid EFB Copy Format ({:#X})! (GetEFBCopyBlockHeightInTexels)", - static_cast(format)); + PanicAlertFmt("Invalid EFB Copy Format {}! (GetEFBCopyBlockHeightInTexels)", format); return 4; } } @@ -247,8 +242,7 @@ TextureFormat TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat format) case EFBCopyFormat::XFB: return TextureFormat::XFB; default: - PanicAlertFmt("Invalid EFB Copy Format ({:#X})! (GetEFBCopyBaseFormat)", - static_cast(format)); + PanicAlertFmt("Invalid EFB Copy Format ()! (GetEFBCopyBaseFormat)", format); return static_cast(format); } } -- cgit v1.2.3 From 850e524514c364f7f619e891f4dc2d687fa019f9 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 22 Feb 2022 18:22:47 -0800 Subject: Use fmt::to_string for texture format overlay This required adding parentheses to the font used by that. --- Source/Core/VideoCommon/TextureDecoder_Common.cpp | 80 ++--------------------- 1 file changed, 4 insertions(+), 76 deletions(-) (limited to 'Source/Core/VideoCommon/TextureDecoder_Common.cpp') diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp index bc2de947ea..51ea0572f2 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp @@ -242,7 +242,7 @@ TextureFormat TexDecoder_GetEFBCopyBaseFormat(EFBCopyFormat format) case EFBCopyFormat::XFB: return TextureFormat::XFB; default: - PanicAlertFmt("Invalid EFB Copy Format ()! (GetEFBCopyBaseFormat)", format); + PanicAlertFmt("Invalid EFB Copy Format {}! (GetEFBCopyBaseFormat)", format); return static_cast(format); } } @@ -253,77 +253,6 @@ void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center) TexFmt_Overlay_Center = center; } -static const char* texfmt[] = { - // pixel - "I4", - "I8", - "IA4", - "IA8", - "RGB565", - "RGB5A3", - "RGBA8", - "0x07", - "C4", - "C8", - "C14X2", - "0x0B", - "0x0C", - "0x0D", - "CMPR", - "0x0F", - // Z-buffer - "0x10", - "Z8", - "0x12", - "Z16", - "0x14", - "0x15", - "Z24X8", - "0x17", - "0x18", - "0x19", - "0x1A", - "0x1B", - "0x1C", - "0x1D", - "0x1E", - "0x1F", - // pixel + copy - "CR4", - "0x21", - "CRA4", - "CRA8", - "0x24", - "0x25", - "CYUVA8", - "CA8", - "CR8", - "CG8", - "CB8", - "CRG8", - "CGB8", - "0x2D", - "0x2E", - "XFB", - // Z + copy - "CZ4", - "0x31", - "0x32", - "0x33", - "0x34", - "0x35", - "0x36", - "0x37", - "0x38", - "CZ8M", - "CZ8L", - "0x3B", - "CZ16L", - "0x3D", - "0x3E", - "0x3F", -}; - static void TexDecoder_DrawOverlay(u8* dst, int width, int height, TextureFormat texformat) { int w = std::min(width, 40); @@ -338,11 +267,11 @@ static void TexDecoder_DrawOverlay(u8* dst, int width, int height, TextureFormat yoff = 0; } - const char* fmt = texfmt[static_cast(texformat) & 15]; - while (*fmt) + const auto fmt_str = fmt::to_string(texformat); + for (char ch : fmt_str) { int xcnt = 0; - int nchar = sfont_map[(int)*fmt]; + int nchar = sfont_map[ch]; const unsigned char* ptr = sfont_raw[nchar]; // each char is up to 9x10 @@ -363,7 +292,6 @@ static void TexDecoder_DrawOverlay(u8* dst, int width, int height, TextureFormat ptr += 9; } xoff += xcnt; - fmt++; } } -- cgit v1.2.3 From a6e06f38adb933187605ac07ef7a0cb1940afa80 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Tue, 22 Feb 2022 20:42:23 -0800 Subject: Add notes about precision of YUV->RGB conversion factors for XFB --- Source/Core/VideoCommon/TextureDecoder_Common.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Source/Core/VideoCommon/TextureDecoder_Common.cpp') diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp index 51ea0572f2..30121aeb7b 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp @@ -629,6 +629,8 @@ void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth // We do the inverse BT.601 conversion for YCbCr to RGB // http://www.equasys.de/colorconversion.html#YCbCr-RGBColorFormatConversion + // TODO: Use more precise numbers for this conversion (although on real hardware, the XFB isn't + // in a real texture format, so does this conversion actually ever happen?) u8 R = std::clamp(int(1.164f * Y + 1.596f * V), 0, 255); u8 G = std::clamp(int(1.164f * Y - 0.392f * U - 0.813f * V), 0, 255); u8 B = std::clamp(int(1.164f * Y + 2.017f * U), 0, 255); @@ -694,6 +696,8 @@ void TexDecoder_DecodeXFB(u8* dst, const u8* src, u32 width, u32 height, u32 str // We do the inverse BT.601 conversion for YCbCr to RGB // http://www.equasys.de/colorconversion.html#YCbCr-RGBColorFormatConversion + // TODO: Use more precise numbers for this conversion (although on real hardware, the XFB + // isn't in a real texture format, so does this conversion actually ever happen?) u8 R1 = static_cast(std::clamp(int(1.164f * Y1 + 1.596f * V), 0, 255)); u8 G1 = static_cast(std::clamp(int(1.164f * Y1 - 0.392f * U - 0.813f * V), 0, 255)); u8 B1 = static_cast(std::clamp(int(1.164f * Y1 + 2.017f * U), 0, 255)); -- cgit v1.2.3