FFmpeg
tiff.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 Konstantin Shishkov
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * TIFF image decoder
24  * @author Konstantin Shishkov
25  */
26 
27 #include "config.h"
28 #if CONFIG_ZLIB
29 #include <zlib.h>
30 #endif
31 #if CONFIG_LZMA
32 #define LZMA_API_STATIC
33 #include <lzma.h>
34 #endif
35 
36 #include "libavutil/attributes.h"
37 #include "libavutil/avstring.h"
38 #include "libavutil/intreadwrite.h"
39 #include "libavutil/imgutils.h"
40 #include "libavutil/opt.h"
41 #include "avcodec.h"
42 #include "bytestream.h"
43 #include "faxcompr.h"
44 #include "internal.h"
45 #include "lzw.h"
46 #include "mathops.h"
47 #include "tiff.h"
48 #include "tiff_data.h"
49 #include "thread.h"
50 #include "get_bits.h"
51 
52 typedef struct TiffContext {
53  AVClass *class;
56 
58  uint16_t get_page;
60 
62  int width, height;
63  unsigned int bpp, bppcount;
64  uint32_t palette[256];
66  int le;
69  int planar;
70  int subsampling[2];
71  int fax_opts;
72  int predictor;
74  uint32_t res[4];
76  unsigned last_tag;
77 
78  int is_bayer;
80  unsigned white_level;
81 
82  uint32_t sub_ifd;
83  uint16_t cur_page;
84 
85  int strips, rps, sstype;
86  int sot;
89 
93  unsigned int yuv_line_size;
95  unsigned int fax_buffer_size;
96 
99 } TiffContext;
100 
101 static void tiff_set_type(TiffContext *s, enum TiffType tiff_type) {
102  if (s->tiff_type < tiff_type) // Prioritize higher-valued entries
103  s->tiff_type = tiff_type;
104 }
105 
106 static void free_geotags(TiffContext *const s)
107 {
108  int i;
109  for (i = 0; i < s->geotag_count; i++) {
110  if (s->geotags[i].val)
111  av_freep(&s->geotags[i].val);
112  }
113  av_freep(&s->geotags);
114  s->geotag_count = 0;
115 }
116 
117 #define RET_GEOKEY(TYPE, array, element)\
118  if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
119  key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
120  return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
121 
122 static const char *get_geokey_name(int key)
123 {
124  RET_GEOKEY(VERT, vert, name);
125  RET_GEOKEY(PROJ, proj, name);
126  RET_GEOKEY(GEOG, geog, name);
127  RET_GEOKEY(CONF, conf, name);
128 
129  return NULL;
130 }
131 
132 static int get_geokey_type(int key)
133 {
134  RET_GEOKEY(VERT, vert, type);
135  RET_GEOKEY(PROJ, proj, type);
136  RET_GEOKEY(GEOG, geog, type);
137  RET_GEOKEY(CONF, conf, type);
138 
139  return AVERROR_INVALIDDATA;
140 }
141 
142 static int cmp_id_key(const void *id, const void *k)
143 {
144  return *(const int*)id - ((const TiffGeoTagKeyName*)k)->key;
145 }
146 
147 static const char *search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
148 {
149  TiffGeoTagKeyName *r = bsearch(&id, keys, n, sizeof(keys[0]), cmp_id_key);
150  if(r)
151  return r->name;
152 
153  return NULL;
154 }
155 
156 static char *get_geokey_val(int key, int val)
157 {
158  char *ap;
159 
161  return av_strdup("undefined");
163  return av_strdup("User-Defined");
164 
165 #define RET_GEOKEY_VAL(TYPE, array)\
166  if (val >= TIFF_##TYPE##_OFFSET &&\
167  val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
168  return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
169 
170  switch (key) {
172  RET_GEOKEY_VAL(GT_MODEL_TYPE, gt_model_type);
173  break;
175  RET_GEOKEY_VAL(GT_RASTER_TYPE, gt_raster_type);
176  break;
180  RET_GEOKEY_VAL(LINEAR_UNIT, linear_unit);
181  break;
184  RET_GEOKEY_VAL(ANGULAR_UNIT, angular_unit);
185  break;
187  RET_GEOKEY_VAL(GCS_TYPE, gcs_type);
188  RET_GEOKEY_VAL(GCSE_TYPE, gcse_type);
189  break;
191  RET_GEOKEY_VAL(GEODETIC_DATUM, geodetic_datum);
192  RET_GEOKEY_VAL(GEODETIC_DATUM_E, geodetic_datum_e);
193  break;
195  RET_GEOKEY_VAL(ELLIPSOID, ellipsoid);
196  break;
198  RET_GEOKEY_VAL(PRIME_MERIDIAN, prime_meridian);
199  break;
202  if(ap) return ap;
203  break;
206  if(ap) return ap;
207  break;
209  RET_GEOKEY_VAL(COORD_TRANS, coord_trans);
210  break;
212  RET_GEOKEY_VAL(VERT_CS, vert_cs);
213  RET_GEOKEY_VAL(ORTHO_VERT_CS, ortho_vert_cs);
214  break;
215 
216  }
217 
218  ap = av_malloc(14);
219  if (ap)
220  snprintf(ap, 14, "Unknown-%d", val);
221  return ap;
222 }
223 
224 static char *doubles2str(double *dp, int count, const char *sep)
225 {
226  int i;
227  char *ap, *ap0;
228  uint64_t component_len;
229  if (!sep) sep = ", ";
230  component_len = 24LL + strlen(sep);
231  if (count >= (INT_MAX - 1)/component_len)
232  return NULL;
233  ap = av_malloc(component_len * count + 1);
234  if (!ap)
235  return NULL;
236  ap0 = ap;
237  ap[0] = '\0';
238  for (i = 0; i < count; i++) {
239  unsigned l = snprintf(ap, component_len, "%.15g%s", dp[i], sep);
240  if(l >= component_len) {
241  av_free(ap0);
242  return NULL;
243  }
244  ap += l;
245  }
246  ap0[strlen(ap0) - strlen(sep)] = '\0';
247  return ap0;
248 }
249 
250 static int add_metadata(int count, int type,
251  const char *name, const char *sep, TiffContext *s, AVFrame *frame)
252 {
253  switch(type) {
254  case TIFF_DOUBLE: return ff_tadd_doubles_metadata(count, name, sep, &s->gb, s->le, &frame->metadata);
255  case TIFF_SHORT : return ff_tadd_shorts_metadata(count, name, sep, &s->gb, s->le, 0, &frame->metadata);
256  case TIFF_STRING: return ff_tadd_string_metadata(count, name, &s->gb, s->le, &frame->metadata);
257  default : return AVERROR_INVALIDDATA;
258  };
259 }
260 
262  unsigned int bpp, uint8_t* dst,
263  int usePtr, const uint8_t *src,
264  uint8_t c, int width, int offset)
265 {
266  switch (bpp) {
267  case 1:
268  while (--width >= 0) {
269  dst[(width+offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
270  dst[(width+offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
271  dst[(width+offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
272  dst[(width+offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
273  dst[(width+offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
274  dst[(width+offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
275  dst[(width+offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
276  dst[(width+offset)*8+0] = (usePtr ? src[width] : c) >> 7;
277  }
278  break;
279  case 2:
280  while (--width >= 0) {
281  dst[(width+offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
282  dst[(width+offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
283  dst[(width+offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
284  dst[(width+offset)*4+0] = (usePtr ? src[width] : c) >> 6;
285  }
286  break;
287  case 4:
288  while (--width >= 0) {
289  dst[(width+offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
290  dst[(width+offset)*2+0] = (usePtr ? src[width] : c) >> 4;
291  }
292  break;
293  case 12: {
294  uint16_t *dst16 = (uint16_t *)dst;
295  GetBitContext gb;
296  init_get_bits8(&gb, src, width);
297  for (int i = 0; i < s->width; i++) {
298  dst16[i] = get_bits(&gb, 12) << 4;
299  }
300  }
301  break;
302  default:
303  if (usePtr) {
304  memcpy(dst + offset, src, width);
305  } else {
306  memset(dst + offset, c, width);
307  }
308  }
309 }
310 
311 static int deinvert_buffer(TiffContext *s, const uint8_t *src, int size)
312 {
313  int i;
314 
315  av_fast_padded_malloc(&s->deinvert_buf, &s->deinvert_buf_size, size);
316  if (!s->deinvert_buf)
317  return AVERROR(ENOMEM);
318  for (i = 0; i < size; i++)
319  s->deinvert_buf[i] = ff_reverse[src[i]];
320 
321  return 0;
322 }
323 
324 static void unpack_gray(TiffContext *s, AVFrame *p,
325  const uint8_t *src, int lnum, int width, int bpp)
326 {
327  GetBitContext gb;
328  uint16_t *dst = (uint16_t *)(p->data[0] + lnum * p->linesize[0]);
329 
330  init_get_bits8(&gb, src, width);
331 
332  for (int i = 0; i < s->width; i++) {
333  dst[i] = get_bits(&gb, bpp);
334  }
335 }
336 
337 static void unpack_yuv(TiffContext *s, AVFrame *p,
338  const uint8_t *src, int lnum)
339 {
340  int i, j, k;
341  int w = (s->width - 1) / s->subsampling[0] + 1;
342  uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
343  uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
344  if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
345  for (i = 0; i < w; i++) {
346  for (j = 0; j < s->subsampling[1]; j++)
347  for (k = 0; k < s->subsampling[0]; k++)
348  p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
349  FFMIN(i * s->subsampling[0] + k, s->width-1)] = *src++;
350  *pu++ = *src++;
351  *pv++ = *src++;
352  }
353  }else{
354  for (i = 0; i < w; i++) {
355  for (j = 0; j < s->subsampling[1]; j++)
356  for (k = 0; k < s->subsampling[0]; k++)
357  p->data[0][(lnum + j) * p->linesize[0] +
358  i * s->subsampling[0] + k] = *src++;
359  *pu++ = *src++;
360  *pv++ = *src++;
361  }
362  }
363 }
364 
365 #if CONFIG_ZLIB
366 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
367  int size)
368 {
369  z_stream zstream = { 0 };
370  int zret;
371 
372  zstream.next_in = (uint8_t *)src;
373  zstream.avail_in = size;
374  zstream.next_out = dst;
375  zstream.avail_out = *len;
376  zret = inflateInit(&zstream);
377  if (zret != Z_OK) {
378  av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
379  return zret;
380  }
381  zret = inflate(&zstream, Z_SYNC_FLUSH);
382  inflateEnd(&zstream);
383  *len = zstream.total_out;
384  return zret == Z_STREAM_END ? Z_OK : zret;
385 }
386 
387 static int tiff_unpack_zlib(TiffContext *s, AVFrame *p, uint8_t *dst, int stride,
388  const uint8_t *src, int size, int width, int lines,
389  int strip_start, int is_yuv)
390 {
391  uint8_t *zbuf;
392  unsigned long outlen;
393  int ret, line;
394  outlen = width * lines;
395  zbuf = av_malloc(outlen);
396  if (!zbuf)
397  return AVERROR(ENOMEM);
398  if (s->fill_order) {
399  if ((ret = deinvert_buffer(s, src, size)) < 0) {
400  av_free(zbuf);
401  return ret;
402  }
403  src = s->deinvert_buf;
404  }
405  ret = tiff_uncompress(zbuf, &outlen, src, size);
406  if (ret != Z_OK) {
407  av_log(s->avctx, AV_LOG_ERROR,
408  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
409  (unsigned long)width * lines, ret);
410  av_free(zbuf);
411  return AVERROR_UNKNOWN;
412  }
413  src = zbuf;
414  for (line = 0; line < lines; line++) {
415  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
416  horizontal_fill(s, s->bpp, dst, 1, src, 0, width, 0);
417  } else {
418  memcpy(dst, src, width);
419  }
420  if (is_yuv) {
421  unpack_yuv(s, p, dst, strip_start + line);
422  line += s->subsampling[1] - 1;
423  }
424  dst += stride;
425  src += width;
426  }
427  av_free(zbuf);
428  return 0;
429 }
430 #endif
431 
432 #if CONFIG_LZMA
433 static int tiff_uncompress_lzma(uint8_t *dst, uint64_t *len, const uint8_t *src,
434  int size)
435 {
436  lzma_stream stream = LZMA_STREAM_INIT;
437  lzma_ret ret;
438 
439  stream.next_in = (uint8_t *)src;
440  stream.avail_in = size;
441  stream.next_out = dst;
442  stream.avail_out = *len;
443  ret = lzma_stream_decoder(&stream, UINT64_MAX, 0);
444  if (ret != LZMA_OK) {
445  av_log(NULL, AV_LOG_ERROR, "LZMA init error: %d\n", ret);
446  return ret;
447  }
448  ret = lzma_code(&stream, LZMA_RUN);
449  lzma_end(&stream);
450  *len = stream.total_out;
451  return ret == LZMA_STREAM_END ? LZMA_OK : ret;
452 }
453 
454 static int tiff_unpack_lzma(TiffContext *s, AVFrame *p, uint8_t *dst, int stride,
455  const uint8_t *src, int size, int width, int lines,
456  int strip_start, int is_yuv)
457 {
458  uint64_t outlen = width * (uint64_t)lines;
459  int ret, line;
460  uint8_t *buf = av_malloc(outlen);
461  if (!buf)
462  return AVERROR(ENOMEM);
463  if (s->fill_order) {
464  if ((ret = deinvert_buffer(s, src, size)) < 0) {
465  av_free(buf);
466  return ret;
467  }
468  src = s->deinvert_buf;
469  }
470  ret = tiff_uncompress_lzma(buf, &outlen, src, size);
471  if (ret != LZMA_OK) {
472  av_log(s->avctx, AV_LOG_ERROR,
473  "Uncompressing failed (%"PRIu64" of %"PRIu64") with error %d\n", outlen,
474  (uint64_t)width * lines, ret);
475  av_free(buf);
476  return AVERROR_UNKNOWN;
477  }
478  src = buf;
479  for (line = 0; line < lines; line++) {
480  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
481  horizontal_fill(s, s->bpp, dst, 1, src, 0, width, 0);
482  } else {
483  memcpy(dst, src, width);
484  }
485  if (is_yuv) {
486  unpack_yuv(s, p, dst, strip_start + line);
487  line += s->subsampling[1] - 1;
488  }
489  dst += stride;
490  src += width;
491  }
492  av_free(buf);
493  return 0;
494 }
495 #endif
496 
497 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
498  const uint8_t *src, int size, int width, int lines)
499 {
500  int i, ret = 0;
501  int line;
502  uint8_t *src2;
503 
504  av_fast_padded_malloc(&s->fax_buffer, &s->fax_buffer_size, size);
505  src2 = s->fax_buffer;
506 
507  if (!src2) {
508  av_log(s->avctx, AV_LOG_ERROR,
509  "Error allocating temporary buffer\n");
510  return AVERROR(ENOMEM);
511  }
512 
513  if (!s->fill_order) {
514  memcpy(src2, src, size);
515  } else {
516  for (i = 0; i < size; i++)
517  src2[i] = ff_reverse[src[i]];
518  }
519  memset(src2 + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
520  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
521  s->compr, s->fax_opts);
522  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
523  for (line = 0; line < lines; line++) {
524  horizontal_fill(s, s->bpp, dst, 1, dst, 0, width, 0);
525  dst += stride;
526  }
527  return ret;
528 }
529 
531  const uint8_t *src, int size, int strip_start, int lines)
532 {
533  PutByteContext pb;
534  int c, line, pixels, code, ret;
535  const uint8_t *ssrc = src;
536  int width = ((s->width * s->bpp) + 7) >> 3;
538  int is_yuv = !(desc->flags & AV_PIX_FMT_FLAG_RGB) &&
539  (desc->flags & AV_PIX_FMT_FLAG_PLANAR) &&
540  desc->nb_components >= 3;
541 
542  if (s->planar)
543  width /= s->bppcount;
544 
545  if (size <= 0)
546  return AVERROR_INVALIDDATA;
547 
548  if (is_yuv) {
549  int bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *
550  s->subsampling[0] * s->subsampling[1] + 7) >> 3;
551  av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);
552  if (s->yuv_line == NULL) {
553  av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
554  return AVERROR(ENOMEM);
555  }
556  dst = s->yuv_line;
557  stride = 0;
558 
559  width = (s->width - 1) / s->subsampling[0] + 1;
560  width = width * s->subsampling[0] * s->subsampling[1] + 2*width;
561  av_assert0(width <= bytes_per_row);
562  av_assert0(s->bpp == 24);
563  }
564  if (s->is_bayer) {
565  width = (s->bpp * s->width + 7) >> 3;
566  }
567  if (p->format == AV_PIX_FMT_GRAY12) {
568  av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, width);
569  if (s->yuv_line == NULL) {
570  av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
571  return AVERROR(ENOMEM);
572  }
573  dst = s->yuv_line;
574  stride = 0;
575  }
576 
577  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
578 #if CONFIG_ZLIB
579  return tiff_unpack_zlib(s, p, dst, stride, src, size, width, lines,
580  strip_start, is_yuv);
581 #else
582  av_log(s->avctx, AV_LOG_ERROR,
583  "zlib support not enabled, "
584  "deflate compression not supported\n");
585  return AVERROR(ENOSYS);
586 #endif
587  }
588  if (s->compr == TIFF_LZMA) {
589 #if CONFIG_LZMA
590  return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,
591  strip_start, is_yuv);
592 #else
593  av_log(s->avctx, AV_LOG_ERROR,
594  "LZMA support not enabled\n");
595  return AVERROR(ENOSYS);
596 #endif
597  }
598  if (s->compr == TIFF_LZW) {
599  if (s->fill_order) {
600  if ((ret = deinvert_buffer(s, src, size)) < 0)
601  return ret;
602  ssrc = src = s->deinvert_buf;
603  }
604  if (size > 1 && !src[0] && (src[1]&1)) {
605  av_log(s->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");
606  }
607  if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
608  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
609  return ret;
610  }
611  for (line = 0; line < lines; line++) {
612  pixels = ff_lzw_decode(s->lzw, dst, width);
613  if (pixels < width) {
614  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
615  pixels, width);
616  return AVERROR_INVALIDDATA;
617  }
618  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
619  horizontal_fill(s, s->bpp, dst, 1, dst, 0, width, 0);
620  if (is_yuv) {
621  unpack_yuv(s, p, dst, strip_start + line);
622  line += s->subsampling[1] - 1;
623  } else if (p->format == AV_PIX_FMT_GRAY12) {
624  unpack_gray(s, p, dst, strip_start + line, width, s->bpp);
625  }
626  dst += stride;
627  }
628  return 0;
629  }
630  if (s->compr == TIFF_CCITT_RLE ||
631  s->compr == TIFF_G3 ||
632  s->compr == TIFF_G4) {
633  if (is_yuv || p->format == AV_PIX_FMT_GRAY12)
634  return AVERROR_INVALIDDATA;
635 
636  return tiff_unpack_fax(s, dst, stride, src, size, width, lines);
637  }
638 
639  bytestream2_init(&s->gb, src, size);
640  bytestream2_init_writer(&pb, dst, is_yuv ? s->yuv_line_size : (stride * lines));
641 
642  for (line = 0; line < lines; line++) {
643  if (src - ssrc > size) {
644  av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
645  return AVERROR_INVALIDDATA;
646  }
647 
648  if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))
649  break;
650  bytestream2_seek_p(&pb, stride * line, SEEK_SET);
651  switch (s->compr) {
652  case TIFF_RAW:
653  if (ssrc + size - src < width)
654  return AVERROR_INVALIDDATA;
655 
656  if (!s->fill_order) {
657  horizontal_fill(s, s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 || s->is_bayer),
658  dst, 1, src, 0, width, 0);
659  } else {
660  int i;
661  for (i = 0; i < width; i++)
662  dst[i] = ff_reverse[src[i]];
663  }
664  src += width;
665  break;
666  case TIFF_PACKBITS:
667  for (pixels = 0; pixels < width;) {
668  if (ssrc + size - src < 2) {
669  av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
670  return AVERROR_INVALIDDATA;
671  }
672  code = s->fill_order ? (int8_t) ff_reverse[*src++]: (int8_t) *src++;
673  if (code >= 0) {
674  code++;
675  if (pixels + code > width ||
676  ssrc + size - src < code) {
677  av_log(s->avctx, AV_LOG_ERROR,
678  "Copy went out of bounds\n");
679  return AVERROR_INVALIDDATA;
680  }
681  horizontal_fill(s, s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),
682  dst, 1, src, 0, code, pixels);
683  src += code;
684  pixels += code;
685  } else if (code != -128) { // -127..-1
686  code = (-code) + 1;
687  if (pixels + code > width) {
688  av_log(s->avctx, AV_LOG_ERROR,
689  "Run went out of bounds\n");
690  return AVERROR_INVALIDDATA;
691  }
692  c = *src++;
693  horizontal_fill(s, s->bpp * (s->avctx->pix_fmt == AV_PIX_FMT_PAL8),
694  dst, 0, NULL, c, code, pixels);
695  pixels += code;
696  }
697  }
698  if (s->fill_order) {
699  int i;
700  for (i = 0; i < width; i++)
701  dst[i] = ff_reverse[dst[i]];
702  }
703  break;
704  }
705  if (is_yuv) {
706  unpack_yuv(s, p, dst, strip_start + line);
707  line += s->subsampling[1] - 1;
708  } else if (p->format == AV_PIX_FMT_GRAY12) {
709  unpack_gray(s, p, dst, strip_start + line, width, s->bpp);
710  }
711  dst += stride;
712  }
713  return 0;
714 }
715 
717 {
718  int ret;
719  int create_gray_palette = 0;
720 
721  // make sure there is no aliasing in the following switch
722  if (s->bpp >= 100 || s->bppcount >= 10) {
723  av_log(s->avctx, AV_LOG_ERROR,
724  "Unsupported image parameters: bpp=%d, bppcount=%d\n",
725  s->bpp, s->bppcount);
726  return AVERROR_INVALIDDATA;
727  }
728 
729  switch (s->planar * 1000 + s->bpp * 10 + s->bppcount + s->is_bayer * 10000) {
730  case 11:
731  if (!s->palette_is_set) {
732  s->avctx->pix_fmt = AV_PIX_FMT_MONOBLACK;
733  break;
734  }
735  case 21:
736  case 41:
737  s->avctx->pix_fmt = AV_PIX_FMT_PAL8;
738  if (!s->palette_is_set) {
739  create_gray_palette = 1;
740  }
741  break;
742  case 81:
743  s->avctx->pix_fmt = s->palette_is_set ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
744  break;
745  case 121:
746  s->avctx->pix_fmt = AV_PIX_FMT_GRAY12;
747  break;
748  case 10081:
749  switch (AV_RL32(s->pattern)) {
750  case 0x02010100:
751  s->avctx->pix_fmt = AV_PIX_FMT_BAYER_RGGB8;
752  break;
753  case 0x00010102:
754  s->avctx->pix_fmt = AV_PIX_FMT_BAYER_BGGR8;
755  break;
756  case 0x01000201:
757  s->avctx->pix_fmt = AV_PIX_FMT_BAYER_GBRG8;
758  break;
759  case 0x01020001:
760  s->avctx->pix_fmt = AV_PIX_FMT_BAYER_GRBG8;
761  break;
762  default:
763  av_log(s->avctx, AV_LOG_ERROR, "Unsupported Bayer pattern: 0x%X\n",
764  AV_RL32(s->pattern));
765  return AVERROR_PATCHWELCOME;
766  }
767  break;
768  case 10121:
769  switch (AV_RL32(s->pattern)) {
770  case 0x02010100:
771  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_RGGB16LE : AV_PIX_FMT_BAYER_RGGB16BE;
772  break;
773  case 0x00010102:
774  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_BGGR16LE : AV_PIX_FMT_BAYER_BGGR16BE;
775  break;
776  case 0x01000201:
777  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_GBRG16LE : AV_PIX_FMT_BAYER_GBRG16BE;
778  break;
779  case 0x01020001:
780  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_GRBG16LE : AV_PIX_FMT_BAYER_GRBG16BE;
781  break;
782  default:
783  av_log(s->avctx, AV_LOG_ERROR, "Unsupported Bayer pattern: 0x%X\n",
784  AV_RL32(s->pattern));
785  return AVERROR_PATCHWELCOME;
786  }
787  break;
788  case 10161:
789  switch (AV_RL32(s->pattern)) {
790  case 0x02010100:
791  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_RGGB16LE : AV_PIX_FMT_BAYER_RGGB16BE;
792  break;
793  case 0x00010102:
794  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_BGGR16LE : AV_PIX_FMT_BAYER_BGGR16BE;
795  break;
796  case 0x01000201:
797  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_GBRG16LE : AV_PIX_FMT_BAYER_GBRG16BE;
798  break;
799  case 0x01020001:
800  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_BAYER_GRBG16LE : AV_PIX_FMT_BAYER_GRBG16BE;
801  break;
802  default:
803  av_log(s->avctx, AV_LOG_ERROR, "Unsupported Bayer pattern: 0x%X\n",
804  AV_RL32(s->pattern));
805  return AVERROR_PATCHWELCOME;
806  }
807  break;
808  case 243:
809  if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
810  if (s->subsampling[0] == 1 && s->subsampling[1] == 1) {
811  s->avctx->pix_fmt = AV_PIX_FMT_YUV444P;
812  } else if (s->subsampling[0] == 2 && s->subsampling[1] == 1) {
813  s->avctx->pix_fmt = AV_PIX_FMT_YUV422P;
814  } else if (s->subsampling[0] == 4 && s->subsampling[1] == 1) {
815  s->avctx->pix_fmt = AV_PIX_FMT_YUV411P;
816  } else if (s->subsampling[0] == 1 && s->subsampling[1] == 2) {
817  s->avctx->pix_fmt = AV_PIX_FMT_YUV440P;
818  } else if (s->subsampling[0] == 2 && s->subsampling[1] == 2) {
819  s->avctx->pix_fmt = AV_PIX_FMT_YUV420P;
820  } else if (s->subsampling[0] == 4 && s->subsampling[1] == 4) {
821  s->avctx->pix_fmt = AV_PIX_FMT_YUV410P;
822  } else {
823  av_log(s->avctx, AV_LOG_ERROR, "Unsupported YCbCr subsampling\n");
824  return AVERROR_PATCHWELCOME;
825  }
826  } else
827  s->avctx->pix_fmt = AV_PIX_FMT_RGB24;
828  break;
829  case 161:
830  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_GRAY16LE : AV_PIX_FMT_GRAY16BE;
831  break;
832  case 162:
833  s->avctx->pix_fmt = AV_PIX_FMT_YA8;
834  break;
835  case 322:
836  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_YA16LE : AV_PIX_FMT_YA16BE;
837  break;
838  case 324:
839  s->avctx->pix_fmt = s->photometric == TIFF_PHOTOMETRIC_SEPARATED ? AV_PIX_FMT_RGB0 : AV_PIX_FMT_RGBA;
840  break;
841  case 405:
842  if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED)
843  s->avctx->pix_fmt = AV_PIX_FMT_RGBA;
844  else {
845  av_log(s->avctx, AV_LOG_ERROR,
846  "bpp=40 without PHOTOMETRIC_SEPARATED is unsupported\n");
847  return AVERROR_PATCHWELCOME;
848  }
849  break;
850  case 483:
851  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGB48LE : AV_PIX_FMT_RGB48BE;
852  break;
853  case 644:
854  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_RGBA64LE : AV_PIX_FMT_RGBA64BE;
855  break;
856  case 1243:
857  s->avctx->pix_fmt = AV_PIX_FMT_GBRP;
858  break;
859  case 1324:
860  s->avctx->pix_fmt = AV_PIX_FMT_GBRAP;
861  break;
862  case 1483:
863  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_GBRP16LE : AV_PIX_FMT_GBRP16BE;
864  break;
865  case 1644:
866  s->avctx->pix_fmt = s->le ? AV_PIX_FMT_GBRAP16LE : AV_PIX_FMT_GBRAP16BE;
867  break;
868  default:
869  av_log(s->avctx, AV_LOG_ERROR,
870  "This format is not supported (bpp=%d, bppcount=%d)\n",
871  s->bpp, s->bppcount);
872  return AVERROR_INVALIDDATA;
873  }
874 
875  if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
876  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(s->avctx->pix_fmt);
877  if((desc->flags & AV_PIX_FMT_FLAG_RGB) ||
878  !(desc->flags & AV_PIX_FMT_FLAG_PLANAR) ||
879  desc->nb_components < 3) {
880  av_log(s->avctx, AV_LOG_ERROR, "Unsupported YCbCr variant\n");
881  return AVERROR_INVALIDDATA;
882  }
883  }
884 
885  if (s->width != s->avctx->width || s->height != s->avctx->height) {
886  ret = ff_set_dimensions(s->avctx, s->width, s->height);
887  if (ret < 0)
888  return ret;
889  }
890  if ((ret = ff_thread_get_buffer(s->avctx, frame, 0)) < 0)
891  return ret;
892  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
893  if (!create_gray_palette)
894  memcpy(frame->f->data[1], s->palette, sizeof(s->palette));
895  else {
896  /* make default grayscale pal */
897  int i;
898  uint32_t *pal = (uint32_t *)frame->f->data[1];
899  for (i = 0; i < 1<<s->bpp; i++)
900  pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->bpp) - 1) * 0x010101;
901  }
902  }
903  return 0;
904 }
905 
906 static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den)
907 {
908  int offset = tag == TIFF_YRES ? 2 : 0;
909  s->res[offset++] = num;
910  s->res[offset] = den;
911  if (s->res[0] && s->res[1] && s->res[2] && s->res[3]) {
912  uint64_t num = s->res[2] * (uint64_t)s->res[1];
913  uint64_t den = s->res[0] * (uint64_t)s->res[3];
914  if (num > INT64_MAX || den > INT64_MAX) {
915  num = num >> 1;
916  den = den >> 1;
917  }
918  av_reduce(&s->avctx->sample_aspect_ratio.num, &s->avctx->sample_aspect_ratio.den,
919  num, den, INT32_MAX);
920  if (!s->avctx->sample_aspect_ratio.den)
921  s->avctx->sample_aspect_ratio = (AVRational) {0, 1};
922  }
923 }
924 
926 {
927  unsigned tag, type, count, off, value = 0, value2 = 0;
928  int i, start;
929  int pos;
930  int ret;
931  double *dp;
932 
933  ret = ff_tread_tag(&s->gb, s->le, &tag, &type, &count, &start);
934  if (ret < 0) {
935  goto end;
936  }
937  if (tag <= s->last_tag)
938  return AVERROR_INVALIDDATA;
939 
940  // We ignore TIFF_STRIP_SIZE as it is sometimes in the logic but wrong order around TIFF_STRIP_OFFS
941  if (tag != TIFF_STRIP_SIZE)
942  s->last_tag = tag;
943 
944  off = bytestream2_tell(&s->gb);
945  if (count == 1) {
946  switch (type) {
947  case TIFF_BYTE:
948  case TIFF_SHORT:
949  case TIFF_LONG:
950  value = ff_tget(&s->gb, type, s->le);
951  break;
952  case TIFF_RATIONAL:
953  value = ff_tget(&s->gb, TIFF_LONG, s->le);
954  value2 = ff_tget(&s->gb, TIFF_LONG, s->le);
955  break;
956  case TIFF_STRING:
957  if (count <= 4) {
958  break;
959  }
960  default:
961  value = UINT_MAX;
962  }
963  }
964 
965  switch (tag) {
966  case TIFF_SUBFILE:
967  s->is_thumbnail = (value != 0);
968  case TIFF_WIDTH:
969  s->width = value;
970  break;
971  case TIFF_HEIGHT:
972  s->height = value;
973  break;
974  case TIFF_BPP:
975  if (count > 5 || count <= 0) {
976  av_log(s->avctx, AV_LOG_ERROR,
977  "This format is not supported (bpp=%d, %d components)\n",
978  value, count);
979  return AVERROR_INVALIDDATA;
980  }
981  s->bppcount = count;
982  if (count == 1)
983  s->bpp = value;
984  else {
985  switch (type) {
986  case TIFF_BYTE:
987  case TIFF_SHORT:
988  case TIFF_LONG:
989  s->bpp = 0;
991  return AVERROR_INVALIDDATA;
992  for (i = 0; i < count; i++)
993  s->bpp += ff_tget(&s->gb, type, s->le);
994  break;
995  default:
996  s->bpp = -1;
997  }
998  }
999  break;
1001  if (count != 1) {
1002  av_log(s->avctx, AV_LOG_ERROR,
1003  "Samples per pixel requires a single value, many provided\n");
1004  return AVERROR_INVALIDDATA;
1005  }
1006  if (value > 5 || value <= 0) {
1007  av_log(s->avctx, AV_LOG_ERROR,
1008  "Invalid samples per pixel %d\n", value);
1009  return AVERROR_INVALIDDATA;
1010  }
1011  if (s->bppcount == 1)
1012  s->bpp *= value;
1013  s->bppcount = value;
1014  break;
1015  case TIFF_COMPR:
1016  s->compr = value;
1017  av_log(s->avctx, AV_LOG_DEBUG, "compression: %d\n", s->compr);
1018  s->predictor = 0;
1019  switch (s->compr) {
1020  case TIFF_RAW:
1021  case TIFF_PACKBITS:
1022  case TIFF_LZW:
1023  case TIFF_CCITT_RLE:
1024  break;
1025  case TIFF_G3:
1026  case TIFF_G4:
1027  s->fax_opts = 0;
1028  break;
1029  case TIFF_DEFLATE:
1030  case TIFF_ADOBE_DEFLATE:
1031 #if CONFIG_ZLIB
1032  break;
1033 #else
1034  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
1035  return AVERROR(ENOSYS);
1036 #endif
1037  case TIFF_JPEG:
1038  case TIFF_NEWJPEG:
1039  avpriv_report_missing_feature(s->avctx, "JPEG compression");
1040  return AVERROR_PATCHWELCOME;
1041  case TIFF_LZMA:
1042 #if CONFIG_LZMA
1043  break;
1044 #else
1045  av_log(s->avctx, AV_LOG_ERROR, "LZMA not compiled in\n");
1046  return AVERROR(ENOSYS);
1047 #endif
1048  default:
1049  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
1050  s->compr);
1051  return AVERROR_INVALIDDATA;
1052  }
1053  break;
1054  case TIFF_ROWSPERSTRIP:
1055  if (!value || (type == TIFF_LONG && value == UINT_MAX))
1056  value = s->height;
1057  s->rps = FFMIN(value, s->height);
1058  break;
1059  case TIFF_STRIP_OFFS:
1060  if (count == 1) {
1061  if (value > INT_MAX) {
1062  av_log(s->avctx, AV_LOG_ERROR,
1063  "strippos %u too large\n", value);
1064  return AVERROR_INVALIDDATA;
1065  }
1066  s->strippos = 0;
1067  s->stripoff = value;
1068  } else
1069  s->strippos = off;
1070  s->strips = count;
1071  if (s->strips == 1)
1072  s->rps = s->height;
1073  s->sot = type;
1074  break;
1075  case TIFF_STRIP_SIZE:
1076  if (count == 1) {
1077  if (value > INT_MAX) {
1078  av_log(s->avctx, AV_LOG_ERROR,
1079  "stripsize %u too large\n", value);
1080  return AVERROR_INVALIDDATA;
1081  }
1082  s->stripsizesoff = 0;
1083  s->stripsize = value;
1084  s->strips = 1;
1085  } else {
1086  s->stripsizesoff = off;
1087  }
1088  s->strips = count;
1089  s->sstype = type;
1090  break;
1091  case TIFF_XRES:
1092  case TIFF_YRES:
1093  set_sar(s, tag, value, value2);
1094  break;
1095  case TIFF_TILE_BYTE_COUNTS:
1096  case TIFF_TILE_LENGTH:
1097  case TIFF_TILE_OFFSETS:
1098  case TIFF_TILE_WIDTH:
1099  av_log(s->avctx, AV_LOG_ERROR, "Tiled images are not supported\n");
1100  return AVERROR_PATCHWELCOME;
1101  break;
1102  case TIFF_PREDICTOR:
1103  s->predictor = value;
1104  break;
1105  case TIFF_SUB_IFDS:
1106  if (count == 1)
1107  s->sub_ifd = value;
1108  else if (count > 1)
1109  s->sub_ifd = ff_tget(&s->gb, TIFF_LONG, s->le); /** Only get the first SubIFD */
1110  break;
1111  case DNG_WHITE_LEVEL:
1112  s->white_level = value;
1113  break;
1114  case TIFF_CFA_PATTERN_DIM:
1115  if (count != 2 || (ff_tget(&s->gb, type, s->le) != 2 &&
1116  ff_tget(&s->gb, type, s->le) != 2)) {
1117  av_log(s->avctx, AV_LOG_ERROR, "CFA Pattern dimensions are not 2x2\n");
1118  return AVERROR_INVALIDDATA;
1119  }
1120  break;
1121  case TIFF_CFA_PATTERN:
1122  s->is_bayer = 1;
1123  s->pattern[0] = ff_tget(&s->gb, type, s->le);
1124  s->pattern[1] = ff_tget(&s->gb, type, s->le);
1125  s->pattern[2] = ff_tget(&s->gb, type, s->le);
1126  s->pattern[3] = ff_tget(&s->gb, type, s->le);
1127  break;
1128  case TIFF_PHOTOMETRIC:
1129  switch (value) {
1132  case TIFF_PHOTOMETRIC_RGB:
1136  case TIFF_PHOTOMETRIC_CFA:
1137  s->photometric = value;
1138  break;
1147  "PhotometricInterpretation 0x%04X",
1148  value);
1149  return AVERROR_PATCHWELCOME;
1150  default:
1151  av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
1152  "unknown\n", value);
1153  return AVERROR_INVALIDDATA;
1154  }
1155  break;
1156  case TIFF_FILL_ORDER:
1157  if (value < 1 || value > 2) {
1158  av_log(s->avctx, AV_LOG_ERROR,
1159  "Unknown FillOrder value %d, trying default one\n", value);
1160  value = 1;
1161  }
1162  s->fill_order = value - 1;
1163  break;
1164  case TIFF_PAL: {
1165  GetByteContext pal_gb[3];
1166  off = type_sizes[type];
1167  if (count / 3 > 256 ||
1168  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
1169  return AVERROR_INVALIDDATA;
1170 
1171  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
1172  bytestream2_skip(&pal_gb[1], count / 3 * off);
1173  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
1174 
1175  off = (type_sizes[type] - 1) << 3;
1176  if (off > 31U) {
1177  av_log(s->avctx, AV_LOG_ERROR, "palette shift %d is out of range\n", off);
1178  return AVERROR_INVALIDDATA;
1179  }
1180 
1181  for (i = 0; i < count / 3; i++) {
1182  uint32_t p = 0xFF000000;
1183  p |= (ff_tget(&pal_gb[0], type, s->le) >> off) << 16;
1184  p |= (ff_tget(&pal_gb[1], type, s->le) >> off) << 8;
1185  p |= ff_tget(&pal_gb[2], type, s->le) >> off;
1186  s->palette[i] = p;
1187  }
1188  s->palette_is_set = 1;
1189  break;
1190  }
1191  case TIFF_PLANAR:
1192  s->planar = value == 2;
1193  break;
1195  if (count != 2) {
1196  av_log(s->avctx, AV_LOG_ERROR, "subsample count invalid\n");
1197  return AVERROR_INVALIDDATA;
1198  }
1199  for (i = 0; i < count; i++) {
1200  s->subsampling[i] = ff_tget(&s->gb, type, s->le);
1201  if (s->subsampling[i] <= 0) {
1202  av_log(s->avctx, AV_LOG_ERROR, "subsampling %d is invalid\n", s->subsampling[i]);
1203  s->subsampling[i] = 1;
1204  return AVERROR_INVALIDDATA;
1205  }
1206  }
1207  break;
1208  case TIFF_T4OPTIONS:
1209  if (s->compr == TIFF_G3)
1210  s->fax_opts = value;
1211  break;
1212  case TIFF_T6OPTIONS:
1213  if (s->compr == TIFF_G4)
1214  s->fax_opts = value;
1215  break;
1216 #define ADD_METADATA(count, name, sep)\
1217  if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
1218  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
1219  goto end;\
1220  }
1222  ADD_METADATA(count, "ModelPixelScaleTag", NULL);
1223  break;
1225  ADD_METADATA(count, "ModelTransformationTag", NULL);
1226  break;
1227  case TIFF_MODEL_TIEPOINT:
1228  ADD_METADATA(count, "ModelTiepointTag", NULL);
1229  break;
1231  if (s->geotag_count) {
1232  avpriv_request_sample(s->avctx, "Multiple geo key directories\n");
1233  return AVERROR_INVALIDDATA;
1234  }
1235  ADD_METADATA(1, "GeoTIFF_Version", NULL);
1236  ADD_METADATA(2, "GeoTIFF_Key_Revision", ".");
1237  s->geotag_count = ff_tget_short(&s->gb, s->le);
1238  if (s->geotag_count > count / 4 - 1) {
1239  s->geotag_count = count / 4 - 1;
1240  av_log(s->avctx, AV_LOG_WARNING, "GeoTIFF key directory buffer shorter than specified\n");
1241  }
1242  if ( bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4
1243  || s->geotag_count == 0) {
1244  s->geotag_count = 0;
1245  return -1;
1246  }
1247  s->geotags = av_mallocz_array(s->geotag_count, sizeof(TiffGeoTag));
1248  if (!s->geotags) {
1249  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
1250  s->geotag_count = 0;
1251  goto end;
1252  }
1253  for (i = 0; i < s->geotag_count; i++) {
1254  s->geotags[i].key = ff_tget_short(&s->gb, s->le);
1255  s->geotags[i].type = ff_tget_short(&s->gb, s->le);
1256  s->geotags[i].count = ff_tget_short(&s->gb, s->le);
1257 
1258  if (!s->geotags[i].type)
1259  s->geotags[i].val = get_geokey_val(s->geotags[i].key, ff_tget_short(&s->gb, s->le));
1260  else
1261  s->geotags[i].offset = ff_tget_short(&s->gb, s->le);
1262  }
1263  break;
1265  if (count >= INT_MAX / sizeof(int64_t))
1266  return AVERROR_INVALIDDATA;
1267  if (bytestream2_get_bytes_left(&s->gb) < count * sizeof(int64_t))
1268  return AVERROR_INVALIDDATA;
1269  dp = av_malloc_array(count, sizeof(double));
1270  if (!dp) {
1271  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
1272  goto end;
1273  }
1274  for (i = 0; i < count; i++)
1275  dp[i] = ff_tget_double(&s->gb, s->le);
1276  for (i = 0; i < s->geotag_count; i++) {
1277  if (s->geotags[i].type == TIFF_GEO_DOUBLE_PARAMS) {
1278  if (s->geotags[i].count == 0
1279  || s->geotags[i].offset + s->geotags[i].count > count) {
1280  av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
1281  } else if (s->geotags[i].val) {
1282  av_log(s->avctx, AV_LOG_WARNING, "Duplicate GeoTIFF key %d\n", s->geotags[i].key);
1283  } else {
1284  char *ap = doubles2str(&dp[s->geotags[i].offset], s->geotags[i].count, ", ");
1285  if (!ap) {
1286  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
1287  av_freep(&dp);
1288  return AVERROR(ENOMEM);
1289  }
1290  s->geotags[i].val = ap;
1291  }
1292  }
1293  }
1294  av_freep(&dp);
1295  break;
1296  case TIFF_GEO_ASCII_PARAMS:
1297  pos = bytestream2_tell(&s->gb);
1298  for (i = 0; i < s->geotag_count; i++) {
1299  if (s->geotags[i].type == TIFF_GEO_ASCII_PARAMS) {
1300  if (s->geotags[i].count == 0
1301  || s->geotags[i].offset + s->geotags[i].count > count) {
1302  av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
1303  } else {
1304  char *ap;
1305 
1306  bytestream2_seek(&s->gb, pos + s->geotags[i].offset, SEEK_SET);
1307  if (bytestream2_get_bytes_left(&s->gb) < s->geotags[i].count)
1308  return AVERROR_INVALIDDATA;
1309  if (s->geotags[i].val)
1310  return AVERROR_INVALIDDATA;
1311  ap = av_malloc(s->geotags[i].count);
1312  if (!ap) {
1313  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
1314  return AVERROR(ENOMEM);
1315  }
1316  bytestream2_get_bufferu(&s->gb, ap, s->geotags[i].count);
1317  ap[s->geotags[i].count - 1] = '\0'; //replace the "|" delimiter with a 0 byte
1318  s->geotags[i].val = ap;
1319  }
1320  }
1321  }
1322  break;
1323  case TIFF_ARTIST:
1324  ADD_METADATA(count, "artist", NULL);
1325  break;
1326  case TIFF_COPYRIGHT:
1327  ADD_METADATA(count, "copyright", NULL);
1328  break;
1329  case TIFF_DATE:
1330  ADD_METADATA(count, "date", NULL);
1331  break;
1332  case TIFF_DOCUMENT_NAME:
1333  ADD_METADATA(count, "document_name", NULL);
1334  break;
1335  case TIFF_HOST_COMPUTER:
1336  ADD_METADATA(count, "computer", NULL);
1337  break;
1339  ADD_METADATA(count, "description", NULL);
1340  break;
1341  case TIFF_MAKE:
1342  ADD_METADATA(count, "make", NULL);
1343  break;
1344  case TIFF_MODEL:
1345  ADD_METADATA(count, "model", NULL);
1346  break;
1347  case TIFF_PAGE_NAME:
1348  ADD_METADATA(count, "page_name", NULL);
1349  break;
1350  case TIFF_PAGE_NUMBER:
1351  ADD_METADATA(count, "page_number", " / ");
1352  // need to seek back to re-read the page number
1353  bytestream2_seek(&s->gb, -count * sizeof(uint16_t), SEEK_CUR);
1354  // read the page number
1355  s->cur_page = ff_tget(&s->gb, TIFF_SHORT, s->le);
1356  // get back to where we were before the previous seek
1357  bytestream2_seek(&s->gb, count * sizeof(uint16_t) - sizeof(uint16_t), SEEK_CUR);
1358  break;
1359  case TIFF_SOFTWARE_NAME:
1360  ADD_METADATA(count, "software", NULL);
1361  break;
1362  case DNG_VERSION:
1363  if (count == 4) {
1364  unsigned int ver[4];
1365  ver[0] = ff_tget(&s->gb, type, s->le);
1366  ver[1] = ff_tget(&s->gb, type, s->le);
1367  ver[2] = ff_tget(&s->gb, type, s->le);
1368  ver[3] = ff_tget(&s->gb, type, s->le);
1369 
1370  av_log(s->avctx, AV_LOG_DEBUG, "DNG file, version %u.%u.%u.%u\n",
1371  ver[0], ver[1], ver[2], ver[3]);
1372 
1374  }
1375  break;
1376  case CINEMADNG_TIME_CODES:
1377  case CINEMADNG_FRAME_RATE:
1378  case CINEMADNG_T_STOP:
1379  case CINEMADNG_REEL_NAME:
1382  break;
1383  default:
1384  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
1385  av_log(s->avctx, AV_LOG_ERROR,
1386  "Unknown or unsupported tag %d/0x%0X\n",
1387  tag, tag);
1388  return AVERROR_INVALIDDATA;
1389  }
1390  }
1391 end:
1392  if (s->bpp > 64U) {
1393  av_log(s->avctx, AV_LOG_ERROR,
1394  "This format is not supported (bpp=%d, %d components)\n",
1395  s->bpp, count);
1396  s->bpp = 0;
1397  return AVERROR_INVALIDDATA;
1398  }
1399  bytestream2_seek(&s->gb, start, SEEK_SET);
1400  return 0;
1401 }
1402 
1403 static int decode_frame(AVCodecContext *avctx,
1404  void *data, int *got_frame, AVPacket *avpkt)
1405 {
1406  TiffContext *const s = avctx->priv_data;
1407  AVFrame *const p = data;
1408  ThreadFrame frame = { .f = data };
1409  unsigned off, last_off;
1410  int le, ret, plane, planes;
1411  int i, j, entries, stride;
1412  unsigned soff, ssize;
1413  uint8_t *dst;
1414  GetByteContext stripsizes;
1415  GetByteContext stripdata;
1416  int retry_for_subifd, retry_for_page;
1417 
1418  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1419 
1420  // parse image header
1421  if ((ret = ff_tdecode_header(&s->gb, &le, &off))) {
1422  av_log(avctx, AV_LOG_ERROR, "Invalid TIFF header\n");
1423  return ret;
1424  } else if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
1425  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
1426  return AVERROR_INVALIDDATA;
1427  }
1428  s->le = le;
1429  // TIFF_BPP is not a required tag and defaults to 1
1430 again:
1431  s->is_thumbnail = 0;
1432  s->bppcount = s->bpp = 1;
1433  s->photometric = TIFF_PHOTOMETRIC_NONE;
1434  s->compr = TIFF_RAW;
1435  s->fill_order = 0;
1436  s->white_level = 0;
1437  s->is_bayer = 0;
1438  s->cur_page = 0;
1439  s->tiff_type = TIFF_TYPE_TIFF;
1440  s->last_tag = 0;
1441  free_geotags(s);
1442 
1443  // Reset these offsets so we can tell if they were set this frame
1444  s->stripsizesoff = s->strippos = 0;
1445  /* parse image file directory */
1446  bytestream2_seek(&s->gb, off, SEEK_SET);
1447  entries = ff_tget_short(&s->gb, le);
1448  if (bytestream2_get_bytes_left(&s->gb) < entries * 12)
1449  return AVERROR_INVALIDDATA;
1450  for (i = 0; i < entries; i++) {
1451  if ((ret = tiff_decode_tag(s, p)) < 0)
1452  return ret;
1453  }
1454 
1455  if (s->get_thumbnail && !s->is_thumbnail) {
1456  av_log(avctx, AV_LOG_INFO, "No embedded thumbnail present\n");
1457  return AVERROR_EOF;
1458  }
1459 
1460  /** whether we should process this IFD's SubIFD */
1461  retry_for_subifd = s->sub_ifd && (s->get_subimage || (!s->get_thumbnail && s->is_thumbnail));
1462  /** whether we should process this multi-page IFD's next page */
1463  retry_for_page = s->get_page && s->cur_page + 1 < s->get_page; // get_page is 1-indexed
1464 
1465  last_off = off;
1466  if (retry_for_page) {
1467  // set offset to the next IFD
1468  off = ff_tget_long(&s->gb, le);
1469  } else if (retry_for_subifd) {
1470  // set offset to the SubIFD
1471  off = s->sub_ifd;
1472  }
1473 
1474  if (retry_for_subifd || retry_for_page) {
1475  if (!off) {
1476  av_log(avctx, AV_LOG_ERROR, "Requested entry not found\n");
1477  return AVERROR_INVALIDDATA;
1478  }
1479  if (off <= last_off) {
1480  avpriv_request_sample(s->avctx, "non increasing IFD offset\n");
1481  return AVERROR_INVALIDDATA;
1482  }
1483  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
1484  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
1485  return AVERROR_INVALIDDATA;
1486  }
1487  s->sub_ifd = 0;
1488  goto again;
1489  }
1490 
1491  for (i = 0; i<s->geotag_count; i++) {
1492  const char *keyname = get_geokey_name(s->geotags[i].key);
1493  if (!keyname) {
1494  av_log(avctx, AV_LOG_WARNING, "Unknown or unsupported GeoTIFF key %d\n", s->geotags[i].key);
1495  continue;
1496  }
1497  if (get_geokey_type(s->geotags[i].key) != s->geotags[i].type) {
1498  av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
1499  continue;
1500  }
1501  ret = av_dict_set(&p->metadata, keyname, s->geotags[i].val, 0);
1502  if (ret<0) {
1503  av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
1504  return ret;
1505  }
1506  }
1507 
1508  if (!s->strippos && !s->stripoff) {
1509  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
1510  return AVERROR_INVALIDDATA;
1511  }
1512  /* now we have the data and may start decoding */
1513  if ((ret = init_image(s, &frame)) < 0)
1514  return ret;
1515 
1516  if (s->strips == 1 && !s->stripsize) {
1517  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
1518  s->stripsize = avpkt->size - s->stripoff;
1519  }
1520 
1521  if (s->stripsizesoff) {
1522  if (s->stripsizesoff >= (unsigned)avpkt->size)
1523  return AVERROR_INVALIDDATA;
1524  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
1525  avpkt->size - s->stripsizesoff);
1526  }
1527  if (s->strippos) {
1528  if (s->strippos >= (unsigned)avpkt->size)
1529  return AVERROR_INVALIDDATA;
1530  bytestream2_init(&stripdata, avpkt->data + s->strippos,
1531  avpkt->size - s->strippos);
1532  }
1533 
1534  if (s->rps <= 0 || s->rps % s->subsampling[1]) {
1535  av_log(avctx, AV_LOG_ERROR, "rps %d invalid\n", s->rps);
1536  return AVERROR_INVALIDDATA;
1537  }
1538 
1539  planes = s->planar ? s->bppcount : 1;
1540  for (plane = 0; plane < planes; plane++) {
1541  uint8_t *five_planes = NULL;
1542  int remaining = avpkt->size;
1543  int decoded_height;
1544  stride = p->linesize[plane];
1545  dst = p->data[plane];
1546  if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
1547  s->avctx->pix_fmt == AV_PIX_FMT_RGBA) {
1548  stride = stride * 5 / 4;
1549  five_planes =
1550  dst = av_malloc(stride * s->height);
1551  if (!dst)
1552  return AVERROR(ENOMEM);
1553  }
1554  for (i = 0; i < s->height; i += s->rps) {
1555  if (i)
1556  dst += s->rps * stride;
1557  if (s->stripsizesoff)
1558  ssize = ff_tget(&stripsizes, s->sstype, le);
1559  else
1560  ssize = s->stripsize;
1561 
1562  if (s->strippos)
1563  soff = ff_tget(&stripdata, s->sot, le);
1564  else
1565  soff = s->stripoff;
1566 
1567  if (soff > avpkt->size || ssize > avpkt->size - soff || ssize > remaining) {
1568  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
1569  av_freep(&five_planes);
1570  return AVERROR_INVALIDDATA;
1571  }
1572  remaining -= ssize;
1573  if ((ret = tiff_unpack_strip(s, p, dst, stride, avpkt->data + soff, ssize, i,
1574  FFMIN(s->rps, s->height - i))) < 0) {
1575  if (avctx->err_recognition & AV_EF_EXPLODE) {
1576  av_freep(&five_planes);
1577  return ret;
1578  }
1579  break;
1580  }
1581  }
1582  decoded_height = FFMIN(i, s->height);
1583 
1584  if (s->predictor == 2) {
1585  if (s->photometric == TIFF_PHOTOMETRIC_YCBCR) {
1586  av_log(s->avctx, AV_LOG_ERROR, "predictor == 2 with YUV is unsupported");
1587  return AVERROR_PATCHWELCOME;
1588  }
1589  dst = five_planes ? five_planes : p->data[plane];
1590  soff = s->bpp >> 3;
1591  if (s->planar)
1592  soff = FFMAX(soff / s->bppcount, 1);
1593  ssize = s->width * soff;
1594  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
1595  s->avctx->pix_fmt == AV_PIX_FMT_RGBA64LE ||
1596  s->avctx->pix_fmt == AV_PIX_FMT_GRAY16LE ||
1597  s->avctx->pix_fmt == AV_PIX_FMT_YA16LE ||
1598  s->avctx->pix_fmt == AV_PIX_FMT_GBRP16LE ||
1599  s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16LE) {
1600  for (i = 0; i < decoded_height; i++) {
1601  for (j = soff; j < ssize; j += 2)
1602  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
1603  dst += stride;
1604  }
1605  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
1606  s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE ||
1607  s->avctx->pix_fmt == AV_PIX_FMT_GRAY16BE ||
1608  s->avctx->pix_fmt == AV_PIX_FMT_YA16BE ||
1609  s->avctx->pix_fmt == AV_PIX_FMT_GBRP16BE ||
1610  s->avctx->pix_fmt == AV_PIX_FMT_GBRAP16BE) {
1611  for (i = 0; i < decoded_height; i++) {
1612  for (j = soff; j < ssize; j += 2)
1613  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
1614  dst += stride;
1615  }
1616  } else {
1617  for (i = 0; i < decoded_height; i++) {
1618  for (j = soff; j < ssize; j++)
1619  dst[j] += dst[j - soff];
1620  dst += stride;
1621  }
1622  }
1623  }
1624 
1625  if (s->photometric == TIFF_PHOTOMETRIC_WHITE_IS_ZERO) {
1626  int c = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255);
1627  dst = p->data[plane];
1628  for (i = 0; i < s->height; i++) {
1629  for (j = 0; j < stride; j++)
1630  dst[j] = c - dst[j];
1631  dst += stride;
1632  }
1633  }
1634 
1635  if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
1636  (s->avctx->pix_fmt == AV_PIX_FMT_RGB0 || s->avctx->pix_fmt == AV_PIX_FMT_RGBA)) {
1637  int x = s->avctx->pix_fmt == AV_PIX_FMT_RGB0 ? 4 : 5;
1638  uint8_t *src = five_planes ? five_planes : p->data[plane];
1639  dst = p->data[plane];
1640  for (i = 0; i < s->height; i++) {
1641  for (j = 0; j < s->width; j++) {
1642  int k = 255 - src[x * j + 3];
1643  int r = (255 - src[x * j ]) * k;
1644  int g = (255 - src[x * j + 1]) * k;
1645  int b = (255 - src[x * j + 2]) * k;
1646  dst[4 * j ] = r * 257 >> 16;
1647  dst[4 * j + 1] = g * 257 >> 16;
1648  dst[4 * j + 2] = b * 257 >> 16;
1649  dst[4 * j + 3] = s->avctx->pix_fmt == AV_PIX_FMT_RGBA ? src[x * j + 4] : 255;
1650  }
1651  src += stride;
1652  dst += p->linesize[plane];
1653  }
1654  av_freep(&five_planes);
1655  } else if (s->photometric == TIFF_PHOTOMETRIC_SEPARATED &&
1656  s->avctx->pix_fmt == AV_PIX_FMT_RGBA64BE) {
1657  dst = p->data[plane];
1658  for (i = 0; i < s->height; i++) {
1659  for (j = 0; j < s->width; j++) {
1660  uint64_t k = 65535 - AV_RB16(dst + 8 * j + 6);
1661  uint64_t r = (65535 - AV_RB16(dst + 8 * j )) * k;
1662  uint64_t g = (65535 - AV_RB16(dst + 8 * j + 2)) * k;
1663  uint64_t b = (65535 - AV_RB16(dst + 8 * j + 4)) * k;
1664  AV_WB16(dst + 8 * j , r * 65537 >> 32);
1665  AV_WB16(dst + 8 * j + 2, g * 65537 >> 32);
1666  AV_WB16(dst + 8 * j + 4, b * 65537 >> 32);
1667  AV_WB16(dst + 8 * j + 6, 65535);
1668  }
1669  dst += p->linesize[plane];
1670  }
1671  }
1672  }
1673 
1674  if (s->planar && s->bppcount > 2) {
1675  FFSWAP(uint8_t*, p->data[0], p->data[2]);
1676  FFSWAP(int, p->linesize[0], p->linesize[2]);
1677  FFSWAP(uint8_t*, p->data[0], p->data[1]);
1678  FFSWAP(int, p->linesize[0], p->linesize[1]);
1679  }
1680 
1681  if (s->is_bayer && s->white_level && s->bpp == 16) {
1682  uint16_t *dst = (uint16_t *)p->data[0];
1683  for (i = 0; i < s->height; i++) {
1684  for (j = 0; j < s->width; j++)
1685  dst[j] = FFMIN((dst[j] / (float)s->white_level) * 65535, 65535);
1686  dst += stride / 2;
1687  }
1688  }
1689 
1690  *got_frame = 1;
1691 
1692  return avpkt->size;
1693 }
1694 
1696 {
1697  TiffContext *s = avctx->priv_data;
1698 
1699  s->width = 0;
1700  s->height = 0;
1701  s->subsampling[0] =
1702  s->subsampling[1] = 1;
1703  s->avctx = avctx;
1704  ff_lzw_decode_open(&s->lzw);
1705  if (!s->lzw)
1706  return AVERROR(ENOMEM);
1708 
1709  return 0;
1710 }
1711 
1712 static av_cold int tiff_end(AVCodecContext *avctx)
1713 {
1714  TiffContext *const s = avctx->priv_data;
1715 
1716  free_geotags(s);
1717 
1718  ff_lzw_decode_close(&s->lzw);
1719  av_freep(&s->deinvert_buf);
1720  s->deinvert_buf_size = 0;
1721  av_freep(&s->yuv_line);
1722  s->yuv_line_size = 0;
1723  av_freep(&s->fax_buffer);
1724  s->fax_buffer_size = 0;
1725  return 0;
1726 }
1727 
1728 #define OFFSET(x) offsetof(TiffContext, x)
1729 static const AVOption tiff_options[] = {
1730  { "subimage", "decode subimage instead if available", OFFSET(get_subimage), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
1731  { "thumbnail", "decode embedded thumbnail subimage instead if available", OFFSET(get_thumbnail), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
1732  { "page", "page number of multi-page image to decode (starting from 1)", OFFSET(get_page), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
1733  { NULL },
1734 };
1735 
1736 static const AVClass tiff_decoder_class = {
1737  .class_name = "TIFF decoder",
1738  .item_name = av_default_item_name,
1739  .option = tiff_options,
1740  .version = LIBAVUTIL_VERSION_INT,
1741 };
1742 
1744  .name = "tiff",
1745  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
1746  .type = AVMEDIA_TYPE_VIDEO,
1747  .id = AV_CODEC_ID_TIFF,
1748  .priv_data_size = sizeof(TiffContext),
1749  .init = tiff_init,
1750  .close = tiff_end,
1751  .decode = decode_frame,
1753  .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS,
1754  .priv_class = &tiff_decoder_class,
1755 };
TiffContext::tiff_type
enum TiffType tiff_type
Definition: tiff.c:61
ff_tadd_string_metadata
int ff_tadd_string_metadata(int count, const char *name, GetByteContext *gb, int le, AVDictionary **metadata)
Adds a string of count characters into the metadata dictionary.
Definition: tiff_common.c:241
TiffContext::gb
GetByteContext gb
Definition: tiff.c:55
AVCodec
AVCodec.
Definition: avcodec.h:3481
stride
int stride
Definition: mace.c:144
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
TIFF_GEOG_LINEAR_UNITS_GEOKEY
@ TIFF_GEOG_LINEAR_UNITS_GEOKEY
Definition: tiff.h:139
AV_PIX_FMT_BAYER_GBRG16LE
@ AV_PIX_FMT_BAYER_GBRG16LE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, little-endian *‍/
Definition: pixfmt.h:268
bytestream2_get_eof
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
Definition: bytestream.h:328
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
r
const char * r
Definition: vf_curves.c:114
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
AV_PIX_FMT_YA8
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
get_geokey_type
static int get_geokey_type(int key)
Definition: tiff.c:132
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
tiff_decode_tag
static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
Definition: tiff.c:925
TIFF_PHOTOMETRIC_ICC_LAB
@ TIFF_PHOTOMETRIC_ICC_LAB
Definition: tiff.h:190
FFSWAP
#define FFSWAP(type, a, b)
Definition: common.h:99
TIFF_JPEG
@ TIFF_JPEG
Definition: tiff.h:123
GetByteContext
Definition: bytestream.h:33
n
int n
Definition: avisynth_c.h:760
AV_PIX_FMT_GBRP16BE
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:174
get_geokey_val
static char * get_geokey_val(int key, int val)
Definition: tiff.c:156
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
TiffContext::strippos
int strippos
Definition: tiff.c:87
TIFF_CFA_PATTERN_DIM
@ TIFF_CFA_PATTERN_DIM
Definition: tiff.h:89
init_image
static int init_image(TiffContext *s, ThreadFrame *frame)
Definition: tiff.c:716
ff_tiff_decoder
AVCodec ff_tiff_decoder
Definition: tiff.c:1743
TIFF_PROJ_COORD_TRANS_GEOKEY
@ TIFF_PROJ_COORD_TRANS_GEOKEY
Definition: tiff.h:152
OFFSET
#define OFFSET(x)
Definition: tiff.c:1728
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2694
TiffContext::sot
int sot
Definition: tiff.c:86
doubles2str
static char * doubles2str(double *dp, int count, const char *sep)
Definition: tiff.c:224
TiffContext::fax_buffer_size
unsigned int fax_buffer_size
Definition: tiff.c:95
count
void INT64 INT64 count
Definition: avisynth_c.h:767
TIFF_CCITT_RLE
@ TIFF_CCITT_RLE
Definition: tiff.h:119
TIFF_GEOG_AZIMUTH_UNITS_GEOKEY
@ TIFF_GEOG_AZIMUTH_UNITS_GEOKEY
Definition: tiff.h:147
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
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:295
AV_PIX_FMT_RGBA64BE
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:205
tiff_end
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:1712
w
uint8_t w
Definition: llviddspenc.c:38
pixels
int pixels
Definition: avisynth_c.h:390
TIFF_ADOBE_DEFLATE
@ TIFF_ADOBE_DEFLATE
Definition: tiff.h:125
internal.h
name
const char * name
Definition: avisynth_c.h:867
TIFF_COPYRIGHT
@ TIFF_COPYRIGHT
Definition: tiff.h:91
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
TIFF_PHOTOMETRIC_ITU_LAB
@ TIFF_PHOTOMETRIC_ITU_LAB
Definition: tiff.h:191
AVOption
AVOption.
Definition: opt.h:246
TIFF_LONG
@ TIFF_LONG
Definition: tiff_common.h:41
b
#define b
Definition: input.c:41
ff_reverse
const uint8_t ff_reverse[256]
Definition: reverse.c:23
data
const char data[16]
Definition: mxf.c:91
RET_GEOKEY_VAL
#define RET_GEOKEY_VAL(TYPE, array)
TIFF_NEWJPEG
@ TIFF_NEWJPEG
Definition: tiff.h:124
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191
deinvert_buffer
static int deinvert_buffer(TiffContext *s, const uint8_t *src, int size)
Definition: tiff.c:311
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
ff_lzw_decode
int ff_lzw_decode(LZWState *p, uint8_t *buf, int len)
Decode given number of bytes NOTE: the algorithm here is inspired from the LZW GIF decoder written by...
Definition: lzw.c:169
TIFF_ROWSPERSTRIP
@ TIFF_ROWSPERSTRIP
Definition: tiff.h:61
TiffContext::pattern
uint8_t pattern[4]
Definition: tiff.c:79
TIFF_GEOG_ELLIPSOID_GEOKEY
@ TIFF_GEOG_ELLIPSOID_GEOKEY
Definition: tiff.h:143
TIFF_GEO_KEY_USER_DEFINED
#define TIFF_GEO_KEY_USER_DEFINED
Definition: tiff_data.h:48
TIFF_PROJECTION_GEOKEY
@ TIFF_PROJECTION_GEOKEY
Definition: tiff.h:151
TIFF_PROJ_LINEAR_UNITS_GEOKEY
@ TIFF_PROJ_LINEAR_UNITS_GEOKEY
Definition: tiff.h:153
TIFF_RAW
@ TIFF_RAW
Definition: tiff.h:118
ff_lzw_decode_close
av_cold void ff_lzw_decode_close(LZWState **p)
Definition: lzw.c:118
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
TIFF_GEO_DOUBLE_PARAMS
@ TIFF_GEO_DOUBLE_PARAMS
Definition: tiff.h:96
AV_PIX_FMT_BAYER_GRBG16BE
@ AV_PIX_FMT_BAYER_GRBG16BE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, big-endian *‍/
Definition: pixfmt.h:271
TiffGeoTagKeyName
Definition: tiff.h:212
TIFF_PHOTOMETRIC_WHITE_IS_ZERO
@ TIFF_PHOTOMETRIC_WHITE_IS_ZERO
Definition: tiff.h:182
thread.h
TIFF_PACKBITS
@ TIFF_PACKBITS
Definition: tiff.h:126
TIFF_GEOG_PRIME_MERIDIAN_GEOKEY
@ TIFF_GEOG_PRIME_MERIDIAN_GEOKEY
Definition: tiff.h:138
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
bytestream2_get_bytes_left
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
TIFF_GEO_KEY_UNDEFINED
#define TIFF_GEO_KEY_UNDEFINED
Definition: tiff_data.h:47
tiff_options
static const AVOption tiff_options[]
Definition: tiff.c:1729
TiffContext::get_thumbnail
int get_thumbnail
Definition: tiff.c:59
TIFF_PHOTOMETRIC_LINEAR_RAW
@ TIFF_PHOTOMETRIC_LINEAR_RAW
Definition: tiff.h:195
AV_PIX_FMT_BAYER_GBRG16BE
@ AV_PIX_FMT_BAYER_GBRG16BE
bayer, GBGB..(odd line), RGRG..(even line), 16-bit samples, big-endian *‍/
Definition: pixfmt.h:269
TIFF_FILL_ORDER
@ TIFF_FILL_ORDER
Definition: tiff.h:54
TIFF_PHOTOMETRIC_ALPHA_MASK
@ TIFF_PHOTOMETRIC_ALPHA_MASK
Definition: tiff.h:186
TiffContext::deinvert_buf_size
int deinvert_buf_size
Definition: tiff.c:91
AV_PIX_FMT_GRAY16BE
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
Definition: pixfmt.h:97
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
TIFF_DATE
@ TIFF_DATE
Definition: tiff.h:74
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
TIFF_TILE_BYTE_COUNTS
@ TIFF_TILE_BYTE_COUNTS
Definition: tiff.h:82
ff_ccitt_unpack
int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr, int opts)
unpack data compressed with CCITT Group 3 1/2-D or Group 4 method
Definition: faxcompr.c:393
unpack_yuv
static void unpack_yuv(TiffContext *s, AVFrame *p, const uint8_t *src, int lnum)
Definition: tiff.c:337
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
tiff_set_type
static void tiff_set_type(TiffContext *s, enum TiffType tiff_type)
Definition: tiff.c:101
U
#define U(x)
Definition: vp56_arith.h:37
start
void INT64 start
Definition: avisynth_c.h:767
inflate
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
Definition: vf_neighbor.c:197
TIFF_YCBCR_SUBSAMPLING
@ TIFF_YCBCR_SUBSAMPLING
Definition: tiff.h:86
TIFF_MAKE
@ TIFF_MAKE
Definition: tiff.h:57
plane
int plane
Definition: avisynth_c.h:384
GetBitContext
Definition: get_bits.h:61
TIFF_GEOG_GEODETIC_DATUM_GEOKEY
@ TIFF_GEOG_GEODETIC_DATUM_GEOKEY
Definition: tiff.h:137
TiffContext::deinvert_buf
uint8_t * deinvert_buf
Definition: tiff.c:90
TIFF_T6OPTIONS
@ TIFF_T6OPTIONS
Definition: tiff.h:70
horizontal_fill
static void av_always_inline horizontal_fill(TiffContext *s, unsigned int bpp, uint8_t *dst, int usePtr, const uint8_t *src, uint8_t c, int width, int offset)
Definition: tiff.c:261
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
TIFF_VERTICAL_CS_TYPE_GEOKEY
@ TIFF_VERTICAL_CS_TYPE_GEOKEY
Definition: tiff.h:173
TIFF_SOFTWARE_NAME
@ TIFF_SOFTWARE_NAME
Definition: tiff.h:73
FF_LZW_TIFF
@ FF_LZW_TIFF
Definition: lzw.h:39
av_reduce
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
src
#define src
Definition: vp8dsp.c:254
TiffContext::geotags
TiffGeoTag * geotags
Definition: tiff.c:98
TIFF_SHORT
@ TIFF_SHORT
Definition: tiff_common.h:40
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
TiffGeoTag
Definition: tiff.h:204
AV_PIX_FMT_BAYER_RGGB16BE
@ AV_PIX_FMT_BAYER_RGGB16BE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, big-endian *‍/
Definition: pixfmt.h:267
buf
void * buf
Definition: avisynth_c.h:766
av_cold
#define av_cold
Definition: attributes.h:84
TiffContext::rps
int rps
Definition: tiff.c:85
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:677
TIFF_SUBFILE
@ TIFF_SUBFILE
Definition: tiff.h:48
CINEMADNG_T_STOP
@ CINEMADNG_T_STOP
Definition: tiff.h:111
bytestream2_init_writer
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:143
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
AV_PIX_FMT_GBRAP16BE
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:216
TiffContext::stripsize
int stripsize
Definition: tiff.c:87
width
#define width
intreadwrite.h
TIFF_G4
@ TIFF_G4
Definition: tiff.h:121
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_PIX_FMT_GBRP16LE
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:175
TiffContext::width
int width
Definition: tiff.c:62
AV_PIX_FMT_BAYER_RGGB16LE
@ AV_PIX_FMT_BAYER_RGGB16LE
bayer, RGRG..(odd line), GBGB..(even line), 16-bit samples, little-endian *‍/
Definition: pixfmt.h:266
AV_PIX_FMT_BAYER_BGGR8
@ AV_PIX_FMT_BAYER_BGGR8
bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples *‍/
Definition: pixfmt.h:260
g
const char * g
Definition: vf_curves.c:115
TiffType
TiffType
TIFF types in ascenting priority (last in the list is highest)
Definition: tiff.h:37
ff_lzw_decode_open
av_cold void ff_lzw_decode_open(LZWState **p)
Definition: lzw.c:113
TIFF_STRIP_SIZE
@ TIFF_STRIP_SIZE
Definition: tiff.h:62
TiffContext::yuv_line
uint8_t * yuv_line
Definition: tiff.c:92
TIFF_GEOGRAPHIC_TYPE_GEOKEY
@ TIFF_GEOGRAPHIC_TYPE_GEOKEY
Definition: tiff.h:135
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
TIFF_STRING
@ TIFF_STRING
Definition: tiff_common.h:39
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
TIFF_PHOTOMETRIC_LOG_L
@ TIFF_PHOTOMETRIC_LOG_L
Definition: tiff.h:193
ff_tadd_shorts_metadata
int ff_tadd_shorts_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
Adds count shorts converted to a string into the metadata dictionary.
Definition: tiff_common.c:178
get_bits.h
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:90
TiffContext::get_page
uint16_t get_page
Definition: tiff.c:58
LZWState
Definition: lzw.c:46
TIFF_IMAGE_DESCRIPTION
@ TIFF_IMAGE_DESCRIPTION
Definition: tiff.h:56
TiffContext::is_bayer
int is_bayer
Definition: tiff.c:78
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
key
const char * key
Definition: hwcontext_opencl.c:168
TiffContext::compr
enum TiffCompr compr
Definition: tiff.c:67
TiffContext::photometric
enum TiffPhotometric photometric
Definition: tiff.c:68
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
search_keyval
static const char * search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
Definition: tiff.c:147
AV_PIX_FMT_BAYER_RGGB8
@ AV_PIX_FMT_BAYER_RGGB8
bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples *‍/
Definition: pixfmt.h:261
if
if(ret)
Definition: filter_design.txt:179
ff_ccitt_unpack_init
av_cold void ff_ccitt_unpack_init(void)
initialize unpacker code
Definition: faxcompr.c:99
TiffContext::geotag_count
int geotag_count
Definition: tiff.c:97
TiffContext::height
int height
Definition: tiff.c:62
AV_PIX_FMT_BAYER_GRBG16LE
@ AV_PIX_FMT_BAYER_GRBG16LE
bayer, GRGR..(odd line), BGBG..(even line), 16-bit samples, little-endian *‍/
Definition: pixfmt.h:270
TIFF_PAGE_NAME
@ TIFF_PAGE_NAME
Definition: tiff.h:66
TIFF_VERTICAL_UNITS_GEOKEY
@ TIFF_VERTICAL_UNITS_GEOKEY
Definition: tiff.h:176
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: avcodec.h:1037
TIFF_LZW
@ TIFF_LZW
Definition: tiff.h:122
tiff_init
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:1695
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
ff_tget_short
unsigned ff_tget_short(GetByteContext *gb, int le)
Reads a short from the bytestream using given endianness.
Definition: tiff_common.c:43
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:1403
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
TIFF_PHOTOMETRIC_YCBCR
@ TIFF_PHOTOMETRIC_YCBCR
Definition: tiff.h:188
TiffContext
Definition: tiff.c:52
AV_WB16
#define AV_WB16(p, v)
Definition: intreadwrite.h:405
TiffContext::is_thumbnail
int is_thumbnail
Definition: tiff.c:75
tiff_data.h
TiffContext::avctx
AVCodecContext * avctx
Definition: tiff.c:54
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AV_PIX_FMT_RGB48LE
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:103
AV_PIX_FMT_YA16LE
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:213
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:76
tiff.h
TIFF_PHOTOMETRIC_PALETTE
@ TIFF_PHOTOMETRIC_PALETTE
Definition: tiff.h:185
TiffContext::get_subimage
int get_subimage
Definition: tiff.c:57
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
AV_PIX_FMT_RGBA64LE
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:206
TIFF_MODEL_TIEPOINT
@ TIFF_MODEL_TIEPOINT
Definition: tiff.h:92
TIFF_PHOTOMETRIC_CIE_LAB
@ TIFF_PHOTOMETRIC_CIE_LAB
Definition: tiff.h:189
mathops.h
TIFF_PAL
@ TIFF_PAL
Definition: tiff.h:78
ONLY_IF_THREADS_ENABLED
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
Definition: internal.h:227
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:964
TIFF_BYTE
@ TIFF_BYTE
Definition: tiff_common.h:38
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
TIFF_ARTIST
@ TIFF_ARTIST
Definition: tiff.h:75
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2705
CINEMADNG_TIME_CODES
@ CINEMADNG_TIME_CODES
Definition: tiff.h:109
TIFF_SAMPLES_PER_PIXEL
@ TIFF_SAMPLES_PER_PIXEL
Definition: tiff.h:60
TIFF_G3
@ TIFF_G3
Definition: tiff.h:120
TIFF_WIDTH
@ TIFF_WIDTH
Definition: tiff.h:49
TIFF_TILE_OFFSETS
@ TIFF_TILE_OFFSETS
Definition: tiff.h:81
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
TiffContext::palette
uint32_t palette[256]
Definition: tiff.c:64
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
PutByteContext
Definition: bytestream.h:37
ff_tread_tag
int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type, unsigned *count, int *next)
Reads the first 3 fields of a TIFF tag, which are the tag id, the tag type and the count of values fo...
Definition: tiff_common.c:286
desc
const char * desc
Definition: nvenc.c:68
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
planes
static const struct @314 planes[]
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
AVPacket::size
int size
Definition: avcodec.h:1478
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:188
TIFF_TYPE_CINEMADNG
@ TIFF_TYPE_CINEMADNG
Digital Negative (DNG) image part of an CinemaDNG image sequence.
Definition: tiff.h:43
TiffContext::fax_buffer
uint8_t * fax_buffer
Definition: tiff.c:94
AV_PIX_FMT_FLAG_RGB
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition: pixdesc.h:148
AV_PIX_FMT_BAYER_BGGR16LE
@ AV_PIX_FMT_BAYER_BGGR16LE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, little-endian *‍/
Definition: pixfmt.h:264
lzw.h
LZW decoding routines.
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
TIFF_DOUBLE
@ TIFF_DOUBLE
Definition: tiff_common.h:49
AV_PIX_FMT_YA16BE
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:212
init_thread_copy
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 add an init_thread_copy() which re-allocates them for other threads. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. If there are inter-frame dependencies
TIFF_GEO_ASCII_PARAMS
@ TIFF_GEO_ASCII_PARAMS
Definition: tiff.h:97
size
int size
Definition: twinvq_data.h:11134
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.
TiffContext::bpp
unsigned int bpp
Definition: tiff.c:63
TIFF_GT_MODEL_TYPE_GEOKEY
@ TIFF_GT_MODEL_TYPE_GEOKEY
Definition: tiff.h:132
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:368
TIFF_DOCUMENT_NAME
@ TIFF_DOCUMENT_NAME
Definition: tiff.h:55
TiffContext::fill_order
int fill_order
Definition: tiff.c:73
val
const char const char void * val
Definition: avisynth_c.h:863
TIFF_MODEL_TRANSFORMATION
@ TIFF_MODEL_TRANSFORMATION
Definition: tiff.h:94
TIFF_TILE_LENGTH
@ TIFF_TILE_LENGTH
Definition: tiff.h:80
TIFF_MODEL
@ TIFF_MODEL
Definition: tiff.h:58
AV_WL16
#define AV_WL16(p, v)
Definition: intreadwrite.h:412
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
TiffContext::white_level
unsigned white_level
Definition: tiff.c:80
TiffContext::stripsizesoff
int stripsizesoff
Definition: tiff.c:87
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
line
Definition: graph2dot.c:48
attributes.h
AV_PIX_FMT_RGB0
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
Definition: pixfmt.h:238
TiffContext::planar
int planar
Definition: tiff.c:69
TIFF_COMPR
@ TIFF_COMPR
Definition: tiff.h:52
TIFF_HEIGHT
@ TIFF_HEIGHT
Definition: tiff.h:50
cmp_id_key
static int cmp_id_key(const void *id, const void *k)
Definition: tiff.c:142
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
tiff_decoder_class
static const AVClass tiff_decoder_class
Definition: tiff.c:1736
RET_GEOKEY
#define RET_GEOKEY(TYPE, array, element)
Definition: tiff.c:117
TIFF_T4OPTIONS
@ TIFF_T4OPTIONS
Definition: tiff.h:69
TIFF_PHOTOMETRIC_LOG_LUV
@ TIFF_PHOTOMETRIC_LOG_LUV
Definition: tiff.h:194
TiffContext::le
int le
Definition: tiff.c:66
CINEMADNG_REEL_NAME
@ CINEMADNG_REEL_NAME
Definition: tiff.h:112
TiffContext::subsampling
int subsampling[2]
Definition: tiff.c:70
TIFF_PAGE_NUMBER
@ TIFF_PAGE_NUMBER
Definition: tiff.h:72
AV_PIX_FMT_RGB48BE
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:102
TIFF_PHOTOMETRIC_CFA
@ TIFF_PHOTOMETRIC_CFA
Definition: tiff.h:192
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
ff_tget_long
unsigned ff_tget_long(GetByteContext *gb, int le)
Reads a long from the bytestream using given endianness.
Definition: tiff_common.c:49
TIFF_PHOTOMETRIC_BLACK_IS_ZERO
@ TIFF_PHOTOMETRIC_BLACK_IS_ZERO
Definition: tiff.h:183
TiffContext::fax_opts
int fax_opts
Definition: tiff.c:71
ff_lzw_decode_init
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
Definition: lzw.c:131
TiffContext::bppcount
unsigned int bppcount
Definition: tiff.c:63
unpack_gray
static void unpack_gray(TiffContext *s, AVFrame *p, const uint8_t *src, int lnum, int width, int bpp)
Definition: tiff.c:324
TiffContext::res
uint32_t res[4]
Definition: tiff.c:74
TIFF_MODEL_PIXEL_SCALE
@ TIFF_MODEL_PIXEL_SCALE
Definition: tiff.h:93
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
TIFF_PLANAR
@ TIFF_PLANAR
Definition: tiff.h:65
AV_PIX_FMT_BAYER_GBRG8
@ AV_PIX_FMT_BAYER_GBRG8
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples *‍/
Definition: pixfmt.h:262
TIFF_TYPE_TIFF
@ TIFF_TYPE_TIFF
TIFF image based on the TIFF 6.0 or TIFF/EP (ISO 12234-2) specifications.
Definition: tiff.h:39
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
av_always_inline
#define av_always_inline
Definition: attributes.h:43
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
uint8_t
uint8_t
Definition: audio_convert.c:194
TIFF_TYPE_DNG
@ TIFF_TYPE_DNG
Digital Negative (DNG) image.
Definition: tiff.h:41
AVCodec::name
const char * name
Name of the codec implementation.
Definition: avcodec.h:3488
DNG_VERSION
@ DNG_VERSION
Definition: tiff.h:102
TiffContext::stripoff
int stripoff
Definition: tiff.c:87
len
int len
Definition: vorbis_enc_data.h:452
TIFF_PHOTOMETRIC_NONE
@ TIFF_PHOTOMETRIC_NONE
Definition: tiff.h:181
TIFF_CFA_PATTERN
@ TIFF_CFA_PATTERN
Definition: tiff.h:90
TIFF_STRIP_OFFS
@ TIFF_STRIP_OFFS
Definition: tiff.h:59
TIFF_TILE_WIDTH
@ TIFF_TILE_WIDTH
Definition: tiff.h:79
avcodec.h
pv
#define pv
Definition: regdef.h:60
AV_PIX_FMT_GBRAP16LE
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:217
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
tag
uint32_t tag
Definition: movenc.c:1496
ret
ret
Definition: filter_design.txt:187
TIFF_HOST_COMPUTER
@ TIFF_HOST_COMPUTER
Definition: tiff.h:76
DNG_WHITE_LEVEL
@ DNG_WHITE_LEVEL
Definition: tiff.h:104
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
TiffContext::palette_is_set
int palette_is_set
Definition: tiff.c:65
AV_PIX_FMT_BAYER_BGGR16BE
@ AV_PIX_FMT_BAYER_BGGR16BE
bayer, BGBG..(odd line), GRGR..(even line), 16-bit samples, big-endian *‍/
Definition: pixfmt.h:265
TIFF_BPP
@ TIFF_BPP
Definition: tiff.h:51
get_geokey_name
static const char * get_geokey_name(int key)
Definition: tiff.c:122
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:790
TIFF_PHOTOMETRIC
@ TIFF_PHOTOMETRIC
Definition: tiff.h:53
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:88
ff_tget_double
double ff_tget_double(GetByteContext *gb, int le)
Reads a double from the bytestream using given endianness.
Definition: tiff_common.c:55
TiffPhotometric
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
Definition: tiff.h:180
TiffContext::last_tag
unsigned last_tag
Definition: tiff.c:76
ff_tiff_proj_cs_type_codes
const TiffGeoTagKeyName ff_tiff_proj_cs_type_codes[]
Definition: tiff_data.c:516
AVCodecContext
main external API structure.
Definition: avcodec.h:1565
ADD_METADATA
#define ADD_METADATA(count, name, sep)
ThreadFrame
Definition: thread.h:34
TiffContext::sstype
int sstype
Definition: tiff.c:85
again
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 again
Definition: filter_design.txt:25
TIFF_PREDICTOR
@ TIFF_PREDICTOR
Definition: tiff.h:77
TIFF_RATIONAL
@ TIFF_RATIONAL
Definition: tiff_common.h:42
config.h
bytestream2_seek_p
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:232
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
AVFrame::metadata
AVDictionary * metadata
metadata.
Definition: frame.h:581
TiffContext::lzw
LZWState * lzw
Definition: tiff.c:88
set_sar
static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den)
Definition: tiff.c:906
TIFF_LZMA
@ TIFF_LZMA
Definition: tiff.h:128
tiff_unpack_fax
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int width, int lines)
Definition: tiff.c:497
TIFF_GEO_KEY_DIRECTORY
@ TIFF_GEO_KEY_DIRECTORY
Definition: tiff.h:95
CINEMADNG_CAMERA_LABEL
@ CINEMADNG_CAMERA_LABEL
Definition: tiff.h:113
AV_PIX_FMT_FLAG_PLANAR
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:144
ff_tdecode_header
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
TIFF_YRES
@ TIFF_YRES
Definition: tiff.h:64
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
faxcompr.h
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:251
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_GRAY16LE
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition: pixfmt.h:98
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
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
bytestream2_get_bufferu
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:273
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
free_geotags
static void free_geotags(TiffContext *const s)
Definition: tiff.c:106
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
TIFF_DEFLATE
@ TIFF_DEFLATE
Definition: tiff.h:127
TIFF_PHOTOMETRIC_RGB
@ TIFF_PHOTOMETRIC_RGB
Definition: tiff.h:184
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:1592
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
TIFF_SUB_IFDS
@ TIFF_SUB_IFDS
Definition: tiff.h:83
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
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
tiff_unpack_strip
static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int stride, const uint8_t *src, int size, int strip_start, int lines)
Definition: tiff.c:530
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
ff_tadd_doubles_metadata
int ff_tadd_doubles_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata)
Adds count doubles converted to a string into the metadata dictionary.
Definition: tiff_common.c:147
TIFF_XRES
@ TIFF_XRES
Definition: tiff.h:63
add_metadata
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition: tiff.c:250
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
TiffCompr
TiffCompr
list of TIFF, TIFF/EP and DNG compression types
Definition: tiff.h:117
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
TIFF_GEOG_ANGULAR_UNITS_GEOKEY
@ TIFF_GEOG_ANGULAR_UNITS_GEOKEY
Definition: tiff.h:141
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
TiffContext::cur_page
uint16_t cur_page
Definition: tiff.c:83
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: avcodec.h:314
avstring.h
type_sizes
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
Definition: tiff_common.h:54
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:369
ff_tiff_projection_codes
const TiffGeoTagKeyName ff_tiff_projection_codes[]
Definition: tiff_data.c:1497
TiffContext::predictor
int predictor
Definition: tiff.c:72
snprintf
#define snprintf
Definition: snprintf.h:34
ff_tget
unsigned ff_tget(GetByteContext *gb, int type, int le)
Reads a byte from the bytestream using given endianness.
Definition: tiff_common.c:62
TIFF_PHOTOMETRIC_SEPARATED
@ TIFF_PHOTOMETRIC_SEPARATED
Definition: tiff.h:187
TiffContext::strips
int strips
Definition: tiff.c:85
TIFF_PROJECTED_CS_TYPE_GEOKEY
@ TIFF_PROJECTED_CS_TYPE_GEOKEY
Definition: tiff.h:149
CINEMADNG_FRAME_RATE
@ CINEMADNG_FRAME_RATE
Definition: tiff.h:110
TiffContext::sub_ifd
uint32_t sub_ifd
Definition: tiff.c:82
AV_PIX_FMT_BAYER_GRBG8
@ AV_PIX_FMT_BAYER_GRBG8
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples *‍/
Definition: pixfmt.h:263
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
TiffContext::yuv_line_size
unsigned int yuv_line_size
Definition: tiff.c:93
AV_RB16
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_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:94
TIFF_GT_RASTER_TYPE_GEOKEY
@ TIFF_GT_RASTER_TYPE_GEOKEY
Definition: tiff.h:133