Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nk_font_bake_convert() for big-endian machines #758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the update. Would you mind making this change in the src destroy? We use paq.sh to combine the files, so wouldn't want to lose your changes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will do the needed changes today or tomorrow and I'll ping you back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the changes on a little endian machine, the conversion still works.

I added the changes to the src directory as well; should I remove them from nuklear.h, or is it OK like it is now?

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 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to have /* comments for C89.

Also, does this still work on non-big endian devices? The RGB bit order should be fine, but I am unclear.

}
}

/* -------------------------------------------------------------
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