97 z_stream zstream = { 0 };
100 zstream.next_in = src;
101 zstream.avail_in =
size;
102 zstream.next_out = dst;
103 zstream.avail_out = *
len;
104 zret = inflateInit(&zstream);
109 zret = inflate(&zstream, Z_SYNC_FLUSH);
110 inflateEnd(&zstream);
111 *len = zstream.total_out;
112 return zret == Z_STREAM_END ? Z_OK : zret;
117 int width,
int lines)
120 unsigned long outlen;
122 outlen = width * lines;
126 ret = tiff_uncompress(zbuf, &outlen, src, size);
129 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
130 (
unsigned long)width * lines, ret);
135 for (line = 0; line < lines; line++) {
136 memcpy(dst, src, width);
147 const uint8_t *src,
int size,
int lines)
155 "Error allocating temporary buffer\n");
164 memcpy(src2, src, size);
166 for (i = 0; i <
size; i++)
177 const uint8_t *src,
int size,
int lines)
179 int c, line, pixels, code, ret;
181 int width = ((s->
width * s->
bpp) + 7) >> 3;
188 return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
191 "zlib support not enabled, "
192 "deflate compression not supported\n");
207 for (line = 0; line < lines; line++) {
208 if (src - ssrc > size) {
214 if (ssrc + size - src < width)
217 memcpy(dst, src, width);
220 for (i = 0; i <
width; i++)
226 for (pixels = 0; pixels <
width;) {
227 if (ssrc + size - src < 2)
229 code = (int8_t) *src++;
232 if (pixels + code > width ||
233 ssrc + size - src < code) {
235 "Copy went out of bounds\n");
238 memcpy(dst + pixels, src, code);
241 }
else if (code != -128) {
243 if (pixels + code > width) {
245 "Run went out of bounds\n");
249 memset(dst + pixels, c, code);
256 if (pixels < width) {
276 "Unsupported image parameters: bpp=%d, bppcount=%d\n",
302 "This format is not supported (bpp=%d, bppcount=%d)\n",
320 pal = (uint32_t *) frame->
data[1];
321 for (i = 0; i < 256; i++)
322 pal[i] = i * 0x010101;
331 unsigned tag, type, count,
off, value = 0;
336 if (end_buf - buf < 12)
354 value =
tget(&buf, type, s->
le);
371 if (count <= 4 &&
type_sizes[type] * count <= 4)
377 if (buf && (buf < start || buf > end_buf)) {
379 "Tag referencing position outside the image\n");
394 "This format is not supported (bpp=%d, %d components)\n",
403 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
404 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
409 for (i = 0; i < count && buf < end_buf; i++)
420 "Samples per pixel requires a single value, many provided\n");
459 if (type ==
TIFF_LONG && value == UINT_MAX)
463 "Incorrect value of rows per strip\n");
480 "Tag referencing position outside the image\n");
496 "Tag referencing position outside the image\n");
521 if (value < 1 || value > 2) {
523 "Unknown FillOrder value %d, trying default one\n", value);
531 if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3)
534 gp = buf + count / 3 *
off;
535 bp = buf + count / 3 * off * 2;
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;
562 "Unknown or unsupported tag %d/0X%0X\n",
574 int buf_size = avpkt->
size;
577 const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
580 int i, j, entries,
stride;
581 unsigned soff, ssize;
585 if (end_buf - buf < 8)
591 else if (
id == 0x4D4D)
605 "The answer to life, universe and everything is not correct!\n");
612 if (off >= UINT_MAX - 14 || end_buf - orig_buf < off + 14) {
616 buf = orig_buf +
off;
618 for (i = 0; i < entries; i++) {
637 for (i = 0; i < s->
height; i += s->
rps) {
652 if (soff > buf_size || ssize > buf_size - soff) {
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];
680 for (j = 0; j < s->
height; j++) {
681 for (i = 0; i < p->
linesize[0]; i++)
682 src[i] = 255 - src[i];
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 unsigned tget_long(const uint8_t **p, int le)
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)
#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.
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.
#define FF_ARRAY_ELEMS(a)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Macro definitions for various function/variable attributes.
av_cold void ff_ccitt_unpack_init(void)
initialize upacker code
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
8 bit with 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...
static av_cold int tiff_init(AVCodecContext *avctx)
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
const uint8_t * stripdata
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
static unsigned tget(const uint8_t **p, int type, int le)
#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(). ...
const uint8_t * stripsizes
#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.
void av_log(void *avcl, int level, const char *fmt,...)
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...
static unsigned tget_short(const uint8_t **p, int le)
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int width
picture width / height.
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
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.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
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.
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)
Y , 16bpp, little-endian.
const uint8_t ff_reverse[256]
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)
static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
CCITT Fax Group 3 and 4 decompression.