X-Git-Url: https://git.piment-noir.org/?p=deb_ffmpeg.git;a=blobdiff_plain;f=ffmpeg%2Flibavcodec%2Fwebp.c;h=4b1c8e7f8b0e80a67523f1adf78fdf739224d951;hp=274708df793456f15a471e27c2b96de5fb38edd3;hb=f6fa7814ccfe3e76514b36cf04f5cd3cb657c8cf;hpb=2ba45a602cbfa7b771effba9b11bb4245c21bc00 diff --git a/ffmpeg/libavcodec/webp.c b/ffmpeg/libavcodec/webp.c index 274708d..4b1c8e7 100644 --- a/ffmpeg/libavcodec/webp.c +++ b/ffmpeg/libavcodec/webp.c @@ -1061,15 +1061,32 @@ static int apply_color_indexing_transform(WebPContext *s) av_free(line); } - for (y = 0; y < img->frame->height; y++) { - for (x = 0; x < img->frame->width; x++) { - p = GET_PIXEL(img->frame, x, y); - i = p[2]; - if (i >= pal->frame->width) { - AV_WB32(p, 0x00000000); - } else { - const uint8_t *pi = GET_PIXEL(pal->frame, i, 0); - AV_COPY32(p, pi); + // switch to local palette if it's worth initializing it + if (img->frame->height * img->frame->width > 300) { + uint8_t palette[256 * 4]; + const int size = pal->frame->width * 4; + av_assert0(size <= 1024U); + memcpy(palette, GET_PIXEL(pal->frame, 0, 0), size); // copy palette + // set extra entries to transparent black + memset(palette + size, 0, 256 * 4 - size); + for (y = 0; y < img->frame->height; y++) { + for (x = 0; x < img->frame->width; x++) { + p = GET_PIXEL(img->frame, x, y); + i = p[2]; + AV_COPY32(p, &palette[i * 4]); + } + } + } else { + for (y = 0; y < img->frame->height; y++) { + for (x = 0; x < img->frame->width; x++) { + p = GET_PIXEL(img->frame, x, y); + i = p[2]; + if (i >= pal->frame->width) { + AV_WB32(p, 0x00000000); + } else { + const uint8_t *pi = GET_PIXEL(pal->frame, i, 0); + AV_COPY32(p, pi); + } } } }