Merge "gif2webp: Bgcolor fix for a special case" into 0.3.0

This commit is contained in:
James Zern 2013-03-25 16:33:51 -07:00 committed by Gerrit Code Review
commit 53c77afc52

View File

@ -117,17 +117,20 @@ 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);
return 1; return 1;
} }
} }
@ -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: {