mirror of
https://github.com/GerbilSoft/rom-properties.git
synced 2025-06-18 11:35:38 -04:00
[PowerVR] pvrtcDecompress(): Fix byte order isuses on BE.
- Use le32_to_cpu() for the source data. - Rearrange Pixel32 on BE. Added non-intrinsic macros using byteorder.h. Can't easily add intrinsic macros without CMake detection. (Might do that later.) ImageDecoderTest BE failures before: 15 ImageDecoderTest BE failures after: 11
This commit is contained in:
parent
f37709935c
commit
a6a52ecc73
45
extlib/PowerVR/PVRTDecompress.cpp
vendored
45
extlib/PowerVR/PVRTDecompress.cpp
vendored
@ -16,14 +16,37 @@
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
// rom-properties: Use librpcpu's byteorder macros.
|
||||
// NOTE: Not able to detect built-in byteswapping intrinsics here.
|
||||
#include "../../src/librpcpu/byteorder.h"
|
||||
#define __swab32(x) \
|
||||
((uint32_t)((((uint32_t)x) << 24) | (((uint32_t)x) >> 24) | \
|
||||
((((uint32_t)x) & 0x0000FF00UL) << 8) | \
|
||||
((((uint32_t)x) & 0x00FF0000UL) >> 8)))
|
||||
#if SYS_BYTEORDER == SYS_LIL_ENDIAN
|
||||
# define le32_to_cpu(x) (x)
|
||||
# define cpu_to_le32(x) (x)
|
||||
#else /* SYS_BYTEORDER == SYS_BIG_ENDIAN */
|
||||
# define le32_to_cpu(x) __swab32(x)
|
||||
# define cpu_to_le32(x) __swab32(x)
|
||||
#endif
|
||||
|
||||
namespace pvr {
|
||||
struct Pixel32
|
||||
{
|
||||
#ifdef PVRTC_SWAP_R_B_CHANNELS
|
||||
#if SYS_BYTEORDER == SYS_LIL_ENDIAN
|
||||
# ifdef PVRTC_SWAP_R_B_CHANNELS
|
||||
uint8_t blue, green, red, alpha;
|
||||
#else /* !PVRTC_SWAP_R_B_CHANNELS */
|
||||
# else /* !PVRTC_SWAP_R_B_CHANNELS */
|
||||
uint8_t red, green, blue, alpha;
|
||||
#endif /* PVRTC_SWAP_R_B_CHANNELS */
|
||||
# endif /* PVRTC_SWAP_R_B_CHANNELS */
|
||||
#else /* SYS_BYTEORDER == SYS_BIG_ENDIAN */
|
||||
# ifdef PVRTC_SWAP_R_B_CHANNELS
|
||||
uint8_t alpha, red, green, blue;
|
||||
# else /* !PVRTC_SWAP_R_B_CHANNELS */
|
||||
uint8_t alpha, blue, green, red;
|
||||
# endif /* PVRTC_SWAP_R_B_CHANNELS */
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Pixel128S
|
||||
@ -562,14 +585,14 @@ static uint32_t pvrtcDecompress(uint8_t* pCompressedData, Pixel32* pDecompressed
|
||||
|
||||
// Access individual elements to fill out PVRTCWord
|
||||
PVRTCWord P, Q, R, S;
|
||||
P.colorData = static_cast<uint32_t>(pWordMembers[WordOffsets[0] + 1]);
|
||||
P.modulationData = static_cast<uint32_t>(pWordMembers[WordOffsets[0]]);
|
||||
Q.colorData = static_cast<uint32_t>(pWordMembers[WordOffsets[1] + 1]);
|
||||
Q.modulationData = static_cast<uint32_t>(pWordMembers[WordOffsets[1]]);
|
||||
R.colorData = static_cast<uint32_t>(pWordMembers[WordOffsets[2] + 1]);
|
||||
R.modulationData = static_cast<uint32_t>(pWordMembers[WordOffsets[2]]);
|
||||
S.colorData = static_cast<uint32_t>(pWordMembers[WordOffsets[3] + 1]);
|
||||
S.modulationData = static_cast<uint32_t>(pWordMembers[WordOffsets[3]]);
|
||||
P.colorData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[0] + 1]));
|
||||
P.modulationData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[0]]));
|
||||
Q.colorData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[1] + 1]));
|
||||
Q.modulationData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[1]]));
|
||||
R.colorData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[2] + 1]));
|
||||
R.modulationData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[2]]));
|
||||
S.colorData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[3] + 1]));
|
||||
S.modulationData = static_cast<uint32_t>(le32_to_cpu(pWordMembers[WordOffsets[3]]));
|
||||
|
||||
// assemble 4 words into struct to get decompressed pixels from
|
||||
pvrtcGetDecompressedPixels<PVRTCII>(P, Q, R, S, pPixels.data(), bpp);
|
||||
|
@ -12,5 +12,7 @@ The following changes have been made to the original:
|
||||
- The Red and Blue channels in the destination images are swapped to
|
||||
match rom-properties' ARGB32 format.
|
||||
|
||||
- Proper byteswapping for Big-Endian architectures.
|
||||
|
||||
To obtain the original PowerVR Native SDK, see the GitHub repository:
|
||||
- https://github.com/powervr-graphics/Native_SDK
|
||||
|
Loading…
Reference in New Issue
Block a user