Remove extra swap code by using more complex condition.

Thanks to Riccardo Mottola.
This commit is contained in:
Fred Kiefer 2021-11-08 22:15:33 +01:00
parent 1262e4606e
commit bc26209457
2 changed files with 11 additions and 26 deletions

View file

@ -100,9 +100,9 @@ typedef enum _NSBitmapFormat
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
Nsbitmapformatalphafirst = 1,
NSBitmapFormatAlphaNonpremultiplied = 2,
NSBitmapFormatFloatingPointSamples = 4,
NSBitmapFormatAlphaFirst = 1,
NSBitmapFormatAlphaNonpremultiplied = (1 << 1),
NSBitmapFormatFloatingPointSamples = (1 << 2),
NSBitmapFormatSixteenBitLittleEndian = (1 << 8),
NSBitmapFormatThirtyTwoBitLittleEndian = (1 << 9),
NSBitmapFormatSixteenBitBigEndian = (1 << 10),

View file

@ -679,7 +679,8 @@ _get_bit_value(unsigned char *base, long msb_off, int bit_width,
long byte2 = byte1 + 1;
uint16_t value;
if (NSHostByteOrder() == NS_BigEndian)
if ((NSHostByteOrder() == NS_BigEndian && !(format & NSBitmapFormatSixteenBitLittleEndian)) ||
(NSHostByteOrder() == NS_LittleEndian && (format & NSBitmapFormatSixteenBitBigEndian)))
{
value = base[byte2] | base[byte1] << 8;
}
@ -687,14 +688,6 @@ _get_bit_value(unsigned char *base, long msb_off, int bit_width,
{
value = base[byte1] | base[byte2] << 8;
}
if (format & NSBitmapFormatSixteenBitLittleEndian)
{
value = GSSwapLittleI16ToHost(value);
}
else if (format & NSBitmapFormatSixteenBitBigEndian)
{
value = GSSwapBigI16ToHost(value);
}
return value;
}
@ -805,24 +798,16 @@ _set_bit_value(unsigned char *base, long msb_off, int bit_width,
long byte2 = byte1 + 1;
uint16_t value16 = value;
if (format & NSBitmapFormatSixteenBitLittleEndian)
if ((NSHostByteOrder() == NS_BigEndian && !(format & NSBitmapFormatSixteenBitLittleEndian)) ||
(NSHostByteOrder() == NS_LittleEndian && (format & NSBitmapFormatSixteenBitBigEndian)))
{
value16 = GSSwapHostI16ToLittle(value16);
}
else if (format & NSBitmapFormatSixteenBitBigEndian)
{
value16 = GSSwapHostI16ToBig(value16);
}
if (NSHostByteOrder() == NS_BigEndian)
{
base[byte1] = (value >> 8);
base[byte2] = (value & 255);
base[byte1] = (value16 >> 8);
base[byte2] = (value16 & 255);
}
else
{
base[byte2] = (value >> 8);
base[byte1] = (value & 255);
base[byte2] = (value16 >> 8);
base[byte1] = (value16 & 255);
}
}
else if (bit_width == 32)