From 543b50c1eb05bccd3b5b2d2e39e097ebe68b80d8 Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Mon, 19 Sep 2022 22:08:42 +0200 Subject: [PATCH] Graphics big-endian compatibility --- src/Graphics/Graphics.cpp | 9 +++++---- src/Graphics/Icons.cpp | 8 ++++---- src/Utilities/structpack.h | 6 ++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Graphics/Graphics.cpp b/src/Graphics/Graphics.cpp index 5646db5..8e5db72 100644 --- a/src/Graphics/Graphics.cpp +++ b/src/Graphics/Graphics.cpp @@ -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); diff --git a/src/Graphics/Icons.cpp b/src/Graphics/Icons.cpp index 37ae32b..df74ac6 100644 --- a/src/Graphics/Icons.cpp +++ b/src/Graphics/Icons.cpp @@ -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++) { diff --git a/src/Utilities/structpack.h b/src/Utilities/structpack.h index 8b84a1b..0749155 100644 --- a/src/Utilities/structpack.h +++ b/src/Utilities/structpack.h @@ -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