73 unsigned v = le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
79 unsigned v = le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
85 av_alias64 i = { .u64 = le ? bytestream2_get_le64(gb) : bytestream2_get_be64(gb)};
92 case TIFF_BYTE :
return bytestream2_get_byte(gb);
95 default :
return UINT_MAX;
109 #define RET_GEOKEY(TYPE, array, element)\
110 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
111 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
112 return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
157 #define RET_GEOKEY_VAL(TYPE, array)\
158 if (val >= TIFF_##TYPE##_OFFSET &&\
159 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
160 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
212 snprintf(ap, 14,
"Unknown-%d", val);
220 uint64_t component_len;
221 if (!sep) sep =
", ";
222 component_len = 15LL + strlen(sep);
223 if (count >= (INT_MAX - 1)/component_len)
225 ap =
av_malloc(component_len * count + 1);
230 for (i = 0; i <
count; i++) {
231 unsigned l =
snprintf(ap, component_len,
"%f%s", dp[i], sep);
232 if(l >= component_len) {
238 ap0[strlen(ap0) - strlen(sep)] =
'\0';
246 uint64_t component_len;
247 if (!sep) sep =
", ";
248 component_len = 7LL + strlen(sep);
249 if (count >= (INT_MAX - 1)/component_len)
251 ap =
av_malloc(component_len * count + 1);
256 for (i = 0; i <
count; i++) {
257 unsigned l =
snprintf(ap, component_len,
"%d%s", sp[i], sep);
258 if (l >= component_len) {
264 ap0[strlen(ap0) - strlen(sep)] =
'\0';
269 const char *
name,
const char *sep,
276 if (count >= INT_MAX /
sizeof(int64_t) || count <= 0)
285 for (i = 0; i <
count; i++)
302 if (count >= INT_MAX /
sizeof(int16_t) || count <= 0)
311 for (i = 0; i <
count; i++)
355 z_stream zstream = { 0 };
358 zstream.next_in = (
uint8_t *)src;
359 zstream.avail_in =
size;
360 zstream.next_out =
dst;
361 zstream.avail_out = *
len;
362 zret = inflateInit(&zstream);
367 zret = inflate(&zstream, Z_SYNC_FLUSH);
368 inflateEnd(&zstream);
369 *len = zstream.total_out;
370 return zret == Z_STREAM_END ? Z_OK : zret;
375 int usePtr,
const uint8_t *src,
380 while (--width >= 0) {
381 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
382 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
383 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
384 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
385 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
386 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
387 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
388 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
392 while (--width >= 0) {
393 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
394 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
395 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
396 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
400 while (--width >= 0) {
401 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
402 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
407 memcpy(dst + offset, src, width);
409 memset(dst + offset, c, width);
415 const uint8_t *src,
int size,
int lines)
427 unsigned long outlen;
429 outlen = width * lines;
440 for (i = 0; i <
size; i++)
445 ret = tiff_uncompress(zbuf, &outlen, src, size);
448 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
449 (
unsigned long)width * lines, ret);
455 for (line = 0; line < lines; line++) {
459 memcpy(dst, src, width);
475 for (i = 0; i <
size; i++)
480 if (size > 1 && !src[0] && (src[1]&1)) {
496 "Error allocating temporary buffer\n");
501 "Uncompressed fax mode is not supported (yet)\n");
506 memcpy(src2, src, size);
508 for (i = 0; i <
size; i++)
521 for (line = 0; line < lines; line++) {
528 for (line = 0; line < lines; line++) {
529 if (src - ssrc > size) {
535 if (ssrc + size - src < width)
539 dst, 1, src, 0, width, 0);
542 for (i = 0; i <
width; i++)
548 for (pixels = 0; pixels <
width;) {
549 if (ssrc + size - src < 2) {
553 code = (int8_t) * src++;
556 if (pixels + code > width) {
558 "Copy went out of bounds\n");
561 if (ssrc + size - src < code) {
566 dst, 1, src, 0, code, pixels);
569 }
else if (code != -128) {
571 if (pixels + code > width) {
573 "Run went out of bounds\n");
578 dst, 0,
NULL, c, code, pixels);
585 if (pixels < width) {
635 "This format is not supported (bpp=%d, bppcount=%d)\n",
651 pal = (uint32_t *) frame->
data[1];
652 for (i = 0; i < 1<<s->
bpp; i++)
653 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
662 int i, j, k, pos,
start;
699 if (count <= 4 &&
type_sizes[type] * count <= 4) {
717 "This format is not supported (bpp=%d, %d components)\n",
726 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
727 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
734 for (i = 0; i <
count; i++)
745 "Samples per pixel requires a single value, many provided\n");
750 "Samples per pixel %d is too large\n", value);
781 "JPEG compression is not supported\n");
790 if (type ==
TIFF_LONG && value == UINT_MAX)
794 "Incorrect value of rows per strip\n");
811 "Tag referencing position outside the image\n");
827 "Tag referencing position outside the image\n");
859 if (value < 1 || value > 2) {
861 "Unknown FillOrder value %d, trying default one\n", value);
872 for (k = 2; k >= 0; k--) {
873 for (i = 0; i < count / 3; i++) {
875 pal[i] = 0xFF
U << 24;
896 #define ADD_METADATA(count, name, sep)\
897 if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
898 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
940 if (count >= INT_MAX /
sizeof(int64_t))
949 for (i = 0; i <
count; i++)
1044 unsigned soff, ssize;
1052 if (avpkt->
size < 8)
1054 id = bytestream2_get_le16u(&s->
gb);
1057 else if (
id == 0x4D4D)
1075 "The answer to life, universe and everything is not correct!\n");
1082 if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1090 for (i = 0; i < entries; i++) {
1143 for (i = 0; i < s->
height; i += s->
rps) {
1154 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1166 ssize = s->
width * soff;
1169 for (i = 0; i < s->
height; i++) {
1170 for (j = soff; j < ssize; j += 2)
1176 for (i = 0; i < s->
height; i++) {
1177 for (j = soff; j < ssize; j += 2)
1182 for (i = 0; i < s->
height; i++) {
1183 for (j = soff; j < ssize; j++)
1184 dst[j] += dst[j - soff];
1192 for (i = 0; i < s->
height; i++) {
1193 for (j = 0; j < p->
linesize[0]; j++)