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  // make sure there is no aliasing in the following switch
240  if (s->bpp >= 100 || s->bppcount >= 10) {
242  "Unsupported image parameters: bpp=%d, bppcount=%d\n",
243  s->bpp, s->bppcount);
244  return AVERROR_INVALIDDATA;
245  }
246 
247  switch (s->bpp * 10 + s->bppcount) {
248  case 11:
250  break;
251  case 81:
253  break;
254  case 243:
256  break;
257  case 161:
259  break;
260  case 324:
262  break;
263  case 483:
265  break;
266  default:
268  "This format is not supported (bpp=%d, bppcount=%d)\n",
269  s->bpp, s->bppcount);
270  return AVERROR_INVALIDDATA;
271  }
272  if (s->width != s->avctx->width || s->height != s->avctx->height) {
273  if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
274  return ret;
276  }
277  if (s->picture.data[0])
278  s->avctx->release_buffer(s->avctx, &s->picture);
279  if ((ret = ff_get_buffer(s->avctx, &s->picture)) < 0) {
280  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
281  return ret;
282  }
283  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
284  if (s->palette_is_set) {
285  memcpy(s->picture.data[1], s->palette, sizeof(s->palette));
286  } else {
287  /* make default grayscale pal */
288  pal = (uint32_t *) s->picture.data[1];
289  for (i = 0; i < 256; i++)
290  pal[i] = i * 0x010101;
291  }
292  }
293  return 0;
294 }
295 
297 {
298  unsigned tag, type, count, off, value = 0;
299  int i, start;
300  uint32_t *pal;
301 
302  if (bytestream2_get_bytes_left(&s->gb) < 12)
303  return -1;
304  tag = tget_short(&s->gb, s->le);
305  type = tget_short(&s->gb, s->le);
306  count = tget_long(&s->gb, s->le);
307  off = tget_long(&s->gb, s->le);
308  start = bytestream2_tell(&s->gb);
309 
310  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
311  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
312  type);
313  return 0;
314  }
315 
316  if (count == 1) {
317  switch (type) {
318  case TIFF_BYTE:
319  case TIFF_SHORT:
320  bytestream2_seek(&s->gb, -4, SEEK_CUR);
321  value = tget(&s->gb, type, s->le);
322  break;
323  case TIFF_LONG:
324  value = off;
325  break;
326  case TIFF_STRING:
327  if (count <= 4) {
328  bytestream2_seek(&s->gb, -4, SEEK_CUR);
329  break;
330  }
331  default:
332  value = UINT_MAX;
333  bytestream2_seek(&s->gb, off, SEEK_SET);
334  }
335  } else {
336  if (count <= 4 && type_sizes[type] * count <= 4)
337  bytestream2_seek(&s->gb, -4, SEEK_CUR);
338  else
339  bytestream2_seek(&s->gb, off, SEEK_SET);
340  }
341 
342  switch (tag) {
343  case TIFF_WIDTH:
344  s->width = value;
345  break;
346  case TIFF_HEIGHT:
347  s->height = value;
348  break;
349  case TIFF_BPP:
350  s->bppcount = count;
351  if (count > 4) {
353  "This format is not supported (bpp=%d, %d components)\n",
354  s->bpp, count);
355  return -1;
356  }
357  if (count == 1)
358  s->bpp = value;
359  else {
360  switch (type) {
361  case TIFF_BYTE:
362  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
363  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
364  break;
365  case TIFF_SHORT:
366  case TIFF_LONG:
367  s->bpp = 0;
368  for (i = 0; i < count; i++)
369  s->bpp += tget(&s->gb, type, s->le);
370  break;
371  default:
372  s->bpp = -1;
373  }
374  }
375  break;
377  if (count != 1) {
379  "Samples per pixel requires a single value, many provided\n");
380  return AVERROR_INVALIDDATA;
381  }
382  if (s->bppcount == 1)
383  s->bpp *= value;
384  s->bppcount = value;
385  break;
386  case TIFF_COMPR:
387  s->compr = value;
388  s->predictor = 0;
389  switch (s->compr) {
390  case TIFF_RAW:
391  case TIFF_PACKBITS:
392  case TIFF_LZW:
393  case TIFF_CCITT_RLE:
394  break;
395  case TIFF_G3:
396  case TIFF_G4:
397  s->fax_opts = 0;
398  break;
399  case TIFF_DEFLATE:
400  case TIFF_ADOBE_DEFLATE:
401 #if CONFIG_ZLIB
402  break;
403 #else
404  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
405  return -1;
406 #endif
407  case TIFF_JPEG:
408  case TIFF_NEWJPEG:
410  "JPEG compression is not supported\n");
411  return -1;
412  default:
413  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
414  s->compr);
415  return -1;
416  }
417  break;
418  case TIFF_ROWSPERSTRIP:
419  if (type == TIFF_LONG && value == UINT_MAX)
420  value = s->avctx->height;
421  if (value < 1) {
423  "Incorrect value of rows per strip\n");
424  return -1;
425  }
426  s->rps = value;
427  break;
428  case TIFF_STRIP_OFFS:
429  if (count == 1) {
430  s->strippos = 0;
431  s->stripoff = value;
432  } else
433  s->strippos = off;
434  s->strips = count;
435  if (s->strips == 1)
436  s->rps = s->height;
437  s->sot = type;
438  break;
439  case TIFF_STRIP_SIZE:
440  if (count == 1) {
441  s->stripsizesoff = 0;
442  s->stripsize = value;
443  s->strips = 1;
444  } else {
445  s->stripsizesoff = off;
446  }
447  s->strips = count;
448  s->sstype = type;
449  break;
450  case TIFF_PREDICTOR:
451  s->predictor = value;
452  break;
453  case TIFF_INVERT:
454  switch (value) {
455  case 0:
456  s->invert = 1;
457  break;
458  case 1:
459  s->invert = 0;
460  break;
461  case 2:
462  case 3:
463  break;
464  default:
465  av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
466  value);
467  return -1;
468  }
469  break;
470  case TIFF_FILL_ORDER:
471  if (value < 1 || value > 2) {
473  "Unknown FillOrder value %d, trying default one\n", value);
474  value = 1;
475  }
476  s->fill_order = value - 1;
477  break;
478  case TIFF_PAL: {
479  GetByteContext pal_gb[3];
480  pal = (uint32_t *) s->palette;
481  off = type_sizes[type];
482  if (count / 3 > 256 ||
483  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
484  return -1;
485  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
486  bytestream2_skip(&pal_gb[1], count / 3 * off);
487  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
488  off = (type_sizes[type] - 1) << 3;
489  for (i = 0; i < count / 3; i++) {
490  uint32_t p = 0xFF000000;
491  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
492  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
493  p |= tget(&pal_gb[2], type, s->le) >> off;
494  pal[i] = p;
495  }
496  s->palette_is_set = 1;
497  break;
498  }
499  case TIFF_PLANAR:
500  if (value == 2) {
501  av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
502  return -1;
503  }
504  break;
505  case TIFF_T4OPTIONS:
506  if (s->compr == TIFF_G3)
507  s->fax_opts = value;
508  break;
509  case TIFF_T6OPTIONS:
510  if (s->compr == TIFF_G4)
511  s->fax_opts = value;
512  break;
513  default:
514  av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
515  tag, tag);
516  }
517  bytestream2_seek(&s->gb, start, SEEK_SET);
518  return 0;
519 }
520 
521 static int decode_frame(AVCodecContext *avctx,
522  void *data, int *got_frame, AVPacket *avpkt)
523 {
524  TiffContext *const s = avctx->priv_data;
525  AVFrame *picture = data;
526  AVFrame *const p = &s->picture;
527  unsigned off;
528  int id, le, ret;
529  int i, j, entries;
530  int stride;
531  unsigned soff, ssize;
532  uint8_t *dst;
533  GetByteContext stripsizes;
534  GetByteContext stripdata;
535 
536  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
537 
538  //parse image header
539  if (avpkt->size < 8)
540  return AVERROR_INVALIDDATA;
541  id = bytestream2_get_le16(&s->gb);
542  if (id == 0x4949)
543  le = 1;
544  else if (id == 0x4D4D)
545  le = 0;
546  else {
547  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
548  return -1;
549  }
550  s->le = le;
551  s->invert = 0;
552  s->compr = TIFF_RAW;
553  s->fill_order = 0;
554  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
555  // that further identifies the file as a TIFF file"
556  if (tget_short(&s->gb, le) != 42) {
557  av_log(avctx, AV_LOG_ERROR,
558  "The answer to life, universe and everything is not correct!\n");
559  return -1;
560  }
561  // Reset these offsets so we can tell if they were set this frame
562  s->stripsizesoff = s->strippos = 0;
563  /* parse image file directory */
564  off = tget_long(&s->gb, le);
565  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
566  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
567  return AVERROR_INVALIDDATA;
568  }
569  bytestream2_seek(&s->gb, off, SEEK_SET);
570  entries = tget_short(&s->gb, le);
571  for (i = 0; i < entries; i++) {
572  if (tiff_decode_tag(s) < 0)
573  return -1;
574  }
575  if (!s->strippos && !s->stripoff) {
576  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
577  return -1;
578  }
579  /* now we have the data and may start decoding */
580  if ((ret = init_image(s)) < 0)
581  return ret;
582 
583  if (s->strips == 1 && !s->stripsize) {
584  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
585  s->stripsize = avpkt->size - s->stripoff;
586  }
587  stride = p->linesize[0];
588  dst = p->data[0];
589 
590  if (s->stripsizesoff) {
591  if (s->stripsizesoff >= avpkt->size)
592  return AVERROR_INVALIDDATA;
593  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
594  avpkt->size - s->stripsizesoff);
595  }
596  if (s->strippos) {
597  if (s->strippos >= avpkt->size)
598  return AVERROR_INVALIDDATA;
599  bytestream2_init(&stripdata, avpkt->data + s->strippos,
600  avpkt->size - s->strippos);
601  }
602 
603  for (i = 0; i < s->height; i += s->rps) {
604  if (s->stripsizesoff)
605  ssize = tget(&stripsizes, s->sstype, le);
606  else
607  ssize = s->stripsize;
608 
609  if (s->strippos)
610  soff = tget(&stripdata, s->sot, le);
611  else
612  soff = s->stripoff;
613 
614  if (soff > avpkt->size || ssize > avpkt->size - soff) {
615  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
616  return -1;
617  }
618  if (tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
619  FFMIN(s->rps, s->height - i)) < 0)
620  break;
621  dst += s->rps * stride;
622  }
623  if (s->predictor == 2) {
624  dst = p->data[0];
625  soff = s->bpp >> 3;
626  ssize = s->width * soff;
627  for (i = 0; i < s->height; i++) {
628  for (j = soff; j < ssize; j++)
629  dst[j] += dst[j - soff];
630  dst += stride;
631  }
632  }
633 
634  if (s->invert) {
635  uint8_t *src;
636  int j;
637 
638  src = s->picture.data[0];
639  for (j = 0; j < s->height; j++) {
640  for (i = 0; i < s->picture.linesize[0]; i++)
641  src[i] = 255 - src[i];
642  src += s->picture.linesize[0];
643  }
644  }
645  *picture = s->picture;
646  *got_frame = 1;
647 
648  return avpkt->size;
649 }
650 
651 static av_cold int tiff_init(AVCodecContext *avctx)
652 {
653  TiffContext *s = avctx->priv_data;
654 
655  s->width = 0;
656  s->height = 0;
657  s->avctx = avctx;
659  avctx->coded_frame = &s->picture;
660  ff_lzw_decode_open(&s->lzw);
662 
663  return 0;
664 }
665 
666 static av_cold int tiff_end(AVCodecContext *avctx)
667 {
668  TiffContext *const s = avctx->priv_data;
669 
671  if (s->picture.data[0])
672  avctx->release_buffer(avctx, &s->picture);
673  return 0;
674 }
675 
677  .name = "tiff",
678  .type = AVMEDIA_TYPE_VIDEO,
679  .id = AV_CODEC_ID_TIFF,
680  .priv_data_size = sizeof(TiffContext),
681  .init = tiff_init,
682  .close = tiff_end,
683  .decode = decode_frame,
684  .capabilities = CODEC_CAP_DR1,
685  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
686 };
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:521
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:651
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:666
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:296
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:604
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:676
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)