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;
154 #define RET_GEOKEY_VAL(TYPE, array)\
155 if (val >= TIFF_##TYPE##_OFFSET &&\
156 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
157 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
207 snprintf(ap, 14,
"Unknown-%d", val);
215 uint64_t component_len;
216 if (!sep) sep =
", ";
217 component_len = 15LL + strlen(sep);
218 if (count >= (INT_MAX - 1)/component_len)
220 ap =
av_malloc(component_len * count + 1);
225 for (i = 0; i < count; i++) {
226 unsigned l =
snprintf(ap, component_len,
"%f%s", dp[i], sep);
227 if(l >= component_len) {
233 ap0[strlen(ap0) - strlen(sep)] =
'\0';
241 uint64_t component_len;
242 if (!sep) sep =
", ";
243 component_len = 7LL + strlen(sep);
244 if (count >= (INT_MAX - 1)/component_len)
246 ap =
av_malloc(component_len * count + 1);
251 for (i = 0; i < count; i++) {
252 unsigned l =
snprintf(ap, component_len,
"%d%s", sp[i], sep);
253 if (l >= component_len) {
259 ap0[strlen(ap0) - strlen(sep)] =
'\0';
264 const char *
name,
const char *sep,
271 if (count >= INT_MAX /
sizeof(int64_t) || count <= 0)
280 for (i = 0; i < count; i++)
297 if (count >= INT_MAX /
sizeof(int16_t) || count <= 0)
306 for (i = 0; i < count; i++)
350 z_stream zstream = { 0 };
353 zstream.next_in = (
uint8_t *)src;
354 zstream.avail_in =
size;
355 zstream.next_out =
dst;
356 zstream.avail_out = *
len;
357 zret = inflateInit(&zstream);
362 zret = inflate(&zstream, Z_SYNC_FLUSH);
363 inflateEnd(&zstream);
364 *len = zstream.total_out;
365 return zret == Z_STREAM_END ? Z_OK : zret;
370 int usePtr,
const uint8_t *src,
375 while (--width >= 0) {
376 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
377 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
378 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
379 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
380 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
381 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
382 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
383 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
387 while (--width >= 0) {
388 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
389 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
390 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
391 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
395 while (--width >= 0) {
396 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
397 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
402 memcpy(dst + offset, src, width);
404 memset(dst + offset, c, width);
410 const uint8_t *src,
int size,
int lines)
412 int c,
line, pixels, code;
422 unsigned long outlen;
424 outlen = width * lines;
435 for (i = 0; i <
size; i++)
440 ret = tiff_uncompress(zbuf, &outlen, src, size);
443 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
444 (
unsigned long)width * lines, ret);
450 for (line = 0; line < lines; line++) {
454 memcpy(dst, src, width);
470 for (i = 0; i <
size; i++)
475 if (size > 1 && !src[0] && (src[1]&1)) {
491 "Error allocating temporary buffer\n");
496 "Uncompressed fax mode is not supported (yet)\n");
501 memcpy(src2, src, size);
503 for (i = 0; i <
size; i++)
516 for (line = 0; line < lines; line++) {
523 for (line = 0; line < lines; line++) {
524 if (src - ssrc > size) {
530 if (ssrc + size - src < width)
534 dst, 1, src, 0, width, 0);
537 for (i = 0; i <
width; i++)
543 for (pixels = 0; pixels <
width;) {
544 if (ssrc + size - src < 2) {
548 code = (int8_t) * src++;
551 if (pixels + code > width) {
553 "Copy went out of bounds\n");
556 if (ssrc + size - src < code) {
561 dst, 1, src, 0, code, pixels);
564 }
else if (code != -128) {
566 if (pixels + code > width) {
568 "Run went out of bounds\n");
573 dst, 0,
NULL, c, code, pixels);
580 if (pixels < width) {
630 "This format is not supported (bpp=%d, bppcount=%d)\n",
651 for (i = 0; i < 1<<s->
bpp; i++)
652 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
661 int i, j, k, pos, start;
698 if (count <= 4 &&
type_sizes[type] * count <= 4) {
716 "This format is not supported (bpp=%d, %d components)\n",
725 s->
bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
726 ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
733 for (i = 0; i < count; i++)
744 "Samples per pixel requires a single value, many provided\n");
775 "JPEG compression is not supported\n");
784 if (type ==
TIFF_LONG && value == UINT_MAX)
788 "Incorrect value of rows per strip\n");
805 "Tag referencing position outside the image\n");
821 "Tag referencing position outside the image\n");
853 if (value < 1 || value > 2) {
855 "Unknown FillOrder value %d, trying default one\n", value);
866 for (k = 2; k >= 0; k--) {
867 for (i = 0; i < count / 3; i++) {
869 pal[i] = 0xFF
U << 24;
890 #define ADD_METADATA(count, name, sep)\
891 if ((ret = add_metadata(count, type, name, sep, s)) < 0) {\
892 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
931 if (count >= INT_MAX /
sizeof(int64_t))
940 for (i = 0; i < count; i++)
1036 unsigned soff, ssize;
1044 if (avpkt->
size < 8)
1046 id = bytestream2_get_le16u(&s->
gb);
1049 else if (
id == 0x4D4D)
1070 "The answer to life, universe and everything is not correct!\n");
1077 if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1085 for (i = 0; i < entries; i++) {
1138 for (i = 0; i < s->
height; i += s->
rps) {
1149 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1161 ssize = s->
width * soff;
1164 for (i = 0; i < s->
height; i++) {
1165 for (j = soff; j < ssize; j += 2)
1171 for (i = 0; i < s->
height; i++) {
1172 for (j = soff; j < ssize; j += 2)
1177 for (i = 0; i < s->
height; i++) {
1178 for (j = soff; j < ssize; j++)
1179 dst[j] += dst[j - soff];
1187 for (i = 0; i < s->
height; i++) {