74 unsigned v = le ? bytestream2_get_le16(gb) : bytestream2_get_be16(gb);
80 unsigned v = le ? bytestream2_get_le32(gb) : bytestream2_get_be32(gb);
86 av_alias64 i = { .u64 = le ? bytestream2_get_le64(gb) : bytestream2_get_be64(gb)};
93 case TIFF_BYTE :
return bytestream2_get_byte(gb);
96 default :
return UINT_MAX;
110 #define RET_GEOKEY(TYPE, array, element)\
111 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
112 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
113 return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
158 #define RET_GEOKEY_VAL(TYPE, array)\
159 if (val >= TIFF_##TYPE##_OFFSET &&\
160 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
161 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
213 snprintf(ap, 14,
"Unknown-%d", val);
221 uint64_t component_len;
222 if (!sep) sep =
", ";
223 component_len = 15LL + strlen(sep);
224 if (count >= (INT_MAX - 1)/component_len)
226 ap =
av_malloc(component_len * count + 1);
231 for (i = 0; i < count; i++) {
232 unsigned l =
snprintf(ap, component_len,
"%f%s", dp[i], sep);
233 if(l >= component_len) {
239 ap0[strlen(ap0) - strlen(sep)] =
'\0';
247 uint64_t component_len;
248 if (!sep) sep =
", ";
249 component_len = 7LL + strlen(sep);
250 if (count >= (INT_MAX - 1)/component_len)
252 ap =
av_malloc(component_len * count + 1);
257 for (i = 0; i < count; i++) {
258 unsigned l =
snprintf(ap, component_len,
"%d%s", sp[i], sep);
259 if (l >= component_len) {
265 ap0[strlen(ap0) - strlen(sep)] =
'\0';
270 const char *
name,
const char *sep,
277 if (count >= INT_MAX /
sizeof(int64_t) || count <= 0)
286 for (i = 0; i < count; i++)
303 if (count >= INT_MAX /
sizeof(int16_t) || count <= 0)
312 for (i = 0; i < count; i++)
356 z_stream zstream = { 0 };
359 zstream.next_in = (
uint8_t *)src;
360 zstream.avail_in =
size;
361 zstream.next_out =
dst;
362 zstream.avail_out = *
len;
363 zret = inflateInit(&zstream);
368 zret = inflate(&zstream, Z_SYNC_FLUSH);
369 inflateEnd(&zstream);
370 *len = zstream.total_out;
371 return zret == Z_STREAM_END ? Z_OK : zret;
376 int usePtr,
const uint8_t *src,
381 while (--width >= 0) {
382 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
383 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
384 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
385 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
386 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
387 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
388 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
389 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
393 while (--width >= 0) {
394 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
395 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
396 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
397 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
401 while (--width >= 0) {
402 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
403 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
408 memcpy(dst + offset, src, width);
410 memset(dst + offset, c, width);
416 const uint8_t *src,
int size,
int lines)
418 int c,
line, pixels, code, ret;
428 unsigned long outlen;
430 outlen = width * lines;
441 for (i = 0; i <
size; i++)
446 ret = tiff_uncompress(zbuf, &outlen, src, size);
449 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
450 (
unsigned long)width * lines, ret);
456 for (line = 0; line < lines; line++) {
460 memcpy(dst, src, width);
476 for (i = 0; i <
size; i++)
481 if (size > 1 && !src[0] && (src[1]&1)) {
497 "Error allocating temporary buffer\n");
502 "Uncompressed fax mode is not supported (yet)\n");
507 memcpy(src2, src, size);
509 for (i = 0; i <
size; i++)
522 for (line = 0; line < lines; line++) {
529 for (line = 0; line < lines; line++) {
530 if (src - ssrc > size) {
536 if (ssrc + size - src < width)
540 dst, 1, src, 0, width, 0);
543 for (i = 0; i <
width; i++)
549 for (pixels = 0; pixels <
width;) {
550 if (ssrc + size - src < 2) {
554 code = (int8_t) * src++;
557 if (pixels + code > width) {
559 "Copy went out of bounds\n");
562 if (ssrc + size - src < code) {
567 dst, 1, src, 0, code, pixels);
570 }
else if (code != -128) {
572 if (pixels + code > width) {
574 "Run went out of bounds\n");
579 dst, 0,
NULL, c, code, pixels);
586 if (pixels < width) {
636 "This format is not supported (bpp=%d, bppcount=%d)\n",
657 for (i = 0; i < 1<<s->
bpp; i++)
658 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
667 int i, j, k, pos, start;
704 if (count <= 4 &&
type_sizes[type] * count <= 4) {
722 "This format is not supported (bpp=%d, %d components)\n",
731 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
732 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
739 for (i = 0; i < count; i++)
750 "Samples per pixel requires a single value, many provided\n");
755 "Samples per pixel %d is too large\n", value);
786 "JPEG compression is not supported\n");
795 if (type ==
TIFF_LONG && value == UINT_MAX)
799 "Incorrect value of rows per strip\n");
816 "Tag referencing position outside the image\n");
832 "Tag referencing position outside the image\n");
864 if (value < 1 || value > 2) {
866 "Unknown FillOrder value %d, trying default one\n", value);
877 for (k = 2; k >= 0; k--) {
878 for (i = 0; i < count / 3; i++) {
880 pal[i] = 0xFF
U << 24;
901 #define ADD_METADATA(count, name, sep)\
902 if ((ret = add_metadata(count, type, name, sep, s)) < 0) {\
903 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
945 if (count >= INT_MAX /
sizeof(int64_t))
954 for (i = 0; i < count; i++)
1050 unsigned soff, ssize;
1058 if (avpkt->
size < 8)
1060 id = bytestream2_get_le16u(&s->
gb);
1063 else if (
id == 0x4D4D)
1084 "The answer to life, universe and everything is not correct!\n");
1091 if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1099 for (i = 0; i < entries; i++) {
1152 for (i = 0; i < s->
height; i += s->
rps) {
1163 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1175 ssize = s->
width * soff;
1178 for (i = 0; i < s->
height; i++) {
1179 for (j = soff; j < ssize; j += 2)
1185 for (i = 0; i < s->
height; i++) {
1186 for (j = soff; j < ssize; j += 2)
1191 for (i = 0; i < s->
height; i++) {
1192 for (j = soff; j < ssize; j++)
1193 dst[j] += dst[j - soff];
1201 for (i = 0; i < s->
height; i++) {