diff options
author | Pascal Massimino <pascal.massimino@gmail.com> | 2014-09-22 14:48:57 -0700 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-10-05 12:47:44 +0200 |
commit | 19fb47684193891b8399dfc8faf1ecfd35ac8a6a (patch) | |
tree | 00d66ddfe514b0c987b5b9e3d46afe2380369c37 /libavcodec/webp.c | |
parent | e81eca0ce59aa4973bc53ec064f83610e3642ce5 (diff) | |
download | ffmpeg-19fb47684193891b8399dfc8faf1ecfd35ac8a6a.tar.gz |
avcodec/webp: add optimization: use local palette with extra padding
for big enough pictures.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/webp.c')
-rw-r--r-- | libavcodec/webp.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 274708df79..92becb6f1c 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1061,15 +1061,31 @@ 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; + 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); + } } } } |