FFmpeg  4.3
exr.c
Go to the documentation of this file.
1 /*
2  * OpenEXR (.exr) image decoder
3  * Copyright (c) 2006 Industrial Light & Magic, a division of Lucas Digital Ltd. LLC
4  * Copyright (c) 2009 Jimmy Christensen
5  *
6  * B44/B44A, Tile, UINT32 added by Jokyo Images support by CNC - French National Center for Cinema
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 /**
26  * @file
27  * OpenEXR decoder
28  * @author Jimmy Christensen
29  *
30  * For more information on the OpenEXR format, visit:
31  * http://openexr.com/
32  *
33  * exr_half2float() is credited to Aaftab Munshi, Dan Ginsburg, Dave Shreiner.
34  */
35 
36 #include <float.h>
37 #include <zlib.h>
38 
39 #include "libavutil/avassert.h"
40 #include "libavutil/common.h"
41 #include "libavutil/imgutils.h"
42 #include "libavutil/intfloat.h"
43 #include "libavutil/avstring.h"
44 #include "libavutil/opt.h"
45 #include "libavutil/color_utils.h"
46 
47 #include "avcodec.h"
48 #include "bytestream.h"
49 
50 #if HAVE_BIGENDIAN
51 #include "bswapdsp.h"
52 #endif
53 
54 #include "exrdsp.h"
55 #include "get_bits.h"
56 #include "internal.h"
57 #include "mathops.h"
58 #include "thread.h"
59 
60 enum ExrCompr {
72 };
73 
79 };
80 
86 };
87 
92 };
93 
94 typedef struct EXRChannel {
95  int xsub, ysub;
97 } EXRChannel;
98 
99 typedef struct EXRTileAttribute {
105 
106 typedef struct EXRThreadData {
109 
111  int tmp_size;
112 
114  uint16_t *lut;
115 
116  int ysize, xsize;
117 
119 } EXRThreadData;
120 
121 typedef struct EXRContext {
122  AVClass *class;
126 
127 #if HAVE_BIGENDIAN
128  BswapDSPContext bbdsp;
129 #endif
130 
133  int channel_offsets[4]; // 0 = red, 1 = green, 2 = blue and 3 = alpha
135 
136  int w, h;
137  uint32_t xmax, xmin;
138  uint32_t ymax, ymin;
139  uint32_t xdelta, ydelta;
140 
142 
143  EXRTileAttribute tile_attr; /* header data attribute of tile */
144  int is_tile; /* 0 if scanline, 1 if tile */
145 
146  int is_luma;/* 1 if there is an Y plane */
147 
149  const uint8_t *buf;
150  int buf_size;
151 
155 
157 
158  const char *layer;
159 
161  float gamma;
163 } EXRContext;
164 
165 /* -15 stored using a single precision bias of 127 */
166 #define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP 0x38000000
167 
168 /* max exponent value in single precision that will be converted
169  * to Inf or Nan when stored as a half-float */
170 #define HALF_FLOAT_MAX_BIASED_EXP_AS_SINGLE_FP_EXP 0x47800000
171 
172 /* 255 is the max exponent biased value */
173 #define FLOAT_MAX_BIASED_EXP (0xFF << 23)
174 
175 #define HALF_FLOAT_MAX_BIASED_EXP (0x1F << 10)
176 
177 /**
178  * Convert a half float as a uint16_t into a full float.
179  *
180  * @param hf half float as uint16_t
181  *
182  * @return float value
183  */
184 static union av_intfloat32 exr_half2float(uint16_t hf)
185 {
186  unsigned int sign = (unsigned int) (hf >> 15);
187  unsigned int mantissa = (unsigned int) (hf & ((1 << 10) - 1));
188  unsigned int exp = (unsigned int) (hf & HALF_FLOAT_MAX_BIASED_EXP);
189  union av_intfloat32 f;
190 
192  // we have a half-float NaN or Inf
193  // half-float NaNs will be converted to a single precision NaN
194  // half-float Infs will be converted to a single precision Inf
196  if (mantissa)
197  mantissa = (1 << 23) - 1; // set all bits to indicate a NaN
198  } else if (exp == 0x0) {
199  // convert half-float zero/denorm to single precision value
200  if (mantissa) {
201  mantissa <<= 1;
203  // check for leading 1 in denorm mantissa
204  while ((mantissa & (1 << 10))) {
205  // for every leading 0, decrement single precision exponent by 1
206  // and shift half-float mantissa value to the left
207  mantissa <<= 1;
208  exp -= (1 << 23);
209  }
210  // clamp the mantissa to 10 bits
211  mantissa &= ((1 << 10) - 1);
212  // shift left to generate single-precision mantissa of 23 bits
213  mantissa <<= 13;
214  }
215  } else {
216  // shift left to generate single-precision mantissa of 23 bits
217  mantissa <<= 13;
218  // generate single precision biased exponent value
220  }
221 
222  f.i = (sign << 31) | exp | mantissa;
223 
224  return f;
225 }
226 
227 static int zip_uncompress(EXRContext *s, const uint8_t *src, int compressed_size,
228  int uncompressed_size, EXRThreadData *td)
229 {
230  unsigned long dest_len = uncompressed_size;
231 
232  if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK ||
233  dest_len != uncompressed_size)
234  return AVERROR_INVALIDDATA;
235 
236  av_assert1(uncompressed_size % 2 == 0);
237 
238  s->dsp.predictor(td->tmp, uncompressed_size);
239  s->dsp.reorder_pixels(td->uncompressed_data, td->tmp, uncompressed_size);
240 
241  return 0;
242 }
243 
244 static int rle_uncompress(EXRContext *ctx, const uint8_t *src, int compressed_size,
245  int uncompressed_size, EXRThreadData *td)
246 {
247  uint8_t *d = td->tmp;
248  const int8_t *s = src;
249  int ssize = compressed_size;
250  int dsize = uncompressed_size;
251  uint8_t *dend = d + dsize;
252  int count;
253 
254  while (ssize > 0) {
255  count = *s++;
256 
257  if (count < 0) {
258  count = -count;
259 
260  if ((dsize -= count) < 0 ||
261  (ssize -= count + 1) < 0)
262  return AVERROR_INVALIDDATA;
263 
264  while (count--)
265  *d++ = *s++;
266  } else {
267  count++;
268 
269  if ((dsize -= count) < 0 ||
270  (ssize -= 2) < 0)
271  return AVERROR_INVALIDDATA;
272 
273  while (count--)
274  *d++ = *s;
275 
276  s++;
277  }
278  }
279 
280  if (dend != d)
281  return AVERROR_INVALIDDATA;
282 
283  av_assert1(uncompressed_size % 2 == 0);
284 
285  ctx->dsp.predictor(td->tmp, uncompressed_size);
286  ctx->dsp.reorder_pixels(td->uncompressed_data, td->tmp, uncompressed_size);
287 
288  return 0;
289 }
290 
291 #define USHORT_RANGE (1 << 16)
292 #define BITMAP_SIZE (1 << 13)
293 
294 static uint16_t reverse_lut(const uint8_t *bitmap, uint16_t *lut)
295 {
296  int i, k = 0;
297 
298  for (i = 0; i < USHORT_RANGE; i++)
299  if ((i == 0) || (bitmap[i >> 3] & (1 << (i & 7))))
300  lut[k++] = i;
301 
302  i = k - 1;
303 
304  memset(lut + k, 0, (USHORT_RANGE - k) * 2);
305 
306  return i;
307 }
308 
309 static void apply_lut(const uint16_t *lut, uint16_t *dst, int dsize)
310 {
311  int i;
312 
313  for (i = 0; i < dsize; ++i)
314  dst[i] = lut[dst[i]];
315 }
316 
317 #define HUF_ENCBITS 16 // literal (value) bit length
318 #define HUF_DECBITS 14 // decoding bit size (>= 8)
319 
320 #define HUF_ENCSIZE ((1 << HUF_ENCBITS) + 1) // encoding table size
321 #define HUF_DECSIZE (1 << HUF_DECBITS) // decoding table size
322 #define HUF_DECMASK (HUF_DECSIZE - 1)
323 
324 typedef struct HufDec {
325  int len;
326  int lit;
327  int *p;
328 } HufDec;
329 
330 static void huf_canonical_code_table(uint64_t *hcode)
331 {
332  uint64_t c, n[59] = { 0 };
333  int i;
334 
335  for (i = 0; i < HUF_ENCSIZE; ++i)
336  n[hcode[i]] += 1;
337 
338  c = 0;
339  for (i = 58; i > 0; --i) {
340  uint64_t nc = ((c + n[i]) >> 1);
341  n[i] = c;
342  c = nc;
343  }
344 
345  for (i = 0; i < HUF_ENCSIZE; ++i) {
346  int l = hcode[i];
347 
348  if (l > 0)
349  hcode[i] = l | (n[l]++ << 6);
350  }
351 }
352 
353 #define SHORT_ZEROCODE_RUN 59
354 #define LONG_ZEROCODE_RUN 63
355 #define SHORTEST_LONG_RUN (2 + LONG_ZEROCODE_RUN - SHORT_ZEROCODE_RUN)
356 #define LONGEST_LONG_RUN (255 + SHORTEST_LONG_RUN)
357 
359  int32_t im, int32_t iM, uint64_t *hcode)
360 {
361  GetBitContext gbit;
362  int ret = init_get_bits8(&gbit, gb->buffer, bytestream2_get_bytes_left(gb));
363  if (ret < 0)
364  return ret;
365 
366  for (; im <= iM; im++) {
367  uint64_t l = hcode[im] = get_bits(&gbit, 6);
368 
369  if (l == LONG_ZEROCODE_RUN) {
370  int zerun = get_bits(&gbit, 8) + SHORTEST_LONG_RUN;
371 
372  if (im + zerun > iM + 1)
373  return AVERROR_INVALIDDATA;
374 
375  while (zerun--)
376  hcode[im++] = 0;
377 
378  im--;
379  } else if (l >= SHORT_ZEROCODE_RUN) {
380  int zerun = l - SHORT_ZEROCODE_RUN + 2;
381 
382  if (im + zerun > iM + 1)
383  return AVERROR_INVALIDDATA;
384 
385  while (zerun--)
386  hcode[im++] = 0;
387 
388  im--;
389  }
390  }
391 
392  bytestream2_skip(gb, (get_bits_count(&gbit) + 7) / 8);
394 
395  return 0;
396 }
397 
398 static int huf_build_dec_table(const uint64_t *hcode, int im,
399  int iM, HufDec *hdecod)
400 {
401  for (; im <= iM; im++) {
402  uint64_t c = hcode[im] >> 6;
403  int i, l = hcode[im] & 63;
404 
405  if (c >> l)
406  return AVERROR_INVALIDDATA;
407 
408  if (l > HUF_DECBITS) {
409  HufDec *pl = hdecod + (c >> (l - HUF_DECBITS));
410  if (pl->len)
411  return AVERROR_INVALIDDATA;
412 
413  pl->lit++;
414 
415  pl->p = av_realloc(pl->p, pl->lit * sizeof(int));
416  if (!pl->p)
417  return AVERROR(ENOMEM);
418 
419  pl->p[pl->lit - 1] = im;
420  } else if (l) {
421  HufDec *pl = hdecod + (c << (HUF_DECBITS - l));
422 
423  for (i = 1 << (HUF_DECBITS - l); i > 0; i--, pl++) {
424  if (pl->len || pl->p)
425  return AVERROR_INVALIDDATA;
426  pl->len = l;
427  pl->lit = im;
428  }
429  }
430  }
431 
432  return 0;
433 }
434 
435 #define get_char(c, lc, gb) \
436 { \
437  c = (c << 8) | bytestream2_get_byte(gb); \
438  lc += 8; \
439 }
440 
441 #define get_code(po, rlc, c, lc, gb, out, oe, outb) \
442 { \
443  if (po == rlc) { \
444  if (lc < 8) \
445  get_char(c, lc, gb); \
446  lc -= 8; \
447  \
448  cs = c >> lc; \
449  \
450  if (out + cs > oe || out == outb) \
451  return AVERROR_INVALIDDATA; \
452  \
453  s = out[-1]; \
454  \
455  while (cs-- > 0) \
456  *out++ = s; \
457  } else if (out < oe) { \
458  *out++ = po; \
459  } else { \
460  return AVERROR_INVALIDDATA; \
461  } \
462 }
463 
464 static int huf_decode(const uint64_t *hcode, const HufDec *hdecod,
465  GetByteContext *gb, int nbits,
466  int rlc, int no, uint16_t *out)
467 {
468  uint64_t c = 0;
469  uint16_t *outb = out;
470  uint16_t *oe = out + no;
471  const uint8_t *ie = gb->buffer + (nbits + 7) / 8; // input byte size
472  uint8_t cs;
473  uint16_t s;
474  int i, lc = 0;
475 
476  while (gb->buffer < ie) {
477  get_char(c, lc, gb);
478 
479  while (lc >= HUF_DECBITS) {
480  const HufDec pl = hdecod[(c >> (lc - HUF_DECBITS)) & HUF_DECMASK];
481 
482  if (pl.len) {
483  lc -= pl.len;
484  get_code(pl.lit, rlc, c, lc, gb, out, oe, outb);
485  } else {
486  int j;
487 
488  if (!pl.p)
489  return AVERROR_INVALIDDATA;
490 
491  for (j = 0; j < pl.lit; j++) {
492  int l = hcode[pl.p[j]] & 63;
493 
494  while (lc < l && bytestream2_get_bytes_left(gb) > 0)
495  get_char(c, lc, gb);
496 
497  if (lc >= l) {
498  if ((hcode[pl.p[j]] >> 6) ==
499  ((c >> (lc - l)) & ((1LL << l) - 1))) {
500  lc -= l;
501  get_code(pl.p[j], rlc, c, lc, gb, out, oe, outb);
502  break;
503  }
504  }
505  }
506 
507  if (j == pl.lit)
508  return AVERROR_INVALIDDATA;
509  }
510  }
511  }
512 
513  i = (8 - nbits) & 7;
514  c >>= i;
515  lc -= i;
516 
517  while (lc > 0) {
518  const HufDec pl = hdecod[(c << (HUF_DECBITS - lc)) & HUF_DECMASK];
519 
520  if (pl.len && lc >= pl.len) {
521  lc -= pl.len;
522  get_code(pl.lit, rlc, c, lc, gb, out, oe, outb);
523  } else {
524  return AVERROR_INVALIDDATA;
525  }
526  }
527 
528  if (out - outb != no)
529  return AVERROR_INVALIDDATA;
530  return 0;
531 }
532 
534  uint16_t *dst, int dst_size)
535 {
536  int32_t src_size, im, iM;
537  uint32_t nBits;
538  uint64_t *freq;
539  HufDec *hdec;
540  int ret, i;
541 
542  src_size = bytestream2_get_le32(gb);
543  im = bytestream2_get_le32(gb);
544  iM = bytestream2_get_le32(gb);
545  bytestream2_skip(gb, 4);
546  nBits = bytestream2_get_le32(gb);
547  if (im < 0 || im >= HUF_ENCSIZE ||
548  iM < 0 || iM >= HUF_ENCSIZE ||
549  src_size < 0)
550  return AVERROR_INVALIDDATA;
551 
552  bytestream2_skip(gb, 4);
553 
554  freq = av_mallocz_array(HUF_ENCSIZE, sizeof(*freq));
555  hdec = av_mallocz_array(HUF_DECSIZE, sizeof(*hdec));
556  if (!freq || !hdec) {
557  ret = AVERROR(ENOMEM);
558  goto fail;
559  }
560 
561  if ((ret = huf_unpack_enc_table(gb, im, iM, freq)) < 0)
562  goto fail;
563 
564  if (nBits > 8 * bytestream2_get_bytes_left(gb)) {
566  goto fail;
567  }
568 
569  if ((ret = huf_build_dec_table(freq, im, iM, hdec)) < 0)
570  goto fail;
571  ret = huf_decode(freq, hdec, gb, nBits, iM, dst_size, dst);
572 
573 fail:
574  for (i = 0; i < HUF_DECSIZE; i++)
575  if (hdec)
576  av_freep(&hdec[i].p);
577 
578  av_free(freq);
579  av_free(hdec);
580 
581  return ret;
582 }
583 
584 static inline void wdec14(uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
585 {
586  int16_t ls = l;
587  int16_t hs = h;
588  int hi = hs;
589  int ai = ls + (hi & 1) + (hi >> 1);
590  int16_t as = ai;
591  int16_t bs = ai - hi;
592 
593  *a = as;
594  *b = bs;
595 }
596 
597 #define NBITS 16
598 #define A_OFFSET (1 << (NBITS - 1))
599 #define MOD_MASK ((1 << NBITS) - 1)
600 
601 static inline void wdec16(uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
602 {
603  int m = l;
604  int d = h;
605  int bb = (m - (d >> 1)) & MOD_MASK;
606  int aa = (d + bb - A_OFFSET) & MOD_MASK;
607  *b = bb;
608  *a = aa;
609 }
610 
611 static void wav_decode(uint16_t *in, int nx, int ox,
612  int ny, int oy, uint16_t mx)
613 {
614  int w14 = (mx < (1 << 14));
615  int n = (nx > ny) ? ny : nx;
616  int p = 1;
617  int p2;
618 
619  while (p <= n)
620  p <<= 1;
621 
622  p >>= 1;
623  p2 = p;
624  p >>= 1;
625 
626  while (p >= 1) {
627  uint16_t *py = in;
628  uint16_t *ey = in + oy * (ny - p2);
629  uint16_t i00, i01, i10, i11;
630  int oy1 = oy * p;
631  int oy2 = oy * p2;
632  int ox1 = ox * p;
633  int ox2 = ox * p2;
634 
635  for (; py <= ey; py += oy2) {
636  uint16_t *px = py;
637  uint16_t *ex = py + ox * (nx - p2);
638 
639  for (; px <= ex; px += ox2) {
640  uint16_t *p01 = px + ox1;
641  uint16_t *p10 = px + oy1;
642  uint16_t *p11 = p10 + ox1;
643 
644  if (w14) {
645  wdec14(*px, *p10, &i00, &i10);
646  wdec14(*p01, *p11, &i01, &i11);
647  wdec14(i00, i01, px, p01);
648  wdec14(i10, i11, p10, p11);
649  } else {
650  wdec16(*px, *p10, &i00, &i10);
651  wdec16(*p01, *p11, &i01, &i11);
652  wdec16(i00, i01, px, p01);
653  wdec16(i10, i11, p10, p11);
654  }
655  }
656 
657  if (nx & p) {
658  uint16_t *p10 = px + oy1;
659 
660  if (w14)
661  wdec14(*px, *p10, &i00, p10);
662  else
663  wdec16(*px, *p10, &i00, p10);
664 
665  *px = i00;
666  }
667  }
668 
669  if (ny & p) {
670  uint16_t *px = py;
671  uint16_t *ex = py + ox * (nx - p2);
672 
673  for (; px <= ex; px += ox2) {
674  uint16_t *p01 = px + ox1;
675 
676  if (w14)
677  wdec14(*px, *p01, &i00, p01);
678  else
679  wdec16(*px, *p01, &i00, p01);
680 
681  *px = i00;
682  }
683  }
684 
685  p2 = p;
686  p >>= 1;
687  }
688 }
689 
690 static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize,
691  int dsize, EXRThreadData *td)
692 {
693  GetByteContext gb;
694  uint16_t maxval, min_non_zero, max_non_zero;
695  uint16_t *ptr;
696  uint16_t *tmp = (uint16_t *)td->tmp;
697  uint16_t *out;
698  uint16_t *in;
699  int ret, i, j;
700  int pixel_half_size;/* 1 for half, 2 for float and uint32 */
702  int tmp_offset;
703 
704  if (!td->bitmap)
705  td->bitmap = av_malloc(BITMAP_SIZE);
706  if (!td->lut)
707  td->lut = av_malloc(1 << 17);
708  if (!td->bitmap || !td->lut) {
709  av_freep(&td->bitmap);
710  av_freep(&td->lut);
711  return AVERROR(ENOMEM);
712  }
713 
714  bytestream2_init(&gb, src, ssize);
715  min_non_zero = bytestream2_get_le16(&gb);
716  max_non_zero = bytestream2_get_le16(&gb);
717 
718  if (max_non_zero >= BITMAP_SIZE)
719  return AVERROR_INVALIDDATA;
720 
721  memset(td->bitmap, 0, FFMIN(min_non_zero, BITMAP_SIZE));
722  if (min_non_zero <= max_non_zero)
723  bytestream2_get_buffer(&gb, td->bitmap + min_non_zero,
724  max_non_zero - min_non_zero + 1);
725  memset(td->bitmap + max_non_zero + 1, 0, BITMAP_SIZE - max_non_zero - 1);
726 
727  maxval = reverse_lut(td->bitmap, td->lut);
728 
729  ret = huf_uncompress(&gb, tmp, dsize / sizeof(uint16_t));
730  if (ret)
731  return ret;
732 
733  ptr = tmp;
734  for (i = 0; i < s->nb_channels; i++) {
735  channel = &s->channels[i];
736 
737  if (channel->pixel_type == EXR_HALF)
738  pixel_half_size = 1;
739  else
740  pixel_half_size = 2;
741 
742  for (j = 0; j < pixel_half_size; j++)
743  wav_decode(ptr + j, td->xsize, pixel_half_size, td->ysize,
744  td->xsize * pixel_half_size, maxval);
745  ptr += td->xsize * td->ysize * pixel_half_size;
746  }
747 
748  apply_lut(td->lut, tmp, dsize / sizeof(uint16_t));
749 
750  out = (uint16_t *)td->uncompressed_data;
751  for (i = 0; i < td->ysize; i++) {
752  tmp_offset = 0;
753  for (j = 0; j < s->nb_channels; j++) {
754  channel = &s->channels[j];
755  if (channel->pixel_type == EXR_HALF)
756  pixel_half_size = 1;
757  else
758  pixel_half_size = 2;
759 
760  in = tmp + tmp_offset * td->xsize * td->ysize + i * td->xsize * pixel_half_size;
761  tmp_offset += pixel_half_size;
762 
763 #if HAVE_BIGENDIAN
764  s->bbdsp.bswap16_buf(out, in, td->xsize * pixel_half_size);
765 #else
766  memcpy(out, in, td->xsize * 2 * pixel_half_size);
767 #endif
768  out += td->xsize * pixel_half_size;
769  }
770  }
771 
772  return 0;
773 }
774 
776  int compressed_size, int uncompressed_size,
777  EXRThreadData *td)
778 {
779  unsigned long dest_len, expected_len = 0;
780  const uint8_t *in = td->tmp;
781  uint8_t *out;
782  int c, i, j;
783 
784  for (i = 0; i < s->nb_channels; i++) {
785  if (s->channels[i].pixel_type == EXR_FLOAT) {
786  expected_len += (td->xsize * td->ysize * 3);/* PRX 24 store float in 24 bit instead of 32 */
787  } else if (s->channels[i].pixel_type == EXR_HALF) {
788  expected_len += (td->xsize * td->ysize * 2);
789  } else {//UINT 32
790  expected_len += (td->xsize * td->ysize * 4);
791  }
792  }
793 
794  dest_len = expected_len;
795 
796  if (uncompress(td->tmp, &dest_len, src, compressed_size) != Z_OK) {
797  return AVERROR_INVALIDDATA;
798  } else if (dest_len != expected_len) {
799  return AVERROR_INVALIDDATA;
800  }
801 
802  out = td->uncompressed_data;
803  for (i = 0; i < td->ysize; i++)
804  for (c = 0; c < s->nb_channels; c++) {
805  EXRChannel *channel = &s->channels[c];
806  const uint8_t *ptr[4];
807  uint32_t pixel = 0;
808 
809  switch (channel->pixel_type) {
810  case EXR_FLOAT:
811  ptr[0] = in;
812  ptr[1] = ptr[0] + td->xsize;
813  ptr[2] = ptr[1] + td->xsize;
814  in = ptr[2] + td->xsize;
815 
816  for (j = 0; j < td->xsize; ++j) {
817  uint32_t diff = ((unsigned)*(ptr[0]++) << 24) |
818  (*(ptr[1]++) << 16) |
819  (*(ptr[2]++) << 8);
820  pixel += diff;
821  bytestream_put_le32(&out, pixel);
822  }
823  break;
824  case EXR_HALF:
825  ptr[0] = in;
826  ptr[1] = ptr[0] + td->xsize;
827  in = ptr[1] + td->xsize;
828  for (j = 0; j < td->xsize; j++) {
829  uint32_t diff = (*(ptr[0]++) << 8) | *(ptr[1]++);
830 
831  pixel += diff;
832  bytestream_put_le16(&out, pixel);
833  }
834  break;
835  case EXR_UINT:
836  ptr[0] = in;
837  ptr[1] = ptr[0] + s->xdelta;
838  ptr[2] = ptr[1] + s->xdelta;
839  ptr[3] = ptr[2] + s->xdelta;
840  in = ptr[3] + s->xdelta;
841 
842  for (j = 0; j < s->xdelta; ++j) {
843  uint32_t diff = ((uint32_t)*(ptr[0]++) << 24) |
844  (*(ptr[1]++) << 16) |
845  (*(ptr[2]++) << 8 ) |
846  (*(ptr[3]++));
847  pixel += diff;
848  bytestream_put_le32(&out, pixel);
849  }
850  break;
851  default:
852  return AVERROR_INVALIDDATA;
853  }
854  }
855 
856  return 0;
857 }
858 
859 static void unpack_14(const uint8_t b[14], uint16_t s[16])
860 {
861  unsigned short shift = (b[ 2] >> 2) & 15;
862  unsigned short bias = (0x20 << shift);
863  int i;
864 
865  s[ 0] = (b[0] << 8) | b[1];
866 
867  s[ 4] = s[ 0] + ((((b[ 2] << 4) | (b[ 3] >> 4)) & 0x3f) << shift) - bias;
868  s[ 8] = s[ 4] + ((((b[ 3] << 2) | (b[ 4] >> 6)) & 0x3f) << shift) - bias;
869  s[12] = s[ 8] + ((b[ 4] & 0x3f) << shift) - bias;
870 
871  s[ 1] = s[ 0] + ((b[ 5] >> 2) << shift) - bias;
872  s[ 5] = s[ 4] + ((((b[ 5] << 4) | (b[ 6] >> 4)) & 0x3f) << shift) - bias;
873  s[ 9] = s[ 8] + ((((b[ 6] << 2) | (b[ 7] >> 6)) & 0x3f) << shift) - bias;
874  s[13] = s[12] + ((b[ 7] & 0x3f) << shift) - bias;
875 
876  s[ 2] = s[ 1] + ((b[ 8] >> 2) << shift) - bias;
877  s[ 6] = s[ 5] + ((((b[ 8] << 4) | (b[ 9] >> 4)) & 0x3f) << shift) - bias;
878  s[10] = s[ 9] + ((((b[ 9] << 2) | (b[10] >> 6)) & 0x3f) << shift) - bias;
879  s[14] = s[13] + ((b[10] & 0x3f) << shift) - bias;
880 
881  s[ 3] = s[ 2] + ((b[11] >> 2) << shift) - bias;
882  s[ 7] = s[ 6] + ((((b[11] << 4) | (b[12] >> 4)) & 0x3f) << shift) - bias;
883  s[11] = s[10] + ((((b[12] << 2) | (b[13] >> 6)) & 0x3f) << shift) - bias;
884  s[15] = s[14] + ((b[13] & 0x3f) << shift) - bias;
885 
886  for (i = 0; i < 16; ++i) {
887  if (s[i] & 0x8000)
888  s[i] &= 0x7fff;
889  else
890  s[i] = ~s[i];
891  }
892 }
893 
894 static void unpack_3(const uint8_t b[3], uint16_t s[16])
895 {
896  int i;
897 
898  s[0] = (b[0] << 8) | b[1];
899 
900  if (s[0] & 0x8000)
901  s[0] &= 0x7fff;
902  else
903  s[0] = ~s[0];
904 
905  for (i = 1; i < 16; i++)
906  s[i] = s[0];
907 }
908 
909 
910 static int b44_uncompress(EXRContext *s, const uint8_t *src, int compressed_size,
911  int uncompressed_size, EXRThreadData *td) {
912  const int8_t *sr = src;
913  int stay_to_uncompress = compressed_size;
914  int nb_b44_block_w, nb_b44_block_h;
915  int index_tl_x, index_tl_y, index_out, index_tmp;
916  uint16_t tmp_buffer[16]; /* B44 use 4x4 half float pixel */
917  int c, iY, iX, y, x;
918  int target_channel_offset = 0;
919 
920  /* calc B44 block count */
921  nb_b44_block_w = td->xsize / 4;
922  if ((td->xsize % 4) != 0)
923  nb_b44_block_w++;
924 
925  nb_b44_block_h = td->ysize / 4;
926  if ((td->ysize % 4) != 0)
927  nb_b44_block_h++;
928 
929  for (c = 0; c < s->nb_channels; c++) {
930  if (s->channels[c].pixel_type == EXR_HALF) {/* B44 only compress half float data */
931  for (iY = 0; iY < nb_b44_block_h; iY++) {
932  for (iX = 0; iX < nb_b44_block_w; iX++) {/* For each B44 block */
933  if (stay_to_uncompress < 3) {
934  av_log(s, AV_LOG_ERROR, "Not enough data for B44A block: %d", stay_to_uncompress);
935  return AVERROR_INVALIDDATA;
936  }
937 
938  if (src[compressed_size - stay_to_uncompress + 2] == 0xfc) { /* B44A block */
939  unpack_3(sr, tmp_buffer);
940  sr += 3;
941  stay_to_uncompress -= 3;
942  } else {/* B44 Block */
943  if (stay_to_uncompress < 14) {
944  av_log(s, AV_LOG_ERROR, "Not enough data for B44 block: %d", stay_to_uncompress);
945  return AVERROR_INVALIDDATA;
946  }
947  unpack_14(sr, tmp_buffer);
948  sr += 14;
949  stay_to_uncompress -= 14;
950  }
951 
952  /* copy data to uncompress buffer (B44 block can exceed target resolution)*/
953  index_tl_x = iX * 4;
954  index_tl_y = iY * 4;
955 
956  for (y = index_tl_y; y < FFMIN(index_tl_y + 4, td->ysize); y++) {
957  for (x = index_tl_x; x < FFMIN(index_tl_x + 4, td->xsize); x++) {
958  index_out = target_channel_offset * td->xsize + y * td->channel_line_size + 2 * x;
959  index_tmp = (y-index_tl_y) * 4 + (x-index_tl_x);
960  td->uncompressed_data[index_out] = tmp_buffer[index_tmp] & 0xff;
961  td->uncompressed_data[index_out + 1] = tmp_buffer[index_tmp] >> 8;
962  }
963  }
964  }
965  }
966  target_channel_offset += 2;
967  } else {/* Float or UINT 32 channel */
968  if (stay_to_uncompress < td->ysize * td->xsize * 4) {
969  av_log(s, AV_LOG_ERROR, "Not enough data for uncompress channel: %d", stay_to_uncompress);
970  return AVERROR_INVALIDDATA;
971  }
972 
973  for (y = 0; y < td->ysize; y++) {
974  index_out = target_channel_offset * td->xsize + y * td->channel_line_size;
975  memcpy(&td->uncompressed_data[index_out], sr, td->xsize * 4);
976  sr += td->xsize * 4;
977  }
978  target_channel_offset += 4;
979 
980  stay_to_uncompress -= td->ysize * td->xsize * 4;
981  }
982  }
983 
984  return 0;
985 }
986 
987 static int decode_block(AVCodecContext *avctx, void *tdata,
988  int jobnr, int threadnr)
989 {
990  EXRContext *s = avctx->priv_data;
991  AVFrame *const p = s->picture;
992  EXRThreadData *td = &s->thread_data[threadnr];
993  const uint8_t *channel_buffer[4] = { 0 };
994  const uint8_t *buf = s->buf;
995  uint64_t line_offset, uncompressed_size;
996  uint8_t *ptr;
997  uint32_t data_size;
998  uint64_t line, col = 0;
999  uint64_t tile_x, tile_y, tile_level_x, tile_level_y;
1000  const uint8_t *src;
1001  int step = s->desc->flags & AV_PIX_FMT_FLAG_FLOAT ? 4 : 2 * s->desc->nb_components;
1002  int axmax = (avctx->width - (s->xmax + 1)) * step; /* nb pixel to add at the right of the datawindow */
1003  int bxmin = s->xmin * step; /* nb pixel to add at the left of the datawindow */
1004  int i, x, buf_size = s->buf_size;
1005  int c, rgb_channel_count;
1006  float one_gamma = 1.0f / s->gamma;
1007  avpriv_trc_function trc_func = avpriv_get_trc_function_from_trc(s->apply_trc_type);
1008  int ret;
1009 
1010  line_offset = AV_RL64(s->gb.buffer + jobnr * 8);
1011 
1012  if (s->is_tile) {
1013  if (buf_size < 20 || line_offset > buf_size - 20)
1014  return AVERROR_INVALIDDATA;
1015 
1016  src = buf + line_offset + 20;
1017 
1018  tile_x = AV_RL32(src - 20);
1019  tile_y = AV_RL32(src - 16);
1020  tile_level_x = AV_RL32(src - 12);
1021  tile_level_y = AV_RL32(src - 8);
1022 
1023  data_size = AV_RL32(src - 4);
1024  if (data_size <= 0 || data_size > buf_size - line_offset - 20)
1025  return AVERROR_INVALIDDATA;
1026 
1027  if (tile_level_x || tile_level_y) { /* tile level, is not the full res level */
1028  avpriv_report_missing_feature(s->avctx, "Subres tile before full res tile");
1029  return AVERROR_PATCHWELCOME;
1030  }
1031 
1032  if (s->xmin || s->ymin) {
1033  avpriv_report_missing_feature(s->avctx, "Tiles with xmin/ymin");
1034  return AVERROR_PATCHWELCOME;
1035  }
1036 
1037  line = s->tile_attr.ySize * tile_y;
1038  col = s->tile_attr.xSize * tile_x;
1039 
1040  if (line < s->ymin || line > s->ymax ||
1041  col < s->xmin || col > s->xmax)
1042  return AVERROR_INVALIDDATA;
1043 
1044  td->ysize = FFMIN(s->tile_attr.ySize, s->ydelta - tile_y * s->tile_attr.ySize);
1045  td->xsize = FFMIN(s->tile_attr.xSize, s->xdelta - tile_x * s->tile_attr.xSize);
1046 
1047  if (col) { /* not the first tile of the line */
1048  bxmin = 0; /* doesn't add pixel at the left of the datawindow */
1049  }
1050 
1051  if ((col + td->xsize) != s->xdelta)/* not the last tile of the line */
1052  axmax = 0; /* doesn't add pixel at the right of the datawindow */
1053 
1054  td->channel_line_size = td->xsize * s->current_channel_offset;/* uncompress size of one line */
1055  uncompressed_size = td->channel_line_size * (uint64_t)td->ysize;/* uncompress size of the block */
1056  } else {
1057  if (buf_size < 8 || line_offset > buf_size - 8)
1058  return AVERROR_INVALIDDATA;
1059 
1060  src = buf + line_offset + 8;
1061  line = AV_RL32(src - 8);
1062 
1063  if (line < s->ymin || line > s->ymax)
1064  return AVERROR_INVALIDDATA;
1065 
1066  data_size = AV_RL32(src - 4);
1067  if (data_size <= 0 || data_size > buf_size - line_offset - 8)
1068  return AVERROR_INVALIDDATA;
1069 
1070  td->ysize = FFMIN(s->scan_lines_per_block, s->ymax - line + 1); /* s->ydelta - line ?? */
1071  td->xsize = s->xdelta;
1072 
1073  td->channel_line_size = td->xsize * s->current_channel_offset;/* uncompress size of one line */
1074  uncompressed_size = td->channel_line_size * (uint64_t)td->ysize;/* uncompress size of the block */
1075 
1076  if ((s->compression == EXR_RAW && (data_size != uncompressed_size ||
1077  line_offset > buf_size - uncompressed_size)) ||
1078  (s->compression != EXR_RAW && (data_size > uncompressed_size ||
1079  line_offset > buf_size - data_size))) {
1080  return AVERROR_INVALIDDATA;
1081  }
1082  }
1083 
1084  if (data_size < uncompressed_size || s->is_tile) { /* td->tmp is use for tile reorganization */
1085  av_fast_padded_malloc(&td->tmp, &td->tmp_size, uncompressed_size);
1086  if (!td->tmp)
1087  return AVERROR(ENOMEM);
1088  }
1089 
1090  if (data_size < uncompressed_size) {
1091  av_fast_padded_malloc(&td->uncompressed_data,
1092  &td->uncompressed_size, uncompressed_size + 64);/* Force 64 padding for AVX2 reorder_pixels dst */
1093 
1094  if (!td->uncompressed_data)
1095  return AVERROR(ENOMEM);
1096 
1098  switch (s->compression) {
1099  case EXR_ZIP1:
1100  case EXR_ZIP16:
1101  ret = zip_uncompress(s, src, data_size, uncompressed_size, td);
1102  break;
1103  case EXR_PIZ:
1104  ret = piz_uncompress(s, src, data_size, uncompressed_size, td);
1105  break;
1106  case EXR_PXR24:
1107  ret = pxr24_uncompress(s, src, data_size, uncompressed_size, td);
1108  break;
1109  case EXR_RLE:
1110  ret = rle_uncompress(s, src, data_size, uncompressed_size, td);
1111  break;
1112  case EXR_B44:
1113  case EXR_B44A:
1114  ret = b44_uncompress(s, src, data_size, uncompressed_size, td);
1115  break;
1116  }
1117  if (ret < 0) {
1118  av_log(avctx, AV_LOG_ERROR, "decode_block() failed.\n");
1119  return ret;
1120  }
1121  src = td->uncompressed_data;
1122  }
1123 
1124  if (!s->is_luma) {
1125  channel_buffer[0] = src + td->xsize * s->channel_offsets[0];
1126  channel_buffer[1] = src + td->xsize * s->channel_offsets[1];
1127  channel_buffer[2] = src + td->xsize * s->channel_offsets[2];
1128  rgb_channel_count = 3;
1129  } else { /* put y data in the first channel_buffer */
1130  channel_buffer[0] = src + td->xsize * s->channel_offsets[1];
1131  rgb_channel_count = 1;
1132  }
1133  if (s->channel_offsets[3] >= 0)
1134  channel_buffer[3] = src + td->xsize * s->channel_offsets[3];
1135 
1136  if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
1137 
1138  /* todo: change this when a floating point pixel format with luma with alpha is implemented */
1139  int channel_count = s->channel_offsets[3] >= 0 ? 4 : rgb_channel_count;
1140  if (s->is_luma) {
1141  channel_buffer[1] = channel_buffer[0];
1142  channel_buffer[2] = channel_buffer[0];
1143  }
1144 
1145  for (c = 0; c < channel_count; c++) {
1146  int plane = s->desc->comp[c].plane;
1147  ptr = p->data[plane] + line * p->linesize[plane] + (col * 4);
1148 
1149  for (i = 0; i < td->ysize; i++, ptr += p->linesize[plane]) {
1150  const uint8_t *src;
1151  union av_intfloat32 *ptr_x;
1152 
1153  src = channel_buffer[c];
1154  ptr_x = (union av_intfloat32 *)ptr;
1155 
1156  // Zero out the start if xmin is not 0
1157  memset(ptr_x, 0, bxmin);
1158  ptr_x += s->xmin;
1159 
1160  if (s->pixel_type == EXR_FLOAT) {
1161  // 32-bit
1162  union av_intfloat32 t;
1163  if (trc_func && c < 3) {
1164  for (x = 0; x < td->xsize; x++) {
1165  t.i = bytestream_get_le32(&src);
1166  t.f = trc_func(t.f);
1167  *ptr_x++ = t;
1168  }
1169  } else {
1170  for (x = 0; x < td->xsize; x++) {
1171  t.i = bytestream_get_le32(&src);
1172  if (t.f > 0.0f && c < 3) /* avoid negative values */
1173  t.f = powf(t.f, one_gamma);
1174  *ptr_x++ = t;
1175  }
1176  }
1177  } else if (s->pixel_type == EXR_HALF) {
1178  // 16-bit
1179  if (c < 3) {
1180  for (x = 0; x < td->xsize; x++) {
1181  *ptr_x++ = s->gamma_table[bytestream_get_le16(&src)];
1182  }
1183  } else {
1184  for (x = 0; x < td->xsize; x++) {
1185  *ptr_x++ = exr_half2float(bytestream_get_le16(&src));;
1186  }
1187  }
1188  }
1189 
1190  // Zero out the end if xmax+1 is not w
1191  memset(ptr_x, 0, axmax);
1192  channel_buffer[c] += td->channel_line_size;
1193  }
1194  }
1195  } else {
1196 
1197  av_assert1(s->pixel_type == EXR_UINT);
1198  ptr = p->data[0] + line * p->linesize[0] + (col * s->desc->nb_components * 2);
1199 
1200  for (i = 0; i < td->ysize; i++, ptr += p->linesize[0]) {
1201 
1202  const uint8_t * a;
1203  const uint8_t *rgb[3];
1204  uint16_t *ptr_x;
1205 
1206  for (c = 0; c < rgb_channel_count; c++) {
1207  rgb[c] = channel_buffer[c];
1208  }
1209 
1210  if (channel_buffer[3])
1211  a = channel_buffer[3];
1212 
1213  ptr_x = (uint16_t *) ptr;
1214 
1215  // Zero out the start if xmin is not 0
1216  memset(ptr_x, 0, bxmin);
1217  ptr_x += s->xmin * s->desc->nb_components;
1218 
1219  for (x = 0; x < td->xsize; x++) {
1220  for (c = 0; c < rgb_channel_count; c++) {
1221  *ptr_x++ = bytestream_get_le32(&rgb[c]) >> 16;
1222  }
1223 
1224  if (channel_buffer[3])
1225  *ptr_x++ = bytestream_get_le32(&a) >> 16;
1226  }
1227 
1228  // Zero out the end if xmax+1 is not w
1229  memset(ptr_x, 0, axmax);
1230 
1231  channel_buffer[0] += td->channel_line_size;
1232  channel_buffer[1] += td->channel_line_size;
1233  channel_buffer[2] += td->channel_line_size;
1234  if (channel_buffer[3])
1235  channel_buffer[3] += td->channel_line_size;
1236  }
1237  }
1238 
1239  return 0;
1240 }
1241 
1242 /**
1243  * Check if the variable name corresponds to its data type.
1244  *
1245  * @param s the EXRContext
1246  * @param value_name name of the variable to check
1247  * @param value_type type of the variable to check
1248  * @param minimum_length minimum length of the variable data
1249  *
1250  * @return bytes to read containing variable data
1251  * -1 if variable is not found
1252  * 0 if buffer ended prematurely
1253  */
1255  const char *value_name,
1256  const char *value_type,
1257  unsigned int minimum_length)
1258 {
1259  int var_size = -1;
1260 
1261  if (bytestream2_get_bytes_left(&s->gb) >= minimum_length &&
1262  !strcmp(s->gb.buffer, value_name)) {
1263  // found value_name, jump to value_type (null terminated strings)
1264  s->gb.buffer += strlen(value_name) + 1;
1265  if (!strcmp(s->gb.buffer, value_type)) {
1266  s->gb.buffer += strlen(value_type) + 1;
1267  var_size = bytestream2_get_le32(&s->gb);
1268  // don't go read past boundaries
1269  if (var_size > bytestream2_get_bytes_left(&s->gb))
1270  var_size = 0;
1271  } else {
1272  // value_type not found, reset the buffer
1273  s->gb.buffer -= strlen(value_name) + 1;
1274  av_log(s->avctx, AV_LOG_WARNING,
1275  "Unknown data type %s for header variable %s.\n",
1276  value_type, value_name);
1277  }
1278  }
1279 
1280  return var_size;
1281 }
1282 
1284 {
1285  AVDictionary *metadata = NULL;
1286  int magic_number, version, i, flags, sar = 0;
1287  int layer_match = 0;
1288  int ret;
1289  int dup_channels = 0;
1290 
1291  s->current_channel_offset = 0;
1292  s->xmin = ~0;
1293  s->xmax = ~0;
1294  s->ymin = ~0;
1295  s->ymax = ~0;
1296  s->xdelta = ~0;
1297  s->ydelta = ~0;
1298  s->channel_offsets[0] = -1;
1299  s->channel_offsets[1] = -1;
1300  s->channel_offsets[2] = -1;
1301  s->channel_offsets[3] = -1;
1302  s->pixel_type = EXR_UNKNOWN;
1303  s->compression = EXR_UNKN;
1304  s->nb_channels = 0;
1305  s->w = 0;
1306  s->h = 0;
1307  s->tile_attr.xSize = -1;
1308  s->tile_attr.ySize = -1;
1309  s->is_tile = 0;
1310  s->is_luma = 0;
1311 
1312  if (bytestream2_get_bytes_left(&s->gb) < 10) {
1313  av_log(s->avctx, AV_LOG_ERROR, "Header too short to parse.\n");
1314  return AVERROR_INVALIDDATA;
1315  }
1316 
1317  magic_number = bytestream2_get_le32(&s->gb);
1318  if (magic_number != 20000630) {
1319  /* As per documentation of OpenEXR, it is supposed to be
1320  * int 20000630 little-endian */
1321  av_log(s->avctx, AV_LOG_ERROR, "Wrong magic number %d.\n", magic_number);
1322  return AVERROR_INVALIDDATA;
1323  }
1324 
1325  version = bytestream2_get_byte(&s->gb);
1326  if (version != 2) {
1327  avpriv_report_missing_feature(s->avctx, "Version %d", version);
1328  return AVERROR_PATCHWELCOME;
1329  }
1330 
1331  flags = bytestream2_get_le24(&s->gb);
1332 
1333  if (flags & 0x02)
1334  s->is_tile = 1;
1335  if (flags & 0x08) {
1336  avpriv_report_missing_feature(s->avctx, "deep data");
1337  return AVERROR_PATCHWELCOME;
1338  }
1339  if (flags & 0x10) {
1340  avpriv_report_missing_feature(s->avctx, "multipart");
1341  return AVERROR_PATCHWELCOME;
1342  }
1343 
1344  // Parse the header
1345  while (bytestream2_get_bytes_left(&s->gb) > 0 && *s->gb.buffer) {
1346  int var_size;
1347  if ((var_size = check_header_variable(s, "channels",
1348  "chlist", 38)) >= 0) {
1349  GetByteContext ch_gb;
1350  if (!var_size) {
1352  goto fail;
1353  }
1354 
1355  bytestream2_init(&ch_gb, s->gb.buffer, var_size);
1356 
1357  while (bytestream2_get_bytes_left(&ch_gb) >= 19) {
1359  enum ExrPixelType current_pixel_type;
1360  int channel_index = -1;
1361  int xsub, ysub;
1362 
1363  if (strcmp(s->layer, "") != 0) {
1364  if (strncmp(ch_gb.buffer, s->layer, strlen(s->layer)) == 0) {
1365  layer_match = 1;
1366  av_log(s->avctx, AV_LOG_INFO,
1367  "Channel match layer : %s.\n", ch_gb.buffer);
1368  ch_gb.buffer += strlen(s->layer);
1369  if (*ch_gb.buffer == '.')
1370  ch_gb.buffer++; /* skip dot if not given */
1371  } else {
1372  layer_match = 0;
1373  av_log(s->avctx, AV_LOG_INFO,
1374  "Channel doesn't match layer : %s.\n", ch_gb.buffer);
1375  }
1376  } else {
1377  layer_match = 1;
1378  }
1379 
1380  if (layer_match) { /* only search channel if the layer match is valid */
1381  if (!av_strcasecmp(ch_gb.buffer, "R") ||
1382  !av_strcasecmp(ch_gb.buffer, "X") ||
1383  !av_strcasecmp(ch_gb.buffer, "U")) {
1384  channel_index = 0;
1385  s->is_luma = 0;
1386  } else if (!av_strcasecmp(ch_gb.buffer, "G") ||
1387  !av_strcasecmp(ch_gb.buffer, "V")) {
1388  channel_index = 1;
1389  s->is_luma = 0;
1390  } else if (!av_strcasecmp(ch_gb.buffer, "Y")) {
1391  channel_index = 1;
1392  s->is_luma = 1;
1393  } else if (!av_strcasecmp(ch_gb.buffer, "B") ||
1394  !av_strcasecmp(ch_gb.buffer, "Z") ||
1395  !av_strcasecmp(ch_gb.buffer, "W")) {
1396  channel_index = 2;
1397  s->is_luma = 0;
1398  } else if (!av_strcasecmp(ch_gb.buffer, "A")) {
1399  channel_index = 3;
1400  } else {
1401  av_log(s->avctx, AV_LOG_WARNING,
1402  "Unsupported channel %.256s.\n", ch_gb.buffer);
1403  }
1404  }
1405 
1406  /* skip until you get a 0 */
1407  while (bytestream2_get_bytes_left(&ch_gb) > 0 &&
1408  bytestream2_get_byte(&ch_gb))
1409  continue;
1410 
1411  if (bytestream2_get_bytes_left(&ch_gb) < 4) {
1412  av_log(s->avctx, AV_LOG_ERROR, "Incomplete header.\n");
1414  goto fail;
1415  }
1416 
1417  current_pixel_type = bytestream2_get_le32(&ch_gb);
1418  if (current_pixel_type >= EXR_UNKNOWN) {
1419  avpriv_report_missing_feature(s->avctx, "Pixel type %d",
1420  current_pixel_type);
1422  goto fail;
1423  }
1424 
1425  bytestream2_skip(&ch_gb, 4);
1426  xsub = bytestream2_get_le32(&ch_gb);
1427  ysub = bytestream2_get_le32(&ch_gb);
1428 
1429  if (xsub != 1 || ysub != 1) {
1431  "Subsampling %dx%d",
1432  xsub, ysub);
1434  goto fail;
1435  }
1436 
1437  if (channel_index >= 0 && s->channel_offsets[channel_index] == -1) { /* channel has not been previously assigned */
1438  if (s->pixel_type != EXR_UNKNOWN &&
1439  s->pixel_type != current_pixel_type) {
1440  av_log(s->avctx, AV_LOG_ERROR,
1441  "RGB channels not of the same depth.\n");
1443  goto fail;
1444  }
1445  s->pixel_type = current_pixel_type;
1446  s->channel_offsets[channel_index] = s->current_channel_offset;
1447  } else if (channel_index >= 0) {
1448  av_log(s->avctx, AV_LOG_WARNING,
1449  "Multiple channels with index %d.\n", channel_index);
1450  if (++dup_channels > 10) {
1452  goto fail;
1453  }
1454  }
1455 
1456  s->channels = av_realloc(s->channels,
1457  ++s->nb_channels * sizeof(EXRChannel));
1458  if (!s->channels) {
1459  ret = AVERROR(ENOMEM);
1460  goto fail;
1461  }
1462  channel = &s->channels[s->nb_channels - 1];
1463  channel->pixel_type = current_pixel_type;
1464  channel->xsub = xsub;
1465  channel->ysub = ysub;
1466 
1467  if (current_pixel_type == EXR_HALF) {
1468  s->current_channel_offset += 2;
1469  } else {/* Float or UINT32 */
1470  s->current_channel_offset += 4;
1471  }
1472  }
1473 
1474  /* Check if all channels are set with an offset or if the channels
1475  * are causing an overflow */
1476  if (!s->is_luma) {/* if we expected to have at least 3 channels */
1477  if (FFMIN3(s->channel_offsets[0],
1478  s->channel_offsets[1],
1479  s->channel_offsets[2]) < 0) {
1480  if (s->channel_offsets[0] < 0)
1481  av_log(s->avctx, AV_LOG_ERROR, "Missing red channel.\n");
1482  if (s->channel_offsets[1] < 0)
1483  av_log(s->avctx, AV_LOG_ERROR, "Missing green channel.\n");
1484  if (s->channel_offsets[2] < 0)
1485  av_log(s->avctx, AV_LOG_ERROR, "Missing blue channel.\n");
1487  goto fail;
1488  }
1489  }
1490 
1491  // skip one last byte and update main gb
1492  s->gb.buffer = ch_gb.buffer + 1;
1493  continue;
1494  } else if ((var_size = check_header_variable(s, "dataWindow", "box2i",
1495  31)) >= 0) {
1496  if (!var_size) {
1498  goto fail;
1499  }
1500 
1501  s->xmin = bytestream2_get_le32(&s->gb);
1502  s->ymin = bytestream2_get_le32(&s->gb);
1503  s->xmax = bytestream2_get_le32(&s->gb);
1504  s->ymax = bytestream2_get_le32(&s->gb);
1505  s->xdelta = (s->xmax - s->xmin) + 1;
1506  s->ydelta = (s->ymax - s->ymin) + 1;
1507 
1508  continue;
1509  } else if ((var_size = check_header_variable(s, "displayWindow",
1510  "box2i", 34)) >= 0) {
1511  if (!var_size) {
1513  goto fail;
1514  }
1515 
1516  bytestream2_skip(&s->gb, 8);
1517  s->w = bytestream2_get_le32(&s->gb) + 1;
1518  s->h = bytestream2_get_le32(&s->gb) + 1;
1519 
1520  continue;
1521  } else if ((var_size = check_header_variable(s, "lineOrder",
1522  "lineOrder", 25)) >= 0) {
1523  int line_order;
1524  if (!var_size) {
1526  goto fail;
1527  }
1528 
1529  line_order = bytestream2_get_byte(&s->gb);
1530  av_log(s->avctx, AV_LOG_DEBUG, "line order: %d.\n", line_order);
1531  if (line_order > 2) {
1532  av_log(s->avctx, AV_LOG_ERROR, "Unknown line order.\n");
1534  goto fail;
1535  }
1536 
1537  continue;
1538  } else if ((var_size = check_header_variable(s, "pixelAspectRatio",
1539  "float", 31)) >= 0) {
1540  if (!var_size) {
1542  goto fail;
1543  }
1544 
1545  sar = bytestream2_get_le32(&s->gb);
1546 
1547  continue;
1548  } else if ((var_size = check_header_variable(s, "compression",
1549  "compression", 29)) >= 0) {
1550  if (!var_size) {
1552  goto fail;
1553  }
1554 
1555  if (s->compression == EXR_UNKN)
1556  s->compression = bytestream2_get_byte(&s->gb);
1557  else
1558  av_log(s->avctx, AV_LOG_WARNING,
1559  "Found more than one compression attribute.\n");
1560 
1561  continue;
1562  } else if ((var_size = check_header_variable(s, "tiles",
1563  "tiledesc", 22)) >= 0) {
1564  char tileLevel;
1565 
1566  if (!s->is_tile)
1567  av_log(s->avctx, AV_LOG_WARNING,
1568  "Found tile attribute and scanline flags. Exr will be interpreted as scanline.\n");
1569 
1570  s->tile_attr.xSize = bytestream2_get_le32(&s->gb);
1571  s->tile_attr.ySize = bytestream2_get_le32(&s->gb);
1572 
1573  tileLevel = bytestream2_get_byte(&s->gb);
1574  s->tile_attr.level_mode = tileLevel & 0x0f;
1575  s->tile_attr.level_round = (tileLevel >> 4) & 0x0f;
1576 
1577  if (s->tile_attr.level_mode >= EXR_TILE_LEVEL_UNKNOWN) {
1578  avpriv_report_missing_feature(s->avctx, "Tile level mode %d",
1579  s->tile_attr.level_mode);
1581  goto fail;
1582  }
1583 
1584  if (s->tile_attr.level_round >= EXR_TILE_ROUND_UNKNOWN) {
1585  avpriv_report_missing_feature(s->avctx, "Tile level round %d",
1586  s->tile_attr.level_round);
1588  goto fail;
1589  }
1590 
1591  continue;
1592  } else if ((var_size = check_header_variable(s, "writer",
1593  "string", 1)) >= 0) {
1594  uint8_t key[256] = { 0 };
1595 
1596  bytestream2_get_buffer(&s->gb, key, FFMIN(sizeof(key) - 1, var_size));
1597  av_dict_set(&metadata, "writer", key, 0);
1598 
1599  continue;
1600  }
1601 
1602  // Check if there are enough bytes for a header
1603  if (bytestream2_get_bytes_left(&s->gb) <= 9) {
1604  av_log(s->avctx, AV_LOG_ERROR, "Incomplete header\n");
1606  goto fail;
1607  }
1608 
1609  // Process unknown variables
1610  for (i = 0; i < 2; i++) // value_name and value_type
1611  while (bytestream2_get_byte(&s->gb) != 0);
1612 
1613  // Skip variable length
1614  bytestream2_skip(&s->gb, bytestream2_get_le32(&s->gb));
1615  }
1616 
1617  ff_set_sar(s->avctx, av_d2q(av_int2float(sar), 255));
1618 
1619  if (s->compression == EXR_UNKN) {
1620  av_log(s->avctx, AV_LOG_ERROR, "Missing compression attribute.\n");
1622  goto fail;
1623  }
1624 
1625  if (s->is_tile) {
1626  if (s->tile_attr.xSize < 1 || s->tile_attr.ySize < 1) {
1627  av_log(s->avctx, AV_LOG_ERROR, "Invalid tile attribute.\n");
1629  goto fail;
1630  }
1631  }
1632 
1633  if (bytestream2_get_bytes_left(&s->gb) <= 0) {
1634  av_log(s->avctx, AV_LOG_ERROR, "Incomplete frame.\n");
1636  goto fail;
1637  }
1638 
1639  frame->metadata = metadata;
1640 
1641  // aaand we are done
1642  bytestream2_skip(&s->gb, 1);
1643  return 0;
1644 fail:
1645  av_dict_free(&metadata);
1646  return ret;
1647 }
1648 
1649 static int decode_frame(AVCodecContext *avctx, void *data,
1650  int *got_frame, AVPacket *avpkt)
1651 {
1652  EXRContext *s = avctx->priv_data;
1653  ThreadFrame frame = { .f = data };
1654  AVFrame *picture = data;
1655  uint8_t *ptr;
1656 
1657  int i, y, ret;
1658  int planes;
1659  int out_line_size;
1660  int nb_blocks; /* nb scanline or nb tile */
1661  uint64_t start_offset_table;
1662  uint64_t start_next_scanline;
1663  PutByteContext offset_table_writer;
1664 
1665  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1666 
1667  if ((ret = decode_header(s, picture)) < 0)
1668  return ret;
1669 
1670  switch (s->pixel_type) {
1671  case EXR_FLOAT:
1672  case EXR_HALF:
1673  if (s->channel_offsets[3] >= 0) {
1674  if (!s->is_luma) {
1675  avctx->pix_fmt = AV_PIX_FMT_GBRAPF32;
1676  } else {
1677  /* todo: change this when a floating point pixel format with luma with alpha is implemented */
1678  avctx->pix_fmt = AV_PIX_FMT_GBRAPF32;
1679  }
1680  } else {
1681  if (!s->is_luma) {
1682  avctx->pix_fmt = AV_PIX_FMT_GBRPF32;
1683  } else {
1684  avctx->pix_fmt = AV_PIX_FMT_GRAYF32;
1685  }
1686  }
1687  break;
1688  case EXR_UINT:
1689  if (s->channel_offsets[3] >= 0) {
1690  if (!s->is_luma) {
1691  avctx->pix_fmt = AV_PIX_FMT_RGBA64;
1692  } else {
1693  avctx->pix_fmt = AV_PIX_FMT_YA16;
1694  }
1695  } else {
1696  if (!s->is_luma) {
1697  avctx->pix_fmt = AV_PIX_FMT_RGB48;
1698  } else {
1699  avctx->pix_fmt = AV_PIX_FMT_GRAY16;
1700  }
1701  }
1702  break;
1703  default:
1704  av_log(avctx, AV_LOG_ERROR, "Missing channel list.\n");
1705  return AVERROR_INVALIDDATA;
1706  }
1707 
1708  if (s->apply_trc_type != AVCOL_TRC_UNSPECIFIED)
1709  avctx->color_trc = s->apply_trc_type;
1710 
1711  switch (s->compression) {
1712  case EXR_RAW:
1713  case EXR_RLE:
1714  case EXR_ZIP1:
1715  s->scan_lines_per_block = 1;
1716  break;
1717  case EXR_PXR24:
1718  case EXR_ZIP16:
1719  s->scan_lines_per_block = 16;
1720  break;
1721  case EXR_PIZ:
1722  case EXR_B44:
1723  case EXR_B44A:
1724  s->scan_lines_per_block = 32;
1725  break;
1726  default:
1727  avpriv_report_missing_feature(avctx, "Compression %d", s->compression);
1728  return AVERROR_PATCHWELCOME;
1729  }
1730 
1731  /* Verify the xmin, xmax, ymin, ymax and xdelta before setting
1732  * the actual image size. */
1733  if (s->xmin > s->xmax ||
1734  s->ymin > s->ymax ||
1735  s->xdelta != s->xmax - s->xmin + 1 ||
1736  s->xmax >= s->w ||
1737  s->ymax >= s->h) {
1738  av_log(avctx, AV_LOG_ERROR, "Wrong or missing size information.\n");
1739  return AVERROR_INVALIDDATA;
1740  }
1741 
1742  if ((ret = ff_set_dimensions(avctx, s->w, s->h)) < 0)
1743  return ret;
1744 
1745  s->desc = av_pix_fmt_desc_get(avctx->pix_fmt);
1746  if (!s->desc)
1747  return AVERROR_INVALIDDATA;
1748 
1749  if (s->desc->flags & AV_PIX_FMT_FLAG_FLOAT) {
1750  planes = s->desc->nb_components;
1751  out_line_size = avctx->width * 4;
1752  } else {
1753  planes = 1;
1754  out_line_size = avctx->width * 2 * s->desc->nb_components;
1755  }
1756 
1757  if (s->is_tile) {
1758  nb_blocks = ((s->xdelta + s->tile_attr.xSize - 1) / s->tile_attr.xSize) *
1759  ((s->ydelta + s->tile_attr.ySize - 1) / s->tile_attr.ySize);
1760  } else { /* scanline */
1761  nb_blocks = (s->ydelta + s->scan_lines_per_block - 1) /
1762  s->scan_lines_per_block;
1763  }
1764 
1765  if ((ret = ff_thread_get_buffer(avctx, &frame, 0)) < 0)
1766  return ret;
1767 
1768  if (bytestream2_get_bytes_left(&s->gb) < nb_blocks * 8)
1769  return AVERROR_INVALIDDATA;
1770 
1771  // check offset table and recreate it if need
1772  if (!s->is_tile && bytestream2_peek_le64(&s->gb) == 0) {
1773  av_log(s->avctx, AV_LOG_DEBUG, "recreating invalid scanline offset table\n");
1774 
1775  start_offset_table = bytestream2_tell(&s->gb);
1776  start_next_scanline = start_offset_table + nb_blocks * 8;
1777  bytestream2_init_writer(&offset_table_writer, &avpkt->data[start_offset_table], nb_blocks * 8);
1778 
1779  for (y = 0; y < nb_blocks; y++) {
1780  /* write offset of prev scanline in offset table */
1781  bytestream2_put_le64(&offset_table_writer, start_next_scanline);
1782 
1783  /* get len of next scanline */
1784  bytestream2_seek(&s->gb, start_next_scanline + 4, SEEK_SET);/* skip line number */
1785  start_next_scanline += (bytestream2_get_le32(&s->gb) + 8);
1786  }
1787  bytestream2_seek(&s->gb, start_offset_table, SEEK_SET);
1788  }
1789 
1790  // save pointer we are going to use in decode_block
1791  s->buf = avpkt->data;
1792  s->buf_size = avpkt->size;
1793 
1794  // Zero out the start if ymin is not 0
1795  for (i = 0; i < planes; i++) {
1796  ptr = picture->data[i];
1797  for (y = 0; y < s->ymin; y++) {
1798  memset(ptr, 0, out_line_size);
1799  ptr += picture->linesize[i];
1800  }
1801  }
1802 
1803  s->picture = picture;
1804 
1805  avctx->execute2(avctx, decode_block, s->thread_data, NULL, nb_blocks);
1806 
1807  // Zero out the end if ymax+1 is not h
1808  for (i = 0; i < planes; i++) {
1809  ptr = picture->data[i] + ((s->ymax+1) * picture->linesize[i]);
1810  for (y = s->ymax + 1; y < avctx->height; y++) {
1811  memset(ptr, 0, out_line_size);
1812  ptr += picture->linesize[i];
1813  }
1814  }
1815 
1816  picture->pict_type = AV_PICTURE_TYPE_I;
1817  *got_frame = 1;
1818 
1819  return avpkt->size;
1820 }
1821 
1823 {
1824  EXRContext *s = avctx->priv_data;
1825  uint32_t i;
1826  union av_intfloat32 t;
1827  float one_gamma = 1.0f / s->gamma;
1828  avpriv_trc_function trc_func = NULL;
1829 
1830  s->avctx = avctx;
1831 
1832  ff_exrdsp_init(&s->dsp);
1833 
1834 #if HAVE_BIGENDIAN
1835  ff_bswapdsp_init(&s->bbdsp);
1836 #endif
1837 
1838  trc_func = avpriv_get_trc_function_from_trc(s->apply_trc_type);
1839  if (trc_func) {
1840  for (i = 0; i < 65536; ++i) {
1841  t = exr_half2float(i);
1842  t.f = trc_func(t.f);
1843  s->gamma_table[i] = t;
1844  }
1845  } else {
1846  if (one_gamma > 0.9999f && one_gamma < 1.0001f) {
1847  for (i = 0; i < 65536; ++i) {
1848  s->gamma_table[i] = exr_half2float(i);
1849  }
1850  } else {
1851  for (i = 0; i < 65536; ++i) {
1852  t = exr_half2float(i);
1853  /* If negative value we reuse half value */
1854  if (t.f <= 0.0f) {
1855  s->gamma_table[i] = t;
1856  } else {
1857  t.f = powf(t.f, one_gamma);
1858  s->gamma_table[i] = t;
1859  }
1860  }
1861  }
1862  }
1863 
1864  // allocate thread data, used for non EXR_RAW compression types
1865  s->thread_data = av_mallocz_array(avctx->thread_count, sizeof(EXRThreadData));
1866  if (!s->thread_data)
1867  return AVERROR_INVALIDDATA;
1868 
1869  return 0;
1870 }
1871 
1873 {
1874  EXRContext *s = avctx->priv_data;
1875  int i;
1876  for (i = 0; i < avctx->thread_count; i++) {
1877  EXRThreadData *td = &s->thread_data[i];
1878  av_freep(&td->uncompressed_data);
1879  av_freep(&td->tmp);
1880  av_freep(&td->bitmap);
1881  av_freep(&td->lut);
1882  }
1883 
1884  av_freep(&s->thread_data);
1885  av_freep(&s->channels);
1886 
1887  return 0;
1888 }
1889 
1890 #define OFFSET(x) offsetof(EXRContext, x)
1891 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
1892 static const AVOption options[] = {
1893  { "layer", "Set the decoding layer", OFFSET(layer),
1894  AV_OPT_TYPE_STRING, { .str = "" }, 0, 0, VD },
1895  { "gamma", "Set the float gamma value when decoding", OFFSET(gamma),
1896  AV_OPT_TYPE_FLOAT, { .dbl = 1.0f }, 0.001, FLT_MAX, VD },
1897 
1898  // XXX: Note the abuse of the enum using AVCOL_TRC_UNSPECIFIED to subsume the existing gamma option
1899  { "apply_trc", "color transfer characteristics to apply to EXR linear input", OFFSET(apply_trc_type),
1900  AV_OPT_TYPE_INT, {.i64 = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, VD, "apply_trc_type"},
1901  { "bt709", "BT.709", 0,
1902  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT709 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1903  { "gamma", "gamma", 0,
1904  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_UNSPECIFIED }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1905  { "gamma22", "BT.470 M", 0,
1906  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_GAMMA22 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1907  { "gamma28", "BT.470 BG", 0,
1908  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_GAMMA28 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1909  { "smpte170m", "SMPTE 170 M", 0,
1910  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTE170M }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1911  { "smpte240m", "SMPTE 240 M", 0,
1912  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTE240M }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1913  { "linear", "Linear", 0,
1914  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_LINEAR }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1915  { "log", "Log", 0,
1916  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_LOG }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1917  { "log_sqrt", "Log square root", 0,
1918  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_LOG_SQRT }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1919  { "iec61966_2_4", "IEC 61966-2-4", 0,
1920  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_IEC61966_2_4 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1921  { "bt1361", "BT.1361", 0,
1922  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT1361_ECG }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1923  { "iec61966_2_1", "IEC 61966-2-1", 0,
1924  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_IEC61966_2_1 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1925  { "bt2020_10bit", "BT.2020 - 10 bit", 0,
1926  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_10 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1927  { "bt2020_12bit", "BT.2020 - 12 bit", 0,
1928  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_BT2020_12 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1929  { "smpte2084", "SMPTE ST 2084", 0,
1930  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST2084 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1931  { "smpte428_1", "SMPTE ST 428-1", 0,
1932  AV_OPT_TYPE_CONST, {.i64 = AVCOL_TRC_SMPTEST428_1 }, INT_MIN, INT_MAX, VD, "apply_trc_type"},
1933 
1934  { NULL },
1935 };
1936 
1937 static const AVClass exr_class = {
1938  .class_name = "EXR",
1939  .item_name = av_default_item_name,
1940  .option = options,
1941  .version = LIBAVUTIL_VERSION_INT,
1942 };
1943 
1945  .name = "exr",
1946  .long_name = NULL_IF_CONFIG_SMALL("OpenEXR image"),
1947  .type = AVMEDIA_TYPE_VIDEO,
1948  .id = AV_CODEC_ID_EXR,
1949  .priv_data_size = sizeof(EXRContext),
1950  .init = decode_init,
1951  .close = decode_end,
1952  .decode = decode_frame,
1953  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1955  .priv_class = &exr_class,
1956 };
HufDec::len
int len
Definition: exr.c:325
EXRContext::ymin
uint32_t ymin
Definition: exr.c:138
AVCodec
AVCodec.
Definition: codec.h:190
bswapdsp.h
EXRTileAttribute::level_round
enum ExrTileLevelRound level_round
Definition: exr.c:103
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
EXRThreadData
Definition: exr.c:106
td
#define td
Definition: regdef.h:70
EXR_TILE_ROUND_DOWN
@ EXR_TILE_ROUND_DOWN
Definition: exr.c:90
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
EXRContext::ymax
uint32_t ymax
Definition: exr.c:138
rle_uncompress
static int rle_uncompress(EXRContext *ctx, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
Definition: exr.c:244
EXRThreadData::uncompressed_size
int uncompressed_size
Definition: exr.c:108
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
EXR_DWB
@ EXR_DWB
Definition: exr.c:70
EXRTileAttribute
Definition: exr.c:99
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:480
out
FILE * out
Definition: movenc.c:54
EXRThreadData::lut
uint16_t * lut
Definition: exr.c:114
GetByteContext
Definition: bytestream.h:33
EXR_TILE_LEVEL_ONE
@ EXR_TILE_LEVEL_ONE
Definition: exr.c:82
EXRThreadData::uncompressed_data
uint8_t * uncompressed_data
Definition: exr.c:107
VD
#define VD
Definition: exr.c:1891
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:135
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2549
AVCOL_TRC_LINEAR
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
Definition: pixfmt.h:489
FLOAT_MAX_BIASED_EXP
#define FLOAT_MAX_BIASED_EXP
Definition: exr.c:173
decode_header
static int decode_header(EXRContext *s, AVFrame *frame)
Definition: exr.c:1283
EXRContext::layer
const char * layer
Definition: exr.c:158
pxr24_uncompress
static int pxr24_uncompress(EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
Definition: exr.c:775
av_strcasecmp
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
Definition: avstring.c:213
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
AV_PIX_FMT_FLAG_FLOAT
#define AV_PIX_FMT_FLAG_FLOAT
The pixel format contains IEEE-754 floating point values.
Definition: pixdesc.h:188
EXRContext::xmax
uint32_t xmax
Definition: exr.c:137
ff_exr_decoder
AVCodec ff_exr_decoder
Definition: exr.c:1944
im
float im
Definition: fft.c:82
bytestream2_seek
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:208
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
EXRContext::picture
AVFrame * picture
Definition: exr.c:123
AVCOL_TRC_NB
@ AVCOL_TRC_NB
Not part of ABI.
Definition: pixfmt.h:502
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:26
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1147
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
av_intfloat32::i
uint32_t i
Definition: intfloat.h:28
ExrPixelType
ExrPixelType
Definition: exr.c:74
AVOption
AVOption.
Definition: opt.h:246
b
#define b
Definition: input.c:41
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:483
data
const char data[16]
Definition: mxf.c:91
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: exr.c:1822
HUF_DECMASK
#define HUF_DECMASK
Definition: exr.c:322
reverse_lut
static uint16_t reverse_lut(const uint8_t *bitmap, uint16_t *lut)
Definition: exr.c:294
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: exr.c:1649
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
Definition: mem.c:192
HUF_DECBITS
#define HUF_DECBITS
Definition: exr.c:318
float.h
AVCOL_TRC_BT2020_12
@ AVCOL_TRC_BT2020_12
ITU-R BT2020 for 12-bit system.
Definition: pixfmt.h:496
EXRThreadData::ysize
int ysize
Definition: exr.c:116
AVDictionary
Definition: dict.c:30
options
static const AVOption options[]
Definition: exr.c:1892
EXRThreadData::tmp_size
int tmp_size
Definition: exr.c:111
intfloat.h
thread.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
EXRContext::channel_offsets
int channel_offsets[4]
Definition: exr.c:133
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
EXR_B44A
@ EXR_B44A
Definition: exr.c:68
EXR_HALF
@ EXR_HALF
Definition: exr.c:76
huf_uncompress
static int huf_uncompress(GetByteContext *gb, uint16_t *dst, int dst_size)
Definition: exr.c:533
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
EXRContext::tile_attr
EXRTileAttribute tile_attr
Definition: exr.c:143
apply_lut
static void apply_lut(const uint16_t *lut, uint16_t *dst, int dsize)
Definition: exr.c:309
AVCOL_TRC_IEC61966_2_1
@ AVCOL_TRC_IEC61966_2_1
IEC 61966-2-1 (sRGB or sYCC)
Definition: pixfmt.h:494
fail
#define fail()
Definition: checkasm.h:123
av_int2float
static av_always_inline float av_int2float(uint32_t i)
Reinterpret a 32-bit integer as a float.
Definition: intfloat.h:40
AVCodecContext::thread_count
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition: avcodec.h:1785
EXR_TILE_LEVEL_RIPMAP
@ EXR_TILE_LEVEL_RIPMAP
Definition: exr.c:84
EXR_TILE_ROUND_UNKNOWN
@ EXR_TILE_ROUND_UNKNOWN
Definition: exr.c:91
GetBitContext
Definition: get_bits.h:61
ff_thread_get_buffer
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames. The frames must then be freed with ff_thread_release_buffer(). Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. A good place to put this is where draw_horiz_band() is called - add this if it isn 't called anywhere
x
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo x
Definition: fate.txt:150
AVCOL_TRC_GAMMA28
@ AVCOL_TRC_GAMMA28
also ITU-R BT470BG
Definition: pixfmt.h:486
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:381
AVCOL_TRC_LOG_SQRT
@ AVCOL_TRC_LOG_SQRT
"Logarithmic transfer characteristic (100 * Sqrt(10) : 1 range)"
Definition: pixfmt.h:491
FFMIN3
#define FFMIN3(a, b, c)
Definition: common.h:97
EXRContext::avctx
AVCodecContext * avctx
Definition: exr.c:124
AVCOL_TRC_SMPTEST428_1
@ AVCOL_TRC_SMPTEST428_1
Definition: pixfmt.h:500
EXR_DWA
@ EXR_DWA
Definition: exr.c:69
AVCOL_TRC_GAMMA22
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
Definition: pixfmt.h:485
HufDec
Definition: exr.c:324
HALF_FLOAT_MAX_BIASED_EXP
#define HALF_FLOAT_MAX_BIASED_EXP
Definition: exr.c:175
EXRContext::scan_lines_per_block
int scan_lines_per_block
Definition: exr.c:141
EXRContext::h
int h
Definition: exr.c:136
color_utils.h
ExrDSPContext
Definition: exrdsp.h:25
EXRThreadData::channel_line_size
int channel_line_size
Definition: exr.c:118
USHORT_RANGE
#define USHORT_RANGE
Definition: exr.c:291
avassert.h
decode_end
static av_cold int decode_end(AVCodecContext *avctx)
Definition: exr.c:1872
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
HufDec::lit
int lit
Definition: exr.c:326
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
zip_uncompress
static int zip_uncompress(EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
Definition: exr.c:227
EXR_FLOAT
@ EXR_FLOAT
Definition: exr.c:77
BITMAP_SIZE
#define BITMAP_SIZE
Definition: exr.c:292
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
EXRContext::compression
enum ExrCompr compression
Definition: exr.c:131
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
check_header_variable
static int check_header_variable(EXRContext *s, const char *value_name, const char *value_type, unsigned int minimum_length)
Check if the variable name corresponds to its data type.
Definition: exr.c:1254
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVCOL_TRC_BT1361_ECG
@ AVCOL_TRC_BT1361_ECG
ITU-R BT1361 Extended Colour Gamut.
Definition: pixfmt.h:493
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
EXRContext::current_channel_offset
int current_channel_offset
Definition: exr.c:154
decode_block
static int decode_block(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr)
Definition: exr.c:987
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
EXRChannel::pixel_type
enum ExrPixelType pixel_type
Definition: exr.c:96
ctx
AVFormatContext * ctx
Definition: movenc.c:48
get_bits.h
SHORTEST_LONG_RUN
#define SHORTEST_LONG_RUN
Definition: exr.c:355
key
const char * key
Definition: hwcontext_opencl.c:168
AV_PIX_FMT_GRAYF32
#define AV_PIX_FMT_GRAYF32
Definition: pixfmt.h:429
f
#define f(width, name)
Definition: cbs_vp9.c:255
int32_t
int32_t
Definition: audio_convert.c:194
EXR_ZIP1
@ EXR_ZIP1
Definition: exr.c:63
if
if(ret)
Definition: filter_design.txt:179
EXRContext::desc
const AVPixFmtDescriptor * desc
Definition: exr.c:134
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:106
EXRContext::is_luma
int is_luma
Definition: exr.c:146
AV_CODEC_ID_EXR
@ AV_CODEC_ID_EXR
Definition: codec_id.h:229
AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:387
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
ff_bswapdsp_init
av_cold void ff_bswapdsp_init(BswapDSPContext *c)
Definition: bswapdsp.c:49
exrdsp.h
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
LONG_ZEROCODE_RUN
#define LONG_ZEROCODE_RUN
Definition: exr.c:354
pixel
uint8_t pixel
Definition: tiny_ssim.c:42
SHORT_ZEROCODE_RUN
#define SHORT_ZEROCODE_RUN
Definition: exr.c:353
AVCOL_TRC_IEC61966_2_4
@ AVCOL_TRC_IEC61966_2_4
IEC 61966-2-4.
Definition: pixfmt.h:492
EXR_RLE
@ EXR_RLE
Definition: exr.c:62
EXR_TILE_ROUND_UP
@ EXR_TILE_ROUND_UP
Definition: exr.c:89
AV_RL64
#define AV_RL64
Definition: intreadwrite.h:173
EXRChannel::ysub
int ysub
Definition: exr.c:95
avpriv_get_trc_function_from_trc
avpriv_trc_function avpriv_get_trc_function_from_trc(enum AVColorTransferCharacteristic trc)
Determine the function needed to apply the given AVColorTransferCharacteristic to linear input.
Definition: color_utils.c:170
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
huf_decode
static int huf_decode(const uint64_t *hcode, const HufDec *hdecod, GetByteContext *gb, int nbits, int rlc, int no, uint16_t *out)
Definition: exr.c:464
src
#define src
Definition: vp8dsp.c:254
mathops.h
bytestream2_get_buffer
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:263
ff_exrdsp_init
av_cold void ff_exrdsp_init(ExrDSPContext *c)
Definition: exrdsp.c:49
get_char
#define get_char(c, lc, gb)
Definition: exr.c:435
EXRContext::w
int w
Definition: exr.c:136
AVCOL_TRC_BT2020_10
@ AVCOL_TRC_BT2020_10
ITU-R BT2020 for 10-bit system.
Definition: pixfmt.h:495
av_intfloat32
Definition: intfloat.h:27
unpack_14
static void unpack_14(const uint8_t b[14], uint16_t s[16])
Definition: exr.c:859
EXR_PIZ
@ EXR_PIZ
Definition: exr.c:65
A_OFFSET
#define A_OFFSET
Definition: exr.c:598
exp
int8_t exp
Definition: eval.c:72
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
bytestream2_tell
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:188
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
exr_half2float
static union av_intfloat32 exr_half2float(uint16_t hf)
Convert a half float as a uint16_t into a full float.
Definition: exr.c:184
HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP
#define HALF_FLOAT_MIN_BIASED_EXP_AS_SINGLE_FP_EXP
Definition: exr.c:166
EXRThreadData::bitmap
uint8_t * bitmap
Definition: exr.c:113
PutByteContext
Definition: bytestream.h:37
EXRContext::pixel_type
enum ExrPixelType pixel_type
Definition: exr.c:132
EXRTileAttribute::level_mode
enum ExrTileLevelMode level_mode
Definition: exr.c:102
EXRChannel::xsub
int xsub
Definition: exr.c:95
EXRContext::thread_data
EXRThreadData * thread_data
Definition: exr.c:156
EXR_RAW
@ EXR_RAW
Definition: exr.c:61
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:383
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
wdec14
static void wdec14(uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
Definition: exr.c:584
AVPacket::size
int size
Definition: packet.h:356
wav_decode
static void wav_decode(uint16_t *in, int nx, int ox, int ny, int oy, uint16_t mx)
Definition: exr.c:611
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:186
powf
#define powf(x, y)
Definition: libm.h:50
AVCOL_TRC_SMPTE240M
@ AVCOL_TRC_SMPTE240M
Definition: pixfmt.h:488
MOD_MASK
#define MOD_MASK
Definition: exr.c:599
AVCOL_TRC_SMPTEST2084
@ AVCOL_TRC_SMPTEST2084
Definition: pixfmt.h:498
AVCOL_TRC_LOG
@ AVCOL_TRC_LOG
"Logarithmic transfer characteristic (100:1 range)"
Definition: pixfmt.h:490
EXRTileAttribute::xSize
int32_t xSize
Definition: exr.c:100
AV_PIX_FMT_GBRPF32
#define AV_PIX_FMT_GBRPF32
Definition: pixfmt.h:426
AV_PIX_FMT_RGB48
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:383
EXRThreadData::tmp
uint8_t * tmp
Definition: exr.c:110
EXRContext::is_tile
int is_tile
Definition: exr.c:144
EXR_TILE_LEVEL_MIPMAP
@ EXR_TILE_LEVEL_MIPMAP
Definition: exr.c:83
avpriv_report_missing_feature
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
huf_build_dec_table
static int huf_build_dec_table(const uint64_t *hcode, int im, int iM, HufDec *hdecod)
Definition: exr.c:398
HufDec::p
int * p
Definition: exr.c:327
EXRContext::gamma
float gamma
Definition: exr.c:161
EXRContext::gb
GetByteContext gb
Definition: exr.c:148
height
#define height
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:110
line
Definition: graph2dot.c:48
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:203
EXR_ZIP16
@ EXR_ZIP16
Definition: exr.c:64
EXRContext::apply_trc_type
enum AVColorTransferCharacteristic apply_trc_type
Definition: exr.c:160
version
version
Definition: libkvazaar.c:292
unpack_3
static void unpack_3(const uint8_t b[3], uint16_t s[16])
Definition: exr.c:894
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVCOL_TRC_BT709
@ AVCOL_TRC_BT709
also ITU-R BT1361
Definition: pixfmt.h:482
HUF_DECSIZE
#define HUF_DECSIZE
Definition: exr.c:321
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:226
planes
static const struct @315 planes[]
in
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Definition: audio_convert.c:326
ExrTileLevelRound
ExrTileLevelRound
Definition: exr.c:88
OFFSET
#define OFFSET(x)
Definition: exr.c:1890
get_code
#define get_code(po, rlc, c, lc, gb, out, oe, outb)
Definition: exr.c:441
AV_PIX_FMT_YA16
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:382
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
HUF_ENCSIZE
#define HUF_ENCSIZE
Definition: exr.c:320
common.h
EXRContext::buf
const uint8_t * buf
Definition: exr.c:149
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
EXRThreadData::xsize
int xsize
Definition: exr.c:116
av_fast_padded_malloc
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:70
EXR_PXR24
@ EXR_PXR24
Definition: exr.c:66
av_d2q
AVRational av_d2q(double d, int max)
Convert a double precision floating point number to a rational.
Definition: rational.c:106
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
EXR_UINT
@ EXR_UINT
Definition: exr.c:75
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
EXR_B44
@ EXR_B44
Definition: exr.c:67
avcodec.h
EXRContext::nb_channels
int nb_channels
Definition: exr.c:153
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
huf_unpack_enc_table
static int huf_unpack_enc_table(GetByteContext *gb, int32_t im, int32_t iM, uint64_t *hcode)
Definition: exr.c:358
EXRContext::gamma_table
union av_intfloat32 gamma_table[65536]
Definition: exr.c:162
avpriv_trc_function
double(* avpriv_trc_function)(double)
Definition: color_utils.h:40
ff_set_sar
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition: utils.c:119
AVCodecContext
main external API structure.
Definition: avcodec.h:526
ThreadFrame
Definition: thread.h:34
EXRContext::channels
EXRChannel * channels
Definition: exr.c:152
EXR_UNKNOWN
@ EXR_UNKNOWN
Definition: exr.c:78
AV_RL32
#define AV_RL32
Definition: intreadwrite.h:146
EXRContext::ydelta
uint32_t ydelta
Definition: exr.c:139
wdec16
static void wdec16(uint16_t l, uint16_t h, uint16_t *a, uint16_t *b)
Definition: exr.c:601
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
AV_PIX_FMT_GBRAPF32
#define AV_PIX_FMT_GBRAPF32
Definition: pixfmt.h:427
AVCOL_TRC_SMPTE170M
@ AVCOL_TRC_SMPTE170M
also ITU-R BT601-6 525 or 625 / ITU-R BT1358 525 or 625 / ITU-R BT1700 NTSC
Definition: pixfmt.h:487
huf_canonical_code_table
static void huf_canonical_code_table(uint64_t *hcode)
Definition: exr.c:330
EXR_TILE_LEVEL_UNKNOWN
@ EXR_TILE_LEVEL_UNKNOWN
Definition: exr.c:85
av_intfloat32::f
float f
Definition: intfloat.h:29
shift
static int shift(int a, int b)
Definition: sonic.c:82
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
ff_set_dimensions
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:104
EXRContext::xmin
uint32_t xmin
Definition: exr.c:137
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
diff
static av_always_inline int diff(const uint32_t a, const uint32_t b)
Definition: vf_palettegen.c:136
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ExrCompr
ExrCompr
Definition: exr.c:60
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:70
EXRContext::buf_size
int buf_size
Definition: exr.c:150
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
bytestream.h
imgutils.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:564
ExrTileLevelMode
ExrTileLevelMode
Definition: exr.c:81
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
EXRTileAttribute::ySize
int32_t ySize
Definition: exr.c:101
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
exr_class
static const AVClass exr_class
Definition: exr.c:1937
BswapDSPContext
Definition: bswapdsp.h:24
h
h
Definition: vp9dsp_template.c:2038
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
EXRContext::xdelta
uint32_t xdelta
Definition: exr.c:139
int
int
Definition: ffmpeg_filter.c:192
b44_uncompress
static int b44_uncompress(EXRContext *s, const uint8_t *src, int compressed_size, int uncompressed_size, EXRThreadData *td)
Definition: exr.c:910
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232
AVCodecContext::execute2
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1845
piz_uncompress
static int piz_uncompress(EXRContext *s, const uint8_t *src, int ssize, int dsize, EXRThreadData *td)
Definition: exr.c:690
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40
channel
channel
Definition: ebur128.h:39
EXRContext::dsp
ExrDSPContext dsp
Definition: exr.c:125
EXR_UNKN
@ EXR_UNKN
Definition: exr.c:71
EXRContext
Definition: exr.c:121
EXRChannel
Definition: exr.c:94