diff options
| author | hthh <hthh@hh.ht> | 2017-01-14 11:29:05 +1100 |
|---|---|---|
| committer | hthh <hthh@hh.ht> | 2017-01-15 20:23:26 +1100 |
| commit | 88d52b4d69a4ca4e81c7ac32d2df0c0f826fcc19 (patch) | |
| tree | 032115824c50ead073a0d8fe928b051f5996b29e /Source/Core | |
| parent | 5d4e4aa561dc7de12cd54f35a98adcccd85bb5d3 (diff) | |
TextureDecoder: Deduplicate some utility code
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/VideoCommon/TextureDecoder.h | 5 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/TextureDecoder_Common.cpp | 13 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/TextureDecoder_Generic.cpp | 14 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/TextureDecoder_Util.h | 25 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/TextureDecoder_x64.cpp | 14 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/VideoCommon.vcxproj.filters | 3 |
6 files changed, 31 insertions, 43 deletions
diff --git a/Source/Core/VideoCommon/TextureDecoder.h b/Source/Core/VideoCommon/TextureDecoder.h index 977a81ecc4..44834c0623 100644 --- a/Source/Core/VideoCommon/TextureDecoder.h +++ b/Source/Core/VideoCommon/TextureDecoder.h @@ -88,8 +88,3 @@ void TexDecoder_SetTexFmtOverlayOptions(bool enable, bool center); /* Internal method, implemented by TextureDecoder_Generic and TextureDecoder_x64. */ void _TexDecoder_DecodeImpl(u32* dst, const u8* src, int width, int height, int texformat, const u8* tlut, TlutFormat tlutfmt); - -static constexpr int DXTBlend(int v1, int v2) -{ - return ((v1 * 3 + v2 * 5) >> 3); -} diff --git a/Source/Core/VideoCommon/TextureDecoder_Common.cpp b/Source/Core/VideoCommon/TextureDecoder_Common.cpp index af1d5e9148..7f151b2406 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Common.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Common.cpp @@ -10,6 +10,7 @@ #include "Common/MsgHandler.h" #include "VideoCommon/LookUpTables.h" #include "VideoCommon/TextureDecoder.h" +#include "VideoCommon/TextureDecoder_Util.h" #include "VideoCommon/sfont.inc" static bool TexFmt_Overlay_Enable = false; @@ -422,18 +423,6 @@ static inline u32 DecodePixel_Paletted(u16 pixel, TlutFormat tlutfmt) } } -struct DXTBlock -{ - u16 color1; - u16 color2; - u8 lines[4]; -}; - -static inline u32 MakeRGBA(int r, int g, int b, int a) -{ - return (a << 24) | (b << 16) | (g << 8) | r; -} - void TexDecoder_DecodeTexel(u8* dst, const u8* src, int s, int t, int imageWidth, int texformat, const u8* tlut_, TlutFormat tlutfmt) { diff --git a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp index 114b9b8207..eb7ed141ef 100644 --- a/Source/Core/VideoCommon/TextureDecoder_Generic.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_Generic.cpp @@ -10,6 +10,7 @@ #include "Common/CommonTypes.h" #include "VideoCommon/LookUpTables.h" #include "VideoCommon/TextureDecoder.h" +#include "VideoCommon/TextureDecoder_Util.h" //#include "VideoCommon/VideoCommon.h" // to get debug logs #include "VideoCommon/VideoConfig.h" @@ -140,18 +141,6 @@ static inline void DecodeBytes_RGBA8(u32* dst, const u16* src, const u16* src2) #endif } -struct DXTBlock -{ - u16 color1; - u16 color2; - u8 lines[4]; -}; - -static inline u32 MakeRGBA(int r, int g, int b, int a) -{ - return (a << 24) | (b << 16) | (g << 8) | r; -} - static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch) { // S3TC Decoder (Note: GCN decodes differently from PC so we can't use native support) @@ -169,7 +158,6 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch) colors[1] = MakeRGBA(red2, green2, blue2, 255); if (c1 > c2) { - // Approximation of x/3: 3/8 (1/2 - 1/8) colors[2] = MakeRGBA(DXTBlend(red2, red1), DXTBlend(green2, green1), DXTBlend(blue2, blue1), 255); colors[3] = diff --git a/Source/Core/VideoCommon/TextureDecoder_Util.h b/Source/Core/VideoCommon/TextureDecoder_Util.h new file mode 100644 index 0000000000..6f34eeb56c --- /dev/null +++ b/Source/Core/VideoCommon/TextureDecoder_Util.h @@ -0,0 +1,25 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include "Common/CommonTypes.h" + +struct DXTBlock +{ + u16 color1; + u16 color2; + u8 lines[4]; +}; + +constexpr u32 MakeRGBA(int r, int g, int b, int a) +{ + return (a << 24) | (b << 16) | (g << 8) | r; +} + +constexpr int DXTBlend(int v1, int v2) +{ + // 3/8 blend, which is close to 1/3 + return ((v1 * 3 + v2 * 5) >> 3); +} diff --git a/Source/Core/VideoCommon/TextureDecoder_x64.cpp b/Source/Core/VideoCommon/TextureDecoder_x64.cpp index fd00fa73bd..4697e8ba1b 100644 --- a/Source/Core/VideoCommon/TextureDecoder_x64.cpp +++ b/Source/Core/VideoCommon/TextureDecoder_x64.cpp @@ -14,6 +14,7 @@ #include "VideoCommon/LookUpTables.h" #include "VideoCommon/TextureDecoder.h" +#include "VideoCommon/TextureDecoder_Util.h" // GameCube/Wii texture decoder @@ -57,13 +58,6 @@ static inline u32 DecodePixel_RGB5A3(u16 val) return r | (g << 8) | (b << 16) | (a << 24); } -struct DXTBlock -{ - u16 color1; - u16 color2; - u8 lines[4]; -}; - static inline void DecodeBytes_C4_IA8(u32* dst, const u8* src, const u8* tlut_) { const u16* tlut = (u16*)tlut_; @@ -168,11 +162,6 @@ static inline void DecodeBytes_IA4(u32* dst, const u8* src) } #ifdef CHECK -static inline u32 MakeRGBA(int r, int g, int b, int a) -{ - return (a << 24) | (b << 16) | (g << 8) | r; -} - static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch) { // S3TC Decoder (Note: GCN decodes differently from PC so we can't use native support) @@ -190,7 +179,6 @@ static void DecodeDXTBlock(u32* dst, const DXTBlock* src, int pitch) colors[1] = MakeRGBA(red2, green2, blue2, 255); if (c1 > c2) { - // Approximation of x/3: 3/8 (1/2 - 1/8) colors[2] = MakeRGBA(DXTBlend(red2, red1), DXTBlend(green2, green1), DXTBlend(blue2, blue1), 255); colors[3] = diff --git a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters index 5340250808..e9a742a409 100644 --- a/Source/Core/VideoCommon/VideoCommon.vcxproj.filters +++ b/Source/Core/VideoCommon/VideoCommon.vcxproj.filters @@ -203,6 +203,9 @@ <ClInclude Include="TextureDecoder.h"> <Filter>Decoding</Filter> </ClInclude> + <ClInclude Include="TextureDecoder_Util.h"> + <Filter>Decoding</Filter> + </ClInclude> <ClInclude Include="BPFunctions.h"> <Filter>Register Sections</Filter> </ClInclude> |
