84 #define RET_GEOKEY(TYPE, array, element)\
85 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
86 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
87 return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
132 #define RET_GEOKEY_VAL(TYPE, array)\
133 if (val >= TIFF_##TYPE##_OFFSET &&\
134 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
135 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
187 snprintf(ap, 14,
"Unknown-%d", val);
195 uint64_t component_len;
196 if (!sep) sep =
", ";
197 component_len = 15LL + strlen(sep);
198 if (count >= (INT_MAX - 1)/component_len)
200 ap =
av_malloc(component_len * count + 1);
205 for (i = 0; i <
count; i++) {
206 unsigned l =
snprintf(ap, component_len,
"%f%s", dp[i], sep);
207 if(l >= component_len) {
213 ap0[strlen(ap0) - strlen(sep)] =
'\0';
234 while (--width >= 0) {
235 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
236 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
237 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
238 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
239 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
240 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
241 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
242 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
246 while (--width >= 0) {
247 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
248 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
249 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
250 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
254 while (--width >= 0) {
255 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
256 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
261 memcpy(dst + offset, src, width);
263 memset(dst + offset, c, width);
275 for (i = 0; i <
size; i++)
285 z_stream zstream = { 0 };
288 zstream.next_in = (
uint8_t *)src;
289 zstream.avail_in =
size;
290 zstream.next_out = dst;
291 zstream.avail_out = *
len;
292 zret = inflateInit(&zstream);
297 zret = inflate(&zstream, Z_SYNC_FLUSH);
298 inflateEnd(&zstream);
299 *len = zstream.total_out;
300 return zret == Z_STREAM_END ? Z_OK : zret;
305 int width,
int lines)
308 unsigned long outlen;
310 outlen = width * lines;
321 ret = tiff_uncompress(zbuf, &outlen, src, size);
324 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
325 (
unsigned long)width * lines, ret);
330 for (line = 0; line < lines; line++) {
334 memcpy(dst, src, width);
346 const uint8_t *src,
int size,
int width,
int lines)
355 "Error allocating temporary buffer\n");
364 memcpy(src2, src, size);
366 for (i = 0; i <
size; i++)
373 for (line = 0; line < lines; line++) {
382 const uint8_t *src,
int size,
int lines)
384 int c, line, pixels, code,
ret;
386 int width = ((s->
width * s->
bpp) + 7) >> 3;
396 return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
399 "zlib support not enabled, "
400 "deflate compression not supported\n");
410 if (size > 1 && !src[0] && (src[1]&1)) {
423 for (line = 0; line < lines; line++) {
424 if (src - ssrc > size) {
430 if (ssrc + size - src < width)
434 dst, 1, src, 0, width, 0);
437 for (i = 0; i <
width; i++)
443 for (pixels = 0; pixels <
width;) {
444 if (ssrc + size - src < 2) {
451 if (pixels + code > width ||
452 ssrc + size - src < code) {
454 "Copy went out of bounds\n");
458 dst, 1, src, 0, code, pixels);
461 }
else if (code != -128) {
463 if (pixels + code > width) {
465 "Run went out of bounds\n");
470 dst, 0, NULL, c, code, pixels);
476 for (i = 0; i <
width; i++)
482 if (pixels < width) {
544 "This format is not supported (bpp=%d, bppcount=%d)\n",
560 pal = (uint32_t *) frame->
f->
data[1];
561 for (i = 0; i < 1<<s->
bpp; i++)
562 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
571 int i, j, k, pos,
start;
609 "This format is not supported (bpp=%d, %d components)\n",
623 for (i = 0; i <
count; i++)
634 "Samples per pixel requires a single value, many provided\n");
639 "Samples per pixel %d is too large\n", value);
678 if (type ==
TIFF_LONG && value == UINT_MAX)
682 "Incorrect value of rows per strip\n");
699 "Tag referencing position outside the image\n");
715 "Tag referencing position outside the image\n");
747 if (value < 1 || value > 2) {
749 "Unknown FillOrder value %d, trying default one\n", value);
760 for (k = 2; k >= 0; k--) {
761 for (i = 0; i < count / 3; i++) {
763 pal[i] = 0xFF
U << 24;
781 #define ADD_METADATA(count, name, sep)\
782 if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
783 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
825 if (count >= INT_MAX /
sizeof(int64_t))
834 for (i = 0; i <
count; i++)
915 "Unknown or unsupported tag %d/0X%0X\n",
932 int le,
ret, plane, planes;
933 int i, j, entries,
stride;
934 unsigned soff, ssize;
945 }
else if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
964 for (i = 0; i < entries; i++) {
1016 for (plane = 0; plane < planes; plane++) {
1018 dst = p->
data[plane];
1019 for (i = 0; i < s->
height; i += s->
rps) {
1030 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1043 dst = p->
data[plane];
1047 ssize = s->
width * soff;
1052 for (i = 0; i < s->
height; i++) {
1053 for (j = soff; j < ssize; j += 2)
1061 for (i = 0; i < s->
height; i++) {
1062 for (j = soff; j < ssize; j += 2)
1067 for (i = 0; i < s->
height; i++) {
1068 for (j = soff; j < ssize; j++)
1069 dst[j] += dst[j - soff];
1076 dst = p->
data[plane];
1077 for (i = 0; i < s->
height; i++) {
1078 for (j = 0; j < p->
linesize[plane]; j++)