85 default :
return UINT_MAX;
93 z_stream zstream = { 0 };
96 zstream.next_in = src;
97 zstream.avail_in =
size;
98 zstream.next_out = dst;
99 zstream.avail_out = *
len;
100 zret = inflateInit(&zstream);
105 zret = inflate(&zstream, Z_SYNC_FLUSH);
106 inflateEnd(&zstream);
107 *len = zstream.total_out;
108 return zret == Z_STREAM_END ? Z_OK : zret;
113 const uint8_t *src,
int size,
int lines)
115 int c,
line, pixels, code;
125 unsigned long outlen;
127 outlen = width * lines;
131 ret = tiff_uncompress(zbuf, &outlen, src, size);
134 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
135 (
unsigned long)width * lines, ret);
140 for (line = 0; line < lines; line++) {
141 memcpy(dst, src, width);
163 "Error allocating temporary buffer\n");
168 "Uncompressed fax mode is not supported (yet)\n");
173 memcpy(src2, src, size);
175 for (i = 0; i <
size; i++)
190 for (line = 0; line < lines; line++) {
191 if (src - ssrc > size) {
197 if (ssrc + size - src < width)
200 memcpy(dst, src, width);
203 for (i = 0; i <
width; i++)
209 for (pixels = 0; pixels <
width;) {
210 if (ssrc + size - src < 2)
212 code = (int8_t) * src++;
215 if (pixels + code > width ||
216 ssrc + size - src < code) {
218 "Copy went out of bounds\n");
221 memcpy(dst + pixels, src, code);
224 }
else if (code != -128) {
226 if (pixels + code > width) {
228 "Run went out of bounds\n");
232 memset(dst + pixels, c, code);
239 if (pixels < width) {
277 "This format is not supported (bpp=%d, bppcount=%d)\n",
298 for (i = 0; i < 256; i++)
299 pal[i] = i * 0x010101;
308 unsigned tag, type, count,
off, value = 0;
313 if (end_buf - buf < 12)
331 value =
tget(&buf, type, s->
le);
348 if (count <= 4 &&
type_sizes[type] * count <= 4) {
355 if (buf && (buf < start || buf > end_buf)) {
357 "Tag referencing position outside the image\n");
372 "This format is not supported (bpp=%d, %d components)\n",
381 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
382 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
387 for (i = 0; i < count && buf < end_buf; i++)
398 "Samples per pixel requires a single value, many provided\n");
429 "JPEG compression is not supported\n");
438 if (type ==
TIFF_LONG && value == UINT_MAX)
442 "Incorrect value of rows per strip\n");
459 "Tag referencing position outside the image\n");
475 "Tag referencing position outside the image\n");
500 if (value < 1 || value > 2) {
502 "Unknown FillOrder value %d, trying default one\n", value);
510 if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3)
513 gp = buf + count / 3 *
off;
514 bp = buf + count / 3 * off * 2;
516 for (i = 0; i < count / 3; i++) {
517 j = (
tget(&rp, type, s->
le) >>
off) << 16;
518 j |= (
tget(&gp, type, s->
le) >>
off) << 8;
549 int buf_size = avpkt->
size;
553 const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
558 unsigned soff, ssize;
562 if (end_buf - buf < 8)
568 else if (
id == 0x4D4D)
582 "The answer to life, universe and everything is not correct!\n");
589 if (off >= UINT_MAX - 14 || end_buf - orig_buf < off + 14) {
593 buf = orig_buf +
off;
595 for (i = 0; i < entries; i++) {
614 for (i = 0; i < s->
height; i += s->
rps) {
629 if (soff > buf_size || ssize > buf_size - soff) {
641 ssize = s->
width * soff;
642 for (i = 0; i < s->
height; i++) {
643 for (j = soff; j < ssize; j++)
644 dst[j] += dst[j - soff];
654 for (j = 0; j < s->
height; j++) {
656 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 ...
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)
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
packed RGB 8:8:8, 24bpp, RGBRGB...
AVFrame * coded_frame
the picture in the bitstream
void avcodec_set_dimensions(AVCodecContext *s, int width, int height)
av_cold void ff_lzw_decode_close(LZWState **p)
av_cold void ff_lzw_decode_open(LZWState **p)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
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)
static int init_image(TiffContext *s)
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)
const uint8_t * stripdata
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
static int init(AVCodecParserContext *s)
static unsigned tget(const uint8_t **p, int type, int le)
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. ...
struct TiffContext TiffContext
static av_cold int tiff_end(AVCodecContext *avctx)
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)
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...
int width
picture width / height.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
TiffCompr
list of TIFF compression types
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
static void close(AVCodecParserContext *s)
void avcodec_get_frame_defaults(AVFrame *frame)
Set the fields of the given AVFrame to default values.
#define FF_ARRAY_ELEMS(a)
#define FF_INPUT_BUFFER_PADDING_SIZE
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...
#define AVERROR_INVALIDDATA
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
Y , 16bpp, little-endian.
const uint8_t ff_reverse[256]
This structure stores compressed data.
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.
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)