FFmpeg  2.8.17
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
iff.c
Go to the documentation of this file.
1 /*
2  * IFF ACBM/DEEP/ILBM/PBM bitmap decoder
3  * Copyright (c) 2010 Peter Ross <pross@xvid.org>
4  * Copyright (c) 2010 Sebastian Vater <cdgs.basty@googlemail.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * IFF ACBM/DEEP/ILBM/PBM bitmap decoder
26  */
27 
28 #include <stdint.h>
29 
30 #include "libavutil/imgutils.h"
31 #include "bytestream.h"
32 #include "avcodec.h"
33 #include "get_bits.h"
34 #include "internal.h"
35 
36 // TODO: masking bits
37 typedef enum {
42 } mask_type;
43 
44 typedef struct IffContext {
46  int planesize;
48  uint8_t * ham_buf; ///< temporary buffer for planar to chunky conversation
49  uint32_t *ham_palbuf; ///< HAM decode table
50  uint32_t *mask_buf; ///< temporary buffer for palette indices
51  uint32_t *mask_palbuf; ///< masking palette table
52  unsigned compression; ///< delta compression method used
53  unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM)
54  unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
55  unsigned flags; ///< 1 for EHB, 0 is no extra half darkening
56  unsigned transparency; ///< TODO: transparency color index in palette
57  unsigned masking; ///< TODO: masking method used
58  int init; // 1 if buffer and palette data already initialized, 0 otherwise
59  int16_t tvdc[16]; ///< TVDC lookup table
60 } IffContext;
61 
62 #define LUT8_PART(plane, v) \
63  AV_LE2NE64C(UINT64_C(0x0000000)<<32 | v) << plane, \
64  AV_LE2NE64C(UINT64_C(0x1000000)<<32 | v) << plane, \
65  AV_LE2NE64C(UINT64_C(0x0010000)<<32 | v) << plane, \
66  AV_LE2NE64C(UINT64_C(0x1010000)<<32 | v) << plane, \
67  AV_LE2NE64C(UINT64_C(0x0000100)<<32 | v) << plane, \
68  AV_LE2NE64C(UINT64_C(0x1000100)<<32 | v) << plane, \
69  AV_LE2NE64C(UINT64_C(0x0010100)<<32 | v) << plane, \
70  AV_LE2NE64C(UINT64_C(0x1010100)<<32 | v) << plane, \
71  AV_LE2NE64C(UINT64_C(0x0000001)<<32 | v) << plane, \
72  AV_LE2NE64C(UINT64_C(0x1000001)<<32 | v) << plane, \
73  AV_LE2NE64C(UINT64_C(0x0010001)<<32 | v) << plane, \
74  AV_LE2NE64C(UINT64_C(0x1010001)<<32 | v) << plane, \
75  AV_LE2NE64C(UINT64_C(0x0000101)<<32 | v) << plane, \
76  AV_LE2NE64C(UINT64_C(0x1000101)<<32 | v) << plane, \
77  AV_LE2NE64C(UINT64_C(0x0010101)<<32 | v) << plane, \
78  AV_LE2NE64C(UINT64_C(0x1010101)<<32 | v) << plane
79 
80 #define LUT8(plane) { \
81  LUT8_PART(plane, 0x0000000), \
82  LUT8_PART(plane, 0x1000000), \
83  LUT8_PART(plane, 0x0010000), \
84  LUT8_PART(plane, 0x1010000), \
85  LUT8_PART(plane, 0x0000100), \
86  LUT8_PART(plane, 0x1000100), \
87  LUT8_PART(plane, 0x0010100), \
88  LUT8_PART(plane, 0x1010100), \
89  LUT8_PART(plane, 0x0000001), \
90  LUT8_PART(plane, 0x1000001), \
91  LUT8_PART(plane, 0x0010001), \
92  LUT8_PART(plane, 0x1010001), \
93  LUT8_PART(plane, 0x0000101), \
94  LUT8_PART(plane, 0x1000101), \
95  LUT8_PART(plane, 0x0010101), \
96  LUT8_PART(plane, 0x1010101), \
97 }
98 
99 // 8 planes * 8-bit mask
100 static const uint64_t plane8_lut[8][256] = {
101  LUT8(0), LUT8(1), LUT8(2), LUT8(3),
102  LUT8(4), LUT8(5), LUT8(6), LUT8(7),
103 };
104 
105 #define LUT32(plane) { \
106  0, 0, 0, 0, \
107  0, 0, 0, 1U << plane, \
108  0, 0, 1U << plane, 0, \
109  0, 0, 1U << plane, 1U << plane, \
110  0, 1U << plane, 0, 0, \
111  0, 1U << plane, 0, 1U << plane, \
112  0, 1U << plane, 1U << plane, 0, \
113  0, 1U << plane, 1U << plane, 1U << plane, \
114  1U << plane, 0, 0, 0, \
115  1U << plane, 0, 0, 1U << plane, \
116  1U << plane, 0, 1U << plane, 0, \
117  1U << plane, 0, 1U << plane, 1U << plane, \
118  1U << plane, 1U << plane, 0, 0, \
119  1U << plane, 1U << plane, 0, 1U << plane, \
120  1U << plane, 1U << plane, 1U << plane, 0, \
121  1U << plane, 1U << plane, 1U << plane, 1U << plane, \
122 }
123 
124 // 32 planes * 4-bit mask * 4 lookup tables each
125 static const uint32_t plane32_lut[32][16*4] = {
126  LUT32( 0), LUT32( 1), LUT32( 2), LUT32( 3),
127  LUT32( 4), LUT32( 5), LUT32( 6), LUT32( 7),
128  LUT32( 8), LUT32( 9), LUT32(10), LUT32(11),
129  LUT32(12), LUT32(13), LUT32(14), LUT32(15),
130  LUT32(16), LUT32(17), LUT32(18), LUT32(19),
131  LUT32(20), LUT32(21), LUT32(22), LUT32(23),
132  LUT32(24), LUT32(25), LUT32(26), LUT32(27),
133  LUT32(28), LUT32(29), LUT32(30), LUT32(31),
134 };
135 
136 // Gray to RGB, required for palette table of grayscale images with bpp < 8
137 static av_always_inline uint32_t gray2rgb(const uint32_t x) {
138  return x << 16 | x << 8 | x;
139 }
140 
141 /**
142  * Convert CMAP buffer (stored in extradata) to lavc palette format
143  */
144 static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
145 {
146  IffContext *s = avctx->priv_data;
147  int count, i;
148  const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
149  int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
150 
151  if (avctx->bits_per_coded_sample > 8) {
152  av_log(avctx, AV_LOG_ERROR, "bits_per_coded_sample > 8 not supported\n");
153  return AVERROR_INVALIDDATA;
154  }
155 
156  count = 1 << avctx->bits_per_coded_sample;
157  // If extradata is smaller than actually needed, fill the remaining with black.
158  count = FFMIN(palette_size / 3, count);
159  if (count) {
160  for (i = 0; i < count; i++)
161  pal[i] = 0xFF000000 | AV_RB24(palette + i*3);
162  if (s->flags && count >= 32) { // EHB
163  for (i = 0; i < 32; i++)
164  pal[i + 32] = 0xFF000000 | (AV_RB24(palette + i*3) & 0xFEFEFE) >> 1;
165  count = FFMAX(count, 64);
166  }
167  } else { // Create gray-scale color palette for bps < 8
168  count = 1 << avctx->bits_per_coded_sample;
169 
170  for (i = 0; i < count; i++)
171  pal[i] = 0xFF000000 | gray2rgb((i * 255) >> avctx->bits_per_coded_sample);
172  }
173  if (s->masking == MASK_HAS_MASK) {
174  if ((1 << avctx->bits_per_coded_sample) < count) {
175  avpriv_request_sample(avctx, "overlapping mask");
176  return AVERROR_PATCHWELCOME;
177  }
178  memcpy(pal + (1 << avctx->bits_per_coded_sample), pal, count * 4);
179  for (i = 0; i < count; i++)
180  pal[i] &= 0xFFFFFF;
181  } else if (s->masking == MASK_HAS_TRANSPARENT_COLOR &&
182  s->transparency < 1 << avctx->bits_per_coded_sample)
183  pal[s->transparency] &= 0xFFFFFF;
184  return 0;
185 }
186 
187 /**
188  * Extracts the IFF extra context and updates internal
189  * decoder structures.
190  *
191  * @param avctx the AVCodecContext where to extract extra context to
192  * @param avpkt the AVPacket to extract extra context from or NULL to use avctx
193  * @return >= 0 in case of success, a negative error code otherwise
194  */
195 static int extract_header(AVCodecContext *const avctx,
196  const AVPacket *const avpkt) {
197  const uint8_t *buf;
198  unsigned buf_size;
199  IffContext *s = avctx->priv_data;
200  int i, palette_size;
201 
202  if (avctx->extradata_size < 2) {
203  av_log(avctx, AV_LOG_ERROR, "not enough extradata\n");
204  return AVERROR_INVALIDDATA;
205  }
206  palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
207 
208  if (avpkt) {
209  int image_size;
210  if (avpkt->size < 2)
211  return AVERROR_INVALIDDATA;
212  image_size = avpkt->size - AV_RB16(avpkt->data);
213  buf = avpkt->data;
214  buf_size = bytestream_get_be16(&buf);
215  if (buf_size <= 1 || image_size <= 1) {
216  av_log(avctx, AV_LOG_ERROR,
217  "Invalid image size received: %u -> image data offset: %d\n",
218  buf_size, image_size);
219  return AVERROR_INVALIDDATA;
220  }
221  } else {
222  buf = avctx->extradata;
223  buf_size = bytestream_get_be16(&buf);
224  if (buf_size <= 1 || palette_size < 0) {
225  av_log(avctx, AV_LOG_ERROR,
226  "Invalid palette size received: %u -> palette data offset: %d\n",
227  buf_size, palette_size);
228  return AVERROR_INVALIDDATA;
229  }
230  }
231 
232  if (buf_size >= 41) {
233  s->compression = bytestream_get_byte(&buf);
234  s->bpp = bytestream_get_byte(&buf);
235  s->ham = bytestream_get_byte(&buf);
236  s->flags = bytestream_get_byte(&buf);
237  s->transparency = bytestream_get_be16(&buf);
238  s->masking = bytestream_get_byte(&buf);
239  for (i = 0; i < 16; i++)
240  s->tvdc[i] = bytestream_get_be16(&buf);
241 
242  if (s->ham) {
243  if (s->bpp > 8) {
244  av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham);
245  return AVERROR_INVALIDDATA;
246  } if (s->ham != (s->bpp > 6 ? 6 : 4)) {
247  av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u, BPP: %u\n", s->ham, s->bpp);
248  return AVERROR_INVALIDDATA;
249  }
250  }
251 
252  if (s->masking == MASK_HAS_MASK) {
253  if (s->bpp >= 8 && !s->ham) {
254  avctx->pix_fmt = AV_PIX_FMT_RGB32;
255  av_freep(&s->mask_buf);
256  av_freep(&s->mask_palbuf);
258  if (!s->mask_buf)
259  return AVERROR(ENOMEM);
260  if (s->bpp > 16) {
261  av_log(avctx, AV_LOG_ERROR, "bpp %d too large for palette\n", s->bpp);
262  av_freep(&s->mask_buf);
263  return AVERROR(ENOMEM);
264  }
265  s->mask_palbuf = av_malloc((2 << s->bpp) * sizeof(uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE);
266  if (!s->mask_palbuf) {
267  av_freep(&s->mask_buf);
268  return AVERROR(ENOMEM);
269  }
270  }
271  s->bpp++;
272  } else if (s->masking != MASK_NONE && s->masking != MASK_HAS_TRANSPARENT_COLOR) {
273  av_log(avctx, AV_LOG_ERROR, "Masking not supported\n");
274  return AVERROR_PATCHWELCOME;
275  }
276  if (!s->bpp || s->bpp > 32) {
277  av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp);
278  return AVERROR_INVALIDDATA;
279  }
280 
281  av_freep(&s->ham_buf);
282  av_freep(&s->ham_palbuf);
283 
284  if (s->ham) {
285  int i, count = FFMIN(palette_size / 3, 1 << s->ham);
286  int ham_count;
287  const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata);
288  int extra_space = 1;
289 
290  if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ') && s->ham == 4)
291  extra_space = 4;
292 
294  if (!s->ham_buf)
295  return AVERROR(ENOMEM);
296 
297  ham_count = 8 * (1 << s->ham);
298  s->ham_palbuf = av_malloc(extra_space * (ham_count << !!(s->masking == MASK_HAS_MASK)) * sizeof (uint32_t) + AV_INPUT_BUFFER_PADDING_SIZE);
299  if (!s->ham_palbuf) {
300  av_freep(&s->ham_buf);
301  return AVERROR(ENOMEM);
302  }
303 
304  if (count) { // HAM with color palette attached
305  // prefill with black and palette and set HAM take direct value mask to zero
306  memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t));
307  for (i=0; i < count; i++) {
308  s->ham_palbuf[i*2+1] = 0xFF000000 | AV_RL24(palette + i*3);
309  }
310  count = 1 << s->ham;
311  } else { // HAM with grayscale color palette
312  count = 1 << s->ham;
313  for (i=0; i < count; i++) {
314  s->ham_palbuf[i*2] = 0xFF000000; // take direct color value from palette
315  s->ham_palbuf[i*2+1] = 0xFF000000 | av_le2ne32(gray2rgb((i * 255) >> s->ham));
316  }
317  }
318  for (i=0; i < count; i++) {
319  uint32_t tmp = i << (8 - s->ham);
320  tmp |= tmp >> s->ham;
321  s->ham_palbuf[(i+count)*2] = 0xFF00FFFF; // just modify blue color component
322  s->ham_palbuf[(i+count*2)*2] = 0xFFFFFF00; // just modify red color component
323  s->ham_palbuf[(i+count*3)*2] = 0xFFFF00FF; // just modify green color component
324  s->ham_palbuf[(i+count)*2+1] = 0xFF000000 | tmp << 16;
325  s->ham_palbuf[(i+count*2)*2+1] = 0xFF000000 | tmp;
326  s->ham_palbuf[(i+count*3)*2+1] = 0xFF000000 | tmp << 8;
327  }
328  if (s->masking == MASK_HAS_MASK) {
329  for (i = 0; i < ham_count; i++)
330  s->ham_palbuf[(1 << s->bpp) + i] = s->ham_palbuf[i] | 0xFF000000;
331  }
332  }
333  }
334 
335  return 0;
336 }
337 
339 {
340  IffContext *s = avctx->priv_data;
341  av_frame_free(&s->frame);
342  av_freep(&s->planebuf);
343  av_freep(&s->ham_buf);
344  av_freep(&s->ham_palbuf);
345  return 0;
346 }
347 
349 {
350  IffContext *s = avctx->priv_data;
351  int err;
352 
353  if (avctx->bits_per_coded_sample <= 8) {
354  int palette_size;
355 
356  if (avctx->extradata_size >= 2)
357  palette_size = avctx->extradata_size - AV_RB16(avctx->extradata);
358  else
359  palette_size = 0;
360  avctx->pix_fmt = (avctx->bits_per_coded_sample < 8) ||
361  (avctx->extradata_size >= 2 && palette_size) ? AV_PIX_FMT_PAL8 : AV_PIX_FMT_GRAY8;
362  } else if (avctx->bits_per_coded_sample <= 32) {
363  if (avctx->codec_tag == MKTAG('R', 'G', 'B', '8')) {
364  avctx->pix_fmt = AV_PIX_FMT_RGB32;
365  } else if (avctx->codec_tag == MKTAG('R', 'G', 'B', 'N')) {
366  avctx->pix_fmt = AV_PIX_FMT_RGB444;
367  } else if (avctx->codec_tag != MKTAG('D', 'E', 'E', 'P')) {
368  if (avctx->bits_per_coded_sample == 24) {
369  avctx->pix_fmt = AV_PIX_FMT_0BGR32;
370  } else if (avctx->bits_per_coded_sample == 32) {
371  avctx->pix_fmt = AV_PIX_FMT_BGR32;
372  } else {
373  avpriv_request_sample(avctx, "unknown bits_per_coded_sample");
374  return AVERROR_PATCHWELCOME;
375  }
376  }
377  } else {
378  return AVERROR_INVALIDDATA;
379  }
380 
381  if ((err = av_image_check_size(avctx->width, avctx->height, 0, avctx)))
382  return err;
383  s->planesize = FFALIGN(avctx->width, 16) >> 3; // Align plane size in bits to word-boundary
385  if (!s->planebuf)
386  return AVERROR(ENOMEM);
387 
388  s->bpp = avctx->bits_per_coded_sample;
389  s->frame = av_frame_alloc();
390  if (!s->frame) {
391  decode_end(avctx);
392  return AVERROR(ENOMEM);
393  }
394 
395  if ((err = extract_header(avctx, NULL)) < 0)
396  return err;
397 
398  return 0;
399 }
400 
401 /**
402  * Decode interleaved plane buffer up to 8bpp
403  * @param dst Destination buffer
404  * @param buf Source buffer
405  * @param buf_size
406  * @param plane plane number to decode as
407  */
408 static void decodeplane8(uint8_t *dst, const uint8_t *buf, int buf_size, int plane)
409 {
410  const uint64_t *lut;
411  if (plane >= 8) {
412  av_log(NULL, AV_LOG_WARNING, "Ignoring extra planes beyond 8\n");
413  return;
414  }
415  lut = plane8_lut[plane];
416  do {
417  uint64_t v = AV_RN64A(dst) | lut[*buf++];
418  AV_WN64A(dst, v);
419  dst += 8;
420  } while (--buf_size);
421 }
422 
423 /**
424  * Decode interleaved plane buffer up to 24bpp
425  * @param dst Destination buffer
426  * @param buf Source buffer
427  * @param buf_size
428  * @param plane plane number to decode as
429  */
430 static void decodeplane32(uint32_t *dst, const uint8_t *buf, int buf_size, int plane)
431 {
432  const uint32_t *lut = plane32_lut[plane];
433  do {
434  unsigned mask = (*buf >> 2) & ~3;
435  dst[0] |= lut[mask++];
436  dst[1] |= lut[mask++];
437  dst[2] |= lut[mask++];
438  dst[3] |= lut[mask];
439  mask = (*buf++ << 2) & 0x3F;
440  dst[4] |= lut[mask++];
441  dst[5] |= lut[mask++];
442  dst[6] |= lut[mask++];
443  dst[7] |= lut[mask];
444  dst += 8;
445  } while (--buf_size);
446 }
447 
448 #define DECODE_HAM_PLANE32(x) \
449  first = buf[x] << 1; \
450  second = buf[(x)+1] << 1; \
451  delta &= pal[first++]; \
452  delta |= pal[first]; \
453  dst[x] = delta; \
454  delta &= pal[second++]; \
455  delta |= pal[second]; \
456  dst[(x)+1] = delta
457 
458 /**
459  * Converts one line of HAM6/8-encoded chunky buffer to 24bpp.
460  *
461  * @param dst the destination 24bpp buffer
462  * @param buf the source 8bpp chunky buffer
463  * @param pal the HAM decode table
464  * @param buf_size the plane size in bytes
465  */
466 static void decode_ham_plane32(uint32_t *dst, const uint8_t *buf,
467  const uint32_t *const pal, unsigned buf_size)
468 {
469  uint32_t delta = pal[1]; /* first palette entry */
470  do {
471  uint32_t first, second;
476  buf += 8;
477  dst += 8;
478  } while (--buf_size);
479 }
480 
481 static void lookup_pal_indicies(uint32_t *dst, const uint32_t *buf,
482  const uint32_t *const pal, unsigned width)
483 {
484  do {
485  *dst++ = pal[*buf++];
486  } while (--width);
487 }
488 
489 /**
490  * Decode one complete byterun1 encoded line.
491  *
492  * @param dst the destination buffer where to store decompressed bitstream
493  * @param dst_size the destination plane size in bytes
494  * @param buf the source byterun1 compressed bitstream
495  * @param buf_end the EOF of source byterun1 compressed bitstream
496  * @return number of consumed bytes in byterun1 compressed bitstream
497  */
498 static int decode_byterun(uint8_t *dst, int dst_size,
499  const uint8_t *buf, const uint8_t *const buf_end)
500 {
501  const uint8_t *const buf_start = buf;
502  unsigned x;
503  for (x = 0; x < dst_size && buf < buf_end;) {
504  unsigned length;
505  const int8_t value = *buf++;
506  if (value >= 0) {
507  length = FFMIN3(value + 1, dst_size - x, buf_end - buf);
508  memcpy(dst + x, buf, length);
509  buf += length;
510  } else if (value > -128) {
511  length = FFMIN(-value + 1, dst_size - x);
512  memset(dst + x, *buf++, length);
513  } else { // noop
514  continue;
515  }
516  x += length;
517  }
518  if (x < dst_size) {
519  av_log(NULL, AV_LOG_WARNING, "decode_byterun ended before plane size\n");
520  memset(dst+x, 0, dst_size - x);
521  }
522  return buf - buf_start;
523 }
524 
525 #define DECODE_RGBX_COMMON(type) \
526  if (!length) { \
527  length = bytestream2_get_byte(gb); \
528  if (!length) { \
529  length = bytestream2_get_be16(gb); \
530  if (!length) \
531  return; \
532  } \
533  } \
534  for (i = 0; i < length; i++) { \
535  *(type *)(dst + y*linesize + x * sizeof(type)) = pixel; \
536  x += 1; \
537  if (x >= width) { \
538  y += 1; \
539  if (y >= height) \
540  return; \
541  x = 0; \
542  } \
543  }
544 
545 /**
546  * Decode RGB8 buffer
547  * @param[out] dst Destination buffer
548  * @param width Width of destination buffer (pixels)
549  * @param height Height of destination buffer (pixels)
550  * @param linesize Line size of destination buffer (bytes)
551  */
552 static void decode_rgb8(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
553 {
554  int x = 0, y = 0, i, length;
555  while (bytestream2_get_bytes_left(gb) >= 4) {
556  uint32_t pixel = 0xFF000000 | bytestream2_get_be24(gb);
557  length = bytestream2_get_byte(gb) & 0x7F;
558  DECODE_RGBX_COMMON(uint32_t)
559  }
560 }
561 
562 /**
563  * Decode RGBN buffer
564  * @param[out] dst Destination buffer
565  * @param width Width of destination buffer (pixels)
566  * @param height Height of destination buffer (pixels)
567  * @param linesize Line size of destination buffer (bytes)
568  */
569 static void decode_rgbn(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
570 {
571  int x = 0, y = 0, i, length;
572  while (bytestream2_get_bytes_left(gb) >= 2) {
573  uint32_t pixel = bytestream2_get_be16u(gb);
574  length = pixel & 0x7;
575  pixel >>= 4;
576  DECODE_RGBX_COMMON(uint16_t)
577  }
578 }
579 
580 /**
581  * Decode DEEP RLE 32-bit buffer
582  * @param[out] dst Destination buffer
583  * @param[in] src Source buffer
584  * @param src_size Source buffer size (bytes)
585  * @param width Width of destination buffer (pixels)
586  * @param height Height of destination buffer (pixels)
587  * @param linesize Line size of destination buffer (bytes)
588  */
589 static void decode_deep_rle32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize)
590 {
591  const uint8_t *src_end = src + src_size;
592  int x = 0, y = 0, i;
593  while (src_end - src >= 5) {
594  int opcode;
595  opcode = *(int8_t *)src++;
596  if (opcode >= 0) {
597  int size = opcode + 1;
598  for (i = 0; i < size; i++) {
599  int length = FFMIN(size - i, width - x);
600  if (src_end - src < length * 4)
601  return;
602  memcpy(dst + y*linesize + x * 4, src, length * 4);
603  src += length * 4;
604  x += length;
605  i += length;
606  if (x >= width) {
607  x = 0;
608  y += 1;
609  if (y >= height)
610  return;
611  }
612  }
613  } else {
614  int size = -opcode + 1;
615  uint32_t pixel = AV_RN32(src);
616  for (i = 0; i < size; i++) {
617  *(uint32_t *)(dst + y*linesize + x * 4) = pixel;
618  x += 1;
619  if (x >= width) {
620  x = 0;
621  y += 1;
622  if (y >= height)
623  return;
624  }
625  }
626  src += 4;
627  }
628  }
629 }
630 
631 /**
632  * Decode DEEP TVDC 32-bit buffer
633  * @param[out] dst Destination buffer
634  * @param[in] src Source buffer
635  * @param src_size Source buffer size (bytes)
636  * @param width Width of destination buffer (pixels)
637  * @param height Height of destination buffer (pixels)
638  * @param linesize Line size of destination buffer (bytes)
639  * @param[int] tvdc TVDC lookup table
640  */
641 static void decode_deep_tvdc32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize, const int16_t *tvdc)
642 {
643  int x = 0, y = 0, plane = 0;
644  int8_t pixel = 0;
645  int i, j;
646 
647  for (i = 0; i < src_size * 2;) {
648 #define GETNIBBLE ((i & 1) ? (src[i>>1] & 0xF) : (src[i>>1] >> 4))
649  int d = tvdc[GETNIBBLE];
650  i++;
651  if (d) {
652  pixel += d;
653  dst[y * linesize + x*4 + plane] = pixel;
654  x++;
655  } else {
656  if (i >= src_size * 2)
657  return;
658  d = GETNIBBLE + 1;
659  i++;
660  d = FFMIN(d, width - x);
661  for (j = 0; j < d; j++) {
662  dst[y * linesize + x*4 + plane] = pixel;
663  x++;
664  }
665  }
666  if (x >= width) {
667  plane++;
668  if (plane >= 4) {
669  y++;
670  if (y >= height)
671  return;
672  plane = 0;
673  }
674  x = 0;
675  pixel = 0;
676  i = (i + 1) & ~1;
677  }
678  }
679 }
680 
681 static int unsupported(AVCodecContext *avctx)
682 {
683  IffContext *s = avctx->priv_data;
684  avpriv_request_sample(avctx, "bitmap (compression %i, bpp %i, ham %i)", s->compression, s->bpp, s->ham);
685  return AVERROR_INVALIDDATA;
686 }
687 
688 static int decode_frame(AVCodecContext *avctx,
689  void *data, int *got_frame,
690  AVPacket *avpkt)
691 {
692  IffContext *s = avctx->priv_data;
693  const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL;
694  const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0;
695  const uint8_t *buf_end = buf + buf_size;
696  int y, plane, res;
697  GetByteContext gb;
698  const AVPixFmtDescriptor *desc;
699 
700  if ((res = extract_header(avctx, avpkt)) < 0)
701  return res;
702  if ((res = ff_reget_buffer(avctx, s->frame)) < 0)
703  return res;
704 
705  desc = av_pix_fmt_desc_get(avctx->pix_fmt);
706 
707  if (!s->init && avctx->bits_per_coded_sample <= 8 - (s->masking == MASK_HAS_MASK) &&
708  avctx->pix_fmt == AV_PIX_FMT_PAL8) {
709  if ((res = cmap_read_palette(avctx, (uint32_t *)s->frame->data[1])) < 0)
710  return res;
711  } else if (!s->init && avctx->bits_per_coded_sample <= 8 &&
712  avctx->pix_fmt == AV_PIX_FMT_RGB32) {
713  if ((res = cmap_read_palette(avctx, s->mask_palbuf)) < 0)
714  return res;
715  }
716  s->init = 1;
717 
718  switch (s->compression) {
719  case 0:
720  if (avctx->codec_tag == MKTAG('A', 'C', 'B', 'M')) {
721  if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
722  memset(s->frame->data[0], 0, avctx->height * s->frame->linesize[0]);
723  for (plane = 0; plane < s->bpp; plane++) {
724  for (y = 0; y < avctx->height && buf < buf_end; y++) {
725  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
726  decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane);
727  buf += s->planesize;
728  }
729  }
730  } else if (s->ham) { // HAM to AV_PIX_FMT_BGR32
731  memset(s->frame->data[0], 0, avctx->height * s->frame->linesize[0]);
732  for (y = 0; y < avctx->height; y++) {
733  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
734  memset(s->ham_buf, 0, s->planesize * 8);
735  for (plane = 0; plane < s->bpp; plane++) {
736  const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize;
737  if (start >= buf_end)
738  break;
739  decodeplane8(s->ham_buf, start, FFMIN(s->planesize, buf_end - start), plane);
740  }
741  decode_ham_plane32((uint32_t *)row, s->ham_buf, s->ham_palbuf, s->planesize);
742  }
743  } else
744  return unsupported(avctx);
745  } else if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) {
746  int raw_width = avctx->width * (av_get_bits_per_pixel(desc) >> 3);
747  int x;
748  for (y = 0; y < avctx->height && buf < buf_end; y++) {
749  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
750  memcpy(row, buf, FFMIN(raw_width, buf_end - buf));
751  buf += raw_width;
752  if (avctx->pix_fmt == AV_PIX_FMT_BGR32) {
753  for (x = 0; x < avctx->width; x++)
754  row[4 * x + 3] = row[4 * x + 3] & 0xF0 | (row[4 * x + 3] >> 4);
755  }
756  }
757  } else if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M')) { // interleaved
758  if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
759  for (y = 0; y < avctx->height; y++) {
760  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
761  memset(row, 0, avctx->width);
762  for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
763  decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane);
764  buf += s->planesize;
765  }
766  }
767  } else if (s->ham) { // HAM to AV_PIX_FMT_BGR32
768  for (y = 0; y < avctx->height; y++) {
769  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
770  memset(s->ham_buf, 0, s->planesize * 8);
771  for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
772  decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), plane);
773  buf += s->planesize;
774  }
775  decode_ham_plane32((uint32_t *)row, s->ham_buf, s->ham_palbuf, s->planesize);
776  }
777  } else { // AV_PIX_FMT_BGR32
778  for (y = 0; y < avctx->height; y++) {
779  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
780  memset(row, 0, avctx->width << 2);
781  for (plane = 0; plane < s->bpp && buf < buf_end; plane++) {
782  decodeplane32((uint32_t *)row, buf,
783  FFMIN(s->planesize, buf_end - buf), plane);
784  buf += s->planesize;
785  }
786  }
787  }
788  } else if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ')) { // IFF-PBM
789  if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
790  for (y = 0; y < avctx->height && buf_end > buf; y++) {
791  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
792  memcpy(row, buf, FFMIN(avctx->width, buf_end - buf));
793  buf += avctx->width + (avctx->width % 2); // padding if odd
794  }
795  } else if (s->ham) { // IFF-PBM: HAM to AV_PIX_FMT_BGR32
796  for (y = 0; y < avctx->height && buf_end > buf; y++) {
797  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
798  memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf));
799  buf += avctx->width + (avctx->width & 1); // padding if odd
800  decode_ham_plane32((uint32_t *)row, s->ham_buf, s->ham_palbuf, s->planesize);
801  }
802  } else
803  return unsupported(avctx);
804  }
805  break;
806  case 1:
807  if (avctx->codec_tag == MKTAG('I', 'L', 'B', 'M')) { // interleaved
808  if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
809  for (y = 0; y < avctx->height; y++) {
810  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
811  memset(row, 0, avctx->width);
812  for (plane = 0; plane < s->bpp; plane++) {
813  buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
814  decodeplane8(row, s->planebuf, s->planesize, plane);
815  }
816  }
817  } else if (avctx->bits_per_coded_sample <= 8) { //8-bit (+ mask) to AV_PIX_FMT_BGR32
818  for (y = 0; y < avctx->height; y++) {
819  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
820  memset(s->mask_buf, 0, avctx->width * sizeof(uint32_t));
821  for (plane = 0; plane < s->bpp; plane++) {
822  buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
823  decodeplane32(s->mask_buf, s->planebuf, s->planesize, plane);
824  }
825  lookup_pal_indicies((uint32_t *)row, s->mask_buf, s->mask_palbuf, avctx->width);
826  }
827  } else if (s->ham) { // HAM to AV_PIX_FMT_BGR32
828  for (y = 0; y < avctx->height; y++) {
829  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
830  memset(s->ham_buf, 0, s->planesize * 8);
831  for (plane = 0; plane < s->bpp; plane++) {
832  buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
833  decodeplane8(s->ham_buf, s->planebuf, s->planesize, plane);
834  }
835  decode_ham_plane32((uint32_t *)row, s->ham_buf, s->ham_palbuf, s->planesize);
836  }
837  } else { // AV_PIX_FMT_BGR32
838  for (y = 0; y < avctx->height; y++) {
839  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
840  memset(row, 0, avctx->width << 2);
841  for (plane = 0; plane < s->bpp; plane++) {
842  buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end);
843  decodeplane32((uint32_t *)row, s->planebuf, s->planesize, plane);
844  }
845  }
846  }
847  } else if (avctx->codec_tag == MKTAG('P', 'B', 'M', ' ')) { // IFF-PBM
848  if (avctx->pix_fmt == AV_PIX_FMT_PAL8 || avctx->pix_fmt == AV_PIX_FMT_GRAY8) {
849  for (y = 0; y < avctx->height; y++) {
850  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
851  buf += decode_byterun(row, avctx->width, buf, buf_end);
852  }
853  } else if (s->ham) { // IFF-PBM: HAM to AV_PIX_FMT_BGR32
854  for (y = 0; y < avctx->height; y++) {
855  uint8_t *row = &s->frame->data[0][y * s->frame->linesize[0]];
856  buf += decode_byterun(s->ham_buf, avctx->width, buf, buf_end);
857  decode_ham_plane32((uint32_t *)row, s->ham_buf, s->ham_palbuf, s->planesize);
858  }
859  } else
860  return unsupported(avctx);
861  } else if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) { // IFF-DEEP
862  if (av_get_bits_per_pixel(desc) == 32)
863  decode_deep_rle32(s->frame->data[0], buf, buf_size, avctx->width, avctx->height, s->frame->linesize[0]);
864  else
865  return unsupported(avctx);
866  }
867  break;
868  case 4:
869  bytestream2_init(&gb, buf, buf_size);
870  if (avctx->codec_tag == MKTAG('R', 'G', 'B', '8') && avctx->pix_fmt == AV_PIX_FMT_RGB32)
871  decode_rgb8(&gb, s->frame->data[0], avctx->width, avctx->height, s->frame->linesize[0]);
872  else if (avctx->codec_tag == MKTAG('R', 'G', 'B', 'N') && avctx->pix_fmt == AV_PIX_FMT_RGB444)
873  decode_rgbn(&gb, s->frame->data[0], avctx->width, avctx->height, s->frame->linesize[0]);
874  else
875  return unsupported(avctx);
876  break;
877  case 5:
878  if (avctx->codec_tag == MKTAG('D', 'E', 'E', 'P')) {
879  if (av_get_bits_per_pixel(desc) == 32)
880  decode_deep_tvdc32(s->frame->data[0], buf, buf_size, avctx->width, avctx->height, s->frame->linesize[0], s->tvdc);
881  else
882  return unsupported(avctx);
883  } else
884  return unsupported(avctx);
885  break;
886  default:
887  return unsupported(avctx);
888  }
889 
890  if ((res = av_frame_ref(data, s->frame)) < 0)
891  return res;
892 
893  *got_frame = 1;
894 
895  return buf_size;
896 }
897 
898 #if CONFIG_IFF_ILBM_DECODER
899 AVCodec ff_iff_ilbm_decoder = {
900  .name = "iff",
901  .long_name = NULL_IF_CONFIG_SMALL("IFF"),
902  .type = AVMEDIA_TYPE_VIDEO,
903  .id = AV_CODEC_ID_IFF_ILBM,
904  .priv_data_size = sizeof(IffContext),
905  .init = decode_init,
906  .close = decode_end,
907  .decode = decode_frame,
908  .capabilities = AV_CODEC_CAP_DR1,
909 };
910 #endif
911 #if CONFIG_IFF_BYTERUN1_DECODER
912 AVCodec ff_iff_byterun1_decoder = {
913  .name = "iff",
914  .long_name = NULL_IF_CONFIG_SMALL("IFF"),
915  .type = AVMEDIA_TYPE_VIDEO,
917  .priv_data_size = sizeof(IffContext),
918  .init = decode_init,
919  .close = decode_end,
920  .decode = decode_frame,
921  .capabilities = AV_CODEC_CAP_DR1,
922 };
923 #endif
int plane
Definition: avisynth_c.h:291
Definition: iff.c:41
#define NULL
Definition: coverity.c:32
float v
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static void decodeplane32(uint32_t *dst, const uint8_t *buf, int buf_size, int plane)
Decode interleaved plane buffer up to 24bpp.
Definition: iff.c:430
unsigned compression
delta compression method used
Definition: iff.c:52
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
uint32_t * mask_palbuf
masking palette table
Definition: iff.c:51
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
unsigned masking
TODO: masking method used.
Definition: iff.c:57
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:2081
#define avpriv_request_sample(...)
unsigned transparency
TODO: transparency color index in palette.
Definition: iff.c:56
static int cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
Convert CMAP buffer (stored in extradata) to lavc palette format.
Definition: iff.c:144
int size
Definition: avcodec.h:1434
#define AV_RB24
Definition: intreadwrite.h:64
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1732
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
#define av_le2ne32(x)
Definition: bswap.h:96
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:373
unsigned flags
1 for EHB, 0 is no extra half darkening
Definition: iff.c:55
AVCodec.
Definition: avcodec.h:3482
#define FFALIGN(x, a)
Definition: common.h:97
static void decodeplane8(uint8_t *dst, const uint8_t *buf, int buf_size, int plane)
Decode interleaved plane buffer up to 8bpp.
Definition: iff.c:408
uint32_t * mask_buf
temporary buffer for palette indices
Definition: iff.c:50
#define DECODE_HAM_PLANE32(x)
Definition: iff.c:448
static av_cold int decode_end(AVCodecContext *avctx)
Definition: iff.c:338
uint8_t * planebuf
Definition: iff.c:47
uint8_t
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:135
static void decode_deep_tvdc32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize, const int16_t *tvdc)
Decode DEEP TVDC 32-bit buffer.
Definition: iff.c:641
float delta
8 bit with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:78
uint8_t * ham_buf
temporary buffer for planar to chunky conversation
Definition: iff.c:48
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:366
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1627
Definition: iff.c:38
uint8_t * data
Definition: avcodec.h:1433
#define FFMIN3(a, b, c)
Definition: common.h:93
bitstream reader API header.
mask_type
Definition: iff.c:37
ptrdiff_t size
Definition: opengl_enc.c:101
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:3006
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static const uint16_t mask[17]
Definition: lzw.c:38
#define AV_RB16
Definition: intreadwrite.h:53
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:178
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
GLsizei GLsizei * length
Definition: opengl_enc.c:115
#define AV_PIX_FMT_0BGR32
Definition: pixfmt.h:366
const char * name
Name of the codec implementation.
Definition: avcodec.h:3489
GLsizei count
Definition: opengl_enc.c:109
#define FFMAX(a, b)
Definition: common.h:90
Libavcodec external API header.
#define GETNIBBLE
#define LUT32(plane)
Definition: iff.c:105
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:266
int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame)
Identical in function to av_frame_make_writable(), except it uses ff_get_buffer() to allocate the buf...
Definition: utils.c:1097
#define FFMIN(a, b)
Definition: common.h:92
float y
Definition: iff.c:44
int width
picture width / height.
Definition: avcodec.h:1691
GLsizei GLboolean const GLfloat * value
Definition: opengl_enc.c:109
#define AV_WN64A(p, v)
Definition: intreadwrite.h:542
AVFrame * frame
Definition: iff.c:45
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:363
int init
Definition: iff.c:58
AVS_Value src
Definition: avisynth_c.h:482
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
#define DECODE_RGBX_COMMON(type)
Definition: iff.c:525
main external API structure.
Definition: avcodec.h:1512
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:361
int planesize
Definition: iff.c:46
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1544
void * buf
Definition: avisynth_c.h:553
int extradata_size
Definition: avcodec.h:1628
BYTE int const BYTE int int int height
Definition: avisynth_c.h:676
static av_always_inline uint32_t gray2rgb(const uint32_t x)
Definition: iff.c:137
static void decode_rgbn(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
Decode RGBN buffer.
Definition: iff.c:569
#define AV_RN32(p)
Definition: intreadwrite.h:364
uint8_t pixel
Definition: tiny_ssim.c:42
#define AV_RL24
Definition: intreadwrite.h:78
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:521
int palette
Definition: v4l.c:61
Y , 8bpp.
Definition: pixfmt.h:75
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:280
unsigned ham
0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise)
Definition: iff.c:54
static const uint32_t plane32_lut[32][16 *4]
Definition: iff.c:125
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: iff.c:688
static void decode_rgb8(GetByteContext *gb, uint8_t *dst, int width, int height, int linesize)
Decode RGB8 buffer.
Definition: iff.c:552
#define LUT8(plane)
Definition: iff.c:80
static void decode_ham_plane32(uint32_t *dst, const uint8_t *buf, const uint32_t *const pal, unsigned buf_size)
Converts one line of HAM6/8-encoded chunky buffer to 24bpp.
Definition: iff.c:466
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
static av_cold int decode_init(AVCodecContext *avctx)
Definition: iff.c:348
void * priv_data
Definition: avcodec.h:1554
static const uint64_t plane8_lut[8][256]
Definition: iff.c:100
#define av_freep(p)
void INT64 start
Definition: avisynth_c.h:553
#define av_always_inline
Definition: attributes.h:37
static int extract_header(AVCodecContext *const avctx, const AVPacket *const avpkt)
Extracts the IFF extra context and updates internal decoder structures.
Definition: iff.c:195
static void lookup_pal_indicies(uint32_t *dst, const uint32_t *buf, const uint32_t *const pal, unsigned width)
Definition: iff.c:481
int16_t tvdc[16]
TVDC lookup table.
Definition: iff.c:59
static int decode_byterun(uint8_t *dst, int dst_size, const uint8_t *buf, const uint8_t *const buf_end)
Decode one complete byterun1 encoded line.
Definition: iff.c:498
static int unsupported(AVCodecContext *avctx)
Definition: iff.c:681
#define AV_RN64A(p)
Definition: intreadwrite.h:530
#define MKTAG(a, b, c, d)
Definition: common.h:341
This structure stores compressed data.
Definition: avcodec.h:1410
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
uint32_t * ham_palbuf
HAM decode table.
Definition: iff.c:49
unsigned bpp
bits per plane to decode (differs from bits_per_coded_sample if HAM)
Definition: iff.c:53
static void decode_deep_rle32(uint8_t *dst, const uint8_t *src, int src_size, int width, int height, int linesize)
Decode DEEP RLE 32-bit buffer.
Definition: iff.c:589
static int width