All: Generic big-endian changes

This commit is contained in:
Jeffrey Pfau 2015-10-19 23:49:35 -07:00
parent ea204bbfed
commit 24da1097ba
2 changed files with 11 additions and 3 deletions

View File

@ -73,6 +73,15 @@ typedef intptr_t ssize_t;
void* _ptr = (ARR); \ void* _ptr = (ARR); \
__asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr)); \ __asm__("sthbrx %0, %1, %2" : : "r"(SRC), "b"(_ptr), "r"(_addr)); \
} }
#elif defined __BIG_ENDIAN__
#if defined(__llvm__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
#define LOAD_32LE(DEST, ADDR, ARR) DEST = __builtin_bswap32(((uint32_t*) ARR)[(ADDR) >> 2])
#define LOAD_16LE(DEST, ADDR, ARR) DEST = __builtin_bswap16(((uint16_t*) ARR)[(ADDR) >> 1])
#define STORE_32LE(SRC, ADDR, ARR) ((uint32_t*) ARR)[(ADDR) >> 2] = __builtin_bswap32(SRC)
#define STORE_16LE(SRC, ADDR, ARR) ((uint16_t*) ARR)[(ADDR) >> 1] = __builtin_bswap16(SRC)
#else
#error Big endian build not supported on this platform.
#endif
#else #else
#define LOAD_32LE(DEST, ADDR, ARR) DEST = ((uint32_t*) ARR)[(ADDR) >> 2] #define LOAD_32LE(DEST, ADDR, ARR) DEST = ((uint32_t*) ARR)[(ADDR) >> 2]
#define LOAD_16LE(DEST, ADDR, ARR) DEST = ((uint16_t*) ARR)[(ADDR) >> 1] #define LOAD_16LE(DEST, ADDR, ARR) DEST = ((uint16_t*) ARR)[(ADDR) >> 1]

View File

@ -65,7 +65,7 @@ bool PNGWritePixels(png_structp png, unsigned width, unsigned height, unsigned s
for (i = 0; i < height; ++i) { for (i = 0; i < height; ++i) {
unsigned x; unsigned x;
for (x = 0; x < width; ++x) { for (x = 0; x < width; ++x) {
#if defined(__POWERPC__) || defined(__PPC__) #ifdef __BIG_ENDIAN__
row[x * 3] = pixelData[stride * i * 4 + x * 4 + 3]; row[x * 3] = pixelData[stride * i * 4 + x * 4 + 3];
row[x * 3 + 1] = pixelData[stride * i * 4 + x * 4 + 2]; row[x * 3 + 1] = pixelData[stride * i * 4 + x * 4 + 2];
row[x * 3 + 2] = pixelData[stride * i * 4 + x * 4 + 1]; row[x * 3 + 2] = pixelData[stride * i * 4 + x * 4 + 1];
@ -173,8 +173,7 @@ bool PNGReadPixels(png_structp png, png_infop info, void* pixels, unsigned width
png_read_row(png, row, 0); png_read_row(png, row, 0);
unsigned x; unsigned x;
for (x = 0; x < pngWidth; ++x) { for (x = 0; x < pngWidth; ++x) {
#if __BIG_ENDIAN__
#if defined(__POWERPC__) || defined(__PPC__)
pixelData[stride * i * 4 + x * 4 + 3] = row[x * 3]; pixelData[stride * i * 4 + x * 4 + 3] = row[x * 3];
pixelData[stride * i * 4 + x * 4 + 2] = row[x * 3 + 1]; pixelData[stride * i * 4 + x * 4 + 2] = row[x * 3 + 1];
pixelData[stride * i * 4 + x * 4 + 1] = row[x * 3 + 2]; pixelData[stride * i * 4 + x * 4 + 1] = row[x * 3 + 2];