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 planar;
56  int fax_opts;
57  int predictor;
59 
60  int strips, rps, sstype;
61  int sot;
64 } TiffContext;
65 
66 static unsigned tget_short(GetByteContext *gb, int le)
67 {
68  return le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
69 }
70 
71 static unsigned tget_long(GetByteContext *gb, int le)
72 {
73  return le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
74 }
75 
76 static unsigned tget(GetByteContext *gb, int type, int le)
77 {
78  switch (type) {
79  case TIFF_BYTE: return bytestream2_get_byte(gb);
80  case TIFF_SHORT: return tget_short(gb, le);
81  case TIFF_LONG: return tget_long(gb, le);
82  default: return UINT_MAX;
83  }
84 }
85 
86 #if CONFIG_ZLIB
87 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
88  int size)
89 {
90  z_stream zstream = { 0 };
91  int zret;
92 
93  zstream.next_in = src;
94  zstream.avail_in = size;
95  zstream.next_out = dst;
96  zstream.avail_out = *len;
97  zret = inflateInit(&zstream);
98  if (zret != Z_OK) {
99  av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
100  return zret;
101  }
102  zret = inflate(&zstream, Z_SYNC_FLUSH);
103  inflateEnd(&zstream);
104  *len = zstream.total_out;
105  return zret == Z_STREAM_END ? Z_OK : zret;
106 }
107 
108 static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
109  const uint8_t *src, int size,
110  int width, int lines)
111 {
112  uint8_t *zbuf;
113  unsigned long outlen;
114  int ret, line;
115  outlen = width * lines;
116  zbuf = av_malloc(outlen);
117  if (!zbuf)
118  return AVERROR(ENOMEM);
119  ret = tiff_uncompress(zbuf, &outlen, src, size);
120  if (ret != Z_OK) {
122  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
123  (unsigned long)width * lines, ret);
124  av_free(zbuf);
125  return AVERROR_UNKNOWN;
126  }
127  src = zbuf;
128  for (line = 0; line < lines; line++) {
129  memcpy(dst, src, width);
130  dst += stride;
131  src += width;
132  }
133  av_free(zbuf);
134  return 0;
135 }
136 #endif
137 
138 
139 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
140  const uint8_t *src, int size, int lines)
141 {
142  int i, ret = 0;
143  uint8_t *src2 = av_malloc((unsigned)size +
145 
146  if (!src2) {
148  "Error allocating temporary buffer\n");
149  return AVERROR(ENOMEM);
150  }
151  if (s->fax_opts & 2) {
152  avpriv_request_sample(s->avctx, "Uncompressed fax mode");
153  av_free(src2);
154  return AVERROR_PATCHWELCOME;
155  }
156  if (!s->fill_order) {
157  memcpy(src2, src, size);
158  } else {
159  for (i = 0; i < size; i++)
160  src2[i] = ff_reverse[src[i]];
161  }
162  memset(src2 + size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
163  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
164  s->compr, s->fax_opts);
165  av_free(src2);
166  return ret;
167 }
168 
169 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
170  const uint8_t *src, int size, int lines)
171 {
172  PutByteContext pb;
173  int c, line, pixels, code, ret;
174  int width = ((s->width * s->bpp) + 7) >> 3;
175 
176  if (s->planar)
177  width /= s->bppcount;
178 
179  if (size <= 0)
180  return AVERROR_INVALIDDATA;
181 
182  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
183 #if CONFIG_ZLIB
184  return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
185 #else
187  "zlib support not enabled, "
188  "deflate compression not supported\n");
189  return AVERROR(ENOSYS);
190 #endif
191  }
192  if (s->compr == TIFF_LZW) {
193  if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
194  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
195  return ret;
196  }
197  for (line = 0; line < lines; line++) {
198  pixels = ff_lzw_decode(s->lzw, dst, width);
199  if (pixels < width) {
200  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
201  pixels, width);
202  return AVERROR_INVALIDDATA;
203  }
204  dst += stride;
205  }
206  return 0;
207  }
208  if (s->compr == TIFF_CCITT_RLE ||
209  s->compr == TIFF_G3 ||
210  s->compr == TIFF_G4) {
211  return tiff_unpack_fax(s, dst, stride, src, size, lines);
212  }
213 
214  bytestream2_init(&s->gb, src, size);
215  bytestream2_init_writer(&pb, dst, stride * lines);
216 
217  for (line = 0; line < lines; line++) {
218  if (bytestream2_get_bytes_left(&s->gb) == 0 || bytestream2_get_eof(&pb))
219  break;
220  bytestream2_seek_p(&pb, stride * line, SEEK_SET);
221  switch (s->compr) {
222  case TIFF_RAW:
223  if (!s->fill_order) {
224  bytestream2_copy_buffer(&pb, &s->gb, width);
225  } else {
226  int i;
227  for (i = 0; i < width; i++)
228  bytestream2_put_byte(&pb, ff_reverse[bytestream2_get_byte(&s->gb)]);
229  }
230  break;
231  case TIFF_PACKBITS:
232  for (pixels = 0; pixels < width;) {
233  code = ff_u8_to_s8(bytestream2_get_byte(&s->gb));
234  if (code >= 0) {
235  code++;
236  bytestream2_copy_buffer(&pb, &s->gb, code);
237  pixels += code;
238  } else if (code != -128) { // -127..-1
239  code = (-code) + 1;
240  c = bytestream2_get_byte(&s->gb);
241  bytestream2_set_buffer(&pb, c, code);
242  pixels += code;
243  }
244  }
245  break;
246  }
247  }
248  return 0;
249 }
250 
251 static int init_image(TiffContext *s, AVFrame *frame)
252 {
253  int ret;
254 
255  // make sure there is no aliasing in the following switch
256  if (s->bpp >= 100 || s->bppcount >= 10) {
258  "Unsupported image parameters: bpp=%d, bppcount=%d\n",
259  s->bpp, s->bppcount);
260  return AVERROR_INVALIDDATA;
261  }
262 
263  switch (s->planar * 1000 + s->bpp * 10 + s->bppcount) {
264  case 11:
266  break;
267  case 81:
269  break;
270  case 243:
272  break;
273  case 161:
275  break;
276  case 162:
278  break;
279  case 322:
281  break;
282  case 324:
284  break;
285  case 483:
287  break;
288  case 644:
290  break;
291  case 1243:
293  break;
294  case 1324:
296  break;
297  case 1483:
299  break;
300  case 1644:
302  break;
303  default:
305  "This format is not supported (bpp=%d, bppcount=%d)\n",
306  s->bpp, s->bppcount);
307  return AVERROR_INVALIDDATA;
308  }
309  if (s->width != s->avctx->width || s->height != s->avctx->height) {
310  ret = ff_set_dimensions(s->avctx, s->width, s->height);
311  if (ret < 0)
312  return ret;
313  }
314  if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0) {
315  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
316  return ret;
317  }
318  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
319  memcpy(frame->data[1], s->palette, sizeof(s->palette));
320  }
321  return 0;
322 }
323 
325 {
326  unsigned tag, type, count, off, value = 0;
327  int i, start;
328 
329  if (bytestream2_get_bytes_left(&s->gb) < 12)
330  return AVERROR_INVALIDDATA;
331  tag = tget_short(&s->gb, s->le);
332  type = tget_short(&s->gb, s->le);
333  count = tget_long(&s->gb, s->le);
334  off = tget_long(&s->gb, s->le);
335  start = bytestream2_tell(&s->gb);
336 
337  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
338  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
339  type);
340  return 0;
341  }
342 
343  if (count == 1) {
344  switch (type) {
345  case TIFF_BYTE:
346  case TIFF_SHORT:
347  bytestream2_seek(&s->gb, -4, SEEK_CUR);
348  value = tget(&s->gb, type, s->le);
349  break;
350  case TIFF_LONG:
351  value = off;
352  break;
353  case TIFF_STRING:
354  if (count <= 4) {
355  bytestream2_seek(&s->gb, -4, SEEK_CUR);
356  break;
357  }
358  default:
359  value = UINT_MAX;
360  bytestream2_seek(&s->gb, off, SEEK_SET);
361  }
362  } else {
363  if (count <= 4 && type_sizes[type] * count <= 4)
364  bytestream2_seek(&s->gb, -4, SEEK_CUR);
365  else
366  bytestream2_seek(&s->gb, off, SEEK_SET);
367  }
368 
369  switch (tag) {
370  case TIFF_WIDTH:
371  s->width = value;
372  break;
373  case TIFF_HEIGHT:
374  s->height = value;
375  break;
376  case TIFF_BPP:
377  s->bppcount = count;
378  if (count > 4) {
380  "This format is not supported (bpp=%d, %d components)\n",
381  s->bpp, count);
382  return AVERROR_INVALIDDATA;
383  }
384  if (count == 1)
385  s->bpp = value;
386  else {
387  switch (type) {
388  case TIFF_BYTE:
389  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
390  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
391  break;
392  case TIFF_SHORT:
393  case TIFF_LONG:
394  s->bpp = 0;
395  for (i = 0; i < count; i++)
396  s->bpp += tget(&s->gb, type, s->le);
397  break;
398  default:
399  s->bpp = -1;
400  }
401  }
402  break;
404  if (count != 1) {
406  "Samples per pixel requires a single value, many provided\n");
407  return AVERROR_INVALIDDATA;
408  }
409  if (s->bppcount == 1)
410  s->bpp *= value;
411  s->bppcount = value;
412  break;
413  case TIFF_COMPR:
414  s->compr = value;
415  s->predictor = 0;
416  switch (s->compr) {
417  case TIFF_RAW:
418  case TIFF_PACKBITS:
419  case TIFF_LZW:
420  case TIFF_CCITT_RLE:
421  break;
422  case TIFF_G3:
423  case TIFF_G4:
424  s->fax_opts = 0;
425  break;
426  case TIFF_DEFLATE:
427  case TIFF_ADOBE_DEFLATE:
428 #if CONFIG_ZLIB
429  break;
430 #else
431  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
432  return AVERROR(ENOSYS);
433 #endif
434  case TIFF_JPEG:
435  case TIFF_NEWJPEG:
436  avpriv_report_missing_feature(s->avctx, "JPEG compression");
437  return AVERROR_PATCHWELCOME;
438  case TIFF_LZMA:
439  avpriv_report_missing_feature(s->avctx, "LZMA compression");
440  return AVERROR_PATCHWELCOME;
441  default:
442  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
443  s->compr);
444  return AVERROR_INVALIDDATA;
445  }
446  break;
447  case TIFF_ROWSPERSTRIP:
448  if (!value || (type == TIFF_LONG && value == UINT_MAX))
449  value = s->height;
450  s->rps = FFMIN(value, s->height);
451  break;
452  case TIFF_STRIP_OFFS:
453  if (count == 1) {
454  s->strippos = 0;
455  s->stripoff = value;
456  } else
457  s->strippos = off;
458  s->strips = count;
459  if (s->strips == 1)
460  s->rps = s->height;
461  s->sot = type;
462  break;
463  case TIFF_STRIP_SIZE:
464  if (count == 1) {
465  s->stripsizesoff = 0;
466  s->stripsize = value;
467  s->strips = 1;
468  } else {
469  s->stripsizesoff = off;
470  }
471  s->strips = count;
472  s->sstype = type;
473  break;
474  case TIFF_PREDICTOR:
475  s->predictor = value;
476  break;
477  case TIFF_PHOTOMETRIC:
478  switch (value) {
483  s->photometric = value;
484  break;
496  "PhotometricInterpretation 0x%04X",
497  value);
498  return AVERROR_PATCHWELCOME;
499  default:
500  av_log(s->avctx, AV_LOG_ERROR, "PhotometricInterpretation %u is "
501  "unknown\n", value);
502  return AVERROR_INVALIDDATA;
503  }
504  break;
505  case TIFF_FILL_ORDER:
506  if (value < 1 || value > 2) {
508  "Unknown FillOrder value %d, trying default one\n", value);
509  value = 1;
510  }
511  s->fill_order = value - 1;
512  break;
513  case TIFF_PAL: {
514  GetByteContext pal_gb[3];
515  off = type_sizes[type];
516  if (count / 3 > 256 ||
517  bytestream2_get_bytes_left(&s->gb) < count / 3 * off * 3)
518  return AVERROR_INVALIDDATA;
519  pal_gb[0] = pal_gb[1] = pal_gb[2] = s->gb;
520  bytestream2_skip(&pal_gb[1], count / 3 * off);
521  bytestream2_skip(&pal_gb[2], count / 3 * off * 2);
522  off = (type_sizes[type] - 1) << 3;
523  for (i = 0; i < count / 3; i++) {
524  uint32_t p = 0xFF000000;
525  p |= (tget(&pal_gb[0], type, s->le) >> off) << 16;
526  p |= (tget(&pal_gb[1], type, s->le) >> off) << 8;
527  p |= tget(&pal_gb[2], type, s->le) >> off;
528  s->palette[i] = p;
529  }
530  s->palette_is_set = 1;
531  break;
532  }
533  case TIFF_PLANAR:
534  s->planar = value == 2;
535  break;
536  case TIFF_T4OPTIONS:
537  if (s->compr == TIFF_G3)
538  s->fax_opts = value;
539  break;
540  case TIFF_T6OPTIONS:
541  if (s->compr == TIFF_G4)
542  s->fax_opts = value;
543  break;
544  default:
545  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
547  "Unknown or unsupported tag %d/0X%0X\n",
548  tag, tag);
549  return AVERROR_INVALIDDATA;
550  }
551  }
552  bytestream2_seek(&s->gb, start, SEEK_SET);
553  return 0;
554 }
555 
557  void *data, int *got_frame, AVPacket *avpkt)
558 {
559  TiffContext *const s = avctx->priv_data;
560  AVFrame *const p = data;
561  unsigned off;
562  int id, le, ret, plane, planes;
563  int i, j, entries, stride;
564  unsigned soff, ssize;
565  uint8_t *dst;
566  GetByteContext stripsizes;
567  GetByteContext stripdata;
568 
569  bytestream2_init(&s->gb, avpkt->data, avpkt->size);
570 
571  // parse image header
572  if (avpkt->size < 8)
573  return AVERROR_INVALIDDATA;
574  id = bytestream2_get_le16(&s->gb);
575  if (id == 0x4949)
576  le = 1;
577  else if (id == 0x4D4D)
578  le = 0;
579  else {
580  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
581  return AVERROR_INVALIDDATA;
582  }
583  s->le = le;
585  s->compr = TIFF_RAW;
586  s->fill_order = 0;
587  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
588  // that further identifies the file as a TIFF file"
589  if (tget_short(&s->gb, le) != 42) {
590  av_log(avctx, AV_LOG_ERROR,
591  "The answer to life, universe and everything is not correct!\n");
592  return AVERROR_INVALIDDATA;
593  }
594  // Reset these offsets so we can tell if they were set this frame
595  s->stripsizesoff = s->strippos = 0;
596  /* parse image file directory */
597  off = tget_long(&s->gb, le);
598  if (off >= UINT_MAX - 14 || avpkt->size < off + 14) {
599  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
600  return AVERROR_INVALIDDATA;
601  }
602  bytestream2_seek(&s->gb, off, SEEK_SET);
603  entries = tget_short(&s->gb, le);
604  for (i = 0; i < entries; i++) {
605  if ((ret = tiff_decode_tag(s)) < 0)
606  return ret;
607  }
608  if (!s->strippos && !s->stripoff) {
609  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
610  return AVERROR_INVALIDDATA;
611  }
612  /* now we have the data and may start decoding */
613  if ((ret = init_image(s, p)) < 0)
614  return ret;
615 
616  if (s->strips == 1 && !s->stripsize) {
617  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
618  s->stripsize = avpkt->size - s->stripoff;
619  }
620 
621  if (s->stripsizesoff) {
622  if (s->stripsizesoff >= avpkt->size)
623  return AVERROR_INVALIDDATA;
624  bytestream2_init(&stripsizes, avpkt->data + s->stripsizesoff,
625  avpkt->size - s->stripsizesoff);
626  }
627  if (s->strippos) {
628  if (s->strippos >= avpkt->size)
629  return AVERROR_INVALIDDATA;
630  bytestream2_init(&stripdata, avpkt->data + s->strippos,
631  avpkt->size - s->strippos);
632  }
633 
634  planes = s->planar ? s->bppcount : 1;
635  for (plane = 0; plane < planes; plane++) {
636  stride = p->linesize[plane];
637  dst = p->data[plane];
638  for (i = 0; i < s->height; i += s->rps) {
639  if (s->stripsizesoff)
640  ssize = tget(&stripsizes, s->sstype, le);
641  else
642  ssize = s->stripsize;
643 
644  if (s->strippos)
645  soff = tget(&stripdata, s->sot, le);
646  else
647  soff = s->stripoff;
648 
649  if (soff > avpkt->size || ssize > avpkt->size - soff) {
650  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
651  return AVERROR_INVALIDDATA;
652  }
653  if ((ret = tiff_unpack_strip(s, dst, stride, avpkt->data + soff, ssize,
654  FFMIN(s->rps, s->height - i))) < 0) {
655  if (avctx->err_recognition & AV_EF_EXPLODE)
656  return ret;
657  break;
658  }
659  dst += s->rps * stride;
660  }
661  if (s->predictor == 2) {
662  dst = p->data[plane];
663  soff = s->bpp >> 3;
664  ssize = s->width * soff;
665  if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48LE ||
667  for (i = 0; i < s->height; i++) {
668  for (j = soff; j < ssize; j += 2)
669  AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff));
670  dst += stride;
671  }
672  } else if (s->avctx->pix_fmt == AV_PIX_FMT_RGB48BE ||
674  for (i = 0; i < s->height; i++) {
675  for (j = soff; j < ssize; j += 2)
676  AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff));
677  dst += stride;
678  }
679  } else {
680  for (i = 0; i < s->height; i++) {
681  for (j = soff; j < ssize; j++)
682  dst[j] += dst[j - soff];
683  dst += stride;
684  }
685  }
686  }
687 
689  dst = p->data[plane];
690  for (i = 0; i < s->height; i++) {
691  for (j = 0; j < stride; j++)
692  dst[j] = 255 - dst[j];
693  dst += stride;
694  }
695  }
696  }
697 
698  if (s->planar && s->bppcount > 2) {
699  FFSWAP(uint8_t*, p->data[0], p->data[2]);
700  FFSWAP(int, p->linesize[0], p->linesize[2]);
701  FFSWAP(uint8_t*, p->data[0], p->data[1]);
702  FFSWAP(int, p->linesize[0], p->linesize[1]);
703  }
704 
705  *got_frame = 1;
706 
707  return avpkt->size;
708 }
709 
711 {
712  TiffContext *s = avctx->priv_data;
713 
714  s->width = 0;
715  s->height = 0;
716  s->avctx = avctx;
717  ff_lzw_decode_open(&s->lzw);
719 
720  return 0;
721 }
722 
724 {
725  TiffContext *const s = avctx->priv_data;
726 
728  return 0;
729 }
730 
732  .name = "tiff",
733  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
734  .type = AVMEDIA_TYPE_VIDEO,
735  .id = AV_CODEC_ID_TIFF,
736  .priv_data_size = sizeof(TiffContext),
737  .init = tiff_init,
738  .close = tiff_end,
739  .decode = decode_frame,
740  .capabilities = AV_CODEC_CAP_DR1,
741 };
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:303
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
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:169
int fill_order
Definition: tiff.c:58
unsigned int bpp
Definition: tiff.c:49
enum AVCodecID id
Definition: mxfenc.c:85
8 bits gray, 8 bits alpha
Definition: pixfmt.h:143
int sstype
Definition: tiff.c:60
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:130
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:61
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:134
TIFF tables.
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:162
int size
Definition: avcodec.h:1347
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
Definition: bytestream.h:141
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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:251
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1621
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:132
#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:213
static unsigned tget_short(GetByteContext *gb, int le)
Definition: tiff.c:66
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:3120
Definition: tiff.h:69
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:556
Macro definitions for various function/variable attributes.
static unsigned tget_long(GetByteContext *gb, int le)
Definition: tiff.c:71
av_cold void ff_ccitt_unpack_init(void)
initialize unpacker code
Definition: faxcompr.c:99
planar GBRA 4:4:4:4 64bpp, big-endian
Definition: pixfmt.h:209
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 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:70
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:107
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:196
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:710
const char data[16]
Definition: mxf.c:70
uint8_t * data
Definition: avcodec.h:1346
planar GBR 4:4:4 48bpp, big-endian
Definition: pixfmt.h:167
uint32_t tag
Definition: movenc.c:854
int stripoff
Definition: tiff.c:62
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:63
#define AV_WL16(p, val)
Definition: intreadwrite.h:231
Definition: tiff.h:56
int planar
Definition: tiff.c:55
#define src
Definition: vp8dsp.c:254
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:124
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:190
16 bits gray, 16 bits alpha (big-endian)
Definition: pixfmt.h:205
int sot
Definition: tiff.c:61
#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:161
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:148
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:723
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:145
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:151
Definition: graph2dot.c:48
static int tiff_decode_tag(TiffContext *s)
Definition: tiff.c:324
const char * name
Name of the codec implementation.
Definition: avcodec.h:3127
int width
Definition: tiff.c:48
int strips
Definition: tiff.c:60
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:90
int predictor
Definition: tiff.c:57
enum TiffPhotometric photometric
Definition: tiff.c:54
int stripsize
Definition: tiff.c:62
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2670
#define FFMIN(a, b)
Definition: common.h:66
int le
Definition: tiff.c:52
int width
picture width / height.
Definition: avcodec.h:1580
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: avconv.c:1288
int rps
Definition: tiff.c:60
#define AV_EF_EXPLODE
Definition: avcodec.h:2681
static unsigned tget(GetByteContext *gb, int type, int le)
Definition: tiff.c:76
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:229
static av_always_inline int bytestream2_tell(GetByteContext *g)
Definition: bytestream.h:185
uint32_t palette[256]
Definition: tiff.c:50
NULL
Definition: eval.c:55
Definition: tiff.h:38
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:158
enum TiffCompr compr
Definition: tiff.c:53
unsigned int bppcount
Definition: tiff.c:49
main external API structure.
Definition: avcodec.h:1409
Definition: tiff.h:67
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:589
Definition: tiff.h:79
static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, GetByteContext *g, unsigned int size)
Definition: bytestream.h:340
AVCodecContext * avctx
Definition: tiff.c:45
Y , 16bpp, big-endian.
Definition: pixfmt.h:94
int strippos
Definition: tiff.c:62
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:146
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:69
int stripsizesoff
Definition: tiff.c:62
Y , 8bpp.
Definition: pixfmt.h:67
common internal api header.
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
Definition: bytestream.h:325
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:208
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:106
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:582
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:638
void * priv_data
Definition: avcodec.h:1451
int len
Y , 16bpp, little-endian.
Definition: pixfmt.h:95
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
Definition: bytestream.h:205
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:206
int fax_opts
Definition: tiff.c:56
AVCodec ff_tiff_decoder
Definition: tiff.c:731
Definition: tiff.h:82
planar GBR 4:4:4 48bpp, little-endian
Definition: pixfmt.h:168
const uint8_t ff_reverse[256]
Definition: mathtables.c:72
#define FFSWAP(type, a, b)
Definition: common.h:69
GetByteContext gb
Definition: tiff.c:46
#define AV_WB16(p, val)
Definition: intreadwrite.h:218
planar GBRA 4:4:4:4 64bpp, little-endian
Definition: pixfmt.h:210
This structure stores compressed data.
Definition: avcodec.h:1323
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:139
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:838
CCITT Fax Group 3 and 4 decompression.
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:197