mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-28 14:38:21 +01:00
gif2webp: Bgcolor fix for a special case
When transparent color index and background color index are same, we should set background color to 0x00ffffff (transparent). For this, we delay setting the background color until we have read the first frame. Change-Id: I443609b9c7697a2b94a66992460cff8465b3c127
This commit is contained in:
parent
5f25c396ab
commit
a5ebd143d6
@ -117,14 +117,17 @@ static int ReadSubImage(GifFileType* gif, WebPPicture* pic, WebPPicture* view) {
|
|||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetColorFromIndex(const ColorMapObject* const color_map, GifWord idx,
|
static int GetBackgroundColor(const ColorMapObject* const color_map,
|
||||||
uint32_t* const argb) {
|
GifWord bgcolor_idx, uint32_t* const bgcolor) {
|
||||||
assert(color_map != NULL && color_map->Colors != NULL);
|
if (transparent_index != -1 && bgcolor_idx == transparent_index) {
|
||||||
if (idx >= color_map->ColorCount) {
|
*bgcolor = TRANSPARENT_COLOR; // Special case.
|
||||||
return 0; // Invalid index.
|
return 1;
|
||||||
|
} else if (color_map == NULL || color_map->Colors == NULL
|
||||||
|
|| bgcolor_idx >= color_map->ColorCount) {
|
||||||
|
return 0; // Invalid color map or index.
|
||||||
} else {
|
} else {
|
||||||
const GifColorType color = color_map->Colors[idx];
|
const GifColorType color = color_map->Colors[bgcolor_idx];
|
||||||
*argb = (0xff << 24)
|
*bgcolor = (0xff << 24)
|
||||||
| (color.Red << 16)
|
| (color.Red << 16)
|
||||||
| (color.Green << 8)
|
| (color.Green << 8)
|
||||||
| (color.Blue << 0);
|
| (color.Blue << 0);
|
||||||
@ -199,6 +202,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
WebPMuxFrameInfo frame;
|
WebPMuxFrameInfo frame;
|
||||||
WebPMuxAnimParams anim = { WHITE_COLOR, 0 };
|
WebPMuxAnimParams anim = { WHITE_COLOR, 0 };
|
||||||
|
|
||||||
|
int is_first_frame = 1;
|
||||||
int done;
|
int done;
|
||||||
int c;
|
int c;
|
||||||
int quiet = 0;
|
int quiet = 0;
|
||||||
@ -283,14 +287,6 @@ int main(int argc, const char *argv[]) {
|
|||||||
picture.custom_ptr = &memory;
|
picture.custom_ptr = &memory;
|
||||||
if (!WebPPictureAlloc(&picture)) goto End;
|
if (!WebPPictureAlloc(&picture)) goto End;
|
||||||
|
|
||||||
if (gif->SColorMap != NULL &&
|
|
||||||
!GetColorFromIndex(gif->SColorMap, gif->SBackGroundColor,
|
|
||||||
&anim.bgcolor)) {
|
|
||||||
fprintf(stderr, "GIF decode warning: invalid background color index. "
|
|
||||||
"Assuming white background.\n");
|
|
||||||
}
|
|
||||||
ClearPicture(&picture, anim.bgcolor);
|
|
||||||
|
|
||||||
mux = WebPMuxNew();
|
mux = WebPMuxNew();
|
||||||
if (mux == NULL) {
|
if (mux == NULL) {
|
||||||
fprintf(stderr, "ERROR: could not create a mux object.\n");
|
fprintf(stderr, "ERROR: could not create a mux object.\n");
|
||||||
@ -379,6 +375,15 @@ int main(int argc, const char *argv[]) {
|
|||||||
: WEBP_MUX_DISPOSE_NONE;
|
: WEBP_MUX_DISPOSE_NONE;
|
||||||
}
|
}
|
||||||
transparent_index = (flags & GIF_TRANSPARENT_MASK) ? data[4] : -1;
|
transparent_index = (flags & GIF_TRANSPARENT_MASK) ? data[4] : -1;
|
||||||
|
if (is_first_frame) {
|
||||||
|
if (!GetBackgroundColor(gif->SColorMap, gif->SBackGroundColor,
|
||||||
|
&anim.bgcolor)) {
|
||||||
|
fprintf(stderr, "GIF decode warning: invalid background color "
|
||||||
|
"index. Assuming white background.\n");
|
||||||
|
}
|
||||||
|
ClearPicture(&picture, anim.bgcolor);
|
||||||
|
is_first_frame = 0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PLAINTEXT_EXT_FUNC_CODE: {
|
case PLAINTEXT_EXT_FUNC_CODE: {
|
||||||
|
Loading…
Reference in New Issue
Block a user