2 * WebP (.webp) image decoder
3 * Copyright (c) 2013 Aneesh Dogra <aneesh@sugarlabs.org>
4 * Copyright (c) 2013 Justin Ruggles <justin.ruggles@gmail.com>
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 * @author Aneesh Dogra <aneesh@sugarlabs.org>
28 * Container and Lossy decoding
30 * @author Justin Ruggles <justin.ruggles@gmail.com>
32 * Compressed alpha for lossy
34 * @author James Almer <jamrial@gmail.com>
43 #define BITSTREAM_READER_LE
44 #include "libavutil/imgutils.h"
46 #include "bytestream.h"
53 #define VP8X_FLAG_ANIMATION 0x02
54 #define VP8X_FLAG_XMP_METADATA 0x04
55 #define VP8X_FLAG_EXIF_METADATA 0x08
56 #define VP8X_FLAG_ALPHA 0x10
57 #define VP8X_FLAG_ICC 0x20
59 #define MAX_PALETTE_SIZE 256
60 #define MAX_CACHE_BITS 11
61 #define NUM_CODE_LENGTH_CODES 19
62 #define HUFFMAN_CODES_PER_META_CODE 5
63 #define NUM_LITERAL_CODES 256
64 #define NUM_LENGTH_CODES 24
65 #define NUM_DISTANCE_CODES 40
66 #define NUM_SHORT_DISTANCES 120
67 #define MAX_HUFFMAN_CODE_LENGTH 15
69 static const uint16_t alphabet_sizes[HUFFMAN_CODES_PER_META_CODE] = {
70 NUM_LITERAL_CODES + NUM_LENGTH_CODES,
71 NUM_LITERAL_CODES, NUM_LITERAL_CODES, NUM_LITERAL_CODES,
75 static const uint8_t code_length_code_order[NUM_CODE_LENGTH_CODES] = {
76 17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
79 static const int8_t lz77_distance_offsets[NUM_SHORT_DISTANCES][2] = {
80 { 0, 1 }, { 1, 0 }, { 1, 1 }, { -1, 1 }, { 0, 2 }, { 2, 0 }, { 1, 2 }, { -1, 2 },
81 { 2, 1 }, { -2, 1 }, { 2, 2 }, { -2, 2 }, { 0, 3 }, { 3, 0 }, { 1, 3 }, { -1, 3 },
82 { 3, 1 }, { -3, 1 }, { 2, 3 }, { -2, 3 }, { 3, 2 }, { -3, 2 }, { 0, 4 }, { 4, 0 },
83 { 1, 4 }, { -1, 4 }, { 4, 1 }, { -4, 1 }, { 3, 3 }, { -3, 3 }, { 2, 4 }, { -2, 4 },
84 { 4, 2 }, { -4, 2 }, { 0, 5 }, { 3, 4 }, { -3, 4 }, { 4, 3 }, { -4, 3 }, { 5, 0 },
85 { 1, 5 }, { -1, 5 }, { 5, 1 }, { -5, 1 }, { 2, 5 }, { -2, 5 }, { 5, 2 }, { -5, 2 },
86 { 4, 4 }, { -4, 4 }, { 3, 5 }, { -3, 5 }, { 5, 3 }, { -5, 3 }, { 0, 6 }, { 6, 0 },
87 { 1, 6 }, { -1, 6 }, { 6, 1 }, { -6, 1 }, { 2, 6 }, { -2, 6 }, { 6, 2 }, { -6, 2 },
88 { 4, 5 }, { -4, 5 }, { 5, 4 }, { -5, 4 }, { 3, 6 }, { -3, 6 }, { 6, 3 }, { -6, 3 },
89 { 0, 7 }, { 7, 0 }, { 1, 7 }, { -1, 7 }, { 5, 5 }, { -5, 5 }, { 7, 1 }, { -7, 1 },
90 { 4, 6 }, { -4, 6 }, { 6, 4 }, { -6, 4 }, { 2, 7 }, { -2, 7 }, { 7, 2 }, { -7, 2 },
91 { 3, 7 }, { -3, 7 }, { 7, 3 }, { -7, 3 }, { 5, 6 }, { -5, 6 }, { 6, 5 }, { -6, 5 },
92 { 8, 0 }, { 4, 7 }, { -4, 7 }, { 7, 4 }, { -7, 4 }, { 8, 1 }, { 8, 2 }, { 6, 6 },
93 { -6, 6 }, { 8, 3 }, { 5, 7 }, { -5, 7 }, { 7, 5 }, { -7, 5 }, { 8, 4 }, { 6, 7 },
94 { -6, 7 }, { 7, 6 }, { -7, 6 }, { 8, 5 }, { 7, 7 }, { -7, 7 }, { 8, 6 }, { 8, 7 }
97 enum AlphaCompression {
98 ALPHA_COMPRESSION_NONE,
99 ALPHA_COMPRESSION_VP8L,
104 ALPHA_FILTER_HORIZONTAL,
105 ALPHA_FILTER_VERTICAL,
106 ALPHA_FILTER_GRADIENT,
110 PREDICTOR_TRANSFORM = 0,
113 COLOR_INDEXING_TRANSFORM = 3,
116 enum PredictionMode {
122 PRED_MODE_AVG_T_AVG_L_TR,
127 PRED_MODE_AVG_AVG_L_TL_AVG_T_TR,
129 PRED_MODE_ADD_SUBTRACT_FULL,
130 PRED_MODE_ADD_SUBTRACT_HALF,
141 /* The structure of WebP lossless is an optional series of transformation data,
142 * followed by the primary image. The primary image also optionally contains
143 * an entropy group mapping if there are multiple entropy groups. There is a
144 * basic image type called an "entropy coded image" that is used for all of
145 * these. The type of each entropy coded image is referred to by the
146 * specification as its role. */
148 /* Primary Image: Stores the actual pixels of the image. */
151 /* Entropy Image: Defines which Huffman group to use for different areas of
152 * the primary image. */
155 /* Predictors: Defines which predictor type to use for different areas of
156 * the primary image. */
157 IMAGE_ROLE_PREDICTOR,
159 /* Color Transform Data: Defines the color transformation for different
160 * areas of the primary image. */
161 IMAGE_ROLE_COLOR_TRANSFORM,
163 /* Color Index: Stored as an image of height == 1. */
164 IMAGE_ROLE_COLOR_INDEXING,
169 typedef struct HuffReader {
170 VLC vlc; /* Huffman decoder context */
171 int simple; /* whether to use simple mode */
172 int nb_symbols; /* number of coded symbols */
173 uint16_t simple_symbols[2]; /* symbols for simple mode */
176 typedef struct ImageContext {
177 enum ImageRole role; /* role of this image */
178 AVFrame *frame; /* AVFrame for data */
179 int color_cache_bits; /* color cache size, log2 */
180 uint32_t *color_cache; /* color cache data */
181 int nb_huffman_groups; /* number of huffman groups */
182 HuffReader *huffman_groups; /* reader for each huffman group */
183 int size_reduction; /* relative size compared to primary image, log2 */
184 int is_alpha_primary;
187 typedef struct WebPContext {
188 VP8Context v; /* VP8 Context used for lossy decoding */
189 GetBitContext gb; /* bitstream reader for main image chunk */
190 AVFrame *alpha_frame; /* AVFrame for alpha data decompressed from VP8L */
191 AVCodecContext *avctx; /* parent AVCodecContext */
192 int initialized; /* set once the VP8 context is initialized */
193 int has_alpha; /* has a separate alpha chunk */
194 enum AlphaCompression alpha_compression; /* compression type for alpha chunk */
195 enum AlphaFilter alpha_filter; /* filtering method for alpha chunk */
196 uint8_t *alpha_data; /* alpha chunk data */
197 int alpha_data_size; /* alpha chunk data size */
198 int has_exif; /* set after an EXIF chunk has been processed */
199 AVDictionary *exif_metadata; /* EXIF chunk data */
200 int width; /* image width */
201 int height; /* image height */
202 int lossless; /* indicates lossless or lossy */
204 int nb_transforms; /* number of transforms */
205 enum TransformType transforms[4]; /* transformations used in the image, in order */
206 int reduced_width; /* reduced width for index image, if applicable */
207 int nb_huffman_groups; /* number of huffman groups in the primary image */
208 ImageContext image[IMAGE_ROLE_NB]; /* image context for each role */
211 #define GET_PIXEL(frame, x, y) \
212 ((frame)->data[0] + (y) * frame->linesize[0] + 4 * (x))
214 #define GET_PIXEL_COMP(frame, x, y, c) \
215 (*((frame)->data[0] + (y) * frame->linesize[0] + 4 * (x) + c))
217 static void image_ctx_free(ImageContext *img)
221 av_free(img->color_cache);
222 if (img->role != IMAGE_ROLE_ARGB && !img->is_alpha_primary)
223 av_frame_free(&img->frame);
224 if (img->huffman_groups) {
225 for (i = 0; i < img->nb_huffman_groups; i++) {
226 for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; j++)
227 ff_free_vlc(&img->huffman_groups[i * HUFFMAN_CODES_PER_META_CODE + j].vlc);
229 av_free(img->huffman_groups);
231 memset(img, 0, sizeof(*img));
235 /* Differs from get_vlc2() in the following ways:
236 * - codes are bit-reversed
237 * - assumes 8-bit table to make reversal simpler
238 * - assumes max depth of 2 since the max code length for WebP is 15
240 static av_always_inline int webp_get_vlc(GetBitContext *gb, VLC_TYPE (*table)[2])
247 UPDATE_CACHE(re, gb);
249 index = SHOW_UBITS(re, gb, 8);
250 index = ff_reverse[index];
251 code = table[index][0];
255 LAST_SKIP_BITS(re, gb, 8);
256 UPDATE_CACHE(re, gb);
260 index = SHOW_UBITS(re, gb, nb_bits);
261 index = (ff_reverse[index] >> (8 - nb_bits)) + code;
262 code = table[index][0];
265 SKIP_BITS(re, gb, n);
267 CLOSE_READER(re, gb);
272 static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb)
275 if (r->nb_symbols == 1)
276 return r->simple_symbols[0];
278 return r->simple_symbols[get_bits1(gb)];
280 return webp_get_vlc(gb, r->vlc.table);
283 static int huff_reader_build_canonical(HuffReader *r, int *code_lengths,
286 int len = 0, sym, code = 0, ret;
287 int max_code_length = 0;
290 /* special-case 1 symbol since the vlc reader cannot handle it */
291 for (sym = 0; sym < alphabet_size; sym++) {
292 if (code_lengths[sym] > 0) {
301 r->simple_symbols[0] = code;
306 for (sym = 0; sym < alphabet_size; sym++)
307 max_code_length = FFMAX(max_code_length, code_lengths[sym]);
309 if (max_code_length == 0 || max_code_length > MAX_HUFFMAN_CODE_LENGTH)
310 return AVERROR(EINVAL);
312 codes = av_malloc_array(alphabet_size, sizeof(*codes));
314 return AVERROR(ENOMEM);
318 for (len = 1; len <= max_code_length; len++) {
319 for (sym = 0; sym < alphabet_size; sym++) {
320 if (code_lengths[sym] != len)
327 if (!r->nb_symbols) {
329 return AVERROR_INVALIDDATA;
332 ret = init_vlc(&r->vlc, 8, alphabet_size,
333 code_lengths, sizeof(*code_lengths), sizeof(*code_lengths),
334 codes, sizeof(*codes), sizeof(*codes), 0);
345 static void read_huffman_code_simple(WebPContext *s, HuffReader *hc)
347 hc->nb_symbols = get_bits1(&s->gb) + 1;
349 if (get_bits1(&s->gb))
350 hc->simple_symbols[0] = get_bits(&s->gb, 8);
352 hc->simple_symbols[0] = get_bits1(&s->gb);
354 if (hc->nb_symbols == 2)
355 hc->simple_symbols[1] = get_bits(&s->gb, 8);
360 static int read_huffman_code_normal(WebPContext *s, HuffReader *hc,
363 HuffReader code_len_hc = { { 0 }, 0, 0, { 0 } };
364 int *code_lengths = NULL;
365 int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 };
366 int i, symbol, max_symbol, prev_code_len, ret;
367 int num_codes = 4 + get_bits(&s->gb, 4);
369 if (num_codes > NUM_CODE_LENGTH_CODES)
370 return AVERROR_INVALIDDATA;
372 for (i = 0; i < num_codes; i++)
373 code_length_code_lengths[code_length_code_order[i]] = get_bits(&s->gb, 3);
375 ret = huff_reader_build_canonical(&code_len_hc, code_length_code_lengths,
376 NUM_CODE_LENGTH_CODES);
380 code_lengths = av_mallocz_array(alphabet_size, sizeof(*code_lengths));
382 ret = AVERROR(ENOMEM);
386 if (get_bits1(&s->gb)) {
387 int bits = 2 + 2 * get_bits(&s->gb, 3);
388 max_symbol = 2 + get_bits(&s->gb, bits);
389 if (max_symbol > alphabet_size) {
390 av_log(s->avctx, AV_LOG_ERROR, "max symbol %d > alphabet size %d\n",
391 max_symbol, alphabet_size);
392 ret = AVERROR_INVALIDDATA;
396 max_symbol = alphabet_size;
401 while (symbol < alphabet_size) {
406 code_len = huff_reader_get_symbol(&code_len_hc, &s->gb);
408 /* Code length code [0..15] indicates literal code lengths. */
409 code_lengths[symbol++] = code_len;
411 prev_code_len = code_len;
413 int repeat = 0, length = 0;
416 /* Code 16 repeats the previous non-zero value [3..6] times,
417 * i.e., 3 + ReadBits(2) times. If code 16 is used before a
418 * non-zero value has been emitted, a value of 8 is repeated. */
419 repeat = 3 + get_bits(&s->gb, 2);
420 length = prev_code_len;
423 /* Code 17 emits a streak of zeros [3..10], i.e.,
424 * 3 + ReadBits(3) times. */
425 repeat = 3 + get_bits(&s->gb, 3);
428 /* Code 18 emits a streak of zeros of length [11..138], i.e.,
429 * 11 + ReadBits(7) times. */
430 repeat = 11 + get_bits(&s->gb, 7);
433 if (symbol + repeat > alphabet_size) {
434 av_log(s->avctx, AV_LOG_ERROR,
435 "invalid symbol %d + repeat %d > alphabet size %d\n",
436 symbol, repeat, alphabet_size);
437 ret = AVERROR_INVALIDDATA;
441 code_lengths[symbol++] = length;
445 ret = huff_reader_build_canonical(hc, code_lengths, alphabet_size);
448 ff_free_vlc(&code_len_hc.vlc);
449 av_free(code_lengths);
453 static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role,
456 #define PARSE_BLOCK_SIZE(w, h) do { \
457 block_bits = get_bits(&s->gb, 3) + 2; \
458 blocks_w = FFALIGN((w), 1 << block_bits) >> block_bits; \
459 blocks_h = FFALIGN((h), 1 << block_bits) >> block_bits; \
462 static int decode_entropy_image(WebPContext *s)
465 int ret, block_bits, width, blocks_w, blocks_h, x, y, max;
468 if (s->reduced_width > 0)
469 width = s->reduced_width;
471 PARSE_BLOCK_SIZE(width, s->height);
473 ret = decode_entropy_coded_image(s, IMAGE_ROLE_ENTROPY, blocks_w, blocks_h);
477 img = &s->image[IMAGE_ROLE_ENTROPY];
478 img->size_reduction = block_bits;
480 /* the number of huffman groups is determined by the maximum group number
481 * coded in the entropy image */
483 for (y = 0; y < img->frame->height; y++) {
484 for (x = 0; x < img->frame->width; x++) {
485 int p0 = GET_PIXEL_COMP(img->frame, x, y, 1);
486 int p1 = GET_PIXEL_COMP(img->frame, x, y, 2);
487 int p = p0 << 8 | p1;
491 s->nb_huffman_groups = max + 1;
496 static int parse_transform_predictor(WebPContext *s)
498 int block_bits, blocks_w, blocks_h, ret;
500 PARSE_BLOCK_SIZE(s->width, s->height);
502 ret = decode_entropy_coded_image(s, IMAGE_ROLE_PREDICTOR, blocks_w,
507 s->image[IMAGE_ROLE_PREDICTOR].size_reduction = block_bits;
512 static int parse_transform_color(WebPContext *s)
514 int block_bits, blocks_w, blocks_h, ret;
516 PARSE_BLOCK_SIZE(s->width, s->height);
518 ret = decode_entropy_coded_image(s, IMAGE_ROLE_COLOR_TRANSFORM, blocks_w,
523 s->image[IMAGE_ROLE_COLOR_TRANSFORM].size_reduction = block_bits;
528 static int parse_transform_color_indexing(WebPContext *s)
531 int width_bits, index_size, ret, x;
534 index_size = get_bits(&s->gb, 8) + 1;
538 else if (index_size <= 4)
540 else if (index_size <= 16)
545 ret = decode_entropy_coded_image(s, IMAGE_ROLE_COLOR_INDEXING,
550 img = &s->image[IMAGE_ROLE_COLOR_INDEXING];
551 img->size_reduction = width_bits;
553 s->reduced_width = (s->width + ((1 << width_bits) - 1)) >> width_bits;
555 /* color index values are delta-coded */
556 ct = img->frame->data[0] + 4;
557 for (x = 4; x < img->frame->width * 4; x++, ct++)
563 static HuffReader *get_huffman_group(WebPContext *s, ImageContext *img,
566 ImageContext *gimg = &s->image[IMAGE_ROLE_ENTROPY];
569 if (gimg->size_reduction > 0) {
570 int group_x = x >> gimg->size_reduction;
571 int group_y = y >> gimg->size_reduction;
572 int g0 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 1);
573 int g1 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 2);
574 group = g0 << 8 | g1;
577 return &img->huffman_groups[group * HUFFMAN_CODES_PER_META_CODE];
580 static av_always_inline void color_cache_put(ImageContext *img, uint32_t c)
582 uint32_t cache_idx = (0x1E35A7BD * c) >> (32 - img->color_cache_bits);
583 img->color_cache[cache_idx] = c;
586 static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role,
591 int i, j, ret, x, y, width;
593 img = &s->image[role];
597 img->frame = av_frame_alloc();
599 return AVERROR(ENOMEM);
602 img->frame->format = AV_PIX_FMT_ARGB;
603 img->frame->width = w;
604 img->frame->height = h;
606 if (role == IMAGE_ROLE_ARGB && !img->is_alpha_primary) {
607 ThreadFrame pt = { .f = img->frame };
608 ret = ff_thread_get_buffer(s->avctx, &pt, 0);
610 ret = av_frame_get_buffer(img->frame, 1);
614 if (get_bits1(&s->gb)) {
615 img->color_cache_bits = get_bits(&s->gb, 4);
616 if (img->color_cache_bits < 1 || img->color_cache_bits > 11) {
617 av_log(s->avctx, AV_LOG_ERROR, "invalid color cache bits: %d\n",
618 img->color_cache_bits);
619 return AVERROR_INVALIDDATA;
621 img->color_cache = av_mallocz_array(1 << img->color_cache_bits,
622 sizeof(*img->color_cache));
623 if (!img->color_cache)
624 return AVERROR(ENOMEM);
626 img->color_cache_bits = 0;
629 img->nb_huffman_groups = 1;
630 if (role == IMAGE_ROLE_ARGB && get_bits1(&s->gb)) {
631 ret = decode_entropy_image(s);
634 img->nb_huffman_groups = s->nb_huffman_groups;
636 img->huffman_groups = av_mallocz_array(img->nb_huffman_groups *
637 HUFFMAN_CODES_PER_META_CODE,
638 sizeof(*img->huffman_groups));
639 if (!img->huffman_groups)
640 return AVERROR(ENOMEM);
642 for (i = 0; i < img->nb_huffman_groups; i++) {
643 hg = &img->huffman_groups[i * HUFFMAN_CODES_PER_META_CODE];
644 for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; j++) {
645 int alphabet_size = alphabet_sizes[j];
646 if (!j && img->color_cache_bits > 0)
647 alphabet_size += 1 << img->color_cache_bits;
649 if (get_bits1(&s->gb)) {
650 read_huffman_code_simple(s, &hg[j]);
652 ret = read_huffman_code_normal(s, &hg[j], alphabet_size);
659 width = img->frame->width;
660 if (role == IMAGE_ROLE_ARGB && s->reduced_width > 0)
661 width = s->reduced_width;
664 while (y < img->frame->height) {
667 hg = get_huffman_group(s, img, x, y);
668 v = huff_reader_get_symbol(&hg[HUFF_IDX_GREEN], &s->gb);
669 if (v < NUM_LITERAL_CODES) {
670 /* literal pixel values */
671 uint8_t *p = GET_PIXEL(img->frame, x, y);
673 p[1] = huff_reader_get_symbol(&hg[HUFF_IDX_RED], &s->gb);
674 p[3] = huff_reader_get_symbol(&hg[HUFF_IDX_BLUE], &s->gb);
675 p[0] = huff_reader_get_symbol(&hg[HUFF_IDX_ALPHA], &s->gb);
676 if (img->color_cache_bits)
677 color_cache_put(img, AV_RB32(p));
683 } else if (v < NUM_LITERAL_CODES + NUM_LENGTH_CODES) {
684 /* LZ77 backwards mapping */
685 int prefix_code, length, distance, ref_x, ref_y;
687 /* parse length and distance */
688 prefix_code = v - NUM_LITERAL_CODES;
689 if (prefix_code < 4) {
690 length = prefix_code + 1;
692 int extra_bits = (prefix_code - 2) >> 1;
693 int offset = 2 + (prefix_code & 1) << extra_bits;
694 length = offset + get_bits(&s->gb, extra_bits) + 1;
696 prefix_code = huff_reader_get_symbol(&hg[HUFF_IDX_DIST], &s->gb);
697 if (prefix_code > 39) {
698 av_log(s->avctx, AV_LOG_ERROR,
699 "distance prefix code too large: %d\n", prefix_code);
700 return AVERROR_INVALIDDATA;
702 if (prefix_code < 4) {
703 distance = prefix_code + 1;
705 int extra_bits = prefix_code - 2 >> 1;
706 int offset = 2 + (prefix_code & 1) << extra_bits;
707 distance = offset + get_bits(&s->gb, extra_bits) + 1;
710 /* find reference location */
711 if (distance <= NUM_SHORT_DISTANCES) {
712 int xi = lz77_distance_offsets[distance - 1][0];
713 int yi = lz77_distance_offsets[distance - 1][1];
714 distance = FFMAX(1, xi + yi * width);
716 distance -= NUM_SHORT_DISTANCES;
727 while (distance >= width) {
732 ref_x = width - distance;
735 ref_x = FFMAX(0, ref_x);
736 ref_y = FFMAX(0, ref_y);
739 * source and dest regions can overlap and wrap lines, so just
741 for (i = 0; i < length; i++) {
742 uint8_t *p_ref = GET_PIXEL(img->frame, ref_x, ref_y);
743 uint8_t *p = GET_PIXEL(img->frame, x, y);
746 if (img->color_cache_bits)
747 color_cache_put(img, AV_RB32(p));
754 if (ref_x == width) {
758 if (y == img->frame->height || ref_y == img->frame->height)
762 /* read from color cache */
763 uint8_t *p = GET_PIXEL(img->frame, x, y);
764 int cache_idx = v - (NUM_LITERAL_CODES + NUM_LENGTH_CODES);
766 if (!img->color_cache_bits) {
767 av_log(s->avctx, AV_LOG_ERROR, "color cache not found\n");
768 return AVERROR_INVALIDDATA;
770 if (cache_idx >= 1 << img->color_cache_bits) {
771 av_log(s->avctx, AV_LOG_ERROR,
772 "color cache index out-of-bounds\n");
773 return AVERROR_INVALIDDATA;
775 AV_WB32(p, img->color_cache[cache_idx]);
787 /* PRED_MODE_BLACK */
788 static void inv_predict_0(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
789 const uint8_t *p_t, const uint8_t *p_tr)
791 AV_WB32(p, 0xFF000000);
795 static void inv_predict_1(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
796 const uint8_t *p_t, const uint8_t *p_tr)
802 static void inv_predict_2(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
803 const uint8_t *p_t, const uint8_t *p_tr)
809 static void inv_predict_3(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
810 const uint8_t *p_t, const uint8_t *p_tr)
816 static void inv_predict_4(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
817 const uint8_t *p_t, const uint8_t *p_tr)
822 /* PRED_MODE_AVG_T_AVG_L_TR */
823 static void inv_predict_5(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
824 const uint8_t *p_t, const uint8_t *p_tr)
826 p[0] = p_t[0] + (p_l[0] + p_tr[0] >> 1) >> 1;
827 p[1] = p_t[1] + (p_l[1] + p_tr[1] >> 1) >> 1;
828 p[2] = p_t[2] + (p_l[2] + p_tr[2] >> 1) >> 1;
829 p[3] = p_t[3] + (p_l[3] + p_tr[3] >> 1) >> 1;
832 /* PRED_MODE_AVG_L_TL */
833 static void inv_predict_6(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
834 const uint8_t *p_t, const uint8_t *p_tr)
836 p[0] = p_l[0] + p_tl[0] >> 1;
837 p[1] = p_l[1] + p_tl[1] >> 1;
838 p[2] = p_l[2] + p_tl[2] >> 1;
839 p[3] = p_l[3] + p_tl[3] >> 1;
842 /* PRED_MODE_AVG_L_T */
843 static void inv_predict_7(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
844 const uint8_t *p_t, const uint8_t *p_tr)
846 p[0] = p_l[0] + p_t[0] >> 1;
847 p[1] = p_l[1] + p_t[1] >> 1;
848 p[2] = p_l[2] + p_t[2] >> 1;
849 p[3] = p_l[3] + p_t[3] >> 1;
852 /* PRED_MODE_AVG_TL_T */
853 static void inv_predict_8(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
854 const uint8_t *p_t, const uint8_t *p_tr)
856 p[0] = p_tl[0] + p_t[0] >> 1;
857 p[1] = p_tl[1] + p_t[1] >> 1;
858 p[2] = p_tl[2] + p_t[2] >> 1;
859 p[3] = p_tl[3] + p_t[3] >> 1;
862 /* PRED_MODE_AVG_T_TR */
863 static void inv_predict_9(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
864 const uint8_t *p_t, const uint8_t *p_tr)
866 p[0] = p_t[0] + p_tr[0] >> 1;
867 p[1] = p_t[1] + p_tr[1] >> 1;
868 p[2] = p_t[2] + p_tr[2] >> 1;
869 p[3] = p_t[3] + p_tr[3] >> 1;
872 /* PRED_MODE_AVG_AVG_L_TL_AVG_T_TR */
873 static void inv_predict_10(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
874 const uint8_t *p_t, const uint8_t *p_tr)
876 p[0] = (p_l[0] + p_tl[0] >> 1) + (p_t[0] + p_tr[0] >> 1) >> 1;
877 p[1] = (p_l[1] + p_tl[1] >> 1) + (p_t[1] + p_tr[1] >> 1) >> 1;
878 p[2] = (p_l[2] + p_tl[2] >> 1) + (p_t[2] + p_tr[2] >> 1) >> 1;
879 p[3] = (p_l[3] + p_tl[3] >> 1) + (p_t[3] + p_tr[3] >> 1) >> 1;
882 /* PRED_MODE_SELECT */
883 static void inv_predict_11(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
884 const uint8_t *p_t, const uint8_t *p_tr)
886 int diff = (FFABS(p_l[0] - p_tl[0]) - FFABS(p_t[0] - p_tl[0])) +
887 (FFABS(p_l[1] - p_tl[1]) - FFABS(p_t[1] - p_tl[1])) +
888 (FFABS(p_l[2] - p_tl[2]) - FFABS(p_t[2] - p_tl[2])) +
889 (FFABS(p_l[3] - p_tl[3]) - FFABS(p_t[3] - p_tl[3]));
896 /* PRED_MODE_ADD_SUBTRACT_FULL */
897 static void inv_predict_12(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
898 const uint8_t *p_t, const uint8_t *p_tr)
900 p[0] = av_clip_uint8(p_l[0] + p_t[0] - p_tl[0]);
901 p[1] = av_clip_uint8(p_l[1] + p_t[1] - p_tl[1]);
902 p[2] = av_clip_uint8(p_l[2] + p_t[2] - p_tl[2]);
903 p[3] = av_clip_uint8(p_l[3] + p_t[3] - p_tl[3]);
906 static av_always_inline uint8_t clamp_add_subtract_half(int a, int b, int c)
909 return av_clip_uint8(d + (d - c) / 2);
912 /* PRED_MODE_ADD_SUBTRACT_HALF */
913 static void inv_predict_13(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
914 const uint8_t *p_t, const uint8_t *p_tr)
916 p[0] = clamp_add_subtract_half(p_l[0], p_t[0], p_tl[0]);
917 p[1] = clamp_add_subtract_half(p_l[1], p_t[1], p_tl[1]);
918 p[2] = clamp_add_subtract_half(p_l[2], p_t[2], p_tl[2]);
919 p[3] = clamp_add_subtract_half(p_l[3], p_t[3], p_tl[3]);
922 typedef void (*inv_predict_func)(uint8_t *p, const uint8_t *p_l,
923 const uint8_t *p_tl, const uint8_t *p_t,
924 const uint8_t *p_tr);
926 static const inv_predict_func inverse_predict[14] = {
927 inv_predict_0, inv_predict_1, inv_predict_2, inv_predict_3,
928 inv_predict_4, inv_predict_5, inv_predict_6, inv_predict_7,
929 inv_predict_8, inv_predict_9, inv_predict_10, inv_predict_11,
930 inv_predict_12, inv_predict_13,
933 static void inverse_prediction(AVFrame *frame, enum PredictionMode m, int x, int y)
935 uint8_t *dec, *p_l, *p_tl, *p_t, *p_tr;
938 dec = GET_PIXEL(frame, x, y);
939 p_l = GET_PIXEL(frame, x - 1, y);
940 p_tl = GET_PIXEL(frame, x - 1, y - 1);
941 p_t = GET_PIXEL(frame, x, y - 1);
942 if (x == frame->width - 1)
943 p_tr = GET_PIXEL(frame, 0, y);
945 p_tr = GET_PIXEL(frame, x + 1, y - 1);
947 inverse_predict[m](p, p_l, p_tl, p_t, p_tr);
955 static int apply_predictor_transform(WebPContext *s)
957 ImageContext *img = &s->image[IMAGE_ROLE_ARGB];
958 ImageContext *pimg = &s->image[IMAGE_ROLE_PREDICTOR];
961 for (y = 0; y < img->frame->height; y++) {
962 for (x = 0; x < img->frame->width; x++) {
963 int tx = x >> pimg->size_reduction;
964 int ty = y >> pimg->size_reduction;
965 enum PredictionMode m = GET_PIXEL_COMP(pimg->frame, tx, ty, 2);
976 av_log(s->avctx, AV_LOG_ERROR,
977 "invalid predictor mode: %d\n", m);
978 return AVERROR_INVALIDDATA;
980 inverse_prediction(img->frame, m, x, y);
986 static av_always_inline uint8_t color_transform_delta(uint8_t color_pred,
989 return (int)ff_u8_to_s8(color_pred) * ff_u8_to_s8(color) >> 5;
992 static int apply_color_transform(WebPContext *s)
994 ImageContext *img, *cimg;
998 img = &s->image[IMAGE_ROLE_ARGB];
999 cimg = &s->image[IMAGE_ROLE_COLOR_TRANSFORM];
1001 for (y = 0; y < img->frame->height; y++) {
1002 for (x = 0; x < img->frame->width; x++) {
1003 cx = x >> cimg->size_reduction;
1004 cy = y >> cimg->size_reduction;
1005 cp = GET_PIXEL(cimg->frame, cx, cy);
1006 p = GET_PIXEL(img->frame, x, y);
1008 p[1] += color_transform_delta(cp[3], p[2]);
1009 p[3] += color_transform_delta(cp[2], p[2]) +
1010 color_transform_delta(cp[1], p[1]);
1016 static int apply_subtract_green_transform(WebPContext *s)
1019 ImageContext *img = &s->image[IMAGE_ROLE_ARGB];
1021 for (y = 0; y < img->frame->height; y++) {
1022 for (x = 0; x < img->frame->width; x++) {
1023 uint8_t *p = GET_PIXEL(img->frame, x, y);
1031 static int apply_color_indexing_transform(WebPContext *s)
1038 img = &s->image[IMAGE_ROLE_ARGB];
1039 pal = &s->image[IMAGE_ROLE_COLOR_INDEXING];
1041 if (pal->size_reduction > 0) {
1044 int pixel_bits = 8 >> pal->size_reduction;
1046 line = av_malloc(img->frame->linesize[0]);
1048 return AVERROR(ENOMEM);
1050 for (y = 0; y < img->frame->height; y++) {
1051 p = GET_PIXEL(img->frame, 0, y);
1052 memcpy(line, p, img->frame->linesize[0]);
1053 init_get_bits(&gb_g, line, img->frame->linesize[0] * 8);
1054 skip_bits(&gb_g, 16);
1056 for (x = 0; x < img->frame->width; x++) {
1057 p = GET_PIXEL(img->frame, x, y);
1058 p[2] = get_bits(&gb_g, pixel_bits);
1060 if (i == 1 << pal->size_reduction) {
1061 skip_bits(&gb_g, 24);
1069 // switch to local palette if it's worth initializing it
1070 if (img->frame->height * img->frame->width > 300) {
1071 uint8_t palette[256 * 4];
1072 const int size = pal->frame->width * 4;
1073 av_assert0(size <= 1024U);
1074 memcpy(palette, GET_PIXEL(pal->frame, 0, 0), size); // copy palette
1075 // set extra entries to transparent black
1076 memset(palette + size, 0, 256 * 4 - size);
1077 for (y = 0; y < img->frame->height; y++) {
1078 for (x = 0; x < img->frame->width; x++) {
1079 p = GET_PIXEL(img->frame, x, y);
1081 AV_COPY32(p, &palette[i * 4]);
1085 for (y = 0; y < img->frame->height; y++) {
1086 for (x = 0; x < img->frame->width; x++) {
1087 p = GET_PIXEL(img->frame, x, y);
1089 if (i >= pal->frame->width) {
1090 AV_WB32(p, 0x00000000);
1092 const uint8_t *pi = GET_PIXEL(pal->frame, i, 0);
1102 static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p,
1103 int *got_frame, uint8_t *data_start,
1104 unsigned int data_size, int is_alpha_chunk)
1106 WebPContext *s = avctx->priv_data;
1109 if (!is_alpha_chunk) {
1111 avctx->pix_fmt = AV_PIX_FMT_ARGB;
1114 ret = init_get_bits8(&s->gb, data_start, data_size);
1118 if (!is_alpha_chunk) {
1119 if (get_bits(&s->gb, 8) != 0x2F) {
1120 av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless signature\n");
1121 return AVERROR_INVALIDDATA;
1124 w = get_bits(&s->gb, 14) + 1;
1125 h = get_bits(&s->gb, 14) + 1;
1126 if (s->width && s->width != w) {
1127 av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",
1131 if (s->height && s->height != h) {
1132 av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",
1137 ret = ff_set_dimensions(avctx, s->width, s->height);
1141 s->has_alpha = get_bits1(&s->gb);
1143 if (get_bits(&s->gb, 3) != 0x0) {
1144 av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless version\n");
1145 return AVERROR_INVALIDDATA;
1148 if (!s->width || !s->height)
1154 /* parse transformations */
1155 s->nb_transforms = 0;
1156 s->reduced_width = 0;
1157 while (get_bits1(&s->gb)) {
1158 enum TransformType transform = get_bits(&s->gb, 2);
1159 s->transforms[s->nb_transforms++] = transform;
1160 switch (transform) {
1161 case PREDICTOR_TRANSFORM:
1162 ret = parse_transform_predictor(s);
1164 case COLOR_TRANSFORM:
1165 ret = parse_transform_color(s);
1167 case COLOR_INDEXING_TRANSFORM:
1168 ret = parse_transform_color_indexing(s);
1172 goto free_and_return;
1175 /* decode primary image */
1176 s->image[IMAGE_ROLE_ARGB].frame = p;
1178 s->image[IMAGE_ROLE_ARGB].is_alpha_primary = 1;
1179 ret = decode_entropy_coded_image(s, IMAGE_ROLE_ARGB, w, h);
1181 goto free_and_return;
1183 /* apply transformations */
1184 for (i = s->nb_transforms - 1; i >= 0; i--) {
1185 switch (s->transforms[i]) {
1186 case PREDICTOR_TRANSFORM:
1187 ret = apply_predictor_transform(s);
1189 case COLOR_TRANSFORM:
1190 ret = apply_color_transform(s);
1192 case SUBTRACT_GREEN:
1193 ret = apply_subtract_green_transform(s);
1195 case COLOR_INDEXING_TRANSFORM:
1196 ret = apply_color_indexing_transform(s);
1200 goto free_and_return;
1204 p->pict_type = AV_PICTURE_TYPE_I;
1209 for (i = 0; i < IMAGE_ROLE_NB; i++)
1210 image_ctx_free(&s->image[i]);
1215 static void alpha_inverse_prediction(AVFrame *frame, enum AlphaFilter m)
1220 ls = frame->linesize[3];
1222 /* filter first row using horizontal filter */
1223 dec = frame->data[3] + 1;
1224 for (x = 1; x < frame->width; x++, dec++)
1227 /* filter first column using vertical filter */
1228 dec = frame->data[3] + ls;
1229 for (y = 1; y < frame->height; y++, dec += ls)
1230 *dec += *(dec - ls);
1232 /* filter the rest using the specified filter */
1234 case ALPHA_FILTER_HORIZONTAL:
1235 for (y = 1; y < frame->height; y++) {
1236 dec = frame->data[3] + y * ls + 1;
1237 for (x = 1; x < frame->width; x++, dec++)
1241 case ALPHA_FILTER_VERTICAL:
1242 for (y = 1; y < frame->height; y++) {
1243 dec = frame->data[3] + y * ls + 1;
1244 for (x = 1; x < frame->width; x++, dec++)
1245 *dec += *(dec - ls);
1248 case ALPHA_FILTER_GRADIENT:
1249 for (y = 1; y < frame->height; y++) {
1250 dec = frame->data[3] + y * ls + 1;
1251 for (x = 1; x < frame->width; x++, dec++)
1252 dec[0] += av_clip_uint8(*(dec - 1) + *(dec - ls) - *(dec - ls - 1));
1258 static int vp8_lossy_decode_alpha(AVCodecContext *avctx, AVFrame *p,
1259 uint8_t *data_start,
1260 unsigned int data_size)
1262 WebPContext *s = avctx->priv_data;
1265 if (s->alpha_compression == ALPHA_COMPRESSION_NONE) {
1268 bytestream2_init(&gb, data_start, data_size);
1269 for (y = 0; y < s->height; y++)
1270 bytestream2_get_buffer(&gb, p->data[3] + p->linesize[3] * y,
1272 } else if (s->alpha_compression == ALPHA_COMPRESSION_VP8L) {
1274 int alpha_got_frame = 0;
1276 s->alpha_frame = av_frame_alloc();
1277 if (!s->alpha_frame)
1278 return AVERROR(ENOMEM);
1280 ret = vp8_lossless_decode_frame(avctx, s->alpha_frame, &alpha_got_frame,
1281 data_start, data_size, 1);
1283 av_frame_free(&s->alpha_frame);
1286 if (!alpha_got_frame) {
1287 av_frame_free(&s->alpha_frame);
1288 return AVERROR_INVALIDDATA;
1291 /* copy green component of alpha image to alpha plane of primary image */
1292 for (y = 0; y < s->height; y++) {
1293 ap = GET_PIXEL(s->alpha_frame, 0, y) + 2;
1294 pp = p->data[3] + p->linesize[3] * y;
1295 for (x = 0; x < s->width; x++) {
1301 av_frame_free(&s->alpha_frame);
1304 /* apply alpha filtering */
1305 if (s->alpha_filter)
1306 alpha_inverse_prediction(p, s->alpha_filter);
1311 static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p,
1312 int *got_frame, uint8_t *data_start,
1313 unsigned int data_size)
1315 WebPContext *s = avctx->priv_data;
1319 if (!s->initialized) {
1320 ff_vp8_decode_init(avctx);
1323 avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
1327 if (data_size > INT_MAX) {
1328 av_log(avctx, AV_LOG_ERROR, "unsupported chunk size\n");
1329 return AVERROR_PATCHWELCOME;
1332 av_init_packet(&pkt);
1333 pkt.data = data_start;
1334 pkt.size = data_size;
1336 ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
1338 ret = vp8_lossy_decode_alpha(avctx, p, s->alpha_data,
1339 s->alpha_data_size);
1346 static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
1349 AVFrame * const p = data;
1350 WebPContext *s = avctx->priv_data;
1353 uint32_t chunk_type, chunk_size;
1362 bytestream2_init(&gb, avpkt->data, avpkt->size);
1364 if (bytestream2_get_bytes_left(&gb) < 12)
1365 return AVERROR_INVALIDDATA;
1367 if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
1368 av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
1369 return AVERROR_INVALIDDATA;
1372 chunk_size = bytestream2_get_le32(&gb);
1373 if (bytestream2_get_bytes_left(&gb) < chunk_size)
1374 return AVERROR_INVALIDDATA;
1376 if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
1377 av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
1378 return AVERROR_INVALIDDATA;
1381 av_dict_free(&s->exif_metadata);
1382 while (bytestream2_get_bytes_left(&gb) > 0) {
1383 char chunk_str[5] = { 0 };
1385 chunk_type = bytestream2_get_le32(&gb);
1386 chunk_size = bytestream2_get_le32(&gb);
1387 if (chunk_size == UINT32_MAX)
1388 return AVERROR_INVALIDDATA;
1389 chunk_size += chunk_size & 1;
1391 if (bytestream2_get_bytes_left(&gb) < chunk_size)
1392 return AVERROR_INVALIDDATA;
1394 switch (chunk_type) {
1395 case MKTAG('V', 'P', '8', ' '):
1397 ret = vp8_lossy_decode_frame(avctx, p, got_frame,
1398 avpkt->data + bytestream2_tell(&gb),
1403 bytestream2_skip(&gb, chunk_size);
1405 case MKTAG('V', 'P', '8', 'L'):
1407 ret = vp8_lossless_decode_frame(avctx, p, got_frame,
1408 avpkt->data + bytestream2_tell(&gb),
1413 bytestream2_skip(&gb, chunk_size);
1415 case MKTAG('V', 'P', '8', 'X'):
1416 vp8x_flags = bytestream2_get_byte(&gb);
1417 bytestream2_skip(&gb, 3);
1418 s->width = bytestream2_get_le24(&gb) + 1;
1419 s->height = bytestream2_get_le24(&gb) + 1;
1420 ret = av_image_check_size(s->width, s->height, 0, avctx);
1424 case MKTAG('A', 'L', 'P', 'H'): {
1425 int alpha_header, filter_m, compression;
1427 if (!(vp8x_flags & VP8X_FLAG_ALPHA)) {
1428 av_log(avctx, AV_LOG_WARNING,
1429 "ALPHA chunk present, but alpha bit not set in the "
1432 if (chunk_size == 0) {
1433 av_log(avctx, AV_LOG_ERROR, "invalid ALPHA chunk size\n");
1434 return AVERROR_INVALIDDATA;
1436 alpha_header = bytestream2_get_byte(&gb);
1437 s->alpha_data = avpkt->data + bytestream2_tell(&gb);
1438 s->alpha_data_size = chunk_size - 1;
1439 bytestream2_skip(&gb, s->alpha_data_size);
1441 filter_m = (alpha_header >> 2) & 0x03;
1442 compression = alpha_header & 0x03;
1444 if (compression > ALPHA_COMPRESSION_VP8L) {
1445 av_log(avctx, AV_LOG_VERBOSE,
1446 "skipping unsupported ALPHA chunk\n");
1449 s->alpha_compression = compression;
1450 s->alpha_filter = filter_m;
1455 case MKTAG('E', 'X', 'I', 'F'): {
1456 int le, ifd_offset, exif_offset = bytestream2_tell(&gb);
1457 GetByteContext exif_gb;
1460 av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra EXIF chunk\n");
1463 if (!(vp8x_flags & VP8X_FLAG_EXIF_METADATA))
1464 av_log(avctx, AV_LOG_WARNING,
1465 "EXIF chunk present, but Exif bit not set in the "
1469 bytestream2_init(&exif_gb, avpkt->data + exif_offset,
1470 avpkt->size - exif_offset);
1471 if (ff_tdecode_header(&exif_gb, &le, &ifd_offset) < 0) {
1472 av_log(avctx, AV_LOG_ERROR, "invalid TIFF header "
1477 bytestream2_seek(&exif_gb, ifd_offset, SEEK_SET);
1478 if (avpriv_exif_decode_ifd(avctx, &exif_gb, le, 0, &s->exif_metadata) < 0) {
1479 av_log(avctx, AV_LOG_ERROR, "error decoding Exif data\n");
1483 av_dict_copy(avpriv_frame_get_metadatap(data), s->exif_metadata, 0);
1486 av_dict_free(&s->exif_metadata);
1487 bytestream2_skip(&gb, chunk_size);
1490 case MKTAG('I', 'C', 'C', 'P'):
1491 case MKTAG('A', 'N', 'I', 'M'):
1492 case MKTAG('A', 'N', 'M', 'F'):
1493 case MKTAG('X', 'M', 'P', ' '):
1494 AV_WL32(chunk_str, chunk_type);
1495 av_log(avctx, AV_LOG_VERBOSE, "skipping unsupported chunk: %s\n",
1497 bytestream2_skip(&gb, chunk_size);
1500 AV_WL32(chunk_str, chunk_type);
1501 av_log(avctx, AV_LOG_VERBOSE, "skipping unknown chunk: %s\n",
1503 bytestream2_skip(&gb, chunk_size);
1509 av_log(avctx, AV_LOG_ERROR, "image data not found\n");
1510 return AVERROR_INVALIDDATA;
1516 static av_cold int webp_decode_close(AVCodecContext *avctx)
1518 WebPContext *s = avctx->priv_data;
1521 return ff_vp8_decode_free(avctx);
1526 AVCodec ff_webp_decoder = {
1528 .long_name = NULL_IF_CONFIG_SMALL("WebP image"),
1529 .type = AVMEDIA_TYPE_VIDEO,
1530 .id = AV_CODEC_ID_WEBP,
1531 .priv_data_size = sizeof(WebPContext),
1532 .decode = webp_decode_frame,
1533 .close = webp_decode_close,
1534 .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,