Skip to content

Commit

Permalink
Fix nk_font_bake_convert() for big-endian machines
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mardy committed Dec 30, 2024
1 parent 7f406ee commit cf7ffca
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Binary file modified demo/rawfb/sdl/demo
Binary file not shown.
Binary file modified demo/rawfb/x11/bin/demo
Binary file not shown.
12 changes: 8 additions & 4 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -17230,7 +17230,7 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
const void *in_memory)
{
int n = 0;
nk_rune *dst;
nk_byte *dst;
const nk_byte *src;

NK_ASSERT(out_memory);
Expand All @@ -17239,10 +17239,14 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
NK_ASSERT(img_height);
if (!out_memory || !in_memory || !img_height || !img_width) return;

dst = (nk_rune*)out_memory;
dst = (nk_byte*)out_memory;
src = (const nk_byte*)in_memory;
for (n = (int)(img_width * img_height); n > 0; n--)
*dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF;
for (n = (int)(img_width * img_height); n > 0; n--) {
*dst++ = 0xff; /* r */
*dst++ = 0xff; /* g */
*dst++ = 0xff; /* b */
*dst++ = *src++; /* a */
}
}

/* -------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions src/nuklear_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
const void *in_memory)
{
int n = 0;
nk_rune *dst;
nk_byte *dst;
const nk_byte *src;

NK_ASSERT(out_memory);
Expand All @@ -432,10 +432,14 @@ nk_font_bake_convert(void *out_memory, int img_width, int img_height,
NK_ASSERT(img_height);
if (!out_memory || !in_memory || !img_height || !img_width) return;

dst = (nk_rune*)out_memory;
dst = (nk_byte*)out_memory;
src = (const nk_byte*)in_memory;
for (n = (int)(img_width * img_height); n > 0; n--)
*dst++ = ((nk_rune)(*src++) << 24) | 0x00FFFFFF;
for (n = (int)(img_width * img_height); n > 0; n--) {
*dst++ = 0xff; /* r */
*dst++ = 0xff; /* g */
*dst++ = 0xff; /* b */
*dst++ = *src++; /* a */
}
}

/* -------------------------------------------------------------
Expand Down

0 comments on commit cf7ffca

Please sign in to comment.