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  switch (s->bpp * 10 + s->bppcount) {
252  case 11:
254  break;
255  case 81:
257  break;
258  case 243:
260  break;
261  case 161:
263  break;
264  case 162:
266  break;
267  case 322:
269  break;
270  case 324:
272  break;
273  case 483:
275  break;
276  default:
278  "This format is not supported (bpp=%d, bppcount=%d)\n",
279  s->bpp, s->bppcount);
280  return AVERROR_INVALIDDATA;
281  }
282  if (s->width != s->avctx->width || s->height != s->avctx->height) {
283  ret = ff_set_dimensions(s->avctx, s->width, s->height);
284  if (ret < 0)
285  return ret;
286  }
287  if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0) {
288  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
289  return ret;
290  }
291  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
292  memcpy(frame->data[1], s->palette, sizeof(s->palette));
293  }
294  return 0;
295 }
296 
298 {
299  unsigned tag, type, count, off, value = 0;
300  int i, start;
301 
302  if (bytestream2_get_bytes_left(&s->gb) < 12)
303  return AVERROR_INVALIDDATA;
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 AVERROR_INVALIDDATA;
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 AVERROR(ENOSYS);
406 #endif
407  case TIFF_JPEG:
408  case TIFF_NEWJPEG:
409  avpriv_report_missing_feature(s->avctx, "JPEG compression");
410  return AVERROR_PATCHWELCOME;
411  case TIFF_LZMA:
412  avpriv_report_missing_feature(s->avctx, "LZMA compression");
413  return AVERROR_PATCHWELCOME;
414  default:
415  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
416  s->compr);
417  return AVERROR_INVALIDDATA;
418  }
419  break;
420  case TIFF_ROWSPERSTRIP:
421  if (!value || (type == TIFF_LONG && value == UINT_MAX))
422  value = s->height;
423  s->rps = FFMIN(value, s->height);
424  break;
425  case TIFF_STRIP_OFFS:
426  if (count == 1) {
427  s->strippos = 0;
428  s->stripoff = value;
429  } else
430  s->strippos = off;
431  s->strips = count;
432  if (s->strips == 1)
433  s->rps = s->height;
434  s->sot = type;
435  break;
436  case TIFF_STRIP_SIZE:
437  if (count == 1) {
438  s->stripsizesoff = 0;
439  s->stripsize = value;
440  s->strips = 1;
441  } else {
442  s->stripsizesoff = off;
443  }
444  s->strips = count;
445  s->sstype = type;
446  break;
447  case TIFF_PREDICTOR:
448  s->predictor = value;
449  break;
450  case TIFF_PHOTOMETRIC:
451  switch (value) {
456  s->photometric = value;
457  break;
469  "PhotometricInterpretation 0x%04X",
470  value);
471  return AVERROR_PATCHWELCOME;
472  default:
473  av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
474  "unknown\n", value);
475  return AVERROR_INVALIDDATA;
476  }
477  break;
478  case TIFF_FILL_ORDER:
479  if (value < 1 || value > 2) {
481  "Unknown FillOrder value %d, trying default one\n", value);
482  value = 1;
483  }
484  s->fill_order = value - 1;
485  break;
486  case TIFF_PAL: {
487  GetByteContext pal_gb[3];
488  off = type_sizes[type];
489  if (count / 3 > 256 ||
490  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
491  return AVERROR_INVALIDDATA;
492  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
493  bytestream2_skip(&pal_gb[1], count / 3 * off);
494  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
495  off = (type_sizes[type] - 1) << 3;
496  for (i = 0; i < count / 3; i++) {
497  uint32_t p = 0xFF000000;
498  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
499  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
500  p |= tget(&pal_gb[2], type, s->le) >> off;
501  s->palette[i] = p;
502  }
503  s->palette_is_set = 1;
504  break;
505  }
506  case TIFF_PLANAR:
507  if (value == 2) {
508  avpriv_report_missing_feature(s->avctx, "Planar format");
509  return AVERROR_PATCHWELCOME;
510  }
511  break;
512  case TIFF_T4OPTIONS:
513  if (s->compr == TIFF_G3)
514  s->fax_opts = value;
515  break;
516  case TIFF_T6OPTIONS:
517  if (s->compr == TIFF_G4)
518  s->fax_opts = value;
519  break;
520  default:
521  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
523  "Unknown or unsupported tag %d/0X%0X\n",
524  tag, tag);
525  return AVERROR_INVALIDDATA;
526  }
527  }
528  bytestream2_seek(&s->gb, start, SEEK_SET);
529  return 0;
530 }
531 
532 static int decode_frame(AVCodecContext *avctx,
533  void *data, int *got_frame, AVPacket *avpkt)
534 {
535  TiffContext *const s = avctx->priv_data;
536  AVFrame *const p = data;
537  unsigned off;
538  int id, le, ret;
539  int i, j, entries, stride;
540  unsigned soff, ssize;
541  uint8_t *dst;
542  GetByteContext stripsizes;
543  GetByteContext stripdata;
544 
545  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
546 
547  // parse image header
548  if (avpkt->size < 8)
549  return AVERROR_INVALIDDATA;
550  id = bytestream2_get_le16(&s->gb);
551  if (id == 0x4949)
552  le = 1;
553  else if (id == 0x4D4D)
554  le = 0;
555  else {
556  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
557  return AVERROR_INVALIDDATA;
558  }
559  s->le = le;
561  s->compr = TIFF_RAW;
562  s->fill_order = 0;
563  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
564  // that further identifies the file as a TIFF file"
565  if (tget_short(&s->gb, le) != 42) {
566  av_log(avctx, AV_LOG_ERROR,
567  "The answer to life, universe and everything is not correct!\n");
568  return AVERROR_INVALIDDATA;
569  }
570  // Reset these offsets so we can tell if they were set this frame
571  s->stripsizesoff = s->strippos = 0;
572  /* parse image file directory */
573  off = tget_long(&s->gb, le);
574  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
575  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
576  return AVERROR_INVALIDDATA;
577  }
578  bytestream2_seek(&s->gb, off, SEEK_SET);
579  entries = tget_short(&s->gb, le);
580  for (i = 0; i < entries; i++) {
581  if ((ret = tiff_decode_tag(s)) < 0)
582  return ret;
583  }
584  if (!s->strippos && !s->stripoff) {
585  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
586  return AVERROR_INVALIDDATA;
587  }
588  /* now we have the data and may start decoding */
589  if ((ret = init_image(s, p)) < 0)
590  return ret;
591 
592  if (s->strips == 1 && !s->stripsize) {
593  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
594  s->stripsize = avpkt->size - s->stripoff;
595  }
596  stride = p->linesize[0];
597  dst = p->data[0];
598 
599  if (s->stripsizesoff) {
600  if (s->stripsizesoff >= avpkt->size)
601  return AVERROR_INVALIDDATA;
602  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
603  avpkt->size - s->stripsizesoff);
604  }
605  if (s->strippos) {
606  if (s->strippos >= avpkt->size)
607  return AVERROR_INVALIDDATA;
608  bytestream2_init(&stripdata, avpkt->data + s->strippos,
609  avpkt->size - s->strippos);
610  }
611 
612  for (i = 0; i < s->height; i += s->rps) {
613  if (s->stripsizesoff)
614  ssize = tget(&stripsizes, s->sstype, le);
615  else
616  ssize = s->stripsize;
617 
618  if (s->strippos)
619  soff = tget(&stripdata, s->sot, le);
620  else
621  soff = s->stripoff;
622 
623  if (soff > avpkt->size || ssize > avpkt->size - soff) {
624  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
625  return AVERROR_INVALIDDATA;
626  }
627  if ((ret = tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
628  FFMIN(s->rps, s->height - i))) < 0) {
629  if (avctx->err_recognition & AV_EF_EXPLODE)
630  return ret;
631  break;
632  }
633  dst += s->rps * stride;
634  }
635  if (s->predictor == 2) {
636  dst = p->data[0];
637  soff = s->bpp >> 3;
638  ssize = s->width * soff;
639  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE) {
640  for (i = 0; i < s->height; i++) {
641  for (j = soff; j < ssize; j += 2)
642  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
643  dst += stride;
644  }
645  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE) {
646  for (i = 0; i < s->height; i++) {
647  for (j = soff; j < ssize; j += 2)
648  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
649  dst += stride;
650  }
651  } else {
652  for (i = 0; i < s->height; i++) {
653  for (j = soff; j < ssize; j++)
654  dst[j] += dst[j - soff];
655  dst += stride;
656  }
657  }
658  }
659 
661  dst = p->data[0];
662  for (i = 0; i < s->height; i++) {
663  for (j = 0; j < p->linesize[0]; j++)
664  dst[j] = 255 - dst[j];
665  dst += stride;
666  }
667  }
668  *got_frame = 1;
669 
670  return avpkt->size;
671 }
672 
673 static av_cold int tiff_init(AVCodecContext *avctx)
674 {
675  TiffContext *s = avctx->priv_data;
676 
677  s->width = 0;
678  s->height = 0;
679  s->avctx = avctx;
680  ff_lzw_decode_open(&s->lzw);
682 
683  return 0;
684 }
685 
686 static av_cold int tiff_end(AVCodecContext *avctx)
687 {
688  TiffContext *const s = avctx->priv_data;
689 
691  return 0;
692 }
693 
695  .name = "tiff",
696  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
697  .type = AVMEDIA_TYPE_VIDEO,
698  .id = AV_CODEC_ID_TIFF,
699  .priv_data_size = sizeof(TiffContext),
700  .init = tiff_init,
701  .close = tiff_end,
702  .decode = decode_frame,
703  .capabilities = CODEC_CAP_DR1,
704 };
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
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
16bit gray, 16bit alpha (big-endian)
Definition: pixfmt.h:206
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
int sstype
Definition: tiff.c:59
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
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
#define AV_RL16(x)
Definition: intreadwrite.h:220
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
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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
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
Y , 16bpp, big-endian.
Definition: pixfmt.h:100
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:532
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.
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
16bit gray, 16bit alpha (little-endian)
Definition: pixfmt.h:207
#define AV_RB16(x)
Definition: intreadwrite.h:208
uint8_t
const char * name
Name of the codec implementation.
Definition: avcodec.h:2803
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:673
#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
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
8bit gray, 8bit alpha
Definition: pixfmt.h:144
int sot
Definition: tiff.c:60
#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:686
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
#define AV_WB16(p, d)
Definition: intreadwrite.h:213
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:297
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
Libavcodec external API header.
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
#define AV_WL16(p, d)
Definition: intreadwrite.h:225
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
int le
Definition: tiff.c:52
int width
picture width / height.
Definition: avcodec.h:1224
int rps
Definition: tiff.c:59
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
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
#define FF_ARRAY_ELEMS(a)
Definition: common.h:61
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
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
#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
#define av_cold
Definition: attributes.h:66
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
#define AV_EF_EXPLODE
Definition: avcodec.h:2417
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
uint8_t * data
Definition: avcodec.h:973
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
int strippos
Definition: tiff.c:61
void * priv_data
Definition: avcodec.h:1092
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
LZW decoding routines.
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
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
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
Y , 16bpp, little-endian.
Definition: pixfmt.h:101
int len
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:694
Definition: tiff.h:82
const uint8_t ff_reverse[256]
Definition: mathtables.c:72
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:75
GetByteContext gb
Definition: tiff.c:46
Y , 8bpp.
Definition: pixfmt.h:73
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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
#define FFMIN(a, b)
Definition: common.h:57
CCITT Fax Group 3 and 4 decompression.