Skip to content

Commit cf7ffca

Browse files
committed
Fix nk_font_bake_convert() for big-endian machines
Fix the byte order for converting alpha images into RGBA by writing the destination byte-by-byte. The compiler should anyway be able to optimize this.
1 parent 7f406ee commit cf7ffca

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

demo/rawfb/sdl/demo

-25.4 KB
Binary file not shown.

demo/rawfb/x11/bin/demo

-21 KB
Binary file not shown.

nuklear.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -17230,7 +17230,7 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
1723017230
const void *in_memory)
1723117231
{
1723217232
int n = 0;
17233-
nk_rune *dst;
17233+
nk_byte *dst;
1723417234
const nk_byte *src;
1723517235

1723617236
NK_ASSERT(out_memory);
@@ -17239,10 +17239,14 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
1723917239
NK_ASSERT(img_height);
1724017240
if (!out_memory || !in_memory || !img_height || !img_width) return;
1724117241

17242-
dst = (nk_rune*)out_memory;
17242+
dst = (nk_byte*)out_memory;
1724317243
src = (const nk_byte*)in_memory;
17244-
for (n = (int)(img_width * img_height); n > 0; n--)
17245-
*dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF;
17244+
for (n = (int)(img_width * img_height); n > 0; n--) {
17245+
*dst++ = 0xff; /* r */
17246+
*dst++ = 0xff; /* g */
17247+
*dst++ = 0xff; /* b */
17248+
*dst++ = *src++; /* a */
17249+
}
1724617250
}
1724717251

1724817252
/* -------------------------------------------------------------

src/nuklear_font.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
423423
const void *in_memory)
424424
{
425425
int n = 0;
426-
nk_rune *dst;
426+
nk_byte *dst;
427427
const nk_byte *src;
428428

429429
NK_ASSERT(out_memory);
@@ -432,10 +432,14 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
432432
NK_ASSERT(img_height);
433433
if (!out_memory || !in_memory || !img_height || !img_width) return;
434434

435-
dst = (nk_rune*)out_memory;
435+
dst = (nk_byte*)out_memory;
436436
src = (const nk_byte*)in_memory;
437-
for (n = (int)(img_width * img_height); n > 0; n--)
438-
*dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF;
437+
for (n = (int)(img_width * img_height); n > 0; n--) {
438+
*dst++ = 0xff; /* r */
439+
*dst++ = 0xff; /* g */
440+
*dst++ = 0xff; /* b */
441+
*dst++ = *src++; /* a */
442+
}
439443
}
440444

441445
/* -------------------------------------------------------------

0 commit comments

Comments
 (0)