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];