diff --git a/examples/anim_diff.c b/examples/anim_diff.c index a91c8b34..011a6581 100644 --- a/examples/anim_diff.c +++ b/examples/anim_diff.c @@ -110,6 +110,20 @@ static int CompareValues(uint32_t a, uint32_t b, const char* output_str) { return 1; } +static int CompareBackgroundColor(uint32_t bg1, uint32_t bg2, int premultiply) { + if (premultiply) { + const int alpha1 = (bg1 >> 24) & 0xff; + const int alpha2 = (bg2 >> 24) & 0xff; + if (alpha1 == 0 && alpha2 == 0) return 1; + } + if (bg1 != bg2) { + fprintf(stderr, "Background color mismatch: 0x%08x vs 0x%08x\n", + bg1, bg2); + return 0; + } + return 1; +} + // Note: As long as frame durations and reconstructed frames are identical, it // is OK for other aspects like offsets, dispose/blend method to vary. static int CompareAnimatedImagePair(const AnimatedImage* const img1, @@ -131,8 +145,8 @@ static int CompareAnimatedImagePair(const AnimatedImage* const img1, if (is_multi_frame_image) { // Checks relevant for multi-frame images only. ok = CompareValues(img1->loop_count, img2->loop_count, "Loop count mismatch") && ok; - ok = CompareValues(img1->bgcolor, img2->bgcolor, - "Background color mismatch") && ok; + ok = CompareBackgroundColor(img1->bgcolor, img2->bgcolor, + premultiply) && ok; } for (i = 0; i < img1->num_frames; ++i) { diff --git a/examples/anim_util.c b/examples/anim_util.c index 417fec2f..73fc7b97 100644 --- a/examples/anim_util.c +++ b/examples/anim_util.c @@ -396,7 +396,7 @@ static uint32_t GetBackgroundColorGIF(GifFileType* gif) { const ColorMapObject* const color_map = gif->SColorMap; if (transparent_index != NO_TRANSPARENT_COLOR && gif->SBackGroundColor == transparent_index) { - return 0x00ffffff; // Special case: transparent white. + return 0x00000000; // Special case: transparent black. } else if (color_map == NULL || color_map->Colors == NULL || gif->SBackGroundColor >= color_map->ColorCount) { return 0xffffffff; // Invalid: assume white. diff --git a/examples/gifdec.c b/examples/gifdec.c index 8c36af61..c535a407 100644 --- a/examples/gifdec.c +++ b/examples/gifdec.c @@ -21,7 +21,7 @@ #include "webp/encode.h" #include "webp/mux_types.h" -#define GIF_TRANSPARENT_COLOR 0x00ffffff +#define GIF_TRANSPARENT_COLOR 0x00000000 #define GIF_WHITE_COLOR 0xffffffff #define GIF_TRANSPARENT_MASK 0x01 #define GIF_DISPOSE_MASK 0x07