68 return le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
73 return le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
79 case TIFF_BYTE:
return bytestream2_get_byte(gb);
82 default:
return UINT_MAX;
90 z_stream zstream = { 0 };
93 zstream.next_in =
src;
94 zstream.avail_in =
size;
95 zstream.next_out = dst;
96 zstream.avail_out = *
len;
97 zret = inflateInit(&zstream);
102 zret = inflate(&zstream, Z_SYNC_FLUSH);
103 inflateEnd(&zstream);
104 *
len = zstream.total_out;
105 return zret == Z_STREAM_END ? Z_OK : zret;
110 int width,
int lines)
113 unsigned long outlen;
115 outlen =
width * lines;
119 ret = tiff_uncompress(zbuf, &outlen,
src,
size);
122 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
123 (
unsigned long)
width * lines, ret);
128 for (line = 0; line < lines; line++) {
148 "Error allocating temporary buffer\n");
157 memcpy(src2, src, size);
159 for (i = 0; i <
size; i++)
173 int c,
line, pixels, code, ret;
184 return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
187 "zlib support not enabled, " 188 "deflate compression not supported\n");
197 for (line = 0; line < lines; line++) {
199 if (pixels < width) {
217 for (line = 0; line < lines; line++) {
227 for (i = 0; i <
width; i++)
228 bytestream2_put_byte(&pb,
ff_reverse[bytestream2_get_byte(&s->
gb)]);
232 for (pixels = 0; pixels <
width;) {
238 }
else if (code != -128) {
240 c = bytestream2_get_byte(&s->
gb);
258 "Unsupported image parameters: bpp=%d, bppcount=%d\n",
305 "This format is not supported (bpp=%d, bppcount=%d)\n",
326 unsigned tag, type, count, off, value = 0;
363 if (count <= 4 &&
type_sizes[type] * count <= 4)
380 "This format is not supported (bpp=%d, %d components)\n",
389 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
390 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
395 for (i = 0; i < count; i++)
406 "Samples per pixel requires a single value, many provided\n");
448 if (!value || (type ==
TIFF_LONG && value == UINT_MAX))
496 "PhotometricInterpretation 0x%04X",
506 if (value < 1 || value > 2) {
508 "Unknown FillOrder value %d, trying default one\n", value);
516 if (count / 3 > 256 ||
519 pal_gb[0] = pal_gb[1] = pal_gb[2] = s->
gb;
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;
547 "Unknown or unsupported tag %d/0X%0X\n",
562 int id,
le, ret, plane, planes;
563 int i, j, entries,
stride;
564 unsigned soff, ssize;
574 id = bytestream2_get_le16(&s->
gb);
577 else if (
id == 0x4D4D)
591 "The answer to life, universe and everything is not correct!\n");
598 if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
604 for (i = 0; i < entries; i++) {
635 for (plane = 0; plane < planes; plane++) {
637 dst = p->
data[plane];
638 for (i = 0; i < s->
height; i += s->
rps) {
645 soff =
tget(&stripdata, s->
sot, le);
649 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
662 dst = p->
data[plane];
664 ssize = s->
width * soff;
667 for (i = 0; i < s->
height; i++) {
668 for (j = soff; j < ssize; j += 2)
674 for (i = 0; i < s->
height; i++) {
675 for (j = soff; j < ssize; j += 2)
680 for (i = 0; i < s->
height; i++) {
681 for (j = soff; j < ssize; j++)
682 dst[j] += dst[j - soff];
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];
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...
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_always_inline void bytestream2_set_buffer(PutByteContext *p, const uint8_t c, unsigned int size)
This structure describes decoded (raw) audio or video data.
static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
8 bits gray, 8 bits alpha
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
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.
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
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)
av_cold void ff_lzw_decode_open(LZWState **p)
static int init_image(TiffContext *s, AVFrame *frame)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define FF_ARRAY_ELEMS(a)
static int8_t ff_u8_to_s8(uint8_t a)
static unsigned tget_short(GetByteContext *gb, int le)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Macro definitions for various function/variable attributes.
static unsigned tget_long(GetByteContext *gb, int le)
av_cold void ff_ccitt_unpack_init(void)
initialize unpacker code
planar GBRA 4:4:4:4 64bpp, big-endian
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
8 bits with AV_PIX_FMT_RGB32 palette
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
static av_cold int tiff_init(AVCodecContext *avctx)
planar GBR 4:4:4 48bpp, big-endian
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
16 bits gray, 16 bits alpha (big-endian)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int tiff_end(AVCodecContext *avctx)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
static int tiff_decode_tag(TiffContext *s)
const char * name
Name of the codec implementation.
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
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
enum TiffPhotometric photometric
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int width
picture width / height.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
static unsigned tget(GetByteContext *gb, int type, int le)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
TiffCompr
list of TIFF compression types
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static av_always_inline unsigned int bytestream2_copy_buffer(PutByteContext *p, GetByteContext *g, unsigned int size)
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.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
common internal api header.
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
planar GBRA 4:4:4:4 32bpp
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static av_cold int init(AVCodecParserContext *s)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Y , 16bpp, little-endian.
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
16 bits gray, 16 bits alpha (little-endian)
planar GBR 4:4:4 48bpp, little-endian
const uint8_t ff_reverse[256]
#define FFSWAP(type, a, b)
planar GBRA 4:4:4:4 64bpp, little-endian
This structure stores compressed data.
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int lines)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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...