92 #define RET_GEOKEY(TYPE, array, element)\
93 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
94 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
95 return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
140 #define RET_GEOKEY_VAL(TYPE, array)\
141 if (val >= TIFF_##TYPE##_OFFSET &&\
142 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
143 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
195 snprintf(ap, 14,
"Unknown-%d", val);
203 uint64_t component_len;
204 if (!sep) sep =
", ";
205 component_len = 24LL + strlen(sep);
206 if (count >= (INT_MAX - 1)/component_len)
208 ap =
av_malloc(component_len * count + 1);
213 for (i = 0; i <
count; i++) {
214 unsigned l =
snprintf(ap, component_len,
"%.15g%s", dp[i], sep);
215 if(l >= component_len) {
221 ap0[strlen(ap0) - strlen(sep)] =
'\0';
242 while (--width >= 0) {
243 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
244 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
245 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
246 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
247 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
248 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
249 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
250 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
254 while (--width >= 0) {
255 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
256 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
257 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
258 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
262 while (--width >= 0) {
263 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
264 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
269 memcpy(dst + offset, src, width);
271 memset(dst + offset, c, width);
283 for (i = 0; i <
size; i++)
297 for (i = 0; i < w; i++) {
306 for (i = 0; i < w; i++) {
321 z_stream zstream = { 0 };
324 zstream.next_in = (
uint8_t *)src;
325 zstream.avail_in =
size;
326 zstream.next_out = dst;
327 zstream.avail_out = *
len;
328 zret = inflateInit(&zstream);
333 zret = inflate(&zstream, Z_SYNC_FLUSH);
334 inflateEnd(&zstream);
335 *len = zstream.total_out;
336 return zret == Z_STREAM_END ? Z_OK : zret;
341 int strip_start,
int is_yuv)
344 unsigned long outlen;
346 outlen = width * lines;
357 ret = tiff_uncompress(zbuf, &outlen, src, size);
360 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
361 (
unsigned long)width * lines, ret);
366 for (line = 0; line < lines; line++) {
370 memcpy(dst, src, width);
385 static int tiff_uncompress_lzma(
uint8_t *dst, uint64_t *len,
const uint8_t *src,
388 lzma_stream stream = LZMA_STREAM_INIT;
391 stream.next_in = (
uint8_t *)src;
392 stream.avail_in =
size;
393 stream.next_out = dst;
394 stream.avail_out = *
len;
395 ret = lzma_stream_decoder(&stream, UINT64_MAX, 0);
396 if (ret != LZMA_OK) {
400 ret = lzma_code(&stream, LZMA_RUN);
402 *len = stream.total_out;
403 return ret == LZMA_STREAM_END ? LZMA_OK :
ret;
407 const uint8_t *src,
int size,
int width,
int lines,
408 int strip_start,
int is_yuv)
410 uint64_t outlen = width * lines;
422 ret = tiff_uncompress_lzma(buf, &outlen, src, size);
423 if (ret != LZMA_OK) {
425 "Uncompressing failed (%"PRIu64
" of %"PRIu64
") with error %d\n", outlen,
426 (uint64_t)width * lines, ret);
431 for (line = 0; line < lines; line++) {
435 memcpy(dst, src, width);
450 const uint8_t *src,
int size,
int width,
int lines)
459 "Error allocating temporary buffer\n");
468 memcpy(src2, src, size);
470 for (i = 0; i <
size; i++)
477 for (line = 0; line < lines; line++) {
486 const uint8_t *src,
int size,
int strip_start,
int lines)
489 int c, line, pixels, code,
ret;
491 int width = ((s->
width * s->
bpp) + 7) >> 3;
520 return tiff_unpack_zlib(s, p, dst, stride, src, size, width, lines,
521 strip_start, is_yuv);
524 "zlib support not enabled, "
525 "deflate compression not supported\n");
531 return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,
532 strip_start, is_yuv);
535 "LZMA support not enabled\n");
545 if (size > 1 && !src[0] && (src[1]&1)) {
552 for (line = 0; line < lines; line++) {
554 if (pixels < width) {
581 for (line = 0; line < lines; line++) {
582 if (src - ssrc > size) {
592 if (ssrc + size - src < width)
597 dst, 1, src, 0, width, 0);
600 for (i = 0; i <
width; i++)
606 for (pixels = 0; pixels <
width;) {
607 if (ssrc + size - src < 2) {
614 if (pixels + code > width ||
615 ssrc + size - src < code) {
617 "Copy went out of bounds\n");
621 dst, 1, src, 0, code, pixels);
624 }
else if (code != -128) {
626 if (pixels + code > width) {
628 "Run went out of bounds\n");
633 dst, 0, NULL, c, code, pixels);
639 for (i = 0; i <
width; i++)
656 int create_gray_palette = 0;
668 create_gray_palette = 1;
727 "This format is not supported (bpp=%d, bppcount=%d)\n",
750 if (!create_gray_palette)
755 uint32_t *pal = (uint32_t *)frame->
f->
data[1];
756 for (i = 0; i < 1<<s->
bpp; i++)
757 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
766 s->
res[offset++] = num;
770 s->
res[2] * (uint64_t)s->
res[1], s->
res[0] * (uint64_t)s->
res[3], INT32_MAX);
818 "This format is not supported (bpp=%d, %d components)\n",
832 for (i = 0; i <
count; i++)
843 "Samples per pixel requires a single value, many provided\n");
848 "Samples per pixel %d is too large\n", value);
894 if (!value || (type ==
TIFF_LONG && value == UINT_MAX))
922 set_sar(s, tag, value, value2);
953 "PhotometricInterpretation 0x%04X",
965 "Unknown FillOrder value %d, trying default one\n", value);
973 if (count / 3 > 256 ||
977 pal_gb[0] = pal_gb[1] = pal_gb[2] = s->
gb;
982 for (i = 0; i < count / 3; i++) {
983 uint32_t p = 0xFF000000;
984 p |= (
ff_tget(&pal_gb[0], type, s->
le) >> off) << 16;
985 p |= (
ff_tget(&pal_gb[1], type, s->
le) >> off) << 8;
986 p |=
ff_tget(&pal_gb[2], type, s->
le) >> off;
1000 for (i = 0; i <
count; i++)
1011 #define ADD_METADATA(count, name, sep)\
1012 if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
1013 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
1055 if (count >= INT_MAX /
sizeof(int64_t))
1064 for (i = 0; i <
count; i++)
1145 "Unknown or unsupported tag %d/0X%0X\n",
1162 int le,
ret, plane, planes;
1163 int i, j, entries, stride;
1164 unsigned soff, ssize;
1175 }
else if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1194 for (i = 0; i < entries; i++) {
1248 for (plane = 0; plane < planes; plane++) {
1250 dst = p->
data[plane];
1251 for (i = 0; i < s->
height; i += s->
rps) {
1262 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1272 dst += s->
rps * stride;
1279 dst = p->
data[plane];
1283 ssize = s->
width * soff;
1288 for (i = 0; i < s->
height; i++) {
1289 for (j = soff; j < ssize; j += 2)
1297 for (i = 0; i < s->
height; i++) {
1298 for (j = soff; j < ssize; j += 2)
1303 for (i = 0; i < s->
height; i++) {
1304 for (j = soff; j < ssize; j++)
1305 dst[j] += dst[j - soff];
1312 dst = p->
data[plane];
1313 for (i = 0; i < s->
height; i++) {
1314 for (j = 0; j < p->
linesize[plane]; j++)