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  default:
412  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
413  s->compr);
414  return AVERROR_INVALIDDATA;
415  }
416  break;
417  case TIFF_ROWSPERSTRIP:
418  if (!value || (type == TIFF_LONG && value == UINT_MAX))
419  value = s->height;
420  s->rps = FFMIN(value, s->height);
421  break;
422  case TIFF_STRIP_OFFS:
423  if (count == 1) {
424  s->strippos = 0;
425  s->stripoff = value;
426  } else
427  s->strippos = off;
428  s->strips = count;
429  if (s->strips == 1)
430  s->rps = s->height;
431  s->sot = type;
432  break;
433  case TIFF_STRIP_SIZE:
434  if (count == 1) {
435  s->stripsizesoff = 0;
436  s->stripsize = value;
437  s->strips = 1;
438  } else {
439  s->stripsizesoff = off;
440  }
441  s->strips = count;
442  s->sstype = type;
443  break;
444  case TIFF_PREDICTOR:
445  s->predictor = value;
446  break;
447  case TIFF_PHOTOMETRIC:
448  switch (value) {
453  s->photometric = value;
454  break;
466  "PhotometricInterpretation 0x%04X",
467  value);
468  return AVERROR_PATCHWELCOME;
469  default:
470  av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
471  "unknown\n", value);
472  return AVERROR_INVALIDDATA;
473  }
474  break;
475  case TIFF_FILL_ORDER:
476  if (value < 1 || value > 2) {
478  "Unknown FillOrder value %d, trying default one\n", value);
479  value = 1;
480  }
481  s->fill_order = value - 1;
482  break;
483  case TIFF_PAL: {
484  GetByteContext pal_gb[3];
485  off = type_sizes[type];
486  if (count / 3 > 256 ||
487  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
488  return AVERROR_INVALIDDATA;
489  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
490  bytestream2_skip(&pal_gb[1], count / 3 * off);
491  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
492  off = (type_sizes[type] - 1) << 3;
493  for (i = 0; i < count / 3; i++) {
494  uint32_t p = 0xFF000000;
495  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
496  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
497  p |= tget(&pal_gb[2], type, s->le) >> off;
498  s->palette[i] = p;
499  }
500  s->palette_is_set = 1;
501  break;
502  }
503  case TIFF_PLANAR:
504  if (value == 2) {
505  avpriv_report_missing_feature(s->avctx, "Planar format");
506  return AVERROR_PATCHWELCOME;
507  }
508  break;
509  case TIFF_T4OPTIONS:
510  if (s->compr == TIFF_G3)
511  s->fax_opts = value;
512  break;
513  case TIFF_T6OPTIONS:
514  if (s->compr == TIFF_G4)
515  s->fax_opts = value;
516  break;
517  default:
518  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
520  "Unknown or unsupported tag %d/0X%0X\n",
521  tag, tag);
522  return AVERROR_INVALIDDATA;
523  }
524  }
525  bytestream2_seek(&s->gb, start, SEEK_SET);
526  return 0;
527 }
528 
529 static int decode_frame(AVCodecContext *avctx,
530  void *data, int *got_frame, AVPacket *avpkt)
531 {
532  TiffContext *const s = avctx->priv_data;
533  AVFrame *const p = data;
534  unsigned off;
535  int id, le, ret;
536  int i, j, entries, stride;
537  unsigned soff, ssize;
538  uint8_t *dst;
539  GetByteContext stripsizes;
540  GetByteContext stripdata;
541 
542  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
543 
544  // parse image header
545  if (avpkt->size < 8)
546  return AVERROR_INVALIDDATA;
547  id = bytestream2_get_le16(&s->gb);
548  if (id == 0x4949)
549  le = 1;
550  else if (id == 0x4D4D)
551  le = 0;
552  else {
553  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
554  return AVERROR_INVALIDDATA;
555  }
556  s->le = le;
558  s->compr = TIFF_RAW;
559  s->fill_order = 0;
560  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
561  // that further identifies the file as a TIFF file"
562  if (tget_short(&s->gb, le) != 42) {
563  av_log(avctx, AV_LOG_ERROR,
564  "The answer to life, universe and everything is not correct!\n");
565  return AVERROR_INVALIDDATA;
566  }
567  // Reset these offsets so we can tell if they were set this frame
568  s->stripsizesoff = s->strippos = 0;
569  /* parse image file directory */
570  off = tget_long(&s->gb, le);
571  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
572  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
573  return AVERROR_INVALIDDATA;
574  }
575  bytestream2_seek(&s->gb, off, SEEK_SET);
576  entries = tget_short(&s->gb, le);
577  for (i = 0; i < entries; i++) {
578  if ((ret = tiff_decode_tag(s)) < 0)
579  return ret;
580  }
581  if (!s->strippos && !s->stripoff) {
582  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
583  return AVERROR_INVALIDDATA;
584  }
585  /* now we have the data and may start decoding */
586  if ((ret = init_image(s, p)) < 0)
587  return ret;
588 
589  if (s->strips == 1 && !s->stripsize) {
590  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
591  s->stripsize = avpkt->size - s->stripoff;
592  }
593  stride = p->linesize[0];
594  dst = p->data[0];
595 
596  if (s->stripsizesoff) {
597  if (s->stripsizesoff >= avpkt->size)
598  return AVERROR_INVALIDDATA;
599  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
600  avpkt->size - s->stripsizesoff);
601  }
602  if (s->strippos) {
603  if (s->strippos >= avpkt->size)
604  return AVERROR_INVALIDDATA;
605  bytestream2_init(&stripdata, avpkt->data + s->strippos,
606  avpkt->size - s->strippos);
607  }
608 
609  for (i = 0; i < s->height; i += s->rps) {
610  if (s->stripsizesoff)
611  ssize = tget(&stripsizes, s->sstype, le);
612  else
613  ssize = s->stripsize;
614 
615  if (s->strippos)
616  soff = tget(&stripdata, s->sot, le);
617  else
618  soff = s->stripoff;
619 
620  if (soff > avpkt->size || ssize > avpkt->size - soff) {
621  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
622  return AVERROR_INVALIDDATA;
623  }
624  if ((ret = tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
625  FFMIN(s->rps, s->height - i))) < 0) {
626  if (avctx->err_recognition & AV_EF_EXPLODE)
627  return ret;
628  break;
629  }
630  dst += s->rps * stride;
631  }
632  if (s->predictor == 2) {
633  dst = p->data[0];
634  soff = s->bpp >> 3;
635  ssize = s->width * soff;
636  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE) {
637  for (i = 0; i < s->height; i++) {
638  for (j = soff; j < ssize; j += 2)
639  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
640  dst += stride;
641  }
642  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE) {
643  for (i = 0; i < s->height; i++) {
644  for (j = soff; j < ssize; j += 2)
645  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
646  dst += stride;
647  }
648  } else {
649  for (i = 0; i < s->height; i++) {
650  for (j = soff; j < ssize; j++)
651  dst[j] += dst[j - soff];
652  dst += stride;
653  }
654  }
655  }
656 
658  dst = p->data[0];
659  for (i = 0; i < s->height; i++) {
660  for (j = 0; j < p->linesize[0]; j++)
661  dst[j] = 255 - dst[j];
662  dst += stride;
663  }
664  }
665  *got_frame = 1;
666 
667  return avpkt->size;
668 }
669 
670 static av_cold int tiff_init(AVCodecContext *avctx)
671 {
672  TiffContext *s = avctx->priv_data;
673 
674  s->width = 0;
675  s->height = 0;
676  s->avctx = avctx;
677  ff_lzw_decode_open(&s->lzw);
679 
680  return 0;
681 }
682 
683 static av_cold int tiff_end(AVCodecContext *avctx)
684 {
685  TiffContext *const s = avctx->priv_data;
686 
688  return 0;
689 }
690 
692  .name = "tiff",
693  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
694  .type = AVMEDIA_TYPE_VIDEO,
695  .id = AV_CODEC_ID_TIFF,
696  .priv_data_size = sizeof(TiffContext),
697  .init = tiff_init,
698  .close = tiff_end,
699  .decode = decode_frame,
700  .capabilities = CODEC_CAP_DR1,
701 };
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:85
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
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:968
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:1248
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:2790
Definition: tiff.h:69
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:529
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:670
#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:967
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:104
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:683
#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:297
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:168
const char * name
Name of the codec implementation.
Definition: avcodec.h:2797
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:2400
#define FFMIN(a, b)
Definition: common.h:57
int le
Definition: tiff.c:52
int width
picture width / height.
Definition: avcodec.h:1218
int rps
Definition: tiff.c:59
#define AV_EF_EXPLODE
Definition: avcodec.h:2411
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:1044
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:603
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: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:1086
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:691
Definition: tiff.h:81
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:944
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.