QD3D/Graphics big-endian compatibility

This commit is contained in:
Iliyas Jorio 2022-09-03 00:53:11 +02:00
parent a1e1b62681
commit e567db5327
4 changed files with 12 additions and 5 deletions

View File

@ -576,7 +576,9 @@ void CopyBits(
// if the source pixel is not equal to the background color. // if the source pixel is not equal to the background color.
UInt32 transparentColor = penBG; UInt32 transparentColor = penBG;
#if !(__BIG_ENDIAN__)
ByteswapInts(sizeof(transparentColor), 1, &transparentColor); // need to byteswap because ARGBPixmap.GetPtr returns a pointer to raw (big-endian) ARGB ints ByteswapInts(sizeof(transparentColor), 1, &transparentColor); // need to byteswap because ARGBPixmap.GetPtr returns a pointer to raw (big-endian) ARGB ints
#endif
for (int y = 0; y < srcRectHeight; y++) for (int y = 0; y < srcRectHeight; y++)
{ {

View File

@ -543,11 +543,11 @@ TQ3Pixmap* Q3MetaFileParser::ParsePixmap(uint32_t chunkType, uint32_t chunkSize)
f.Skip(rowBytes - width * bytesPerPixel); f.Skip(rowBytes - width * bytesPerPixel);
} }
// Make every pixel little-endian (especially to avoid breaking 16-bit 1-5-5-5 ARGB textures) // Convert to native endianness (especially to avoid breaking 16-bit 1-5-5-5 ARGB textures)
if (byteOrder == kQ3EndianBig) if (byteOrder != kQ3EndianNative)
{ {
ByteswapInts(bytesPerPixel, width*height, pixmap->image); ByteswapInts(bytesPerPixel, width*height, pixmap->image);
pixmap->byteOrder = kQ3EndianLittle; pixmap->byteOrder = kQ3EndianNative;
} }
Q3Pixmap_ApplyEdgePadding(pixmap); Q3Pixmap_ApplyEdgePadding(pixmap);

View File

@ -110,7 +110,7 @@ void Q3Pixmap_ApplyEdgePadding(TQ3Pixmap* pm)
pm->width, pm->width,
pm->height, pm->height,
pm->rowBytes, pm->rowBytes,
pm->byteOrder==kQ3EndianBig? 0x0080: 0x8000); pm->byteOrder==kQ3EndianNative? 0x8000: 0x0080);
break; break;
case kQ3PixelTypeARGB32: case kQ3PixelTypeARGB32:
@ -120,7 +120,7 @@ void Q3Pixmap_ApplyEdgePadding(TQ3Pixmap* pm)
pm->width, pm->width,
pm->height, pm->height,
pm->rowBytes, pm->rowBytes,
pm->byteOrder==kQ3EndianBig? 0x000000FF: 0xFF000000); pm->byteOrder==kQ3EndianNative? 0xFF000000: 0x000000FF);
break; break;
case kQ3PixelTypeRGB16: case kQ3PixelTypeRGB16:

View File

@ -134,6 +134,11 @@ typedef enum
{ {
kQ3EndianBig = 0, kQ3EndianBig = 0,
kQ3EndianLittle = 1, kQ3EndianLittle = 1,
#if __BIG_ENDIAN__
kQ3EndianNative = kQ3EndianBig,
#else
kQ3EndianNative = kQ3EndianLittle,
#endif
kQ3EndianSize32 = 0xFFFFFFFF kQ3EndianSize32 = 0xFFFFFFFF
} TQ3Endian; } TQ3Endian;