tiff.c
Go to the documentation of this file.
1 /*
2  * TIFF image decoder
3  * Copyright (c) 2006 Konstantin Shishkov
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
28 #include "avcodec.h"
29 #include "bytestream.h"
30 #include "config.h"
31 #if CONFIG_ZLIB
32 #include <zlib.h>
33 #endif
34 #include "lzw.h"
35 #include "tiff.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 
43 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 } TiffContext;
64 
65 static unsigned tget_short(GetByteContext *gb, int le)
66 {
67  return le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
68 }
69 
70 static unsigned tget_long(GetByteContext *gb, int le)
71 {
72  return le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
73 }
74 
75 static unsigned tget(GetByteContext *gb, int type, int le)
76 {
77  switch (type) {
78  case TIFF_BYTE: return bytestream2_get_byte(gb);
79  case TIFF_SHORT: return tget_short(gb, le);
80  case TIFF_LONG: return tget_long(gb, le);
81  default: return UINT_MAX;
82  }
83 }
84 
85 #if CONFIG_ZLIB
86 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
87  int size)
88 {
89  z_stream zstream = { 0 };
90  int zret;
91 
92  zstream.next_in = src;
93  zstream.avail_in = size;
94  zstream.next_out = dst;
95  zstream.avail_out = *len;
96  zret = inflateInit(&zstream);
97  if (zret != Z_OK) {
98  av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
99  return zret;
100  }
101  zret = inflate(&zstream, Z_SYNC_FLUSH);
102  inflateEnd(&zstream);
103  *len = zstream.total_out;
104  return zret == Z_STREAM_END ? Z_OK : zret;
105 }
106 #endif
107 
108 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
109  const uint8_t *src, int size, int lines)
110 {
111  PutByteContext pb;
112  int c, line, pixels, code;
113  int width = ((s->width * s->bpp) + 7) >> 3;
114 
115  if (size <= 0)
116  return AVERROR_INVALIDDATA;
117 
118 #if CONFIG_ZLIB
119  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
120  uint8_t *zbuf;
121  unsigned long outlen;
122  int ret;
123  outlen = width * lines;
124  zbuf = av_malloc(outlen);
125  if (!zbuf)
126  return AVERROR(ENOMEM);
127  ret = tiff_uncompress(zbuf, &outlen, src, size);
128  if (ret != Z_OK) {
130  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
131  (unsigned long)width * lines, ret);
132  av_free(zbuf);
133  return -1;
134  }
135  src = zbuf;
136  for (line = 0; line < lines; line++) {
137  memcpy(dst, src, width);
138  dst += stride;
139  src += width;
140  }
141  av_free(zbuf);
142  return 0;
143  }
144 #endif
145  if (s->compr == TIFF_LZW) {
146  if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) {
147  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
148  return -1;
149  }
150  for (line = 0; line < lines; line++) {
151  pixels = ff_lzw_decode(s->lzw, dst, width);
152  if (pixels < width) {
153  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
154  pixels, width);
155  return AVERROR_INVALIDDATA;
156  }
157  dst += stride;
158  }
159  return 0;
160  }
161  if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
162  || s->compr == TIFF_G4) {
163  int i, ret = 0;
164  uint8_t *src2 = av_malloc((unsigned)size +
166 
167  if (!src2) {
169  "Error allocating temporary buffer\n");
170  return AVERROR(ENOMEM);
171  }
172  if (s->fax_opts & 2) {
174  "Uncompressed fax mode is not supported (yet)\n");
175  av_free(src2);
176  return -1;
177  }
178  if (!s->fill_order) {
179  memcpy(src2, src, size);
180  } else {
181  for (i = 0; i < size; i++)
182  src2[i] = ff_reverse[src[i]];
183  }
184  memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
185  switch (s->compr) {
186  case TIFF_CCITT_RLE:
187  case TIFF_G3:
188  case TIFF_G4:
189  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
190  s->compr, s->fax_opts);
191  break;
192  }
193  av_free(src2);
194  return ret;
195  }
196 
197  bytestream2_init(&s->gb, src, size);
198  bytestream2_init_writer(&pb, dst, stride * lines);
199 
200  for (line = 0; line < lines; line++) {
201  if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))
202  break;
203  bytestream2_seek_p(&pb, stride * line, SEEK_SET);
204  switch (s->compr) {
205  case TIFF_RAW:
206  if (!s->fill_order) {
207  bytestream2_copy_buffer(&pb, &s->gb, width);
208  } else {
209  int i;
210  for (i = 0; i < width; i++)
211  bytestream2_put_byte(&pb, ff_reverse[bytestream2_get_byte(&s->gb)]);
212  }
213  break;
214  case TIFF_PACKBITS:
215  for (pixels = 0; pixels < width;) {
216  code = (int8_t)bytestream2_get_byte(&s->gb);
217  if (code >= 0) {
218  code++;
219  bytestream2_copy_buffer(&pb, &s->gb, code);
220  pixels += code;
221  } else if (code != -128) { // -127..-1
222  code = (-code) + 1;
223  c = bytestream2_get_byte(&s->gb);
224  bytestream2_set_buffer(&pb, c, code);
225  pixels += code;
226  }
227  }
228  break;
229  }
230  }
231  return 0;
232 }
233 
234 static int init_image(TiffContext *s)
235 {
236  int i, ret;
237  uint32_t *pal;
238 
239  switch (s->bpp * 10 + s->bppcount) {
240  case 11:
242  break;
243  case 81:
245  break;
246  case 243:
248  break;
249  case 161:
251  break;
252  case 324:
254  break;
255  case 483:
257  break;
258  default:
260  "This format is not supported (bpp=%d, bppcount=%d)\n",
261  s->bpp, s->bppcount);
262  return AVERROR_INVALIDDATA;
263  }
264  if (s->width != s->avctx->width || s->height != s->avctx->height) {
265  if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
266  return ret;
268  }
269  if (s->picture.data[0])
270  s->avctx->release_buffer(s->avctx, &s->picture);
271  if ((ret = ff_get_buffer(s->avctx, &s->picture)) < 0) {
272  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
273  return ret;
274  }
275  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
276  if (s->palette_is_set) {
277  memcpy(s->picture.data[1], s->palette, sizeof(s->palette));
278  } else {
279  /* make default grayscale pal */
280  pal = (uint32_t *) s->picture.data[1];
281  for (i = 0; i < 256; i++)
282  pal[i] = i * 0x010101;
283  }
284  }
285  return 0;
286 }
287 
289 {
290  unsigned tag, type, count, off, value = 0;
291  int i, start;
292  uint32_t *pal;
293 
294  if (bytestream2_get_bytes_left(&s->gb) < 12)
295  return -1;
296  tag = tget_short(&s->gb, s->le);
297  type = tget_short(&s->gb, s->le);
298  count = tget_long(&s->gb, s->le);
299  off = tget_long(&s->gb, s->le);
300  start = bytestream2_tell(&s->gb);
301 
302  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
303  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
304  type);
305  return 0;
306  }
307 
308  if (count == 1) {
309  switch (type) {
310  case TIFF_BYTE:
311  case TIFF_SHORT:
312  bytestream2_seek(&s->gb, -4, SEEK_CUR);
313  value = tget(&s->gb, type, s->le);
314  break;
315  case TIFF_LONG:
316  value = off;
317  break;
318  case TIFF_STRING:
319  if (count <= 4) {
320  bytestream2_seek(&s->gb, -4, SEEK_CUR);
321  break;
322  }
323  default:
324  value = UINT_MAX;
325  bytestream2_seek(&s->gb, off, SEEK_SET);
326  }
327  } else {
328  if (count <= 4 && type_sizes[type] * count <= 4)
329  bytestream2_seek(&s->gb, -4, SEEK_CUR);
330  else
331  bytestream2_seek(&s->gb, off, SEEK_SET);
332  }
333 
334  switch (tag) {
335  case TIFF_WIDTH:
336  s->width = value;
337  break;
338  case TIFF_HEIGHT:
339  s->height = value;
340  break;
341  case TIFF_BPP:
342  s->bppcount = count;
343  if (count > 4) {
345  "This format is not supported (bpp=%d, %d components)\n",
346  s->bpp, count);
347  return -1;
348  }
349  if (count == 1)
350  s->bpp = value;
351  else {
352  switch (type) {
353  case TIFF_BYTE:
354  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
355  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
356  break;
357  case TIFF_SHORT:
358  case TIFF_LONG:
359  s->bpp = 0;
360  for (i = 0; i < count; i++)
361  s->bpp += tget(&s->gb, type, s->le);
362  break;
363  default:
364  s->bpp = -1;
365  }
366  }
367  break;
369  if (count != 1) {
371  "Samples per pixel requires a single value, many provided\n");
372  return AVERROR_INVALIDDATA;
373  }
374  if (s->bppcount == 1)
375  s->bpp *= value;
376  s->bppcount = value;
377  break;
378  case TIFF_COMPR:
379  s->compr = value;
380  s->predictor = 0;
381  switch (s->compr) {
382  case TIFF_RAW:
383  case TIFF_PACKBITS:
384  case TIFF_LZW:
385  case TIFF_CCITT_RLE:
386  break;
387  case TIFF_G3:
388  case TIFF_G4:
389  s->fax_opts = 0;
390  break;
391  case TIFF_DEFLATE:
392  case TIFF_ADOBE_DEFLATE:
393 #if CONFIG_ZLIB
394  break;
395 #else
396  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
397  return -1;
398 #endif
399  case TIFF_JPEG:
400  case TIFF_NEWJPEG:
402  "JPEG compression is not supported\n");
403  return -1;
404  default:
405  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
406  s->compr);
407  return -1;
408  }
409  break;
410  case TIFF_ROWSPERSTRIP:
411  if (type == TIFF_LONG && value == UINT_MAX)
412  value = s->avctx->height;
413  if (value < 1) {
415  "Incorrect value of rows per strip\n");
416  return -1;
417  }
418  s->rps = value;
419  break;
420  case TIFF_STRIP_OFFS:
421  if (count == 1) {
422  s->strippos = 0;
423  s->stripoff = value;
424  } else
425  s->strippos = off;
426  s->strips = count;
427  if (s->strips == 1)
428  s->rps = s->height;
429  s->sot = type;
430  break;
431  case TIFF_STRIP_SIZE:
432  if (count == 1) {
433  s->stripsizesoff = 0;
434  s->stripsize = value;
435  s->strips = 1;
436  } else {
437  s->stripsizesoff = off;
438  }
439  s->strips = count;
440  s->sstype = type;
441  break;
442  case TIFF_PREDICTOR:
443  s->predictor = value;
444  break;
445  case TIFF_INVERT:
446  switch (value) {
447  case 0:
448  s->invert = 1;
449  break;
450  case 1:
451  s->invert = 0;
452  break;
453  case 2:
454  case 3:
455  break;
456  default:
457  av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
458  value);
459  return -1;
460  }
461  break;
462  case TIFF_FILL_ORDER:
463  if (value < 1 || value > 2) {
465  "Unknown FillOrder value %d, trying default one\n", value);
466  value = 1;
467  }
468  s->fill_order = value - 1;
469  break;
470  case TIFF_PAL: {
471  GetByteContext pal_gb[3];
472  pal = (uint32_t *) s->palette;
473  off = type_sizes[type];
474  if (count / 3 > 256 ||
475  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
476  return -1;
477  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
478  bytestream2_skip(&pal_gb[1], count / 3 * off);
479  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
480  off = (type_sizes[type] - 1) << 3;
481  for (i = 0; i < count / 3; i++) {
482  uint32_t p = 0xFF000000;
483  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
484  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
485  p |= tget(&pal_gb[2], type, s->le) >> off;
486  pal[i] = p;
487  }
488  s->palette_is_set = 1;
489  break;
490  }
491  case TIFF_PLANAR:
492  if (value == 2) {
493  av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
494  return -1;
495  }
496  break;
497  case TIFF_T4OPTIONS:
498  if (s->compr == TIFF_G3)
499  s->fax_opts = value;
500  break;
501  case TIFF_T6OPTIONS:
502  if (s->compr == TIFF_G4)
503  s->fax_opts = value;
504  break;
505  default:
506  av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
507  tag, tag);
508  }
509  bytestream2_seek(&s->gb, start, SEEK_SET);
510  return 0;
511 }
512 
513 static int decode_frame(AVCodecContext *avctx,
514  void *data, int *got_frame, AVPacket *avpkt)
515 {
516  TiffContext *const s = avctx->priv_data;
517  AVFrame *picture = data;
518  AVFrame *const p = &s->picture;
519  unsigned off;
520  int id, le, ret;
521  int i, j, entries;
522  int stride;
523  unsigned soff, ssize;
524  uint8_t *dst;
525  GetByteContext stripsizes;
526  GetByteContext stripdata;
527 
528  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
529 
530  //parse image header
531  if (avpkt->size < 8)
532  return AVERROR_INVALIDDATA;
533  id = bytestream2_get_le16(&s->gb);
534  if (id == 0x4949)
535  le = 1;
536  else if (id == 0x4D4D)
537  le = 0;
538  else {
539  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
540  return -1;
541  }
542  s->le = le;
543  s->invert = 0;
544  s->compr = TIFF_RAW;
545  s->fill_order = 0;
546  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
547  // that further identifies the file as a TIFF file"
548  if (tget_short(&s->gb, le) != 42) {
549  av_log(avctx, AV_LOG_ERROR,
550  "The answer to life, universe and everything is not correct!\n");
551  return -1;
552  }
553  // Reset these offsets so we can tell if they were set this frame
554  s->stripsizesoff = s->strippos = 0;
555  /* parse image file directory */
556  off = tget_long(&s->gb, le);
557  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
558  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
559  return AVERROR_INVALIDDATA;
560  }
561  bytestream2_seek(&s->gb, off, SEEK_SET);
562  entries = tget_short(&s->gb, le);
563  for (i = 0; i < entries; i++) {
564  if (tiff_decode_tag(s) < 0)
565  return -1;
566  }
567  if (!s->strippos && !s->stripoff) {
568  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
569  return -1;
570  }
571  /* now we have the data and may start decoding */
572  if ((ret = init_image(s)) < 0)
573  return ret;
574 
575  if (s->strips == 1 && !s->stripsize) {
576  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
577  s->stripsize = avpkt->size - s->stripoff;
578  }
579  stride = p->linesize[0];
580  dst = p->data[0];
581 
582  if (s->stripsizesoff) {
583  if (s->stripsizesoff >= avpkt->size)
584  return AVERROR_INVALIDDATA;
585  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
586  avpkt->size - s->stripsizesoff);
587  }
588  if (s->strippos) {
589  if (s->strippos >= avpkt->size)
590  return AVERROR_INVALIDDATA;
591  bytestream2_init(&stripdata, avpkt->data + s->strippos,
592  avpkt->size - s->strippos);
593  }
594 
595  for (i = 0; i < s->height; i += s->rps) {
596  if (s->stripsizesoff)
597  ssize = tget(&stripsizes, s->sstype, le);
598  else
599  ssize = s->stripsize;
600 
601  if (s->strippos)
602  soff = tget(&stripdata, s->sot, le);
603  else
604  soff = s->stripoff;
605 
606  if (soff > avpkt->size || ssize > avpkt->size - soff) {
607  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
608  return -1;
609  }
610  if (tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
611  FFMIN(s->rps, s->height - i)) < 0)
612  break;
613  dst += s->rps * stride;
614  }
615  if (s->predictor == 2) {
616  dst = p->data[0];
617  soff = s->bpp >> 3;
618  ssize = s->width * soff;
619  for (i = 0; i < s->height; i++) {
620  for (j = soff; j < ssize; j++)
621  dst[j] += dst[j - soff];
622  dst += stride;
623  }
624  }
625 
626  if (s->invert) {
627  uint8_t *src;
628  int j;
629 
630  src = s->picture.data[0];
631  for (j = 0; j < s->height; j++) {
632  for (i = 0; i < s->picture.linesize[0]; i++)
633  src[i] = 255 - src[i];
634  src += s->picture.linesize[0];
635  }
636  }
637  *picture = s->picture;
638  *got_frame = 1;
639 
640  return avpkt->size;
641 }
642 
643 static av_cold int tiff_init(AVCodecContext *avctx)
644 {
645  TiffContext *s = avctx->priv_data;
646 
647  s->width = 0;
648  s->height = 0;
649  s->avctx = avctx;
651  avctx->coded_frame = &s->picture;
652  ff_lzw_decode_open(&s->lzw);
654 
655  return 0;
656 }
657 
658 static av_cold int tiff_end(AVCodecContext *avctx)
659 {
660  TiffContext *const s = avctx->priv_data;
661 
663  if (s->picture.data[0])
664  avctx->release_buffer(avctx, &s->picture);
665  return 0;
666 }
667 
669  .name = "tiff",
670  .type = AVMEDIA_TYPE_VIDEO,
671  .id = AV_CODEC_ID_TIFF,
672  .priv_data_size = sizeof(TiffContext),
673  .init = tiff_init,
674  .close = tiff_end,
675  .decode = decode_frame,
676  .capabilities = CODEC_CAP_DR1,
677  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
678 };
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:171
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:61
Definition: tiff.h:65
static av_always_inline void bytestream2_set_buffer(PutByteContext *p, const uint8_t c, unsigned int size)
Definition: bytestream.h:301
int size
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:108
int fill_order
Definition: tiff.c:57
unsigned int bpp
Definition: tiff.c:49
enum AVCodecID id
Definition: mxfenc.c:85
int sstype
Definition: tiff.c:59
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
TIFF tables.
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
Definition: utils.c:149
int size
Definition: avcodec.h:916
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:139
av_cold void ff_lzw_decode_close(LZWState **p)
Definition: lzw.c:120
av_cold void ff_lzw_decode_open(LZWState **p)
Definition: lzw.c:115
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
static unsigned tget_short(GetByteContext *gb, int le)
Definition: tiff.c:65
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2960
Definition: tiff.h:69
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:513
Macro definitions for various function/variable attributes.
static unsigned tget_long(GetByteContext *gb, int le)
Definition: tiff.c:70
av_cold void ff_ccitt_unpack_init(void)
initialize upacker code
Definition: faxcompr.c:99
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:228
static int init_image(TiffContext *s)
Definition: tiff.c:234
uint8_t
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
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:109
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:643
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
uint32_t tag
Definition: movenc.c:802
int stripoff
Definition: tiff.c:61
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
Definition: tiff.h:86
Definition: tiff.h:70
LZWState * lzw
Definition: tiff.c:62
AVFrame picture
Definition: tiff.c:45
int invert
Definition: tiff.c:54
static int init(AVCodecParserContext *s)
Definition: h264_parser.c:335
Definition: tiff.h:56
Definition: lzw.c:46
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:139
int sot
Definition: tiff.c:60
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:159
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
struct TiffContext TiffContext
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:658
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
Definition: graph2dot.c:48
static int tiff_decode_tag(TiffContext *s)
Definition: tiff.c:288
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
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:271
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
int predictor
Definition: tiff.c:56
int off
Definition: dsputil_bfin.c:28
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:220
int stripsize
Definition: tiff.c:61
static AVFrame * picture
int le
Definition: tiff.c:52
int width
picture width / height.
Definition: avcodec.h:1508
int rps
Definition: tiff.c:59
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
uint8_t le
Definition: crc.c:30
static unsigned tget(GetByteContext *gb, int type, int le)
Definition: tiff.c:75
int palette_is_set
Definition: tiff.c:51
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
Definition: bytestream.h:227
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:183
uint32_t palette[256]
Definition: tiff.c:50
NULL
Definition: eval.c:52
Definition: tiff.h:38
static int width
Definition: utils.c:156
TiffCompr
list of TIFF compression types
Definition: tiff.h:64
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
enum TiffCompr compr
Definition: tiff.c:53
unsigned int bppcount
Definition: tiff.c:49
main external API structure.
Definition: avcodec.h:1339
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:326
Definition: tiff.h:67
Definition: tiff.h:78
static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, GetByteContext *g, unsigned int size)
Definition: bytestream.h:338
AVCodecContext * avctx
Definition: tiff.c:44
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
Definition: utils.c:602
Y , 16bpp, big-endian.
Definition: pixfmt.h:98
int strippos
Definition: tiff.c:61
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
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:75
int stripsizesoff
Definition: tiff.c:61
common internal api header.
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
Definition: bytestream.h:323
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:108
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
Definition: lzw.c:133
void * priv_data
Definition: avcodec.h:1382
int len
Y , 16bpp, little-endian.
Definition: pixfmt.h:99
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:203
int fax_opts
Definition: tiff.c:55
AVCodec ff_tiff_decoder
Definition: tiff.c:668
Definition: tiff.h:81
const uint8_t ff_reverse[256]
Definition: mathtables.c:70
GetByteContext gb
Definition: tiff.c:46
This structure stores compressed data.
Definition: avcodec.h:898
for(j=16;j >0;--j)
CCITT Fax Group 3 and 4 decompression.
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)