Graphics big-endian compatibility

This commit is contained in:
Iliyas Jorio 2022-09-19 22:08:42 +02:00
parent e567db5327
commit 543b50c1eb
3 changed files with 15 additions and 8 deletions

View File

@ -394,7 +394,7 @@ static void _FillRect(const int left, const int top, const int right, const int
}
curPort->DamageRegion(clippedDstRect);
fillColor = ByteswapScalar(fillColor); // convert to big-endian
fillColor = PackU32BE(&fillColor); // convert to big-endian
UInt32* dst = curPort->pixels.GetPtr(clippedDstRect.left, clippedDstRect.top);
@ -420,7 +420,7 @@ void EraseRect(const struct Rect* r)
void LineTo(short x1, short y1)
{
auto color = ByteswapScalar(penFG);
UInt32 color = PackU32BE(&penFG);
auto offx = curPort->port.portRect.left;
auto offy = curPort->port.portRect.top;
@ -455,7 +455,8 @@ void LineTo(short x1, short y1)
void FrameRect(const Rect* r)
{
auto color = ByteswapScalar(penFG);
UInt32 color = PackU32BE(&penFG);
auto& pm = curPort->pixels;
auto offx = curPort->port.portRect.left;
auto offy = curPort->port.portRect.top;
@ -643,7 +644,7 @@ void DrawStringC(const char* cstr)
void DrawChar(char c)
{
UInt32 fg = ByteswapScalar(penFG);
UInt32 fg = PackU32BE(&penFG);
auto& glyph = SysFont::GetGlyph(c);

View File

@ -29,9 +29,9 @@ static Handle Get4bitIconAsARGB(Handle colorIcon, Ptr bwMask, int width)
if (!bwMask)
;
else if (width == 32)
scanlineMask = Byteswap32(bwMask + y*4);
scanlineMask = UnpackU32BE(bwMask + y*4);
else if (width == 16)
scanlineMask = Byteswap16(bwMask + y*2);
scanlineMask = UnpackU16BE(bwMask + y*2);
for (int x = 0; x < width; x++)
{
@ -73,9 +73,9 @@ static Handle Get8bitIconAsARGB(Handle colorIcon, Ptr bwMask, int width)
if (!bwMask)
;
else if (width == 32)
scanlineMask = Byteswap32(bwMask + y*4);
scanlineMask = UnpackU32BE(bwMask + y*4);
else if (width == 16)
scanlineMask = Byteswap16(bwMask + y*2);
scanlineMask = UnpackU16BE(bwMask + y*2);
for (int x = 0; x < width; x++)
{

View File

@ -191,6 +191,12 @@ static inline int32_t UnpackI32BEInPlace(void* data) { return (int32_t) UnpackU3
static inline int16_t UnpackI16LEInPlace(void* data) { return (int16_t) UnpackU16LEInPlace(data); }
static inline int32_t UnpackI32LEInPlace(void* data) { return (int32_t) UnpackU32LEInPlace(data); }
//-----------------------------------------------------------------------------
// Pack variants. Functionally identical to unpack, but with a different intent:
// convert a native scalar to a specific endianness.
static inline uint32_t PackU32BE(const void *nativeEndianData) { return UnpackU32BE(nativeEndianData); }
#ifdef __cplusplus
}
#endif