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 "avcodec.h"
28 #include "bytestream.h"
29 #include "config.h"
30 #if CONFIG_ZLIB
31 #include <zlib.h>
32 #endif
33 #include "lzw.h"
34 #include "tiff.h"
35 #include "tiff_data.h"
36 #include "faxcompr.h"
37 #include "internal.h"
38 #include "mathops.h"
39 #include "libavutil/attributes.h"
40 #include "libavutil/intreadwrite.h"
41 #include "libavutil/imgutils.h"
42 #include "libavutil/avstring.h"
43 
44 typedef struct TiffContext {
47 
48  int width, height;
49  unsigned int bpp, bppcount;
50  uint32_t palette[256];
52  int le;
54  int invert;
55  int fax_opts;
56  int predictor;
58 
59  int strips, rps, sstype;
60  int sot;
63 
66 
69 } TiffContext;
70 
71 static unsigned tget_short(GetByteContext *gb, int le)
72 {
73  unsigned v = le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
74  return v;
75 }
76 
77 static unsigned tget_long(GetByteContext *gb, int le)
78 {
79  unsigned v = le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
80  return v;
81 }
82 
83 static double tget_double(GetByteContext *gb, int le)
84 {
85  av_alias64 i = { .u64 = le ? bytestream2_get_le64(gb) : bytestream2_get_be64(gb)};
86  return i.f64;
87 }
88 
89 static unsigned tget(GetByteContext *gb, int type, int le)
90 {
91  switch (type) {
92  case TIFF_BYTE : return bytestream2_get_byte(gb);
93  case TIFF_SHORT: return tget_short(gb, le);
94  case TIFF_LONG : return tget_long(gb, le);
95  default : return UINT_MAX;
96  }
97 }
98 
99 static void free_geotags(TiffContext *const s)
100 {
101  int i;
102  for (i = 0; i < s->geotag_count; i++) {
103  if (s->geotags[i].val)
104  av_freep(&s->geotags[i].val);
105  }
106  av_freep(&s->geotags);
107 }
108 
109 #define RET_GEOKEY(TYPE, array, element)\
110  if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
111  key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
112  return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
113 
114 static const char *get_geokey_name(int key)
115 {
116  RET_GEOKEY(VERT, vert, name);
117  RET_GEOKEY(PROJ, proj, name);
118  RET_GEOKEY(GEOG, geog, name);
119  RET_GEOKEY(CONF, conf, name);
120 
121  return NULL;
122 }
123 
124 static int get_geokey_type(int key)
125 {
126  RET_GEOKEY(VERT, vert, type);
127  RET_GEOKEY(PROJ, proj, type);
128  RET_GEOKEY(GEOG, geog, type);
129  RET_GEOKEY(CONF, conf, type);
130 
131  return AVERROR_INVALIDDATA;
132 }
133 
134 static int cmp_id_key(const void *id, const void *k)
135 {
136  return *(const int*)id - ((const TiffGeoTagKeyName*)k)->key;
137 }
138 
139 static const char *search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
140 {
141  TiffGeoTagKeyName *r = bsearch(&id, keys, n, sizeof(keys[0]), cmp_id_key);
142  if(r)
143  return r->name;
144 
145  return NULL;
146 }
147 
148 static char *get_geokey_val(int key, int val)
149 {
150  char *ap;
151 
152  if (val == TIFF_GEO_KEY_UNDEFINED)
153  return av_strdup("undefined");
154  if (val == TIFF_GEO_KEY_USER_DEFINED)
155  return av_strdup("User-Defined");
156 
157 #define RET_GEOKEY_VAL(TYPE, array)\
158  if (val >= TIFF_##TYPE##_OFFSET &&\
159  val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
160  return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
161 
162  switch (key) {
164  RET_GEOKEY_VAL(GT_MODEL_TYPE, gt_model_type);
165  break;
167  RET_GEOKEY_VAL(GT_RASTER_TYPE, gt_raster_type);
168  break;
172  RET_GEOKEY_VAL(LINEAR_UNIT, linear_unit);
173  break;
176  RET_GEOKEY_VAL(ANGULAR_UNIT, angular_unit);
177  break;
179  RET_GEOKEY_VAL(GCS_TYPE, gcs_type);
180  RET_GEOKEY_VAL(GCSE_TYPE, gcse_type);
181  break;
183  RET_GEOKEY_VAL(GEODETIC_DATUM, geodetic_datum);
184  RET_GEOKEY_VAL(GEODETIC_DATUM_E, geodetic_datum_e);
185  break;
187  RET_GEOKEY_VAL(ELLIPSOID, ellipsoid);
188  break;
190  RET_GEOKEY_VAL(PRIME_MERIDIAN, prime_meridian);
191  break;
194  if(ap) return ap;
195  break;
198  if(ap) return ap;
199  break;
201  RET_GEOKEY_VAL(COORD_TRANS, coord_trans);
202  break;
204  RET_GEOKEY_VAL(VERT_CS, vert_cs);
205  RET_GEOKEY_VAL(ORTHO_VERT_CS, ortho_vert_cs);
206  break;
207 
208  }
209 
210  ap = av_malloc(14);
211  if (ap)
212  snprintf(ap, 14, "Unknown-%d", val);
213  return ap;
214 }
215 
216 static char *doubles2str(double *dp, int count, const char *sep)
217 {
218  int i;
219  char *ap, *ap0;
220  uint64_t component_len;
221  if (!sep) sep = ", ";
222  component_len = 15LL + strlen(sep);
223  if (count >= (INT_MAX - 1)/component_len)
224  return NULL;
225  ap = av_malloc(component_len * count + 1);
226  if (!ap)
227  return NULL;
228  ap0 = ap;
229  ap[0] = '\0';
230  for (i = 0; i < count; i++) {
231  unsigned l = snprintf(ap, component_len, "%f%s", dp[i], sep);
232  if(l >= component_len) {
233  av_free(ap0);
234  return NULL;
235  }
236  ap += l;
237  }
238  ap0[strlen(ap0) - strlen(sep)] = '\0';
239  return ap0;
240 }
241 
242 static char *shorts2str(int16_t *sp, int count, const char *sep)
243 {
244  int i;
245  char *ap, *ap0;
246  uint64_t component_len;
247  if (!sep) sep = ", ";
248  component_len = 7LL + strlen(sep);
249  if (count >= (INT_MAX - 1)/component_len)
250  return NULL;
251  ap = av_malloc(component_len * count + 1);
252  if (!ap)
253  return NULL;
254  ap0 = ap;
255  ap[0] = '\0';
256  for (i = 0; i < count; i++) {
257  unsigned l = snprintf(ap, component_len, "%d%s", sp[i], sep);
258  if (l >= component_len) {
259  av_free(ap0);
260  return NULL;
261  }
262  ap += l;
263  }
264  ap0[strlen(ap0) - strlen(sep)] = '\0';
265  return ap0;
266 }
267 
269  const char *name, const char *sep,
271 {
272  char *ap;
273  int i;
274  double *dp;
275 
276  if (count >= INT_MAX / sizeof(int64_t) || count <= 0)
277  return AVERROR_INVALIDDATA;
278  if (bytestream2_get_bytes_left(&s->gb) < count * sizeof(int64_t))
279  return AVERROR_INVALIDDATA;
280 
281  dp = av_malloc(count * sizeof(double));
282  if (!dp)
283  return AVERROR(ENOMEM);
284 
285  for (i = 0; i < count; i++)
286  dp[i] = tget_double(&s->gb, s->le);
287  ap = doubles2str(dp, count, sep);
288  av_freep(&dp);
289  if (!ap)
290  return AVERROR(ENOMEM);
292  return 0;
293 }
294 
295 static int add_shorts_metadata(int count, const char *name,
296  const char *sep, TiffContext *s, AVFrame *frame)
297 {
298  char *ap;
299  int i;
300  int16_t *sp;
301 
302  if (count >= INT_MAX / sizeof(int16_t) || count <= 0)
303  return AVERROR_INVALIDDATA;
304  if (bytestream2_get_bytes_left(&s->gb) < count * sizeof(int16_t))
305  return AVERROR_INVALIDDATA;
306 
307  sp = av_malloc(count * sizeof(int16_t));
308  if (!sp)
309  return AVERROR(ENOMEM);
310 
311  for (i = 0; i < count; i++)
312  sp[i] = tget_short(&s->gb, s->le);
313  ap = shorts2str(sp, count, sep);
314  av_freep(&sp);
315  if (!ap)
316  return AVERROR(ENOMEM);
318  return 0;
319 }
320 
321 static int add_string_metadata(int count, const char *name,
323 {
324  char *value;
325 
326  if (bytestream2_get_bytes_left(&s->gb) < count || count < 0)
327  return AVERROR_INVALIDDATA;
328 
329  value = av_malloc(count + 1);
330  if (!value)
331  return AVERROR(ENOMEM);
332 
333  bytestream2_get_bufferu(&s->gb, value, count);
334  value[count] = 0;
335 
337  return 0;
338 }
339 
340 static int add_metadata(int count, int type,
341  const char *name, const char *sep, TiffContext *s, AVFrame *frame)
342 {
343  switch(type) {
344  case TIFF_DOUBLE: return add_doubles_metadata(count, name, sep, s, frame);
345  case TIFF_SHORT : return add_shorts_metadata(count, name, sep, s, frame);
346  case TIFF_STRING: return add_string_metadata(count, name, s, frame);
347  default : return AVERROR_INVALIDDATA;
348  };
349 }
350 
351 #if CONFIG_ZLIB
352 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
353  int size)
354 {
355  z_stream zstream = { 0 };
356  int zret;
357 
358  zstream.next_in = (uint8_t *)src;
359  zstream.avail_in = size;
360  zstream.next_out = dst;
361  zstream.avail_out = *len;
362  zret = inflateInit(&zstream);
363  if (zret != Z_OK) {
364  av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
365  return zret;
366  }
367  zret = inflate(&zstream, Z_SYNC_FLUSH);
368  inflateEnd(&zstream);
369  *len = zstream.total_out;
370  return zret == Z_STREAM_END ? Z_OK : zret;
371 }
372 #endif
373 
374 static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
375  int usePtr, const uint8_t *src,
376  uint8_t c, int width, int offset)
377 {
378  switch (bpp) {
379  case 1:
380  while (--width >= 0) {
381  dst[(width+offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
382  dst[(width+offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
383  dst[(width+offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
384  dst[(width+offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
385  dst[(width+offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
386  dst[(width+offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
387  dst[(width+offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
388  dst[(width+offset)*8+0] = (usePtr ? src[width] : c) >> 7;
389  }
390  break;
391  case 2:
392  while (--width >= 0) {
393  dst[(width+offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
394  dst[(width+offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
395  dst[(width+offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
396  dst[(width+offset)*4+0] = (usePtr ? src[width] : c) >> 6;
397  }
398  break;
399  case 4:
400  while (--width >= 0) {
401  dst[(width+offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
402  dst[(width+offset)*2+0] = (usePtr ? src[width] : c) >> 4;
403  }
404  break;
405  default:
406  if (usePtr) {
407  memcpy(dst + offset, src, width);
408  } else {
409  memset(dst + offset, c, width);
410  }
411  }
412 }
413 
415  const uint8_t *src, int size, int lines)
416 {
417  int c, line, pixels, code, ret;
418  const uint8_t *ssrc = src;
419  int width = ((s->width * s->bpp) + 7) >> 3;
420 
421  if (size <= 0)
422  return AVERROR_INVALIDDATA;
423 
424 #if CONFIG_ZLIB
425  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
426  uint8_t *src2 = NULL, *zbuf;
427  unsigned long outlen;
428  int i, ret;
429  outlen = width * lines;
430  zbuf = av_malloc(outlen);
431  if (!zbuf)
432  return AVERROR(ENOMEM);
433  if (s->fill_order) {
434  src2 = av_malloc((unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE);
435  if (!src2) {
436  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
437  av_free(zbuf);
438  return AVERROR(ENOMEM);
439  }
440  for (i = 0; i < size; i++)
441  src2[i] = ff_reverse[src[i]];
442  memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
443  src = src2;
444  }
445  ret = tiff_uncompress(zbuf, &outlen, src, size);
446  if (ret != Z_OK) {
448  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
449  (unsigned long)width * lines, ret);
450  av_free(src2);
451  av_free(zbuf);
452  return AVERROR_UNKNOWN;
453  }
454  src = zbuf;
455  for (line = 0; line < lines; line++) {
456  if(s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8){
457  horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
458  }else{
459  memcpy(dst, src, width);
460  }
461  dst += stride;
462  src += width;
463  }
464  av_free(src2);
465  av_free(zbuf);
466  return 0;
467  }
468 #endif
469  if (s->compr == TIFF_LZW) {
470  if (s->fill_order) {
471  int i;
473  if (!s->deinvert_buf)
474  return AVERROR(ENOMEM);
475  for (i = 0; i < size; i++)
476  s->deinvert_buf[i] = ff_reverse[src[i]];
477  src = s->deinvert_buf;
478  ssrc = src;
479  }
480  if (size > 1 && !src[0] && (src[1]&1)) {
481  av_log(s->avctx, AV_LOG_ERROR, "Old style LZW is unsupported\n");
482  }
483  if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
484  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
485  return ret;
486  }
487  }
488  if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
489  || s->compr == TIFF_G4) {
490  int i, ret = 0;
491  uint8_t *src2 = av_malloc((unsigned)size +
493 
494  if (!src2) {
496  "Error allocating temporary buffer\n");
497  return AVERROR(ENOMEM);
498  }
499  if (s->fax_opts & 2) {
501  "Uncompressed fax mode is not supported (yet)\n");
502  av_free(src2);
503  return AVERROR_INVALIDDATA;
504  }
505  if (!s->fill_order) {
506  memcpy(src2, src, size);
507  } else {
508  for (i = 0; i < size; i++)
509  src2[i] = ff_reverse[src[i]];
510  }
511  memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
512  switch (s->compr) {
513  case TIFF_CCITT_RLE:
514  case TIFF_G3:
515  case TIFF_G4:
516  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
517  s->compr, s->fax_opts);
518  break;
519  }
520  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
521  for (line = 0; line < lines; line++) {
522  horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
523  dst += stride;
524  }
525  av_free(src2);
526  return ret;
527  }
528  for (line = 0; line < lines; line++) {
529  if (src - ssrc > size) {
530  av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
531  return AVERROR_INVALIDDATA;
532  }
533  switch (s->compr) {
534  case TIFF_RAW:
535  if (ssrc + size - src < width)
536  return AVERROR_INVALIDDATA;
537  if (!s->fill_order) {
539  dst, 1, src, 0, width, 0);
540  } else {
541  int i;
542  for (i = 0; i < width; i++)
543  dst[i] = ff_reverse[src[i]];
544  }
545  src += width;
546  break;
547  case TIFF_PACKBITS:
548  for (pixels = 0; pixels < width;) {
549  if (ssrc + size - src < 2) {
550  av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
551  return AVERROR_INVALIDDATA;
552  }
553  code = (int8_t) * src++;
554  if (code >= 0) {
555  code++;
556  if (pixels + code > width) {
558  "Copy went out of bounds\n");
559  return AVERROR_INVALIDDATA;
560  }
561  if (ssrc + size - src < code) {
562  av_log(s->avctx, AV_LOG_ERROR, "Read went out of bounds\n");
563  return AVERROR_INVALIDDATA;
564  }
566  dst, 1, src, 0, code, pixels);
567  src += code;
568  pixels += code;
569  } else if (code != -128) { // -127..-1
570  code = (-code) + 1;
571  if (pixels + code > width) {
573  "Run went out of bounds\n");
574  return AVERROR_INVALIDDATA;
575  }
576  c = *src++;
578  dst, 0, NULL, c, code, pixels);
579  pixels += code;
580  }
581  }
582  break;
583  case TIFF_LZW:
584  pixels = ff_lzw_decode(s->lzw, dst, width);
585  if (pixels < width) {
586  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
587  pixels, width);
588  return AVERROR_INVALIDDATA;
589  }
590  if (s->bpp < 8 && s->avctx->pix_fmt == AV_PIX_FMT_PAL8)
591  horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0);
592  break;
593  }
594  dst += stride;
595  }
596  return 0;
597 }
598 
600 {
601  int i, ret;
602  uint32_t *pal;
603 
604  switch (s->bpp * 10 + s->bppcount) {
605  case 11:
606  if (!s->palette_is_set) {
608  break;
609  }
610  case 21:
611  case 41:
612  case 81:
614  break;
615  case 243:
617  break;
618  case 161:
620  break;
621  case 162:
623  break;
624  case 324:
626  break;
627  case 483:
629  break;
630  case 644:
632  break;
633  default:
635  "This format is not supported (bpp=%d, bppcount=%d)\n",
636  s->bpp, s->bppcount);
637  return AVERROR_INVALIDDATA;
638  }
639  if (s->width != s->avctx->width || s->height != s->avctx->height) {
640  if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
641  return ret;
643  }
644  if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0)
645  return ret;
646  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
647  if (s->palette_is_set) {
648  memcpy(frame->data[1], s->palette, sizeof(s->palette));
649  } else {
650  /* make default grayscale pal */
651  pal = (uint32_t *) frame->data[1];
652  for (i = 0; i < 1<<s->bpp; i++)
653  pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->bpp) - 1) * 0x010101;
654  }
655  }
656  return 0;
657 }
658 
660 {
661  unsigned tag, type, count, off, value = 0;
662  int i, j, k, pos, start;
663  int ret;
664  uint32_t *pal;
665  double *dp;
666 
667  tag = tget_short(&s->gb, s->le);
668  type = tget_short(&s->gb, s->le);
669  count = tget_long(&s->gb, s->le);
670  off = tget_long(&s->gb, s->le);
671  start = bytestream2_tell(&s->gb);
672 
673  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
674  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
675  type);
676  return 0;
677  }
678 
679  if (count == 1) {
680  switch (type) {
681  case TIFF_BYTE:
682  case TIFF_SHORT:
683  bytestream2_seek(&s->gb, -4, SEEK_CUR);
684  value = tget(&s->gb, type, s->le);
685  break;
686  case TIFF_LONG:
687  value = off;
688  break;
689  case TIFF_STRING:
690  if (count <= 4) {
691  bytestream2_seek(&s->gb, -4, SEEK_CUR);
692  break;
693  }
694  default:
695  value = UINT_MAX;
696  bytestream2_seek(&s->gb, off, SEEK_SET);
697  }
698  } else {
699  if (count <= 4 && type_sizes[type] * count <= 4) {
700  bytestream2_seek(&s->gb, -4, SEEK_CUR);
701  } else {
702  bytestream2_seek(&s->gb, off, SEEK_SET);
703  }
704  }
705 
706  switch (tag) {
707  case TIFF_WIDTH:
708  s->width = value;
709  break;
710  case TIFF_HEIGHT:
711  s->height = value;
712  break;
713  case TIFF_BPP:
714  s->bppcount = count;
715  if (count > 4) {
717  "This format is not supported (bpp=%d, %d components)\n",
718  s->bpp, count);
719  return AVERROR_INVALIDDATA;
720  }
721  if (count == 1)
722  s->bpp = value;
723  else {
724  switch (type) {
725  case TIFF_BYTE:
726  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
727  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
728  break;
729  case TIFF_SHORT:
730  case TIFF_LONG:
731  s->bpp = 0;
733  return AVERROR_INVALIDDATA;
734  for (i = 0; i < count; i++)
735  s->bpp += tget(&s->gb, type, s->le);
736  break;
737  default:
738  s->bpp = -1;
739  }
740  }
741  break;
743  if (count != 1) {
745  "Samples per pixel requires a single value, many provided\n");
746  return AVERROR_INVALIDDATA;
747  }
748  if (value > 4U) {
750  "Samples per pixel %d is too large\n", value);
751  return AVERROR_INVALIDDATA;
752  }
753  if (s->bppcount == 1)
754  s->bpp *= value;
755  s->bppcount = value;
756  break;
757  case TIFF_COMPR:
758  s->compr = value;
759  s->predictor = 0;
760  switch (s->compr) {
761  case TIFF_RAW:
762  case TIFF_PACKBITS:
763  case TIFF_LZW:
764  case TIFF_CCITT_RLE:
765  break;
766  case TIFF_G3:
767  case TIFF_G4:
768  s->fax_opts = 0;
769  break;
770  case TIFF_DEFLATE:
771  case TIFF_ADOBE_DEFLATE:
772 #if CONFIG_ZLIB
773  break;
774 #else
775  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
776  return AVERROR(ENOSYS);
777 #endif
778  case TIFF_JPEG:
779  case TIFF_NEWJPEG:
781  "JPEG compression is not supported\n");
782  return AVERROR_PATCHWELCOME;
783  default:
784  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
785  s->compr);
786  return AVERROR_INVALIDDATA;
787  }
788  break;
789  case TIFF_ROWSPERSTRIP:
790  if (type == TIFF_LONG && value == UINT_MAX)
791  value = s->height;
792  if (value < 1) {
794  "Incorrect value of rows per strip\n");
795  return AVERROR_INVALIDDATA;
796  }
797  s->rps = value;
798  break;
799  case TIFF_STRIP_OFFS:
800  if (count == 1) {
801  s->strippos = 0;
802  s->stripoff = value;
803  } else
804  s->strippos = off;
805  s->strips = count;
806  if (s->strips == 1)
807  s->rps = s->height;
808  s->sot = type;
809  if (s->strippos > bytestream2_size(&s->gb)) {
811  "Tag referencing position outside the image\n");
812  return AVERROR_INVALIDDATA;
813  }
814  break;
815  case TIFF_STRIP_SIZE:
816  if (count == 1) {
817  s->stripsizesoff = 0;
818  s->stripsize = value;
819  s->strips = 1;
820  } else {
821  s->stripsizesoff = off;
822  }
823  s->strips = count;
824  s->sstype = type;
825  if (s->stripsizesoff > bytestream2_size(&s->gb)) {
827  "Tag referencing position outside the image\n");
828  return AVERROR_INVALIDDATA;
829  }
830  break;
832  case TIFF_TILE_LENGTH:
833  case TIFF_TILE_OFFSETS:
834  case TIFF_TILE_WIDTH:
835  av_log(s->avctx, AV_LOG_ERROR, "Tiled images are not supported\n");
836  return AVERROR_PATCHWELCOME;
837  break;
838  case TIFF_PREDICTOR:
839  s->predictor = value;
840  break;
841  case TIFF_INVERT:
842  switch (value) {
843  case 0:
844  s->invert = 1;
845  break;
846  case 1:
847  s->invert = 0;
848  break;
849  case 2:
850  case 3:
851  break;
852  default:
853  av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
854  value);
855  return AVERROR_INVALIDDATA;
856  }
857  break;
858  case TIFF_FILL_ORDER:
859  if (value < 1 || value > 2) {
861  "Unknown FillOrder value %d, trying default one\n", value);
862  value = 1;
863  }
864  s->fill_order = value - 1;
865  break;
866  case TIFF_PAL:
867  pal = (uint32_t *) s->palette;
868  off = type_sizes[type];
869  if (count / 3 > 256 || bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
870  return AVERROR_INVALIDDATA;
871  off = (type_sizes[type] - 1) << 3;
872  for (k = 2; k >= 0; k--) {
873  for (i = 0; i < count / 3; i++) {
874  if (k == 2)
875  pal[i] = 0xFFU << 24;
876  j = (tget(&s->gb, type, s->le) >> off) << (k * 8);
877  pal[i] |= j;
878  }
879  }
880  s->palette_is_set = 1;
881  break;
882  case TIFF_PLANAR:
883  if (value == 2) {
884  av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
885  return AVERROR_PATCHWELCOME;
886  }
887  break;
888  case TIFF_T4OPTIONS:
889  if (s->compr == TIFF_G3)
890  s->fax_opts = value;
891  break;
892  case TIFF_T6OPTIONS:
893  if (s->compr == TIFF_G4)
894  s->fax_opts = value;
895  break;
896 #define ADD_METADATA(count, name, sep)\
897  if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
898  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
899  return ret;\
900  }
902  ADD_METADATA(count, "ModelPixelScaleTag", NULL);
903  break;
905  ADD_METADATA(count, "ModelTransformationTag", NULL);
906  break;
907  case TIFF_MODEL_TIEPOINT:
908  ADD_METADATA(count, "ModelTiepointTag", NULL);
909  break;
911  ADD_METADATA(1, "GeoTIFF_Version", NULL);
912  ADD_METADATA(2, "GeoTIFF_Key_Revision", ".");
913  s->geotag_count = tget_short(&s->gb, s->le);
914  if (s->geotag_count > count / 4 - 1) {
915  s->geotag_count = count / 4 - 1;
916  av_log(s->avctx, AV_LOG_WARNING, "GeoTIFF key directory buffer shorter than specified\n");
917  }
918  if (bytestream2_get_bytes_left(&s->gb) < s->geotag_count * sizeof(int16_t) * 4) {
919  s->geotag_count = 0;
920  return -1;
921  }
922  s->geotags = av_mallocz(sizeof(TiffGeoTag) * s->geotag_count);
923  if (!s->geotags) {
924  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
925  s->geotag_count = 0;
926  return AVERROR(ENOMEM);
927  }
928  for (i = 0; i < s->geotag_count; i++) {
929  s->geotags[i].key = tget_short(&s->gb, s->le);
930  s->geotags[i].type = tget_short(&s->gb, s->le);
931  s->geotags[i].count = tget_short(&s->gb, s->le);
932 
933  if (!s->geotags[i].type)
934  s->geotags[i].val = get_geokey_val(s->geotags[i].key, tget_short(&s->gb, s->le));
935  else
936  s->geotags[i].offset = tget_short(&s->gb, s->le);
937  }
938  break;
940  if (count >= INT_MAX / sizeof(int64_t))
941  return AVERROR_INVALIDDATA;
942  if (bytestream2_get_bytes_left(&s->gb) < count * sizeof(int64_t))
943  return AVERROR_INVALIDDATA;
944  dp = av_malloc(count * sizeof(double));
945  if (!dp) {
946  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
947  return AVERROR(ENOMEM);
948  }
949  for (i = 0; i < count; i++)
950  dp[i] = tget_double(&s->gb, s->le);
951  for (i = 0; i < s->geotag_count; i++) {
952  if (s->geotags[i].type == TIFF_GEO_DOUBLE_PARAMS) {
953  if (s->geotags[i].count == 0
954  || s->geotags[i].offset + s->geotags[i].count > count) {
955  av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
956  } else {
957  char *ap = doubles2str(&dp[s->geotags[i].offset], s->geotags[i].count, ", ");
958  if (!ap) {
959  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
960  av_freep(&dp);
961  return AVERROR(ENOMEM);
962  }
963  s->geotags[i].val = ap;
964  }
965  }
966  }
967  av_freep(&dp);
968  break;
970  pos = bytestream2_tell(&s->gb);
971  for (i = 0; i < s->geotag_count; i++) {
972  if (s->geotags[i].type == TIFF_GEO_ASCII_PARAMS) {
973  if (s->geotags[i].count == 0
974  || s->geotags[i].offset + s->geotags[i].count > count) {
975  av_log(s->avctx, AV_LOG_WARNING, "Invalid GeoTIFF key %d\n", s->geotags[i].key);
976  } else {
977  char *ap;
978 
979  bytestream2_seek(&s->gb, pos + s->geotags[i].offset, SEEK_SET);
980  if (bytestream2_get_bytes_left(&s->gb) < s->geotags[i].count)
981  return AVERROR_INVALIDDATA;
982  ap = av_malloc(s->geotags[i].count);
983  if (!ap) {
984  av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
985  return AVERROR(ENOMEM);
986  }
987  bytestream2_get_bufferu(&s->gb, ap, s->geotags[i].count);
988  ap[s->geotags[i].count - 1] = '\0'; //replace the "|" delimiter with a 0 byte
989  s->geotags[i].val = ap;
990  }
991  }
992  }
993  break;
994  case TIFF_ARTIST:
995  ADD_METADATA(count, "artist", NULL);
996  break;
997  case TIFF_COPYRIGHT:
998  ADD_METADATA(count, "copyright", NULL);
999  break;
1000  case TIFF_DATE:
1001  ADD_METADATA(count, "date", NULL);
1002  break;
1003  case TIFF_DOCUMENT_NAME:
1004  ADD_METADATA(count, "document_name", NULL);
1005  break;
1006  case TIFF_HOST_COMPUTER:
1007  ADD_METADATA(count, "computer", NULL);
1008  break;
1010  ADD_METADATA(count, "description", NULL);
1011  break;
1012  case TIFF_MAKE:
1013  ADD_METADATA(count, "make", NULL);
1014  break;
1015  case TIFF_MODEL:
1016  ADD_METADATA(count, "model", NULL);
1017  break;
1018  case TIFF_PAGE_NAME:
1019  ADD_METADATA(count, "page_name", NULL);
1020  break;
1021  case TIFF_PAGE_NUMBER:
1022  ADD_METADATA(count, "page_number", " / ");
1023  break;
1024  case TIFF_SOFTWARE_NAME:
1025  ADD_METADATA(count, "software", NULL);
1026  break;
1027  default:
1028  av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
1029  tag, tag);
1030  }
1031  bytestream2_seek(&s->gb, start, SEEK_SET);
1032  return 0;
1033 }
1034 
1036  void *data, int *got_frame, AVPacket *avpkt)
1037 {
1038  TiffContext *const s = avctx->priv_data;
1039  AVFrame *const p = data;
1040  unsigned off;
1041  int id, le, ret;
1042  int i, j, entries;
1043  int stride;
1044  unsigned soff, ssize;
1045  uint8_t *dst;
1046  GetByteContext stripsizes;
1047  GetByteContext stripdata;
1048 
1049  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
1050 
1051  //parse image header
1052  if (avpkt->size < 8)
1053  return AVERROR_INVALIDDATA;
1054  id = bytestream2_get_le16u(&s->gb);
1055  if (id == 0x4949)
1056  le = 1;
1057  else if (id == 0x4D4D)
1058  le = 0;
1059  else {
1060  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
1061  return AVERROR_INVALIDDATA;
1062  }
1063  s->le = le;
1064  // TIFF_BPP is not a required tag and defaults to 1
1065  s->bppcount = s->bpp = 1;
1066  s->invert = 0;
1067  s->compr = TIFF_RAW;
1068  s->fill_order = 0;
1069  free_geotags(s);
1070 
1071  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
1072  // that further identifies the file as a TIFF file"
1073  if (tget_short(&s->gb, le) != 42) {
1074  av_log(avctx, AV_LOG_ERROR,
1075  "The answer to life, universe and everything is not correct!\n");
1076  return AVERROR_INVALIDDATA;
1077  }
1078  // Reset these offsets so we can tell if they were set this frame
1079  s->stripsizesoff = s->strippos = 0;
1080  /* parse image file directory */
1081  off = tget_long(&s->gb, le);
1082  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
1083  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
1084  return AVERROR_INVALIDDATA;
1085  }
1086  bytestream2_seek(&s->gb, off, SEEK_SET);
1087  entries = tget_short(&s->gb, le);
1088  if (bytestream2_get_bytes_left(&s->gb) < entries * 12)
1089  return AVERROR_INVALIDDATA;
1090  for (i = 0; i < entries; i++) {
1091  if ((ret = tiff_decode_tag(s, p)) < 0)
1092  return ret;
1093  }
1094 
1095  for (i = 0; i<s->geotag_count; i++) {
1096  const char *keyname = get_geokey_name(s->geotags[i].key);
1097  if (!keyname) {
1098  av_log(avctx, AV_LOG_WARNING, "Unknown or unsupported GeoTIFF key %d\n", s->geotags[i].key);
1099  continue;
1100  }
1101  if (get_geokey_type(s->geotags[i].key) != s->geotags[i].type) {
1102  av_log(avctx, AV_LOG_WARNING, "Type of GeoTIFF key %d is wrong\n", s->geotags[i].key);
1103  continue;
1104  }
1105  ret = av_dict_set(avpriv_frame_get_metadatap(p), keyname, s->geotags[i].val, 0);
1106  if (ret<0) {
1107  av_log(avctx, AV_LOG_ERROR, "Writing metadata with key '%s' failed\n", keyname);
1108  return ret;
1109  }
1110  }
1111 
1112  if (!s->strippos && !s->stripoff) {
1113  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
1114  return AVERROR_INVALIDDATA;
1115  }
1116  /* now we have the data and may start decoding */
1117  if ((ret = init_image(s, p)) < 0)
1118  return ret;
1119 
1120  if (s->strips == 1 && !s->stripsize) {
1121  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
1122  s->stripsize = avpkt->size - s->stripoff;
1123  }
1124  stride = p->linesize[0];
1125  dst = p->data[0];
1126 
1127  if (s->stripsizesoff) {
1128  if (s->stripsizesoff >= (unsigned)avpkt->size)
1129  return AVERROR_INVALIDDATA;
1130  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff, avpkt->size - s->stripsizesoff);
1131  }
1132  if (s->strippos) {
1133  if (s->strippos >= (unsigned)avpkt->size)
1134  return AVERROR_INVALIDDATA;
1135  bytestream2_init(&stripdata, avpkt->data + s->strippos, avpkt->size - s->strippos);
1136  }
1137 
1138  if (s->rps <= 0) {
1139  av_log(avctx, AV_LOG_ERROR, "rps %d invalid\n", s->rps);
1140  return AVERROR_INVALIDDATA;
1141  }
1142 
1143  for (i = 0; i < s->height; i += s->rps) {
1144  if (s->stripsizesoff)
1145  ssize = tget(&stripsizes, s->sstype, s->le);
1146  else
1147  ssize = s->stripsize;
1148 
1149  if (s->strippos)
1150  soff = tget(&stripdata, s->sot, s->le);
1151  else
1152  soff = s->stripoff;
1153 
1154  if (soff > avpkt->size || ssize > avpkt->size - soff) {
1155  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
1156  return AVERROR_INVALIDDATA;
1157  }
1158  if (tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
1159  FFMIN(s->rps, s->height - i)) < 0)
1160  break;
1161  dst += s->rps * stride;
1162  }
1163  if (s->predictor == 2) {
1164  dst = p->data[0];
1165  soff = s->bpp >> 3;
1166  ssize = s->width * soff;
1167  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
1169  for (i = 0; i < s->height; i++) {
1170  for (j = soff; j < ssize; j += 2)
1171  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
1172  dst += stride;
1173  }
1174  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
1176  for (i = 0; i < s->height; i++) {
1177  for (j = soff; j < ssize; j += 2)
1178  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
1179  dst += stride;
1180  }
1181  } else {
1182  for (i = 0; i < s->height; i++) {
1183  for (j = soff; j < ssize; j++)
1184  dst[j] += dst[j - soff];
1185  dst += stride;
1186  }
1187  }
1188  }
1189 
1190  if (s->invert) {
1191  dst = p->data[0];
1192  for (i = 0; i < s->height; i++) {
1193  for (j = 0; j < p->linesize[0]; j++)
1194  dst[j] = (s->avctx->pix_fmt == AV_PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
1195  dst += p->linesize[0];
1196  }
1197  }
1198  *got_frame = 1;
1199 
1200  return avpkt->size;
1201 }
1202 
1204 {
1205  TiffContext *s = avctx->priv_data;
1206 
1207  s->width = 0;
1208  s->height = 0;
1209  s->avctx = avctx;
1210  ff_lzw_decode_open(&s->lzw);
1212 
1213  return 0;
1214 }
1215 
1217 {
1218  TiffContext *const s = avctx->priv_data;
1219 
1220  free_geotags(s);
1221 
1222  ff_lzw_decode_close(&s->lzw);
1223  av_freep(&s->deinvert_buf);
1224  return 0;
1225 }
1226 
1228  .name = "tiff",
1229  .type = AVMEDIA_TYPE_VIDEO,
1230  .id = AV_CODEC_ID_TIFF,
1231  .priv_data_size = sizeof(TiffContext),
1232  .init = tiff_init,
1233  .close = tiff_end,
1234  .decode = decode_frame,
1235  .capabilities = CODEC_CAP_DR1,
1236  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
1237 };
const char * name
Definition: avisynth_c.h:675
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:170
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
Definition: tiff.h:88
int offset
Definition: tiff.h:179
float v
const char * s
Definition: avisynth_c.h:668
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
const TiffGeoTagKeyName ff_tiff_projection_codes[]
Definition: tiff_data.c:1497
static int add_doubles_metadata(int count, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition: tiff.c:268
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:414
int fill_order
Definition: tiff.c:57
unsigned int bpp
Definition: tiff.c:49
enum AVCodecID id
Definition: mxfenc.c:89
int geotag_count
Definition: tiff.c:67
int sstype
Definition: tiff.c:59
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
const char *const name
Definition: tiff.h:185
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:154
Definition: tiff.h:46
TIFF tables.
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
av_cold void ff_lzw_decode_close(LZWState **p)
Definition: lzw.c:118
static int add_string_metadata(int count, const char *name, TiffContext *s, AVFrame *frame)
Definition: tiff.c:321
static const char * search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
Definition: tiff.c:139
av_cold void ff_lzw_decode_open(LZWState **p)
Definition: lzw.c:113
static int init_image(TiffContext *s, AVFrame *frame)
Definition: tiff.c:599
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
#define AV_RL16
static void free_geotags(TiffContext *const s)
Definition: tiff.c:99
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional FF_INPUT_BUFFER_PADDING_SIZE at the end w...
#define FF_ARRAY_ELEMS(a)
static unsigned tget_short(GetByteContext *gb, int le)
Definition: tiff.c:71
int stride
Definition: mace.c:144
Definition: tiff.h:92
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:268
Definition: tiff.h:91
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:1035
Macro definitions for various function/variable attributes.
static unsigned tget_long(GetByteContext *gb, int le)
Definition: tiff.c:77
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
Definition: tiff.c:659
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
int deinvert_buf_size
Definition: tiff.c:65
av_cold void ff_ccitt_unpack_init(void)
initialize upacker code
Definition: faxcompr.c:99
uint8_t
#define av_cold
Definition: attributes.h:78
char * val
Definition: tiff.h:180
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:79
#define TIFF_GEO_KEY_USER_DEFINED
Definition: tiff_data.h:48
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:112
static char * shorts2str(int16_t *sp, int count, const char *sep)
Definition: tiff.c:242
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:209
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:1203
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
uint8_t * data
uint32_t tag
Definition: movenc.c:894
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition: tiff.c:340
int stripoff
Definition: tiff.c:61
#define sp
Definition: regdef.h:63
Definition: tiff.h:93
LZWState * lzw
Definition: tiff.c:62
int invert
Definition: tiff.c:54
Definition: tiff.h:67
frame
Definition: stft.m:14
static av_always_inline int bytestream2_size(GetByteContext *g)
Definition: bytestream.h:193
#define U(x)
Definition: lzw.c:45
int height
Definition: tiff.c:48
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:49
enum TiffGeoTagKey key
Definition: tiff.h:176
int sot
Definition: tiff.c:60
#define AV_RB16
TIFF data tables.
#define AV_WL16(p, darg)
Definition: intreadwrite.h:250
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
Definition: tiff.h:171
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
struct TiffContext TiffContext
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:1216
Spectrum Plot time data
const char * r
Definition: vf_curves.c:94
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
int width
Definition: tiff.c:48
int strips
Definition: tiff.c:59
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:277
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
external API header
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
int size
int predictor
Definition: tiff.c:56
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
const TiffGeoTagKeyName ff_tiff_proj_cs_type_codes[]
Definition: tiff_data.c:516
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:231
int stripsize
Definition: tiff.c:61
8bit gray, 8bit alpha
Definition: pixfmt.h:141
#define FFMIN(a, b)
Definition: common.h:58
int le
Definition: tiff.c:52
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that&#39;s been allocated with av_malloc() and chilren.
Definition: dict.h:72
ret
Definition: avfilter.c:821
int width
picture width / height.
int rps
Definition: tiff.c:59
#define TIFF_GEO_KEY_UNDEFINED
Definition: tiff_data.h:47
static unsigned tget(GetByteContext *gb, int type, int le)
Definition: tiff.c:89
int palette_is_set
Definition: tiff.c:51
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
for k
uint32_t palette[256]
Definition: tiff.c:50
NULL
Definition: eval.c:55
or the Software in violation of any applicable export control laws in any jurisdiction Except as provided by mandatorily applicable UPF has no obligation to provide you with source code to the Software In the event Software contains any source code
Definition: tiff.h:40
static const char * get_geokey_name(int key)
Definition: tiff.c:114
TiffCompr
list of TIFF compression types
Definition: tiff.h:87
AVS_Value src
Definition: avisynth_c.h:523
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:220
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
enum TiffCompr compr
Definition: tiff.c:53
unsigned int bppcount
Definition: tiff.c:49
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
Definition: tiff.h:90
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
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:62
AVCodecContext * avctx
Definition: tiff.c:45
double value
Definition: eval.c:82
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Y , 16bpp, big-endian.
Definition: pixfmt.h:101
synthesis window for stochastic i
#define AV_WB16(p, darg)
Definition: intreadwrite.h:237
static int add_shorts_metadata(int count, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition: tiff.c:295
#define snprintf
Definition: snprintf.h:34
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
#define type
static int get_geokey_type(int key)
Definition: tiff.c:124
int strippos
Definition: tiff.c:61
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
int count
Definition: tiff.h:178
enum TiffTags type
Definition: tiff.h:177
LZW decoding routines.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:78
int stripsizesoff
Definition: tiff.c:61
uint8_t * deinvert_buf
Definition: tiff.c:64
common internal api header.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:162
static char * get_geokey_val(int key, int val)
Definition: tiff.c:148
static double c[64]
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:111
static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t *dst, int usePtr, const uint8_t *src, uint8_t c, int width, int offset)
Definition: tiff.c:374
static char * doubles2str(double *dp, int count, const char *sep)
Definition: tiff.c:216
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
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define RET_GEOKEY_VAL(TYPE, array)
static double tget_double(GetByteContext *gb, int le)
Definition: tiff.c:83
int len
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip please avoid problems through this extra level of scrutiny For cosmetics only commits you should e g by running git config global user name My Name git config global user email my email which is either set in your personal configuration file through git config core editor or set by one of the following environment VISUAL or EDITOR Log messages should be concise but descriptive Explain why you made a what you did will be obvious from the changes themselves most of the time Saying just bug fix or is bad Remember that people of varying skill levels look at and educate themselves while reading through your code Don t include filenames in log Git provides that information Possibly make the commit message have a descriptive first line
Definition: git-howto.txt:153
Y , 16bpp, little-endian.
Definition: pixfmt.h:102
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:203
int fax_opts
Definition: tiff.c:55
#define RET_GEOKEY(TYPE, array, element)
Definition: tiff.c:109
void INT64 INT64 count
Definition: avisynth_c.h:594
void INT64 start
Definition: avisynth_c.h:594
AVCodec ff_tiff_decoder
Definition: tiff.c:1227
#define av_always_inline
Definition: attributes.h:41
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
const uint8_t ff_reverse[256]
Definition: mathtables.c:72
GetByteContext gb
Definition: tiff.c:46
static int cmp_id_key(const void *id, const void *k)
Definition: tiff.c:134
TiffGeoTag * geotags
Definition: tiff.c:68
#define ADD_METADATA(count, name, sep)
Definition: tiff.h:63
This structure stores compressed data.
for(j=16;j >0;--j)
CCITT Fax Group 3 and 4 decompression.
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:210