Skip to content

Commit

Permalink
Return background color data as 32-bit ints across native code interf…
Browse files Browse the repository at this point in the history
…ace due to uint8_t issues with Rust.
  • Loading branch information
skidder committed Nov 11, 2024
1 parent 2e756fc commit 0fac2ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
20 changes: 16 additions & 4 deletions giflib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,13 @@ struct GifAnimationInfo giflib_decoder_get_animation_info(const giflib_decoder d
found_gcb = true;
DGifExtensionToGCB(ExtData[0], &ExtData[1], &gcb);
// Get background color as soon as we have the GCB
extract_background_color(gif, &gcb, &info.bg_red, &info.bg_green,
&info.bg_blue, &info.bg_alpha);
uint8_t bg_red, bg_green, bg_blue, bg_alpha;
extract_background_color(gif, &gcb, &bg_red, &bg_green,
&bg_blue, &bg_alpha);
info.bg_red = bg_red;
info.bg_green = bg_green;
info.bg_blue = bg_blue;
info.bg_alpha = bg_alpha;
}
// Look for NETSCAPE2.0 extension
else if (!found_loop_count &&
Expand Down Expand Up @@ -1225,8 +1230,15 @@ struct GifAnimationInfo giflib_decoder_get_animation_info(const giflib_decoder d

// If we never found a GCB, still need to set background color
if (!found_gcb) {
extract_background_color(gif, &gcb, &info.bg_red, &info.bg_green,
&info.bg_blue, &info.bg_alpha);
uint8_t bg_red, bg_green, bg_blue, bg_alpha;
extract_background_color(gif, &gcb, &bg_red, &bg_green,
&bg_blue, &bg_alpha);

// convert to int to handle uint limitations in rust FFI
info.bg_red = bg_red;
info.bg_green = bg_green;
info.bg_blue = bg_blue;
info.bg_alpha = bg_alpha;
}

cleanup:
Expand Down
8 changes: 4 additions & 4 deletions giflib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ extern "C" {
struct GifAnimationInfo {
int loop_count;
int frame_count;
uint8_t bg_red;
uint8_t bg_green;
uint8_t bg_blue;
uint8_t bg_alpha;
int bg_red;
int bg_green;
int bg_blue;
int bg_alpha;
};

#define GIF_DISPOSE_NONE 0
Expand Down

0 comments on commit 0fac2ae

Please sign in to comment.