Libav
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 "config.h"
29 #if CONFIG_ZLIB
30 #include <zlib.h>
31 #endif
32 
33 #include "libavutil/attributes.h"
34 #include "libavutil/intreadwrite.h"
35 #include "libavutil/imgutils.h"
36 #include "avcodec.h"
37 #include "bytestream.h"
38 #include "faxcompr.h"
39 #include "internal.h"
40 #include "lzw.h"
41 #include "mathops.h"
42 #include "tiff.h"
43 
44 typedef struct TiffContext {
47 
48  int width, height;
49  unsigned int bpp, bppcount;
50  uint32_t palette[256];
52  int le;
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 
107 static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
108  const uint8_t *src, int size,
109  int width, int lines)
110 {
111  uint8_t *zbuf;
112  unsigned long outlen;
113  int ret, line;
114  outlen = width * lines;
115  zbuf = av_malloc(outlen);
116  if (!zbuf)
117  return AVERROR(ENOMEM);
118  ret = tiff_uncompress(zbuf, &outlen, src, size);
119  if (ret != Z_OK) {
121  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
122  (unsigned long)width * lines, ret);
123  av_free(zbuf);
124  return AVERROR_UNKNOWN;
125  }
126  src = zbuf;
127  for (line = 0; line < lines; line++) {
128  memcpy(dst, src, width);
129  dst += stride;
130  src += width;
131  }
132  av_free(zbuf);
133  return 0;
134 }
135 #endif
136 
137 
138 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
139  const uint8_t *src, int size, int lines)
140 {
141  int i, ret = 0;
142  uint8_t *src2 = av_malloc((unsigned)size +
144 
145  if (!src2) {
147  "Error allocating temporary buffer\n");
148  return AVERROR(ENOMEM);
149  }
150  if (s->fax_opts & 2) {
151  avpriv_request_sample(s->avctx, "Uncompressed fax mode");
152  av_free(src2);
153  return AVERROR_PATCHWELCOME;
154  }
155  if (!s->fill_order) {
156  memcpy(src2, src, size);
157  } else {
158  for (i = 0; i < size; i++)
159  src2[i] = ff_reverse[src[i]];
160  }
161  memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
162  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
163  s->compr, s->fax_opts);
164  av_free(src2);
165  return ret;
166 }
167 
168 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
169  const uint8_t *src, int size, int lines)
170 {
171  PutByteContext pb;
172  int c, line, pixels, code, ret;
173  int width = ((s->width * s->bpp) + 7) >> 3;
174 
175  if (size <= 0)
176  return AVERROR_INVALIDDATA;
177 
178  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
179 #if CONFIG_ZLIB
180  return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
181 #else
183  "zlib support not enabled, "
184  "deflate compression not supported\n");
185  return AVERROR(ENOSYS);
186 #endif
187  }
188  if (s->compr == TIFF_LZW) {
189  if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
190  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
191  return ret;
192  }
193  for (line = 0; line < lines; line++) {
194  pixels = ff_lzw_decode(s->lzw, dst, width);
195  if (pixels < width) {
196  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
197  pixels, width);
198  return AVERROR_INVALIDDATA;
199  }
200  dst += stride;
201  }
202  return 0;
203  }
204  if (s->compr == TIFF_CCITT_RLE ||
205  s->compr == TIFF_G3 ||
206  s->compr == TIFF_G4) {
207  return tiff_unpack_fax(s, dst, stride, src, size, lines);
208  }
209 
210  bytestream2_init(&s->gb, src, size);
211  bytestream2_init_writer(&pb, dst, stride * lines);
212 
213  for (line = 0; line < lines; line++) {
214  if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))
215  break;
216  bytestream2_seek_p(&pb, stride * line, SEEK_SET);
217  switch (s->compr) {
218  case TIFF_RAW:
219  if (!s->fill_order) {
220  bytestream2_copy_buffer(&pb, &s->gb, width);
221  } else {
222  int i;
223  for (i = 0; i < width; i++)
224  bytestream2_put_byte(&pb, ff_reverse[bytestream2_get_byte(&s->gb)]);
225  }
226  break;
227  case TIFF_PACKBITS:
228  for (pixels = 0; pixels < width;) {
229  code = ff_u8_to_s8(bytestream2_get_byte(&s->gb));
230  if (code >= 0) {
231  code++;
232  bytestream2_copy_buffer(&pb, &s->gb, code);
233  pixels += code;
234  } else if (code != -128) { // -127..-1
235  code = (-code) + 1;
236  c = bytestream2_get_byte(&s->gb);
237  bytestream2_set_buffer(&pb, c, code);
238  pixels += code;
239  }
240  }
241  break;
242  }
243  }
244  return 0;
245 }
246 
247 static int init_image(TiffContext *s, AVFrame *frame)
248 {
249  int ret;
250 
251  // make sure there is no aliasing in the following switch
252  if (s->bpp >= 100 || s->bppcount >= 10) {
254  "Unsupported image parameters: bpp=%d, bppcount=%d\n",
255  s->bpp, s->bppcount);
256  return AVERROR_INVALIDDATA;
257  }
258 
259  switch (s->bpp * 10 + s->bppcount) {
260  case 11:
262  break;
263  case 81:
265  break;
266  case 243:
268  break;
269  case 161:
271  break;
272  case 162:
274  break;
275  case 322:
277  break;
278  case 324:
280  break;
281  case 483:
283  break;
284  default:
286  "This format is not supported (bpp=%d, bppcount=%d)\n",
287  s->bpp, s->bppcount);
288  return AVERROR_INVALIDDATA;
289  }
290  if (s->width != s->avctx->width || s->height != s->avctx->height) {
291  ret = ff_set_dimensions(s->avctx, s->width, s->height);
292  if (ret < 0)
293  return ret;
294  }
295  if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0) {
296  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
297  return ret;
298  }
299  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
300  memcpy(frame->data[1], s->palette, sizeof(s->palette));
301  }
302  return 0;
303 }
304 
306 {
307  unsigned tag, type, count, off, value = 0;
308  int i, start;
309 
310  if (bytestream2_get_bytes_left(&s->gb) < 12)
311  return AVERROR_INVALIDDATA;
312  tag = tget_short(&s->gb, s->le);
313  type = tget_short(&s->gb, s->le);
314  count = tget_long(&s->gb, s->le);
315  off = tget_long(&s->gb, s->le);
316  start = bytestream2_tell(&s->gb);
317 
318  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
319  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
320  type);
321  return 0;
322  }
323 
324  if (count == 1) {
325  switch (type) {
326  case TIFF_BYTE:
327  case TIFF_SHORT:
328  bytestream2_seek(&s->gb, -4, SEEK_CUR);
329  value = tget(&s->gb, type, s->le);
330  break;
331  case TIFF_LONG:
332  value = off;
333  break;
334  case TIFF_STRING:
335  if (count <= 4) {
336  bytestream2_seek(&s->gb, -4, SEEK_CUR);
337  break;
338  }
339  default:
340  value = UINT_MAX;
341  bytestream2_seek(&s->gb, off, SEEK_SET);
342  }
343  } else {
344  if (count <= 4 && type_sizes[type] * count <= 4)
345  bytestream2_seek(&s->gb, -4, SEEK_CUR);
346  else
347  bytestream2_seek(&s->gb, off, SEEK_SET);
348  }
349 
350  switch (tag) {
351  case TIFF_WIDTH:
352  s->width = value;
353  break;
354  case TIFF_HEIGHT:
355  s->height = value;
356  break;
357  case TIFF_BPP:
358  s->bppcount = count;
359  if (count > 4) {
361  "This format is not supported (bpp=%d, %d components)\n",
362  s->bpp, count);
363  return AVERROR_INVALIDDATA;
364  }
365  if (count == 1)
366  s->bpp = value;
367  else {
368  switch (type) {
369  case TIFF_BYTE:
370  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
371  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
372  break;
373  case TIFF_SHORT:
374  case TIFF_LONG:
375  s->bpp = 0;
376  for (i = 0; i < count; i++)
377  s->bpp += tget(&s->gb, type, s->le);
378  break;
379  default:
380  s->bpp = -1;
381  }
382  }
383  break;
385  if (count != 1) {
387  "Samples per pixel requires a single value, many provided\n");
388  return AVERROR_INVALIDDATA;
389  }
390  if (s->bppcount == 1)
391  s->bpp *= value;
392  s->bppcount = value;
393  break;
394  case TIFF_COMPR:
395  s->compr = value;
396  s->predictor = 0;
397  switch (s->compr) {
398  case TIFF_RAW:
399  case TIFF_PACKBITS:
400  case TIFF_LZW:
401  case TIFF_CCITT_RLE:
402  break;
403  case TIFF_G3:
404  case TIFF_G4:
405  s->fax_opts = 0;
406  break;
407  case TIFF_DEFLATE:
408  case TIFF_ADOBE_DEFLATE:
409 #if CONFIG_ZLIB
410  break;
411 #else
412  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
413  return AVERROR(ENOSYS);
414 #endif
415  case TIFF_JPEG:
416  case TIFF_NEWJPEG:
417  avpriv_report_missing_feature(s->avctx, "JPEG compression");
418  return AVERROR_PATCHWELCOME;
419  case TIFF_LZMA:
420  avpriv_report_missing_feature(s->avctx, "LZMA compression");
421  return AVERROR_PATCHWELCOME;
422  default:
423  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
424  s->compr);
425  return AVERROR_INVALIDDATA;
426  }
427  break;
428  case TIFF_ROWSPERSTRIP:
429  if (!value || (type == TIFF_LONG && value == UINT_MAX))
430  value = s->height;
431  s->rps = FFMIN(value, s->height);
432  break;
433  case TIFF_STRIP_OFFS:
434  if (count == 1) {
435  s->strippos = 0;
436  s->stripoff = value;
437  } else
438  s->strippos = off;
439  s->strips = count;
440  if (s->strips == 1)
441  s->rps = s->height;
442  s->sot = type;
443  break;
444  case TIFF_STRIP_SIZE:
445  if (count == 1) {
446  s->stripsizesoff = 0;
447  s->stripsize = value;
448  s->strips = 1;
449  } else {
450  s->stripsizesoff = off;
451  }
452  s->strips = count;
453  s->sstype = type;
454  break;
455  case TIFF_PREDICTOR:
456  s->predictor = value;
457  break;
458  case TIFF_PHOTOMETRIC:
459  switch (value) {
464  s->photometric = value;
465  break;
477  "PhotometricInterpretation 0x%04X",
478  value);
479  return AVERROR_PATCHWELCOME;
480  default:
481  av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
482  "unknown\n", value);
483  return AVERROR_INVALIDDATA;
484  }
485  break;
486  case TIFF_FILL_ORDER:
487  if (value < 1 || value > 2) {
489  "Unknown FillOrder value %d, trying default one\n", value);
490  value = 1;
491  }
492  s->fill_order = value - 1;
493  break;
494  case TIFF_PAL: {
495  GetByteContext pal_gb[3];
496  off = type_sizes[type];
497  if (count / 3 > 256 ||
498  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
499  return AVERROR_INVALIDDATA;
500  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
501  bytestream2_skip(&pal_gb[1], count / 3 * off);
502  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
503  off = (type_sizes[type] - 1) << 3;
504  for (i = 0; i < count / 3; i++) {
505  uint32_t p = 0xFF000000;
506  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
507  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
508  p |= tget(&pal_gb[2], type, s->le) >> off;
509  s->palette[i] = p;
510  }
511  s->palette_is_set = 1;
512  break;
513  }
514  case TIFF_PLANAR:
515  if (value == 2) {
516  avpriv_report_missing_feature(s->avctx, "Planar format");
517  return AVERROR_PATCHWELCOME;
518  }
519  break;
520  case TIFF_T4OPTIONS:
521  if (s->compr == TIFF_G3)
522  s->fax_opts = value;
523  break;
524  case TIFF_T6OPTIONS:
525  if (s->compr == TIFF_G4)
526  s->fax_opts = value;
527  break;
528  default:
529  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
531  "Unknown or unsupported tag %d/0X%0X\n",
532  tag, tag);
533  return AVERROR_INVALIDDATA;
534  }
535  }
536  bytestream2_seek(&s->gb, start, SEEK_SET);
537  return 0;
538 }
539 
540 static int decode_frame(AVCodecContext *avctx,
541  void *data, int *got_frame, AVPacket *avpkt)
542 {
543  TiffContext *const s = avctx->priv_data;
544  AVFrame *const p = data;
545  unsigned off;
546  int id, le, ret;
547  int i, j, entries, stride;
548  unsigned soff, ssize;
549  uint8_t *dst;
550  GetByteContext stripsizes;
551  GetByteContext stripdata;
552 
553  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
554 
555  // parse image header
556  if (avpkt->size < 8)
557  return AVERROR_INVALIDDATA;
558  id = bytestream2_get_le16(&s->gb);
559  if (id == 0x4949)
560  le = 1;
561  else if (id == 0x4D4D)
562  le = 0;
563  else {
564  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
565  return AVERROR_INVALIDDATA;
566  }
567  s->le = le;
569  s->compr = TIFF_RAW;
570  s->fill_order = 0;
571  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
572  // that further identifies the file as a TIFF file"
573  if (tget_short(&s->gb, le) != 42) {
574  av_log(avctx, AV_LOG_ERROR,
575  "The answer to life, universe and everything is not correct!\n");
576  return AVERROR_INVALIDDATA;
577  }
578  // Reset these offsets so we can tell if they were set this frame
579  s->stripsizesoff = s->strippos = 0;
580  /* parse image file directory */
581  off = tget_long(&s->gb, le);
582  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
583  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
584  return AVERROR_INVALIDDATA;
585  }
586  bytestream2_seek(&s->gb, off, SEEK_SET);
587  entries = tget_short(&s->gb, le);
588  for (i = 0; i < entries; i++) {
589  if ((ret = tiff_decode_tag(s)) < 0)
590  return ret;
591  }
592  if (!s->strippos && !s->stripoff) {
593  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
594  return AVERROR_INVALIDDATA;
595  }
596  /* now we have the data and may start decoding */
597  if ((ret = init_image(s, p)) < 0)
598  return ret;
599 
600  if (s->strips == 1 && !s->stripsize) {
601  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
602  s->stripsize = avpkt->size - s->stripoff;
603  }
604  stride = p->linesize[0];
605  dst = p->data[0];
606 
607  if (s->stripsizesoff) {
608  if (s->stripsizesoff >= avpkt->size)
609  return AVERROR_INVALIDDATA;
610  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
611  avpkt->size - s->stripsizesoff);
612  }
613  if (s->strippos) {
614  if (s->strippos >= avpkt->size)
615  return AVERROR_INVALIDDATA;
616  bytestream2_init(&stripdata, avpkt->data + s->strippos,
617  avpkt->size - s->strippos);
618  }
619 
620  for (i = 0; i < s->height; i += s->rps) {
621  if (s->stripsizesoff)
622  ssize = tget(&stripsizes, s->sstype, le);
623  else
624  ssize = s->stripsize;
625 
626  if (s->strippos)
627  soff = tget(&stripdata, s->sot, le);
628  else
629  soff = s->stripoff;
630 
631  if (soff > avpkt->size || ssize > avpkt->size - soff) {
632  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
633  return AVERROR_INVALIDDATA;
634  }
635  if ((ret = tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
636  FFMIN(s->rps, s->height - i))) < 0) {
637  if (avctx->err_recognition & AV_EF_EXPLODE)
638  return ret;
639  break;
640  }
641  dst += s->rps * stride;
642  }
643  if (s->predictor == 2) {
644  dst = p->data[0];
645  soff = s->bpp >> 3;
646  ssize = s->width * soff;
647  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE) {
648  for (i = 0; i < s->height; i++) {
649  for (j = soff; j < ssize; j += 2)
650  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
651  dst += stride;
652  }
653  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE) {
654  for (i = 0; i < s->height; i++) {
655  for (j = soff; j < ssize; j += 2)
656  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
657  dst += stride;
658  }
659  } else {
660  for (i = 0; i < s->height; i++) {
661  for (j = soff; j < ssize; j++)
662  dst[j] += dst[j - soff];
663  dst += stride;
664  }
665  }
666  }
667 
669  dst = p->data[0];
670  for (i = 0; i < s->height; i++) {
671  for (j = 0; j < p->linesize[0]; j++)
672  dst[j] = 255 - dst[j];
673  dst += stride;
674  }
675  }
676  *got_frame = 1;
677 
678  return avpkt->size;
679 }
680 
681 static av_cold int tiff_init(AVCodecContext *avctx)
682 {
683  TiffContext *s = avctx->priv_data;
684 
685  s->width = 0;
686  s->height = 0;
687  s->avctx = avctx;
688  ff_lzw_decode_open(&s->lzw);
690 
691  return 0;
692 }
693 
694 static av_cold int tiff_end(AVCodecContext *avctx)
695 {
696  TiffContext *const s = avctx->priv_data;
697 
699  return 0;
700 }
701 
703  .name = "tiff",
704  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
705  .type = AVMEDIA_TYPE_VIDEO,
706  .id = AV_CODEC_ID_TIFF,
707  .priv_data_size = sizeof(TiffContext),
708  .init = tiff_init,
709  .close = tiff_end,
710  .decode = decode_frame,
711  .capabilities = CODEC_CAP_DR1,
712 };
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:62
Definition: tiff.h:65
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
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: frame.h:135
TiffPhotometric
Definition: tiff.h:86
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:168
int fill_order
Definition: tiff.c:57
unsigned int bpp
Definition: tiff.c:49
enum AVCodecID id
Definition: mxfenc.c:84
8bit gray, 8bit alpha
Definition: pixfmt.h:144
int sstype
Definition: tiff.c:59
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
Definition: tiff.h:75
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:133
TIFF tables.
int size
Definition: avcodec.h:974
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
static int init_image(TiffContext *s, AVFrame *frame)
Definition: tiff.c:247
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1254
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:130
#define AV_RL16
Definition: intreadwrite.h:42
#define FF_ARRAY_ELEMS(a)
static int8_t ff_u8_to_s8(uint8_t a)
Definition: mathops.h:222
static unsigned tget_short(GetByteContext *gb, int le)
Definition: tiff.c:65
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2796
Definition: tiff.h:69
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:540
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:275
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t
#define av_cold
Definition: attributes.h:66
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:113
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:681
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:973
uint32_t tag
Definition: movenc.c:844
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:105
Definition: tiff.h:70
LZWState * lzw
Definition: tiff.c:62
Definition: tiff.h:56
Definition: lzw.c:46
int height
Definition: tiff.c:48
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
16bit gray, 16bit alpha (big-endian)
Definition: pixfmt.h:206
int sot
Definition: tiff.c:60
#define AV_RB16
Definition: intreadwrite.h:53
#define AVERROR(e)
Definition: error.h:43
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:150
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:694
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:149
Definition: graph2dot.c:49
static int tiff_decode_tag(TiffContext *s)
Definition: tiff.c:305
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
const char * name
Name of the codec implementation.
Definition: avcodec.h:2803
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:273
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
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...
Definition: avcodec.h:531
enum TiffPhotometric photometric
Definition: tiff.c:54
int stripsize
Definition: tiff.c:61
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2406
#define FFMIN(a, b)
Definition: common.h:57
int le
Definition: tiff.c:52
int width
picture width / height.
Definition: avcodec.h:1224
int rps
Definition: tiff.c:59
#define AV_EF_EXPLODE
Definition: avcodec.h:2417
uint8_t le
Definition: crc.c:250
static unsigned tget(GetByteContext *gb, int type, int le)
Definition: tiff.c:75
int palette_is_set
Definition: tiff.c:51
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
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:55
Definition: tiff.h:38
static int width
Definition: utils.c:156
TiffCompr
list of TIFF compression types
Definition: tiff.h:64
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
enum TiffCompr compr
Definition: tiff.c:53
unsigned int bppcount
Definition: tiff.c:49
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
Definition: tiff.h:67
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:612
Definition: tiff.h:79
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:45
Y , 16bpp, big-endian.
Definition: pixfmt.h:100
#define AV_WB16(p, d)
Definition: intreadwrite.h:213
int strippos
Definition: tiff.c:61
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
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
Y , 8bpp.
Definition: pixfmt.h:73
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:112
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
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:61
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
void * priv_data
Definition: avcodec.h:1092
int len
Y , 16bpp, little-endian.
Definition: pixfmt.h:101
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:203
16bit gray, 16bit alpha (little-endian)
Definition: pixfmt.h:207
int fax_opts
Definition: tiff.c:55
AVCodec ff_tiff_decoder
Definition: tiff.c:702
Definition: tiff.h:82
const uint8_t ff_reverse[256]
Definition: mathtables.c:72
GetByteContext gb
Definition: tiff.c:46
#define AV_WL16(p, d)
Definition: intreadwrite.h:225
This structure stores compressed data.
Definition: avcodec.h:950
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:138
CCITT Fax Group 3 and 4 decompression.