Commit 19fb4768 authored by Pascal Massimino's avatar Pascal Massimino Committed by Michael Niedermayer

avcodec/webp: add optimization: use local palette with extra padding

for big enough pictures.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent e81eca0c
...@@ -1061,15 +1061,31 @@ static int apply_color_indexing_transform(WebPContext *s) ...@@ -1061,15 +1061,31 @@ static int apply_color_indexing_transform(WebPContext *s)
av_free(line); av_free(line);
} }
for (y = 0; y < img->frame->height; y++) { // switch to local palette if it's worth initializing it
for (x = 0; x < img->frame->width; x++) { if (img->frame->height * img->frame->width > 300) {
p = GET_PIXEL(img->frame, x, y); uint8_t palette[256 * 4];
i = p[2]; const int size = pal->frame->width * 4;
if (i >= pal->frame->width) { memcpy(palette, GET_PIXEL(pal->frame, 0, 0), size); // copy palette
AV_WB32(p, 0x00000000); // set extra entries to transparent black
} else { memset(palette + size, 0, 256 * 4 - size);
const uint8_t *pi = GET_PIXEL(pal->frame, i, 0); for (y = 0; y < img->frame->height; y++) {
AV_COPY32(p, pi); 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);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment