Skip to content

Commit

Permalink
Add notes about precision of YUV->RGB conversion factors for XFB
Browse files Browse the repository at this point in the history
  • Loading branch information
Pokechu22 committed Feb 23, 2022
1 parent d70d3e4 commit c65307c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/Core/VideoCommon/TextureConversionShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ static const std::map<TextureFormat, DecodingShaderInfo> s_decoding_shader_info{

// 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?)
{TextureFormat::XFB,
{TEXEL_BUFFER_FORMAT_RGBA8_UINT, 0, 8, 8, false,
R"(
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/VideoCommon/TextureDecoder_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<u8>(std::clamp(int(1.164f * Y1 + 1.596f * V), 0, 255));
u8 G1 = static_cast<u8>(std::clamp(int(1.164f * Y1 - 0.392f * U - 0.813f * V), 0, 255));
u8 B1 = static_cast<u8>(std::clamp(int(1.164f * Y1 + 2.017f * U), 0, 255));
Expand Down

0 comments on commit c65307c

Please sign in to comment.