Skip to content

Commit 9a89381

Browse files
committed
Resync libretro-common
1 parent 5798c79 commit 9a89381

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

  • libretro-common/formats/tga

libretro-common/formats/tga/rtga.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,25 @@ static uint32_t *rtga_tga_load(rtga_context *s,
222222
}
223223
else
224224
{
225-
/* Need ARGB = A<<24|R<<16|G<<8|B.
226-
* TGA bytes [B,G,R,A] as little-endian uint32 is already ARGB.
227-
* Direct memcpy! */
225+
/* !supports_rgba wants each pixel as the uint32 value
226+
* ARGB = A<<24|R<<16|G<<8|B.
227+
* TGA stores bytes [B,G,R,A]; on a little-endian host those
228+
* bytes reinterpreted as a uint32 already equal ARGB, so a
229+
* straight memcpy is correct and fast. On a big-endian host
230+
* the same bytes would read as BGRA, so we must build the
231+
* ARGB value explicitly by shifting. */
232+
#ifndef MSB_FIRST
233+
/* Direct memcpy! (little-endian) */
228234
memcpy(dst, src, tga_width * 4);
235+
#else
236+
for (col = 0; col < tga_width; ++col)
237+
{
238+
uint8_t b = src[0], g = src[1], r = src[2], a = src[3];
239+
dst[col] = ((uint32_t)a << 24) | ((uint32_t)r << 16)
240+
| ((uint32_t)g << 8) | (uint32_t)b;
241+
src += 4;
242+
}
243+
#endif
229244
}
230245
}
231246
else /* tga_comp == 3 */

0 commit comments

Comments
 (0)