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 "faxcompr.h"
38 #include "internal.h"
39 #include "lzw.h"
40 #include "mathops.h"
41 #include "tiff.h"
42 
43 typedef struct TiffContext {
45 
46  int width, height;
47  unsigned int bpp, bppcount;
48  uint32_t palette[256];
50  int le;
52  int invert;
53  int fax_opts;
54  int predictor;
56 
57  int strips, rps, sstype;
58  int sot;
63 } TiffContext;
64 
65 static unsigned tget_short(const uint8_t **p, int le)
66 {
67  unsigned v = le ? AV_RL16(*p) : AV_RB16(*p);
68  *p += 2;
69  return v;
70 }
71 
72 static unsigned tget_long(const uint8_t **p, int le)
73 {
74  unsigned v = le ? AV_RL32(*p) : AV_RB32(*p);
75  *p += 4;
76  return v;
77 }
78 
79 static unsigned tget(const uint8_t **p, int type, int le)
80 {
81  switch (type) {
82  case TIFF_BYTE:
83  return *(*p)++;
84  case TIFF_SHORT:
85  return tget_short(p, le);
86  case TIFF_LONG:
87  return tget_long(p, le);
88  default:
89  return UINT_MAX;
90  }
91 }
92 
93 #if CONFIG_ZLIB
94 static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
95  int size)
96 {
97  z_stream zstream = { 0 };
98  int zret;
99 
100  zstream.next_in = src;
101  zstream.avail_in = size;
102  zstream.next_out = dst;
103  zstream.avail_out = *len;
104  zret = inflateInit(&zstream);
105  if (zret != Z_OK) {
106  av_log(NULL, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
107  return zret;
108  }
109  zret = inflate(&zstream, Z_SYNC_FLUSH);
110  inflateEnd(&zstream);
111  *len = zstream.total_out;
112  return zret == Z_STREAM_END ? Z_OK : zret;
113 }
114 
115 static int tiff_unpack_zlib(TiffContext *s, uint8_t *dst, int stride,
116  const uint8_t *src, int size,
117  int width, int lines)
118 {
119  uint8_t *zbuf;
120  unsigned long outlen;
121  int ret, line;
122  outlen = width * lines;
123  zbuf = av_malloc(outlen);
124  if (!zbuf)
125  return AVERROR(ENOMEM);
126  ret = tiff_uncompress(zbuf, &outlen, src, size);
127  if (ret != Z_OK) {
129  "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
130  (unsigned long)width * lines, ret);
131  av_free(zbuf);
132  return AVERROR_UNKNOWN;
133  }
134  src = zbuf;
135  for (line = 0; line < lines; line++) {
136  memcpy(dst, src, width);
137  dst += stride;
138  src += width;
139  }
140  av_free(zbuf);
141  return 0;
142 }
143 #endif
144 
145 
146 static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride,
147  const uint8_t *src, int size, int lines)
148 {
149  int i, ret = 0;
150  uint8_t *src2 = av_malloc((unsigned)size +
152 
153  if (!src2) {
155  "Error allocating temporary buffer\n");
156  return AVERROR(ENOMEM);
157  }
158  if (s->fax_opts & 2) {
159  avpriv_request_sample(s->avctx, "Uncompressed fax mode");
160  av_free(src2);
161  return AVERROR_PATCHWELCOME;
162  }
163  if (!s->fill_order) {
164  memcpy(src2, src, size);
165  } else {
166  for (i = 0; i < size; i++)
167  src2[i] = ff_reverse[src[i]];
168  }
169  memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
170  ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
171  s->compr, s->fax_opts);
172  av_free(src2);
173  return ret;
174 }
175 
176 static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
177  const uint8_t *src, int size, int lines)
178 {
179  int c, line, pixels, code, ret;
180  const uint8_t *ssrc = src;
181  int width = ((s->width * s->bpp) + 7) >> 3;
182 
183  if (size <= 0)
184  return AVERROR_INVALIDDATA;
185 
186  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
187 #if CONFIG_ZLIB
188  return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
189 #else
191  "zlib support not enabled, "
192  "deflate compression not supported\n");
193  return AVERROR(ENOSYS);
194 #endif
195  }
196  if (s->compr == TIFF_LZW) {
197  if ((ret = ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF)) < 0) {
198  av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
199  return ret;
200  }
201  }
202  if (s->compr == TIFF_CCITT_RLE ||
203  s->compr == TIFF_G3 ||
204  s->compr == TIFF_G4) {
205  return tiff_unpack_fax(s, dst, stride, src, size, lines);
206  }
207  for (line = 0; line < lines; line++) {
208  if (src - ssrc > size) {
209  av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
210  return AVERROR_INVALIDDATA;
211  }
212  switch (s->compr) {
213  case TIFF_RAW:
214  if (ssrc + size - src < width)
215  return AVERROR_INVALIDDATA;
216  if (!s->fill_order) {
217  memcpy(dst, src, width);
218  } else {
219  int i;
220  for (i = 0; i < width; i++)
221  dst[i] = ff_reverse[src[i]];
222  }
223  src += width;
224  break;
225  case TIFF_PACKBITS:
226  for (pixels = 0; pixels < width;) {
227  if (ssrc + size - src < 2)
228  return AVERROR_INVALIDDATA;
229  code = (int8_t) *src++;
230  if (code >= 0) {
231  code++;
232  if (pixels + code > width ||
233  ssrc + size - src < code) {
235  "Copy went out of bounds\n");
236  return AVERROR_INVALIDDATA;
237  }
238  memcpy(dst + pixels, src, code);
239  src += code;
240  pixels += code;
241  } else if (code != -128) { // -127..-1
242  code = (-code) + 1;
243  if (pixels + code > width) {
245  "Run went out of bounds\n");
246  return AVERROR_INVALIDDATA;
247  }
248  c = *src++;
249  memset(dst + pixels, c, code);
250  pixels += code;
251  }
252  }
253  break;
254  case TIFF_LZW:
255  pixels = ff_lzw_decode(s->lzw, dst, width);
256  if (pixels < width) {
257  av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
258  pixels, width);
259  return AVERROR_INVALIDDATA;
260  }
261  break;
262  }
263  dst += stride;
264  }
265  return 0;
266 }
267 
268 static int init_image(TiffContext *s, AVFrame *frame)
269 {
270  int i, ret;
271  uint32_t *pal;
272 
273  // make sure there is no aliasing in the following switch
274  if (s->bpp >= 100 || s->bppcount >= 10) {
276  "Unsupported image parameters: bpp=%d, bppcount=%d\n",
277  s->bpp, s->bppcount);
278  return AVERROR_INVALIDDATA;
279  }
280 
281  switch (s->bpp * 10 + s->bppcount) {
282  case 11:
284  break;
285  case 81:
287  break;
288  case 243:
290  break;
291  case 161:
293  break;
294  case 324:
296  break;
297  case 483:
299  break;
300  default:
302  "This format is not supported (bpp=%d, bppcount=%d)\n",
303  s->bpp, s->bppcount);
304  return AVERROR_INVALIDDATA;
305  }
306  if (s->width != s->avctx->width || s->height != s->avctx->height) {
307  ret = ff_set_dimensions(s->avctx, s->width, s->height);
308  if (ret < 0)
309  return ret;
310  }
311  if ((ret = ff_get_buffer(s->avctx, frame, 0)) < 0) {
312  av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
313  return ret;
314  }
315  if (s->avctx->pix_fmt == AV_PIX_FMT_PAL8) {
316  if (s->palette_is_set) {
317  memcpy(frame->data[1], s->palette, sizeof(s->palette));
318  } else {
319  /* make default grayscale pal */
320  pal = (uint32_t *) frame->data[1];
321  for (i = 0; i < 256; i++)
322  pal[i] = i * 0x010101;
323  }
324  }
325  return 0;
326 }
327 
328 static int tiff_decode_tag(TiffContext *s, const uint8_t *start,
329  const uint8_t *buf, const uint8_t *end_buf)
330 {
331  unsigned tag, type, count, off, value = 0;
332  int i, j;
333  uint32_t *pal;
334  const uint8_t *rp, *gp, *bp;
335 
336  if (end_buf - buf < 12)
337  return AVERROR_INVALIDDATA;
338  tag = tget_short(&buf, s->le);
339  type = tget_short(&buf, s->le);
340  count = tget_long(&buf, s->le);
341  off = tget_long(&buf, s->le);
342 
343  if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
344  av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
345  type);
346  return 0;
347  }
348 
349  if (count == 1) {
350  switch (type) {
351  case TIFF_BYTE:
352  case TIFF_SHORT:
353  buf -= 4;
354  value = tget(&buf, type, s->le);
355  buf = NULL;
356  break;
357  case TIFF_LONG:
358  value = off;
359  buf = NULL;
360  break;
361  case TIFF_STRING:
362  if (count <= 4) {
363  buf -= 4;
364  break;
365  }
366  default:
367  value = UINT_MAX;
368  buf = start + off;
369  }
370  } else {
371  if (count <= 4 && type_sizes[type] * count <= 4)
372  buf -= 4;
373  else
374  buf = start + off;
375  }
376 
377  if (buf && (buf < start || buf > end_buf)) {
379  "Tag referencing position outside the image\n");
380  return AVERROR_INVALIDDATA;
381  }
382 
383  switch (tag) {
384  case TIFF_WIDTH:
385  s->width = value;
386  break;
387  case TIFF_HEIGHT:
388  s->height = value;
389  break;
390  case TIFF_BPP:
391  s->bppcount = count;
392  if (count > 4) {
394  "This format is not supported (bpp=%d, %d components)\n",
395  s->bpp, count);
396  return AVERROR_INVALIDDATA;
397  }
398  if (count == 1)
399  s->bpp = value;
400  else {
401  switch (type) {
402  case TIFF_BYTE:
403  s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
404  ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
405  break;
406  case TIFF_SHORT:
407  case TIFF_LONG:
408  s->bpp = 0;
409  for (i = 0; i < count && buf < end_buf; i++)
410  s->bpp += tget(&buf, type, s->le);
411  break;
412  default:
413  s->bpp = -1;
414  }
415  }
416  break;
418  if (count != 1) {
420  "Samples per pixel requires a single value, many provided\n");
421  return AVERROR_INVALIDDATA;
422  }
423  if (s->bppcount == 1)
424  s->bpp *= value;
425  s->bppcount = value;
426  break;
427  case TIFF_COMPR:
428  s->compr = value;
429  s->predictor = 0;
430  switch (s->compr) {
431  case TIFF_RAW:
432  case TIFF_PACKBITS:
433  case TIFF_LZW:
434  case TIFF_CCITT_RLE:
435  break;
436  case TIFF_G3:
437  case TIFF_G4:
438  s->fax_opts = 0;
439  break;
440  case TIFF_DEFLATE:
441  case TIFF_ADOBE_DEFLATE:
442 #if CONFIG_ZLIB
443  break;
444 #else
445  av_log(s->avctx, AV_LOG_ERROR, "Deflate: ZLib not compiled in\n");
446  return AVERROR(ENOSYS);
447 #endif
448  case TIFF_JPEG:
449  case TIFF_NEWJPEG:
450  avpriv_report_missing_feature(s->avctx, "JPEG compression");
451  return AVERROR_PATCHWELCOME;
452  default:
453  av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
454  s->compr);
455  return AVERROR_INVALIDDATA;
456  }
457  break;
458  case TIFF_ROWSPERSTRIP:
459  if (type == TIFF_LONG && value == UINT_MAX)
460  value = s->avctx->height;
461  if (value < 1) {
463  "Incorrect value of rows per strip\n");
464  return AVERROR_INVALIDDATA;
465  }
466  s->rps = value;
467  break;
468  case TIFF_STRIP_OFFS:
469  if (count == 1) {
470  s->stripdata = NULL;
471  s->stripoff = value;
472  } else
473  s->stripdata = start + off;
474  s->strips = count;
475  if (s->strips == 1)
476  s->rps = s->height;
477  s->sot = type;
478  if (s->stripdata > end_buf) {
480  "Tag referencing position outside the image\n");
481  return AVERROR_INVALIDDATA;
482  }
483  break;
484  case TIFF_STRIP_SIZE:
485  if (count == 1) {
486  s->stripsizes = NULL;
487  s->stripsize = value;
488  s->strips = 1;
489  } else {
490  s->stripsizes = start + off;
491  }
492  s->strips = count;
493  s->sstype = type;
494  if (s->stripsizes > end_buf) {
496  "Tag referencing position outside the image\n");
497  return AVERROR_INVALIDDATA;
498  }
499  break;
500  case TIFF_PREDICTOR:
501  s->predictor = value;
502  break;
503  case TIFF_INVERT:
504  switch (value) {
505  case 0:
506  s->invert = 1;
507  break;
508  case 1:
509  s->invert = 0;
510  break;
511  case 2:
512  case 3:
513  break;
514  default:
515  av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
516  value);
517  return AVERROR_INVALIDDATA;
518  }
519  break;
520  case TIFF_FILL_ORDER:
521  if (value < 1 || value > 2) {
523  "Unknown FillOrder value %d, trying default one\n", value);
524  value = 1;
525  }
526  s->fill_order = value - 1;
527  break;
528  case TIFF_PAL:
529  pal = (uint32_t *) s->palette;
530  off = type_sizes[type];
531  if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3)
532  return AVERROR_INVALIDDATA;
533  rp = buf;
534  gp = buf + count / 3 * off;
535  bp = buf + count / 3 * off * 2;
536  off = (type_sizes[type] - 1) << 3;
537  for (i = 0; i < count / 3; i++) {
538  j = (tget(&rp, type, s->le) >> off) << 16;
539  j |= (tget(&gp, type, s->le) >> off) << 8;
540  j |= tget(&bp, type, s->le) >> off;
541  pal[i] = j;
542  }
543  s->palette_is_set = 1;
544  break;
545  case TIFF_PLANAR:
546  if (value == 2) {
547  avpriv_report_missing_feature(s->avctx, "Planar format");
548  return AVERROR_PATCHWELCOME;
549  }
550  break;
551  case TIFF_T4OPTIONS:
552  if (s->compr == TIFF_G3)
553  s->fax_opts = value;
554  break;
555  case TIFF_T6OPTIONS:
556  if (s->compr == TIFF_G4)
557  s->fax_opts = value;
558  break;
559  default:
560  if (s->avctx->err_recognition & AV_EF_EXPLODE) {
562  "Unknown or unsupported tag %d/0X%0X\n",
563  tag, tag);
564  return AVERROR_INVALIDDATA;
565  }
566  }
567  return 0;
568 }
569 
570 static int decode_frame(AVCodecContext *avctx,
571  void *data, int *got_frame, AVPacket *avpkt)
572 {
573  const uint8_t *buf = avpkt->data;
574  int buf_size = avpkt->size;
575  TiffContext *const s = avctx->priv_data;
576  AVFrame *const p = data;
577  const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
578  unsigned off;
579  int id, le, ret;
580  int i, j, entries, stride;
581  unsigned soff, ssize;
582  uint8_t *dst;
583 
584  // parse image header
585  if (end_buf - buf < 8)
586  return AVERROR_INVALIDDATA;
587  id = AV_RL16(buf);
588  buf += 2;
589  if (id == 0x4949)
590  le = 1;
591  else if (id == 0x4D4D)
592  le = 0;
593  else {
594  av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
595  return AVERROR_INVALIDDATA;
596  }
597  s->le = le;
598  s->invert = 0;
599  s->compr = TIFF_RAW;
600  s->fill_order = 0;
601  // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
602  // that further identifies the file as a TIFF file"
603  if (tget_short(&buf, le) != 42) {
604  av_log(avctx, AV_LOG_ERROR,
605  "The answer to life, universe and everything is not correct!\n");
606  return AVERROR_INVALIDDATA;
607  }
608  // Reset these pointers so we can tell if they were set this frame
609  s->stripsizes = s->stripdata = NULL;
610  /* parse image file directory */
611  off = tget_long(&buf, le);
612  if (off >= UINT_MAX - 14 || end_buf - orig_buf < off + 14) {
613  av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n");
614  return AVERROR_INVALIDDATA;
615  }
616  buf = orig_buf + off;
617  entries = tget_short(&buf, le);
618  for (i = 0; i < entries; i++) {
619  if ((ret = tiff_decode_tag(s, orig_buf, buf, end_buf)) < 0)
620  return ret;
621  buf += 12;
622  }
623  if (!s->stripdata && !s->stripoff) {
624  av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
625  return AVERROR_INVALIDDATA;
626  }
627  /* now we have the data and may start decoding */
628  if ((ret = init_image(s, p)) < 0)
629  return ret;
630 
631  if (s->strips == 1 && !s->stripsize) {
632  av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
633  s->stripsize = buf_size - s->stripoff;
634  }
635  stride = p->linesize[0];
636  dst = p->data[0];
637  for (i = 0; i < s->height; i += s->rps) {
638  if (s->stripsizes) {
639  if (s->stripsizes >= end_buf)
640  return AVERROR_INVALIDDATA;
641  ssize = tget(&s->stripsizes, s->sstype, s->le);
642  } else
643  ssize = s->stripsize;
644 
645  if (s->stripdata) {
646  if (s->stripdata >= end_buf)
647  return AVERROR_INVALIDDATA;
648  soff = tget(&s->stripdata, s->sot, s->le);
649  } else
650  soff = s->stripoff;
651 
652  if (soff > buf_size || ssize > buf_size - soff) {
653  av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
654  return AVERROR_INVALIDDATA;
655  }
656  if ((ret = tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize,
657  FFMIN(s->rps, s->height - i))) < 0) {
658  if (avctx->err_recognition & AV_EF_EXPLODE)
659  return ret;
660  break;
661  }
662  dst += s->rps * stride;
663  }
664  if (s->predictor == 2) {
665  dst = p->data[0];
666  soff = s->bpp >> 3;
667  ssize = s->width * soff;
668  for (i = 0; i < s->height; i++) {
669  for (j = soff; j < ssize; j++)
670  dst[j] += dst[j - soff];
671  dst += stride;
672  }
673  }
674 
675  if (s->invert) {
676  uint8_t *src;
677  int j;
678 
679  src = p->data[0];
680  for (j = 0; j < s->height; j++) {
681  for (i = 0; i < p->linesize[0]; i++)
682  src[i] = 255 - src[i];
683  src += p->linesize[0];
684  }
685  }
686  *got_frame = 1;
687 
688  return buf_size;
689 }
690 
691 static av_cold int tiff_init(AVCodecContext *avctx)
692 {
693  TiffContext *s = avctx->priv_data;
694 
695  s->width = 0;
696  s->height = 0;
697  s->avctx = avctx;
698  ff_lzw_decode_open(&s->lzw);
700 
701  return 0;
702 }
703 
704 static av_cold int tiff_end(AVCodecContext *avctx)
705 {
706  TiffContext *const s = avctx->priv_data;
707 
709  return 0;
710 }
711 
713  .name = "tiff",
714  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
715  .type = AVMEDIA_TYPE_VIDEO,
716  .id = AV_CODEC_ID_TIFF,
717  .priv_data_size = sizeof(TiffContext),
718  .init = tiff_init,
719  .close = tiff_end,
720  .decode = decode_frame,
721  .capabilities = CODEC_CAP_DR1,
722 };
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
int size
static unsigned tget_long(const uint8_t **p, int le)
Definition: tiff.c:72
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
Definition: tiff.c:176
int fill_order
Definition: tiff.c:55
unsigned int bpp
Definition: tiff.c:47
enum AVCodecID id
Definition: mxfenc.c:84
int sstype
Definition: tiff.c:57
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:144
TIFF tables.
int size
Definition: avcodec.h:974
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:268
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
#define AV_RL16
Definition: intreadwrite.h:42
#define FF_ARRAY_ELEMS(a)
int stride
Definition: mace.c:144
AVCodec.
Definition: avcodec.h:2755
Definition: tiff.h:69
Definition: tiff.h:68
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:570
Macro definitions for various function/variable attributes.
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:269
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
#define AV_RB32
Definition: intreadwrite.h:130
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:691
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:711
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
const uint8_t * stripdata
Definition: tiff.c:59
uint32_t tag
Definition: movenc.c:822
int stripoff
Definition: tiff.c:61
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
Definition: tiff.h:86
Definition: tiff.h:70
LZWState * lzw
Definition: tiff.c:62
int invert
Definition: tiff.c:52
Definition: tiff.h:56
static unsigned tget(const uint8_t **p, int type, int le)
Definition: tiff.c:79
Definition: lzw.c:46
int height
Definition: tiff.c:46
#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
const uint8_t * stripsizes
Definition: tiff.c:60
int sot
Definition: tiff.c:58
#define AV_RB16
Definition: intreadwrite.h:53
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:704
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
Definition: graph2dot.c:49
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
int width
Definition: tiff.c:46
int strips
Definition: tiff.c:57
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:54
int off
Definition: dsputil_bfin.c:29
static unsigned tget_short(const uint8_t **p, int le)
Definition: tiff.c:65
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:509
int stripsize
Definition: tiff.c:61
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2390
#define FFMIN(a, b)
Definition: common.h:57
int le
Definition: tiff.c:50
int width
picture width / height.
Definition: avcodec.h:1217
int rps
Definition: tiff.c:57
#define AV_RL32
Definition: intreadwrite.h:146
#define AV_EF_EXPLODE
Definition: avcodec.h:2401
uint8_t le
Definition: crc.c:215
if(ac->has_optimized_func)
int palette_is_set
Definition: tiff.c:49
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
Definition: error.h:57
uint32_t palette[256]
Definition: tiff.c:48
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:125
enum TiffCompr compr
Definition: tiff.c:51
unsigned int bppcount
Definition: tiff.c:47
main external API structure.
Definition: avcodec.h:1054
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
Definition: tiff.h:67
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:575
Definition: tiff.h:78
AVCodecContext * avctx
Definition: tiff.c:44
Y , 16bpp, big-endian.
Definition: pixfmt.h:100
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:113
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
common internal api header.
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:498
void * priv_data
Definition: avcodec.h:1090
int len
Y , 16bpp, little-endian.
Definition: pixfmt.h:101
int fax_opts
Definition: tiff.c:53
AVCodec ff_tiff_decoder
Definition: tiff.c:712
Definition: tiff.h:81
const uint8_t ff_reverse[256]
Definition: mathtables.c:70
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:146
static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
Definition: tiff.c:328
for(j=16;j >0;--j)
CCITT Fax Group 3 and 4 decompression.