FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
webp.c
Go to the documentation of this file.
1 /*
2  * WebP (.webp) image decoder
3  * Copyright (c) 2013 Aneesh Dogra <aneesh@sugarlabs.org>
4  * Copyright (c) 2013 Justin Ruggles <justin.ruggles@gmail.com>
5  *
6  * This file is part of FFmpeg.
7  *
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.
12  *
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.
17  *
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
21  */
22 
23 /**
24  * @file
25  * WebP image decoder
26  *
27  * @author Aneesh Dogra <aneesh@sugarlabs.org>
28  * Container and Lossy decoding
29  *
30  * @author Justin Ruggles <justin.ruggles@gmail.com>
31  * Lossless decoder
32  * Compressed alpha for lossy
33  *
34  * @author James Almer <jamrial@gmail.com>
35  * Exif metadata
36  *
37  * Unimplemented:
38  * - Animation
39  * - ICC profile
40  * - XMP metadata
41  */
42 
43 #define BITSTREAM_READER_LE
44 #include "libavutil/imgutils.h"
45 #include "avcodec.h"
46 #include "bytestream.h"
47 #include "exif.h"
48 #include "internal.h"
49 #include "get_bits.h"
50 #include "thread.h"
51 #include "vp8.h"
52 
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
58 
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
68 
69 static const uint16_t alphabet_sizes[HUFFMAN_CODES_PER_META_CODE] = {
73 };
74 
76  17, 18, 0, 1, 2, 3, 4, 5, 16, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
77 };
78 
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 }
95 };
96 
100 };
101 
107 };
108 
114 };
115 
131 };
132 
139 };
140 
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. */
147 enum ImageRole {
148  /* Primary Image: Stores the actual pixels of the image. */
150 
151  /* Entropy Image: Defines which Huffman group to use for different areas of
152  * the primary image. */
154 
155  /* Predictors: Defines which predictor type to use for different areas of
156  * the primary image. */
158 
159  /* Color Transform Data: Defines the color transformation for different
160  * areas of the primary image. */
162 
163  /* Color Index: Stored as an image of height == 1. */
165 
167 };
168 
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 */
174 } HuffReader;
175 
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 */
185 } ImageContext;
186 
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  int width; /* image width */
200  int height; /* image height */
201  int lossless; /* indicates lossless or lossy */
202 
203  int nb_transforms; /* number of transforms */
204  enum TransformType transforms[4]; /* transformations used in the image, in order */
205  int reduced_width; /* reduced width for index image, if applicable */
206  int nb_huffman_groups; /* number of huffman groups in the primary image */
207  ImageContext image[IMAGE_ROLE_NB]; /* image context for each role */
208 } WebPContext;
209 
210 #define GET_PIXEL(frame, x, y) \
211  ((frame)->data[0] + (y) * frame->linesize[0] + 4 * (x))
212 
213 #define GET_PIXEL_COMP(frame, x, y, c) \
214  (*((frame)->data[0] + (y) * frame->linesize[0] + 4 * (x) + c))
215 
217 {
218  int i, j;
219 
220  av_free(img->color_cache);
221  if (img->role != IMAGE_ROLE_ARGB && !img->is_alpha_primary)
222  av_frame_free(&img->frame);
223  if (img->huffman_groups) {
224  for (i = 0; i < img->nb_huffman_groups; i++) {
225  for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; j++)
226  ff_free_vlc(&img->huffman_groups[i * HUFFMAN_CODES_PER_META_CODE + j].vlc);
227  }
228  av_free(img->huffman_groups);
229  }
230  memset(img, 0, sizeof(*img));
231 }
232 
233 
234 /* Differs from get_vlc2() in the following ways:
235  * - codes are bit-reversed
236  * - assumes 8-bit table to make reversal simpler
237  * - assumes max depth of 2 since the max code length for WebP is 15
238  */
240 {
241  int n, nb_bits;
242  unsigned int index;
243  int code;
244 
245  OPEN_READER(re, gb);
246  UPDATE_CACHE(re, gb);
247 
248  index = SHOW_UBITS(re, gb, 8);
249  index = ff_reverse[index];
250  code = table[index][0];
251  n = table[index][1];
252 
253  if (n < 0) {
254  LAST_SKIP_BITS(re, gb, 8);
255  UPDATE_CACHE(re, gb);
256 
257  nb_bits = -n;
258 
259  index = SHOW_UBITS(re, gb, nb_bits);
260  index = (ff_reverse[index] >> (8 - nb_bits)) + code;
261  code = table[index][0];
262  n = table[index][1];
263  }
264  SKIP_BITS(re, gb, n);
265 
266  CLOSE_READER(re, gb);
267 
268  return code;
269 }
270 
272 {
273  if (r->simple) {
274  if (r->nb_symbols == 1)
275  return r->simple_symbols[0];
276  else
277  return r->simple_symbols[get_bits1(gb)];
278  } else
279  return webp_get_vlc(gb, r->vlc.table);
280 }
281 
282 static int huff_reader_build_canonical(HuffReader *r, int *code_lengths,
283  int alphabet_size)
284 {
285  int len = 0, sym, code = 0, ret;
286  int max_code_length = 0;
287  uint16_t *codes;
288 
289  /* special-case 1 symbol since the vlc reader cannot handle it */
290  for (sym = 0; sym < alphabet_size; sym++) {
291  if (code_lengths[sym] > 0) {
292  len++;
293  code = sym;
294  if (len > 1)
295  break;
296  }
297  }
298  if (len == 1) {
299  r->nb_symbols = 1;
300  r->simple_symbols[0] = code;
301  r->simple = 1;
302  return 0;
303  }
304 
305  for (sym = 0; sym < alphabet_size; sym++)
306  max_code_length = FFMAX(max_code_length, code_lengths[sym]);
307 
308  if (max_code_length == 0 || max_code_length > MAX_HUFFMAN_CODE_LENGTH)
309  return AVERROR(EINVAL);
310 
311  codes = av_malloc_array(alphabet_size, sizeof(*codes));
312  if (!codes)
313  return AVERROR(ENOMEM);
314 
315  code = 0;
316  r->nb_symbols = 0;
317  for (len = 1; len <= max_code_length; len++) {
318  for (sym = 0; sym < alphabet_size; sym++) {
319  if (code_lengths[sym] != len)
320  continue;
321  codes[sym] = code++;
322  r->nb_symbols++;
323  }
324  code <<= 1;
325  }
326  if (!r->nb_symbols) {
327  av_free(codes);
328  return AVERROR_INVALIDDATA;
329  }
330 
331  ret = init_vlc(&r->vlc, 8, alphabet_size,
332  code_lengths, sizeof(*code_lengths), sizeof(*code_lengths),
333  codes, sizeof(*codes), sizeof(*codes), 0);
334  if (ret < 0) {
335  av_free(codes);
336  return ret;
337  }
338  r->simple = 0;
339 
340  av_free(codes);
341  return 0;
342 }
343 
345 {
346  hc->nb_symbols = get_bits1(&s->gb) + 1;
347 
348  if (get_bits1(&s->gb))
349  hc->simple_symbols[0] = get_bits(&s->gb, 8);
350  else
351  hc->simple_symbols[0] = get_bits1(&s->gb);
352 
353  if (hc->nb_symbols == 2)
354  hc->simple_symbols[1] = get_bits(&s->gb, 8);
355 
356  hc->simple = 1;
357 }
358 
360  int alphabet_size)
361 {
362  HuffReader code_len_hc = { { 0 }, 0, 0, { 0 } };
363  int *code_lengths = NULL;
364  int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 };
365  int i, symbol, max_symbol, prev_code_len, ret;
366  int num_codes = 4 + get_bits(&s->gb, 4);
367 
368  if (num_codes > NUM_CODE_LENGTH_CODES)
369  return AVERROR_INVALIDDATA;
370 
371  for (i = 0; i < num_codes; i++)
372  code_length_code_lengths[code_length_code_order[i]] = get_bits(&s->gb, 3);
373 
374  ret = huff_reader_build_canonical(&code_len_hc, code_length_code_lengths,
376  if (ret < 0)
377  goto finish;
378 
379  code_lengths = av_mallocz_array(alphabet_size, sizeof(*code_lengths));
380  if (!code_lengths) {
381  ret = AVERROR(ENOMEM);
382  goto finish;
383  }
384 
385  if (get_bits1(&s->gb)) {
386  int bits = 2 + 2 * get_bits(&s->gb, 3);
387  max_symbol = 2 + get_bits(&s->gb, bits);
388  if (max_symbol > alphabet_size) {
389  av_log(s->avctx, AV_LOG_ERROR, "max symbol %d > alphabet size %d\n",
390  max_symbol, alphabet_size);
391  ret = AVERROR_INVALIDDATA;
392  goto finish;
393  }
394  } else {
395  max_symbol = alphabet_size;
396  }
397 
398  prev_code_len = 8;
399  symbol = 0;
400  while (symbol < alphabet_size) {
401  int code_len;
402 
403  if (!max_symbol--)
404  break;
405  code_len = huff_reader_get_symbol(&code_len_hc, &s->gb);
406  if (code_len < 16) {
407  /* Code length code [0..15] indicates literal code lengths. */
408  code_lengths[symbol++] = code_len;
409  if (code_len)
410  prev_code_len = code_len;
411  } else {
412  int repeat = 0, length = 0;
413  switch (code_len) {
414  case 16:
415  /* Code 16 repeats the previous non-zero value [3..6] times,
416  * i.e., 3 + ReadBits(2) times. If code 16 is used before a
417  * non-zero value has been emitted, a value of 8 is repeated. */
418  repeat = 3 + get_bits(&s->gb, 2);
419  length = prev_code_len;
420  break;
421  case 17:
422  /* Code 17 emits a streak of zeros [3..10], i.e.,
423  * 3 + ReadBits(3) times. */
424  repeat = 3 + get_bits(&s->gb, 3);
425  break;
426  case 18:
427  /* Code 18 emits a streak of zeros of length [11..138], i.e.,
428  * 11 + ReadBits(7) times. */
429  repeat = 11 + get_bits(&s->gb, 7);
430  break;
431  }
432  if (symbol + repeat > alphabet_size) {
434  "invalid symbol %d + repeat %d > alphabet size %d\n",
435  symbol, repeat, alphabet_size);
436  ret = AVERROR_INVALIDDATA;
437  goto finish;
438  }
439  while (repeat-- > 0)
440  code_lengths[symbol++] = length;
441  }
442  }
443 
444  ret = huff_reader_build_canonical(hc, code_lengths, alphabet_size);
445 
446 finish:
447  ff_free_vlc(&code_len_hc.vlc);
448  av_free(code_lengths);
449  return ret;
450 }
451 
452 static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role,
453  int w, int h);
454 
455 #define PARSE_BLOCK_SIZE(w, h) do { \
456  block_bits = get_bits(&s->gb, 3) + 2; \
457  blocks_w = FFALIGN((w), 1 << block_bits) >> block_bits; \
458  blocks_h = FFALIGN((h), 1 << block_bits) >> block_bits; \
459 } while (0)
460 
462 {
463  ImageContext *img;
464  int ret, block_bits, width, blocks_w, blocks_h, x, y, max;
465 
466  width = s->width;
467  if (s->reduced_width > 0)
468  width = s->reduced_width;
469 
470  PARSE_BLOCK_SIZE(width, s->height);
471 
472  ret = decode_entropy_coded_image(s, IMAGE_ROLE_ENTROPY, blocks_w, blocks_h);
473  if (ret < 0)
474  return ret;
475 
476  img = &s->image[IMAGE_ROLE_ENTROPY];
477  img->size_reduction = block_bits;
478 
479  /* the number of huffman groups is determined by the maximum group number
480  * coded in the entropy image */
481  max = 0;
482  for (y = 0; y < img->frame->height; y++) {
483  for (x = 0; x < img->frame->width; x++) {
484  int p0 = GET_PIXEL_COMP(img->frame, x, y, 1);
485  int p1 = GET_PIXEL_COMP(img->frame, x, y, 2);
486  int p = p0 << 8 | p1;
487  max = FFMAX(max, p);
488  }
489  }
490  s->nb_huffman_groups = max + 1;
491 
492  return 0;
493 }
494 
496 {
497  int block_bits, blocks_w, blocks_h, ret;
498 
499  PARSE_BLOCK_SIZE(s->width, s->height);
500 
502  blocks_h);
503  if (ret < 0)
504  return ret;
505 
506  s->image[IMAGE_ROLE_PREDICTOR].size_reduction = block_bits;
507 
508  return 0;
509 }
510 
512 {
513  int block_bits, blocks_w, blocks_h, ret;
514 
515  PARSE_BLOCK_SIZE(s->width, s->height);
516 
518  blocks_h);
519  if (ret < 0)
520  return ret;
521 
523 
524  return 0;
525 }
526 
528 {
529  ImageContext *img;
530  int width_bits, index_size, ret, x;
531  uint8_t *ct;
532 
533  index_size = get_bits(&s->gb, 8) + 1;
534 
535  if (index_size <= 2)
536  width_bits = 3;
537  else if (index_size <= 4)
538  width_bits = 2;
539  else if (index_size <= 16)
540  width_bits = 1;
541  else
542  width_bits = 0;
543 
545  index_size, 1);
546  if (ret < 0)
547  return ret;
548 
549  img = &s->image[IMAGE_ROLE_COLOR_INDEXING];
550  img->size_reduction = width_bits;
551  if (width_bits > 0)
552  s->reduced_width = (s->width + ((1 << width_bits) - 1)) >> width_bits;
553 
554  /* color index values are delta-coded */
555  ct = img->frame->data[0] + 4;
556  for (x = 4; x < img->frame->width * 4; x++, ct++)
557  ct[0] += ct[-4];
558 
559  return 0;
560 }
561 
563  int x, int y)
564 {
566  int group = 0;
567 
568  if (gimg->size_reduction > 0) {
569  int group_x = x >> gimg->size_reduction;
570  int group_y = y >> gimg->size_reduction;
571  int g0 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 1);
572  int g1 = GET_PIXEL_COMP(gimg->frame, group_x, group_y, 2);
573  group = g0 << 8 | g1;
574  }
575 
576  return &img->huffman_groups[group * HUFFMAN_CODES_PER_META_CODE];
577 }
578 
580 {
581  uint32_t cache_idx = (0x1E35A7BD * c) >> (32 - img->color_cache_bits);
582  img->color_cache[cache_idx] = c;
583 }
584 
586  int w, int h)
587 {
588  ImageContext *img;
589  HuffReader *hg;
590  int i, j, ret, x, y, width;
591 
592  img = &s->image[role];
593  img->role = role;
594 
595  if (!img->frame) {
596  img->frame = av_frame_alloc();
597  if (!img->frame)
598  return AVERROR(ENOMEM);
599  }
600 
601  img->frame->format = AV_PIX_FMT_ARGB;
602  img->frame->width = w;
603  img->frame->height = h;
604 
605  if (role == IMAGE_ROLE_ARGB && !img->is_alpha_primary) {
606  ThreadFrame pt = { .f = img->frame };
607  ret = ff_thread_get_buffer(s->avctx, &pt, 0);
608  } else
609  ret = av_frame_get_buffer(img->frame, 1);
610  if (ret < 0)
611  return ret;
612 
613  if (get_bits1(&s->gb)) {
614  img->color_cache_bits = get_bits(&s->gb, 4);
615  if (img->color_cache_bits < 1 || img->color_cache_bits > 11) {
616  av_log(s->avctx, AV_LOG_ERROR, "invalid color cache bits: %d\n",
617  img->color_cache_bits);
618  return AVERROR_INVALIDDATA;
619  }
621  sizeof(*img->color_cache));
622  if (!img->color_cache)
623  return AVERROR(ENOMEM);
624  } else {
625  img->color_cache_bits = 0;
626  }
627 
628  img->nb_huffman_groups = 1;
629  if (role == IMAGE_ROLE_ARGB && get_bits1(&s->gb)) {
630  ret = decode_entropy_image(s);
631  if (ret < 0)
632  return ret;
634  }
637  sizeof(*img->huffman_groups));
638  if (!img->huffman_groups)
639  return AVERROR(ENOMEM);
640 
641  for (i = 0; i < img->nb_huffman_groups; i++) {
643  for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; j++) {
644  int alphabet_size = alphabet_sizes[j];
645  if (!j && img->color_cache_bits > 0)
646  alphabet_size += 1 << img->color_cache_bits;
647 
648  if (get_bits1(&s->gb)) {
649  read_huffman_code_simple(s, &hg[j]);
650  } else {
651  ret = read_huffman_code_normal(s, &hg[j], alphabet_size);
652  if (ret < 0)
653  return ret;
654  }
655  }
656  }
657 
658  width = img->frame->width;
659  if (role == IMAGE_ROLE_ARGB && s->reduced_width > 0)
660  width = s->reduced_width;
661 
662  x = 0; y = 0;
663  while (y < img->frame->height) {
664  int v;
665 
666  hg = get_huffman_group(s, img, x, y);
668  if (v < NUM_LITERAL_CODES) {
669  /* literal pixel values */
670  uint8_t *p = GET_PIXEL(img->frame, x, y);
671  p[2] = v;
672  p[1] = huff_reader_get_symbol(&hg[HUFF_IDX_RED], &s->gb);
673  p[3] = huff_reader_get_symbol(&hg[HUFF_IDX_BLUE], &s->gb);
674  p[0] = huff_reader_get_symbol(&hg[HUFF_IDX_ALPHA], &s->gb);
675  if (img->color_cache_bits)
676  color_cache_put(img, AV_RB32(p));
677  x++;
678  if (x == width) {
679  x = 0;
680  y++;
681  }
682  } else if (v < NUM_LITERAL_CODES + NUM_LENGTH_CODES) {
683  /* LZ77 backwards mapping */
684  int prefix_code, length, distance, ref_x, ref_y;
685 
686  /* parse length and distance */
687  prefix_code = v - NUM_LITERAL_CODES;
688  if (prefix_code < 4) {
689  length = prefix_code + 1;
690  } else {
691  int extra_bits = (prefix_code - 2) >> 1;
692  int offset = 2 + (prefix_code & 1) << extra_bits;
693  length = offset + get_bits(&s->gb, extra_bits) + 1;
694  }
695  prefix_code = huff_reader_get_symbol(&hg[HUFF_IDX_DIST], &s->gb);
696  if (prefix_code > 39) {
698  "distance prefix code too large: %d\n", prefix_code);
699  return AVERROR_INVALIDDATA;
700  }
701  if (prefix_code < 4) {
702  distance = prefix_code + 1;
703  } else {
704  int extra_bits = prefix_code - 2 >> 1;
705  int offset = 2 + (prefix_code & 1) << extra_bits;
706  distance = offset + get_bits(&s->gb, extra_bits) + 1;
707  }
708 
709  /* find reference location */
710  if (distance <= NUM_SHORT_DISTANCES) {
711  int xi = lz77_distance_offsets[distance - 1][0];
712  int yi = lz77_distance_offsets[distance - 1][1];
713  distance = FFMAX(1, xi + yi * width);
714  } else {
715  distance -= NUM_SHORT_DISTANCES;
716  }
717  ref_x = x;
718  ref_y = y;
719  if (distance <= x) {
720  ref_x -= distance;
721  distance = 0;
722  } else {
723  ref_x = 0;
724  distance -= x;
725  }
726  while (distance >= width) {
727  ref_y--;
728  distance -= width;
729  }
730  if (distance > 0) {
731  ref_x = width - distance;
732  ref_y--;
733  }
734  ref_x = FFMAX(0, ref_x);
735  ref_y = FFMAX(0, ref_y);
736 
737  /* copy pixels
738  * source and dest regions can overlap and wrap lines, so just
739  * copy per-pixel */
740  for (i = 0; i < length; i++) {
741  uint8_t *p_ref = GET_PIXEL(img->frame, ref_x, ref_y);
742  uint8_t *p = GET_PIXEL(img->frame, x, y);
743 
744  AV_COPY32(p, p_ref);
745  if (img->color_cache_bits)
746  color_cache_put(img, AV_RB32(p));
747  x++;
748  ref_x++;
749  if (x == width) {
750  x = 0;
751  y++;
752  }
753  if (ref_x == width) {
754  ref_x = 0;
755  ref_y++;
756  }
757  if (y == img->frame->height || ref_y == img->frame->height)
758  break;
759  }
760  } else {
761  /* read from color cache */
762  uint8_t *p = GET_PIXEL(img->frame, x, y);
763  int cache_idx = v - (NUM_LITERAL_CODES + NUM_LENGTH_CODES);
764 
765  if (!img->color_cache_bits) {
766  av_log(s->avctx, AV_LOG_ERROR, "color cache not found\n");
767  return AVERROR_INVALIDDATA;
768  }
769  if (cache_idx >= 1 << img->color_cache_bits) {
771  "color cache index out-of-bounds\n");
772  return AVERROR_INVALIDDATA;
773  }
774  AV_WB32(p, img->color_cache[cache_idx]);
775  x++;
776  if (x == width) {
777  x = 0;
778  y++;
779  }
780  }
781  }
782 
783  return 0;
784 }
785 
786 /* PRED_MODE_BLACK */
787 static void inv_predict_0(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
788  const uint8_t *p_t, const uint8_t *p_tr)
789 {
790  AV_WB32(p, 0xFF000000);
791 }
792 
793 /* PRED_MODE_L */
794 static void inv_predict_1(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
795  const uint8_t *p_t, const uint8_t *p_tr)
796 {
797  AV_COPY32(p, p_l);
798 }
799 
800 /* PRED_MODE_T */
801 static void inv_predict_2(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
802  const uint8_t *p_t, const uint8_t *p_tr)
803 {
804  AV_COPY32(p, p_t);
805 }
806 
807 /* PRED_MODE_TR */
808 static void inv_predict_3(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
809  const uint8_t *p_t, const uint8_t *p_tr)
810 {
811  AV_COPY32(p, p_tr);
812 }
813 
814 /* PRED_MODE_TL */
815 static void inv_predict_4(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
816  const uint8_t *p_t, const uint8_t *p_tr)
817 {
818  AV_COPY32(p, p_tl);
819 }
820 
821 /* PRED_MODE_AVG_T_AVG_L_TR */
822 static void inv_predict_5(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
823  const uint8_t *p_t, const uint8_t *p_tr)
824 {
825  p[0] = p_t[0] + (p_l[0] + p_tr[0] >> 1) >> 1;
826  p[1] = p_t[1] + (p_l[1] + p_tr[1] >> 1) >> 1;
827  p[2] = p_t[2] + (p_l[2] + p_tr[2] >> 1) >> 1;
828  p[3] = p_t[3] + (p_l[3] + p_tr[3] >> 1) >> 1;
829 }
830 
831 /* PRED_MODE_AVG_L_TL */
832 static void inv_predict_6(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
833  const uint8_t *p_t, const uint8_t *p_tr)
834 {
835  p[0] = p_l[0] + p_tl[0] >> 1;
836  p[1] = p_l[1] + p_tl[1] >> 1;
837  p[2] = p_l[2] + p_tl[2] >> 1;
838  p[3] = p_l[3] + p_tl[3] >> 1;
839 }
840 
841 /* PRED_MODE_AVG_L_T */
842 static void inv_predict_7(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
843  const uint8_t *p_t, const uint8_t *p_tr)
844 {
845  p[0] = p_l[0] + p_t[0] >> 1;
846  p[1] = p_l[1] + p_t[1] >> 1;
847  p[2] = p_l[2] + p_t[2] >> 1;
848  p[3] = p_l[3] + p_t[3] >> 1;
849 }
850 
851 /* PRED_MODE_AVG_TL_T */
852 static void inv_predict_8(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
853  const uint8_t *p_t, const uint8_t *p_tr)
854 {
855  p[0] = p_tl[0] + p_t[0] >> 1;
856  p[1] = p_tl[1] + p_t[1] >> 1;
857  p[2] = p_tl[2] + p_t[2] >> 1;
858  p[3] = p_tl[3] + p_t[3] >> 1;
859 }
860 
861 /* PRED_MODE_AVG_T_TR */
862 static void inv_predict_9(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
863  const uint8_t *p_t, const uint8_t *p_tr)
864 {
865  p[0] = p_t[0] + p_tr[0] >> 1;
866  p[1] = p_t[1] + p_tr[1] >> 1;
867  p[2] = p_t[2] + p_tr[2] >> 1;
868  p[3] = p_t[3] + p_tr[3] >> 1;
869 }
870 
871 /* PRED_MODE_AVG_AVG_L_TL_AVG_T_TR */
872 static void inv_predict_10(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
873  const uint8_t *p_t, const uint8_t *p_tr)
874 {
875  p[0] = (p_l[0] + p_tl[0] >> 1) + (p_t[0] + p_tr[0] >> 1) >> 1;
876  p[1] = (p_l[1] + p_tl[1] >> 1) + (p_t[1] + p_tr[1] >> 1) >> 1;
877  p[2] = (p_l[2] + p_tl[2] >> 1) + (p_t[2] + p_tr[2] >> 1) >> 1;
878  p[3] = (p_l[3] + p_tl[3] >> 1) + (p_t[3] + p_tr[3] >> 1) >> 1;
879 }
880 
881 /* PRED_MODE_SELECT */
882 static void inv_predict_11(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
883  const uint8_t *p_t, const uint8_t *p_tr)
884 {
885  int diff = (FFABS(p_l[0] - p_tl[0]) - FFABS(p_t[0] - p_tl[0])) +
886  (FFABS(p_l[1] - p_tl[1]) - FFABS(p_t[1] - p_tl[1])) +
887  (FFABS(p_l[2] - p_tl[2]) - FFABS(p_t[2] - p_tl[2])) +
888  (FFABS(p_l[3] - p_tl[3]) - FFABS(p_t[3] - p_tl[3]));
889  if (diff <= 0)
890  AV_COPY32(p, p_t);
891  else
892  AV_COPY32(p, p_l);
893 }
894 
895 /* PRED_MODE_ADD_SUBTRACT_FULL */
896 static void inv_predict_12(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
897  const uint8_t *p_t, const uint8_t *p_tr)
898 {
899  p[0] = av_clip_uint8(p_l[0] + p_t[0] - p_tl[0]);
900  p[1] = av_clip_uint8(p_l[1] + p_t[1] - p_tl[1]);
901  p[2] = av_clip_uint8(p_l[2] + p_t[2] - p_tl[2]);
902  p[3] = av_clip_uint8(p_l[3] + p_t[3] - p_tl[3]);
903 }
904 
906 {
907  int d = a + b >> 1;
908  return av_clip_uint8(d + (d - c) / 2);
909 }
910 
911 /* PRED_MODE_ADD_SUBTRACT_HALF */
912 static void inv_predict_13(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl,
913  const uint8_t *p_t, const uint8_t *p_tr)
914 {
915  p[0] = clamp_add_subtract_half(p_l[0], p_t[0], p_tl[0]);
916  p[1] = clamp_add_subtract_half(p_l[1], p_t[1], p_tl[1]);
917  p[2] = clamp_add_subtract_half(p_l[2], p_t[2], p_tl[2]);
918  p[3] = clamp_add_subtract_half(p_l[3], p_t[3], p_tl[3]);
919 }
920 
921 typedef void (*inv_predict_func)(uint8_t *p, const uint8_t *p_l,
922  const uint8_t *p_tl, const uint8_t *p_t,
923  const uint8_t *p_tr);
924 
925 static const inv_predict_func inverse_predict[14] = {
930 };
931 
932 static void inverse_prediction(AVFrame *frame, enum PredictionMode m, int x, int y)
933 {
934  uint8_t *dec, *p_l, *p_tl, *p_t, *p_tr;
935  uint8_t p[4];
936 
937  dec = GET_PIXEL(frame, x, y);
938  p_l = GET_PIXEL(frame, x - 1, y);
939  p_tl = GET_PIXEL(frame, x - 1, y - 1);
940  p_t = GET_PIXEL(frame, x, y - 1);
941  if (x == frame->width - 1)
942  p_tr = GET_PIXEL(frame, 0, y);
943  else
944  p_tr = GET_PIXEL(frame, x + 1, y - 1);
945 
946  inverse_predict[m](p, p_l, p_tl, p_t, p_tr);
947 
948  dec[0] += p[0];
949  dec[1] += p[1];
950  dec[2] += p[2];
951  dec[3] += p[3];
952 }
953 
955 {
958  int x, y;
959 
960  for (y = 0; y < img->frame->height; y++) {
961  for (x = 0; x < img->frame->width; x++) {
962  int tx = x >> pimg->size_reduction;
963  int ty = y >> pimg->size_reduction;
964  enum PredictionMode m = GET_PIXEL_COMP(pimg->frame, tx, ty, 2);
965 
966  if (x == 0) {
967  if (y == 0)
968  m = PRED_MODE_BLACK;
969  else
970  m = PRED_MODE_T;
971  } else if (y == 0)
972  m = PRED_MODE_L;
973 
974  if (m > 13) {
976  "invalid predictor mode: %d\n", m);
977  return AVERROR_INVALIDDATA;
978  }
979  inverse_prediction(img->frame, m, x, y);
980  }
981  }
982  return 0;
983 }
984 
986  uint8_t color)
987 {
988  return (int)ff_u8_to_s8(color_pred) * ff_u8_to_s8(color) >> 5;
989 }
990 
992 {
993  ImageContext *img, *cimg;
994  int x, y, cx, cy;
995  uint8_t *p, *cp;
996 
997  img = &s->image[IMAGE_ROLE_ARGB];
998  cimg = &s->image[IMAGE_ROLE_COLOR_TRANSFORM];
999 
1000  for (y = 0; y < img->frame->height; y++) {
1001  for (x = 0; x < img->frame->width; x++) {
1002  cx = x >> cimg->size_reduction;
1003  cy = y >> cimg->size_reduction;
1004  cp = GET_PIXEL(cimg->frame, cx, cy);
1005  p = GET_PIXEL(img->frame, x, y);
1006 
1007  p[1] += color_transform_delta(cp[3], p[2]);
1008  p[3] += color_transform_delta(cp[2], p[2]) +
1009  color_transform_delta(cp[1], p[1]);
1010  }
1011  }
1012  return 0;
1013 }
1014 
1016 {
1017  int x, y;
1019 
1020  for (y = 0; y < img->frame->height; y++) {
1021  for (x = 0; x < img->frame->width; x++) {
1022  uint8_t *p = GET_PIXEL(img->frame, x, y);
1023  p[1] += p[2];
1024  p[3] += p[2];
1025  }
1026  }
1027  return 0;
1028 }
1029 
1031 {
1032  ImageContext *img;
1033  ImageContext *pal;
1034  int i, x, y;
1035  uint8_t *p;
1036 
1037  img = &s->image[IMAGE_ROLE_ARGB];
1038  pal = &s->image[IMAGE_ROLE_COLOR_INDEXING];
1039 
1040  if (pal->size_reduction > 0) {
1041  GetBitContext gb_g;
1042  uint8_t *line;
1043  int pixel_bits = 8 >> pal->size_reduction;
1044 
1045  line = av_malloc(img->frame->linesize[0]);
1046  if (!line)
1047  return AVERROR(ENOMEM);
1048 
1049  for (y = 0; y < img->frame->height; y++) {
1050  p = GET_PIXEL(img->frame, 0, y);
1051  memcpy(line, p, img->frame->linesize[0]);
1052  init_get_bits(&gb_g, line, img->frame->linesize[0] * 8);
1053  skip_bits(&gb_g, 16);
1054  i = 0;
1055  for (x = 0; x < img->frame->width; x++) {
1056  p = GET_PIXEL(img->frame, x, y);
1057  p[2] = get_bits(&gb_g, pixel_bits);
1058  i++;
1059  if (i == 1 << pal->size_reduction) {
1060  skip_bits(&gb_g, 24);
1061  i = 0;
1062  }
1063  }
1064  }
1065  av_free(line);
1066  }
1067 
1068  // switch to local palette if it's worth initializing it
1069  if (img->frame->height * img->frame->width > 300) {
1070  uint8_t palette[256 * 4];
1071  const int size = pal->frame->width * 4;
1072  av_assert0(size <= 1024U);
1073  memcpy(palette, GET_PIXEL(pal->frame, 0, 0), size); // copy palette
1074  // set extra entries to transparent black
1075  memset(palette + size, 0, 256 * 4 - size);
1076  for (y = 0; y < img->frame->height; y++) {
1077  for (x = 0; x < img->frame->width; x++) {
1078  p = GET_PIXEL(img->frame, x, y);
1079  i = p[2];
1080  AV_COPY32(p, &palette[i * 4]);
1081  }
1082  }
1083  } else {
1084  for (y = 0; y < img->frame->height; y++) {
1085  for (x = 0; x < img->frame->width; x++) {
1086  p = GET_PIXEL(img->frame, x, y);
1087  i = p[2];
1088  if (i >= pal->frame->width) {
1089  AV_WB32(p, 0x00000000);
1090  } else {
1091  const uint8_t *pi = GET_PIXEL(pal->frame, i, 0);
1092  AV_COPY32(p, pi);
1093  }
1094  }
1095  }
1096  }
1097 
1098  return 0;
1099 }
1100 
1102  int *got_frame, uint8_t *data_start,
1103  unsigned int data_size, int is_alpha_chunk)
1104 {
1105  WebPContext *s = avctx->priv_data;
1106  int w, h, ret, i, used;
1107 
1108  if (!is_alpha_chunk) {
1109  s->lossless = 1;
1110  avctx->pix_fmt = AV_PIX_FMT_ARGB;
1111  }
1112 
1113  ret = init_get_bits8(&s->gb, data_start, data_size);
1114  if (ret < 0)
1115  return ret;
1116 
1117  if (!is_alpha_chunk) {
1118  if (get_bits(&s->gb, 8) != 0x2F) {
1119  av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless signature\n");
1120  return AVERROR_INVALIDDATA;
1121  }
1122 
1123  w = get_bits(&s->gb, 14) + 1;
1124  h = get_bits(&s->gb, 14) + 1;
1125  if (s->width && s->width != w) {
1126  av_log(avctx, AV_LOG_WARNING, "Width mismatch. %d != %d\n",
1127  s->width, w);
1128  }
1129  s->width = w;
1130  if (s->height && s->height != h) {
1131  av_log(avctx, AV_LOG_WARNING, "Height mismatch. %d != %d\n",
1132  s->width, w);
1133  }
1134  s->height = h;
1135 
1136  ret = ff_set_dimensions(avctx, s->width, s->height);
1137  if (ret < 0)
1138  return ret;
1139 
1140  s->has_alpha = get_bits1(&s->gb);
1141 
1142  if (get_bits(&s->gb, 3) != 0x0) {
1143  av_log(avctx, AV_LOG_ERROR, "Invalid WebP Lossless version\n");
1144  return AVERROR_INVALIDDATA;
1145  }
1146  } else {
1147  if (!s->width || !s->height)
1148  return AVERROR_BUG;
1149  w = s->width;
1150  h = s->height;
1151  }
1152 
1153  /* parse transformations */
1154  s->nb_transforms = 0;
1155  s->reduced_width = 0;
1156  used = 0;
1157  while (get_bits1(&s->gb)) {
1158  enum TransformType transform = get_bits(&s->gb, 2);
1159  if (used & (1 << transform)) {
1160  av_log(avctx, AV_LOG_ERROR, "Transform %d used more than once\n",
1161  transform);
1162  ret = AVERROR_INVALIDDATA;
1163  goto free_and_return;
1164  }
1165  used |= (1 << transform);
1166  s->transforms[s->nb_transforms++] = transform;
1167  switch (transform) {
1168  case PREDICTOR_TRANSFORM:
1169  ret = parse_transform_predictor(s);
1170  break;
1171  case COLOR_TRANSFORM:
1172  ret = parse_transform_color(s);
1173  break;
1176  break;
1177  }
1178  if (ret < 0)
1179  goto free_and_return;
1180  }
1181 
1182  /* decode primary image */
1183  s->image[IMAGE_ROLE_ARGB].frame = p;
1184  if (is_alpha_chunk)
1187  if (ret < 0)
1188  goto free_and_return;
1189 
1190  /* apply transformations */
1191  for (i = s->nb_transforms - 1; i >= 0; i--) {
1192  switch (s->transforms[i]) {
1193  case PREDICTOR_TRANSFORM:
1194  ret = apply_predictor_transform(s);
1195  break;
1196  case COLOR_TRANSFORM:
1197  ret = apply_color_transform(s);
1198  break;
1199  case SUBTRACT_GREEN:
1201  break;
1204  break;
1205  }
1206  if (ret < 0)
1207  goto free_and_return;
1208  }
1209 
1210  *got_frame = 1;
1212  p->key_frame = 1;
1213  ret = data_size;
1214 
1215 free_and_return:
1216  for (i = 0; i < IMAGE_ROLE_NB; i++)
1217  image_ctx_free(&s->image[i]);
1218 
1219  return ret;
1220 }
1221 
1223 {
1224  int x, y, ls;
1225  uint8_t *dec;
1226 
1227  ls = frame->linesize[3];
1228 
1229  /* filter first row using horizontal filter */
1230  dec = frame->data[3] + 1;
1231  for (x = 1; x < frame->width; x++, dec++)
1232  *dec += *(dec - 1);
1233 
1234  /* filter first column using vertical filter */
1235  dec = frame->data[3] + ls;
1236  for (y = 1; y < frame->height; y++, dec += ls)
1237  *dec += *(dec - ls);
1238 
1239  /* filter the rest using the specified filter */
1240  switch (m) {
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 - 1);
1246  }
1247  break;
1248  case ALPHA_FILTER_VERTICAL:
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 += *(dec - ls);
1253  }
1254  break;
1255  case ALPHA_FILTER_GRADIENT:
1256  for (y = 1; y < frame->height; y++) {
1257  dec = frame->data[3] + y * ls + 1;
1258  for (x = 1; x < frame->width; x++, dec++)
1259  dec[0] += av_clip_uint8(*(dec - 1) + *(dec - ls) - *(dec - ls - 1));
1260  }
1261  break;
1262  }
1263 }
1264 
1266  uint8_t *data_start,
1267  unsigned int data_size)
1268 {
1269  WebPContext *s = avctx->priv_data;
1270  int x, y, ret;
1271 
1273  GetByteContext gb;
1274 
1275  bytestream2_init(&gb, data_start, data_size);
1276  for (y = 0; y < s->height; y++)
1277  bytestream2_get_buffer(&gb, p->data[3] + p->linesize[3] * y,
1278  s->width);
1279  } else if (s->alpha_compression == ALPHA_COMPRESSION_VP8L) {
1280  uint8_t *ap, *pp;
1281  int alpha_got_frame = 0;
1282 
1283  s->alpha_frame = av_frame_alloc();
1284  if (!s->alpha_frame)
1285  return AVERROR(ENOMEM);
1286 
1287  ret = vp8_lossless_decode_frame(avctx, s->alpha_frame, &alpha_got_frame,
1288  data_start, data_size, 1);
1289  if (ret < 0) {
1291  return ret;
1292  }
1293  if (!alpha_got_frame) {
1295  return AVERROR_INVALIDDATA;
1296  }
1297 
1298  /* copy green component of alpha image to alpha plane of primary image */
1299  for (y = 0; y < s->height; y++) {
1300  ap = GET_PIXEL(s->alpha_frame, 0, y) + 2;
1301  pp = p->data[3] + p->linesize[3] * y;
1302  for (x = 0; x < s->width; x++) {
1303  *pp = *ap;
1304  pp++;
1305  ap += 4;
1306  }
1307  }
1309  }
1310 
1311  /* apply alpha filtering */
1312  if (s->alpha_filter)
1314 
1315  return 0;
1316 }
1317 
1319  int *got_frame, uint8_t *data_start,
1320  unsigned int data_size)
1321 {
1322  WebPContext *s = avctx->priv_data;
1323  AVPacket pkt;
1324  int ret;
1325 
1326  if (!s->initialized) {
1327  ff_vp8_decode_init(avctx);
1328  s->initialized = 1;
1329  if (s->has_alpha)
1330  avctx->pix_fmt = AV_PIX_FMT_YUVA420P;
1331  }
1332  s->lossless = 0;
1333 
1334  if (data_size > INT_MAX) {
1335  av_log(avctx, AV_LOG_ERROR, "unsupported chunk size\n");
1336  return AVERROR_PATCHWELCOME;
1337  }
1338 
1339  av_init_packet(&pkt);
1340  pkt.data = data_start;
1341  pkt.size = data_size;
1342 
1343  ret = ff_vp8_decode_frame(avctx, p, got_frame, &pkt);
1344  if (s->has_alpha) {
1345  ret = vp8_lossy_decode_alpha(avctx, p, s->alpha_data,
1346  s->alpha_data_size);
1347  if (ret < 0)
1348  return ret;
1349  }
1350  return ret;
1351 }
1352 
1353 static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
1354  AVPacket *avpkt)
1355 {
1356  AVFrame * const p = data;
1357  WebPContext *s = avctx->priv_data;
1358  GetByteContext gb;
1359  int ret;
1360  uint32_t chunk_type, chunk_size;
1361  int vp8x_flags = 0;
1362 
1363  s->avctx = avctx;
1364  s->width = 0;
1365  s->height = 0;
1366  *got_frame = 0;
1367  s->has_alpha = 0;
1368  s->has_exif = 0;
1369  bytestream2_init(&gb, avpkt->data, avpkt->size);
1370 
1371  if (bytestream2_get_bytes_left(&gb) < 12)
1372  return AVERROR_INVALIDDATA;
1373 
1374  if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
1375  av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
1376  return AVERROR_INVALIDDATA;
1377  }
1378 
1379  chunk_size = bytestream2_get_le32(&gb);
1380  if (bytestream2_get_bytes_left(&gb) < chunk_size)
1381  return AVERROR_INVALIDDATA;
1382 
1383  if (bytestream2_get_le32(&gb) != MKTAG('W', 'E', 'B', 'P')) {
1384  av_log(avctx, AV_LOG_ERROR, "missing WEBP tag\n");
1385  return AVERROR_INVALIDDATA;
1386  }
1387 
1388  while (bytestream2_get_bytes_left(&gb) > 8) {
1389  char chunk_str[5] = { 0 };
1390 
1391  chunk_type = bytestream2_get_le32(&gb);
1392  chunk_size = bytestream2_get_le32(&gb);
1393  if (chunk_size == UINT32_MAX)
1394  return AVERROR_INVALIDDATA;
1395  chunk_size += chunk_size & 1;
1396 
1397  if (bytestream2_get_bytes_left(&gb) < chunk_size)
1398  return AVERROR_INVALIDDATA;
1399 
1400  switch (chunk_type) {
1401  case MKTAG('V', 'P', '8', ' '):
1402  if (!*got_frame) {
1403  ret = vp8_lossy_decode_frame(avctx, p, got_frame,
1404  avpkt->data + bytestream2_tell(&gb),
1405  chunk_size);
1406  if (ret < 0)
1407  return ret;
1408  }
1409  bytestream2_skip(&gb, chunk_size);
1410  break;
1411  case MKTAG('V', 'P', '8', 'L'):
1412  if (!*got_frame) {
1413  ret = vp8_lossless_decode_frame(avctx, p, got_frame,
1414  avpkt->data + bytestream2_tell(&gb),
1415  chunk_size, 0);
1416  if (ret < 0)
1417  return ret;
1419  }
1420  bytestream2_skip(&gb, chunk_size);
1421  break;
1422  case MKTAG('V', 'P', '8', 'X'):
1423  vp8x_flags = bytestream2_get_byte(&gb);
1424  bytestream2_skip(&gb, 3);
1425  s->width = bytestream2_get_le24(&gb) + 1;
1426  s->height = bytestream2_get_le24(&gb) + 1;
1427  ret = av_image_check_size(s->width, s->height, 0, avctx);
1428  if (ret < 0)
1429  return ret;
1430  break;
1431  case MKTAG('A', 'L', 'P', 'H'): {
1432  int alpha_header, filter_m, compression;
1433 
1434  if (!(vp8x_flags & VP8X_FLAG_ALPHA)) {
1435  av_log(avctx, AV_LOG_WARNING,
1436  "ALPHA chunk present, but alpha bit not set in the "
1437  "VP8X header\n");
1438  }
1439  if (chunk_size == 0) {
1440  av_log(avctx, AV_LOG_ERROR, "invalid ALPHA chunk size\n");
1441  return AVERROR_INVALIDDATA;
1442  }
1443  alpha_header = bytestream2_get_byte(&gb);
1444  s->alpha_data = avpkt->data + bytestream2_tell(&gb);
1445  s->alpha_data_size = chunk_size - 1;
1447 
1448  filter_m = (alpha_header >> 2) & 0x03;
1449  compression = alpha_header & 0x03;
1450 
1451  if (compression > ALPHA_COMPRESSION_VP8L) {
1452  av_log(avctx, AV_LOG_VERBOSE,
1453  "skipping unsupported ALPHA chunk\n");
1454  } else {
1455  s->has_alpha = 1;
1456  s->alpha_compression = compression;
1457  s->alpha_filter = filter_m;
1458  }
1459 
1460  break;
1461  }
1462  case MKTAG('E', 'X', 'I', 'F'): {
1463  int le, ifd_offset, exif_offset = bytestream2_tell(&gb);
1464  AVDictionary *exif_metadata = NULL;
1465  GetByteContext exif_gb;
1466 
1467  if (s->has_exif) {
1468  av_log(avctx, AV_LOG_VERBOSE, "Ignoring extra EXIF chunk\n");
1469  goto exif_end;
1470  }
1471  if (!(vp8x_flags & VP8X_FLAG_EXIF_METADATA))
1472  av_log(avctx, AV_LOG_WARNING,
1473  "EXIF chunk present, but Exif bit not set in the "
1474  "VP8X header\n");
1475 
1476  s->has_exif = 1;
1477  bytestream2_init(&exif_gb, avpkt->data + exif_offset,
1478  avpkt->size - exif_offset);
1479  if (ff_tdecode_header(&exif_gb, &le, &ifd_offset) < 0) {
1480  av_log(avctx, AV_LOG_ERROR, "invalid TIFF header "
1481  "in Exif data\n");
1482  goto exif_end;
1483  }
1484 
1485  bytestream2_seek(&exif_gb, ifd_offset, SEEK_SET);
1486  if (avpriv_exif_decode_ifd(avctx, &exif_gb, le, 0, &exif_metadata) < 0) {
1487  av_log(avctx, AV_LOG_ERROR, "error decoding Exif data\n");
1488  goto exif_end;
1489  }
1490 
1491  av_dict_copy(avpriv_frame_get_metadatap(data), exif_metadata, 0);
1492 
1493 exif_end:
1494  av_dict_free(&exif_metadata);
1495  bytestream2_skip(&gb, chunk_size);
1496  break;
1497  }
1498  case MKTAG('I', 'C', 'C', 'P'):
1499  case MKTAG('A', 'N', 'I', 'M'):
1500  case MKTAG('A', 'N', 'M', 'F'):
1501  case MKTAG('X', 'M', 'P', ' '):
1502  AV_WL32(chunk_str, chunk_type);
1503  av_log(avctx, AV_LOG_WARNING, "skipping unsupported chunk: %s\n",
1504  chunk_str);
1505  bytestream2_skip(&gb, chunk_size);
1506  break;
1507  default:
1508  AV_WL32(chunk_str, chunk_type);
1509  av_log(avctx, AV_LOG_VERBOSE, "skipping unknown chunk: %s\n",
1510  chunk_str);
1511  bytestream2_skip(&gb, chunk_size);
1512  break;
1513  }
1514  }
1515 
1516  if (!*got_frame) {
1517  av_log(avctx, AV_LOG_ERROR, "image data not found\n");
1518  return AVERROR_INVALIDDATA;
1519  }
1520 
1521  return avpkt->size;
1522 }
1523 
1525 {
1526  WebPContext *s = avctx->priv_data;
1527 
1528  if (s->initialized)
1529  return ff_vp8_decode_free(avctx);
1530 
1531  return 0;
1532 }
1533 
1535  .name = "webp",
1536  .long_name = NULL_IF_CONFIG_SMALL("WebP image"),
1537  .type = AVMEDIA_TYPE_VIDEO,
1538  .id = AV_CODEC_ID_WEBP,
1539  .priv_data_size = sizeof(WebPContext),
1541  .close = webp_decode_close,
1542  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1543 };
int nb_huffman_groups
Definition: webp.c:181
#define extra_bits(eb)
Definition: intrax8.c:159
static int read_huffman_code_normal(WebPContext *s, HuffReader *hc, int alphabet_size)
Definition: webp.c:359
enum ImageRole role
Definition: webp.c:177
#define NULL
Definition: coverity.c:32
HuffReader * huffman_groups
Definition: webp.c:182
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
TransformType
Definition: webp.c:109
static void inv_predict_10(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:872
float re
Definition: fft.c:73
ImageRole
Definition: webp.c:147
misc image utilities
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:247
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:210
int initialized
Definition: webp.c:192
static int parse_transform_color_indexing(WebPContext *s)
Definition: webp.c:527
static HuffReader * get_huffman_group(WebPContext *s, ImageContext *img, int x, int y)
Definition: webp.c:562
HuffmanIndex
Definition: webp.c:133
static const uint8_t code_length_code_order[NUM_CODE_LENGTH_CODES]
Definition: webp.c:75
int size
Definition: avcodec.h:1581
const char * b
Definition: vf_curves.c:109
#define VP8X_FLAG_EXIF_METADATA
Definition: webp.c:55
static void inv_predict_11(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:882
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1877
static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb)
Definition: webp.c:271
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:216
GetBitContext gb
Definition: webp.c:189
static int8_t ff_u8_to_s8(uint8_t a)
Definition: mathops.h:242
static const inv_predict_func inverse_predict[14]
Definition: webp.c:925
static AVPacket pkt
static int apply_color_indexing_transform(WebPContext *s)
Definition: webp.c:1030
AVCodec.
Definition: avcodec.h:3542
EXIF metadata parser.
#define AV_COPY32(d, s)
Definition: intreadwrite.h:586
AlphaCompression
Definition: webp.c:97
static av_always_inline uint8_t clamp_add_subtract_half(int a, int b, int c)
Definition: webp.c:905
enum TransformType transforms[4]
Definition: webp.c:204
uint16_t simple_symbols[2]
Definition: webp.c:173
int height
Definition: webp.c:200
static int vp8_lossy_decode_alpha(AVCodecContext *avctx, AVFrame *p, uint8_t *data_start, unsigned int data_size)
Definition: webp.c:1265
#define NUM_LITERAL_CODES
Definition: webp.c:63
#define img
static av_always_inline void color_cache_put(ImageContext *img, uint32_t c)
Definition: webp.c:579
enum AlphaFilter alpha_filter
Definition: webp.c:195
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
static void inv_predict_9(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:862
uint8_t * alpha_data
Definition: webp.c:196
#define NUM_CODE_LENGTH_CODES
Definition: webp.c:61
int reduced_width
Definition: webp.c:205
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
int nb_huffman_groups
Definition: webp.c:206
uint8_t bits
Definition: crc.c:296
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:140
int nb_symbols
Definition: webp.c:172
Multithreading support functions.
int ff_vp8_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: vp8.c:2683
#define FF_CODEC_PROPERTY_LOSSLESS
Definition: avcodec.h:3472
int simple
Definition: webp.c:171
static void inv_predict_12(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:896
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:87
static AVFrame * frame
#define NUM_SHORT_DISTANCES
Definition: webp.c:66
int pt
Definition: rtp.c:35
static void finish(void)
Definition: movenc.c:338
uint8_t * data
Definition: avcodec.h:1580
bitstream reader API header.
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static int decode_entropy_image(WebPContext *s)
Definition: webp.c:461
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
unsigned m
Definition: audioconvert.c:187
static void inv_predict_1(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:794
#define U(x)
Definition: vp56_arith.h:37
static int apply_color_transform(WebPContext *s)
Definition: webp.c:991
#define VP8X_FLAG_ALPHA
Definition: webp.c:56
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:160
int width
width and height of the video frame
Definition: frame.h:236
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int webp_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: webp.c:1353
static void inv_predict_6(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:832
#define init_vlc(vlc, nb_bits, nb_codes,bits, bits_wrap, bits_size,codes, codes_wrap, codes_size,flags)
Definition: vlc.h:38
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:153
static const struct endianess table[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
const uint8_t ff_reverse[256]
Definition: reverse.c:23
const char * r
Definition: vf_curves.c:107
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:263
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:202
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
int avpriv_exif_decode_ifd(void *logctx, GetByteContext *gbytes, int le, int depth, AVDictionary **metadata)
Recursively decodes all IFD's and adds included TAGS into the metadata dictionary.
Definition: exif.c:122
Definition: graph2dot.c:48
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3549
static void inv_predict_3(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:808
int has_exif
Definition: webp.c:198
VP8Context v
Definition: webp.c:188
static int vp8_lossy_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, uint8_t *data_start, unsigned int data_size)
Definition: webp.c:1318
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define CLOSE_READER(name, gb)
Definition: get_bits.h:131
#define FFMAX(a, b)
Definition: common.h:94
static int vp8_lossless_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, uint8_t *data_start, unsigned int data_size, int is_alpha_chunk)
Definition: webp.c:1101
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:93
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1019
enum AlphaCompression alpha_compression
Definition: webp.c:194
static void image_ctx_free(ImageContext *img)
Definition: webp.c:216
Definition: vlc.h:26
#define SKIP_BITS(name, gb, num)
Definition: get_bits.h:175
static float distance(float x, float y, int band)
static av_always_inline int webp_get_vlc(GetBitContext *gb, VLC_TYPE(*table)[2])
Definition: webp.c:239
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:251
#define PARSE_BLOCK_SIZE(w, h)
Definition: webp.c:455
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:258
static void inv_predict_2(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:801
#define width
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
uint32_t * color_cache
Definition: webp.c:180
AlphaFilter
Definition: webp.c:102
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
AVFrame * frame
Definition: webp.c:178
#define LAST_SKIP_BITS(name, gb, num)
Definition: get_bits.h:181
int n
Definition: avisynth_c.h:547
int has_alpha
Definition: webp.c:193
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:193
uint8_t le
Definition: crc.c:295
void(* inv_predict_func)(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:921
PredictionMode
Definition: webp.c:116
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:248
static const int8_t transform[32][32]
Definition: hevcdsp.c:27
int alpha_data_size
Definition: webp.c:197
Libavcodec external API header.
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:46
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:437
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, int alphabet_size)
Definition: webp.c:282
main external API structure.
Definition: avcodec.h:1649
#define OPEN_READER(name, gb)
Definition: get_bits.h:120
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
static av_always_inline uint8_t color_transform_delta(uint8_t color_pred, uint8_t color)
Definition: webp.c:985
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:292
#define AV_WB32(p, v)
Definition: intreadwrite.h:419
int index
Definition: gxfenc.c:89
AVCodec ff_webp_decoder
Definition: webp.c:1534
static void inv_predict_4(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:815
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:406
static void inv_predict_0(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:787
#define MAX_HUFFMAN_CODE_LENGTH
Definition: webp.c:67
int size_reduction
Definition: webp.c:183
static const uint16_t alphabet_sizes[HUFFMAN_CODES_PER_META_CODE]
Definition: webp.c:69
#define HUFFMAN_CODES_PER_META_CODE
Definition: webp.c:62
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:270
static void read_huffman_code_simple(WebPContext *s, HuffReader *hc)
Definition: webp.c:344
av_cold int ff_vp8_decode_init(AVCodecContext *avctx)
Definition: vp8.c:2767
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
av_cold int ff_vp8_decode_free(AVCodecContext *avctx)
Definition: vp8.c:2697
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:722
int palette
Definition: v4l.c:61
static int parse_transform_predictor(WebPContext *s)
Definition: webp.c:495
#define GET_PIXEL(frame, x, y)
Definition: webp.c:210
static av_cold int webp_decode_close(AVCodecContext *avctx)
Definition: webp.c:1524
int nb_transforms
Definition: webp.c:203
common internal api header.
static int apply_subtract_green_transform(WebPContext *s)
Definition: webp.c:1015
static double c[64]
int is_alpha_primary
Definition: webp.c:184
#define GET_PIXEL_COMP(frame, x, y, c)
Definition: webp.c:213
static void inv_predict_8(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:852
unsigned properties
Definition: avcodec.h:3471
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
void * priv_data
Definition: avcodec.h:1691
static const int8_t lz77_distance_offsets[NUM_SHORT_DISTANCES][2]
Definition: webp.c:79
ImageContext image[IMAGE_ROLE_NB]
Definition: webp.c:207
int width
Definition: webp.c:199
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static int apply_predictor_transform(WebPContext *s)
Definition: webp.c:954
#define av_free(p)
VLC vlc
Definition: webp.c:170
int len
int color_cache_bits
Definition: webp.c:179
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static int parse_transform_color(WebPContext *s)
Definition: webp.c:511
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:253
static void inv_predict_7(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:842
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:208
static int decode_entropy_coded_image(WebPContext *s, enum ImageRole role, int w, int h)
Definition: webp.c:585
static void inv_predict_13(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:912
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset)
Decodes a TIFF header from the input bytestream and sets the endianness in *le and the offset to the ...
Definition: tiff_common.c:261
AVCodecContext * avctx
Definition: webp.c:191
int height
Definition: frame.h:236
static void alpha_inverse_prediction(AVFrame *frame, enum AlphaFilter m)
Definition: webp.c:1222
#define av_always_inline
Definition: attributes.h:39
#define VLC_TYPE
Definition: vlc.h:24
#define av_malloc_array(a, b)
int lossless
Definition: webp.c:201
static void inverse_prediction(AVFrame *frame, enum PredictionMode m, int x, int y)
Definition: webp.c:932
#define MKTAG(a, b, c, d)
Definition: common.h:342
This structure stores compressed data.
Definition: avcodec.h:1557
AVFrame * alpha_frame
Definition: webp.c:190
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:360
static void inv_predict_5(uint8_t *p, const uint8_t *p_l, const uint8_t *p_tl, const uint8_t *p_t, const uint8_t *p_tr)
Definition: webp.c:822
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:956
#define NUM_LENGTH_CODES
Definition: webp.c:64
#define NUM_DISTANCE_CODES
Definition: webp.c:65
#define AV_WL32(p, v)
Definition: intreadwrite.h:426