89 #define RET_GEOKEY(TYPE, array, element)\ 
   90     if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\ 
   91         key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\ 
   92         return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element; 
  137 #define RET_GEOKEY_VAL(TYPE, array)\ 
  138     if (val >= TIFF_##TYPE##_OFFSET &&\ 
  139         val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\ 
  140         return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]); 
  192         snprintf(ap, 14, 
"Unknown-%d", val);
 
  200     uint64_t component_len;
 
  201     if (!sep) sep = 
", ";
 
  202     component_len = 24LL + strlen(sep);
 
  203     if (count >= (INT_MAX - 1)/component_len)
 
  205     ap = 
av_malloc(component_len * count + 1);
 
  210     for (i = 0; i < 
count; i++) {
 
  211         unsigned l = 
snprintf(ap, component_len, 
"%.15g%s", dp[i], sep);
 
  212         if(l >= component_len) {
 
  218     ap0[strlen(ap0) - strlen(sep)] = 
'\0';
 
  239         while (--width >= 0) {
 
  240             dst[(width+
offset)*8+7] = (usePtr ? src[width] : c)      & 0x1;
 
  241             dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
 
  242             dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
 
  243             dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
 
  244             dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
 
  245             dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
 
  246             dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
 
  247             dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
 
  251         while (--width >= 0) {
 
  252             dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
 
  253             dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
 
  254             dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
 
  255             dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
 
  259         while (--width >= 0) {
 
  260             dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
 
  261             dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
 
  266             memcpy(dst + offset, src, width);
 
  268             memset(dst + offset, c, width);
 
  280     for (i = 0; i < 
size; i++)
 
  290     z_stream zstream = { 0 };
 
  293     zstream.next_in   = (
uint8_t *)src;
 
  294     zstream.avail_in  = 
size;
 
  295     zstream.next_out  = dst;
 
  296     zstream.avail_out = *
len;
 
  297     zret              = inflateInit(&zstream);
 
  302     zret = inflate(&zstream, Z_SYNC_FLUSH);
 
  303     inflateEnd(&zstream);
 
  304     *len = zstream.total_out;
 
  305     return zret == Z_STREAM_END ? Z_OK : zret;
 
  310                             int width, 
int lines)
 
  313     unsigned long outlen;
 
  315     outlen = width * lines;
 
  326     ret = tiff_uncompress(zbuf, &outlen, src, size);
 
  329                "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
 
  330                (
unsigned long)width * lines, ret);
 
  335     for (line = 0; line < lines; line++) {
 
  339             memcpy(dst, src, width);
 
  351                            const uint8_t *src, 
int size, 
int width, 
int lines)
 
  360                "Error allocating temporary buffer\n");
 
  369         memcpy(src2, src, size);
 
  371         for (i = 0; i < 
size; i++)
 
  378         for (line = 0; line < lines; line++) {
 
  394         for (i = 0; i < w; i++) {
 
  403         for (i = 0; i < w; i++) {
 
  416                              const uint8_t *src, 
int size, 
int strip_start, 
int lines)
 
  419     int c, line, pixels, code, 
ret;
 
  421     int width = ((s->
width * s->
bpp) + 7) >> 3;
 
  451         return tiff_unpack_zlib(s, dst, stride, src, size, width, lines);
 
  454                "zlib support not enabled, " 
  455                "deflate compression not supported\n");
 
  465         if (size > 1 && !src[0] && (src[1]&1)) {
 
  472         for (line = 0; line < lines; line++) {
 
  474             if (pixels < width) {
 
  501     for (line = 0; line < lines; line++) {
 
  502         if (src - ssrc > size) {
 
  512             if (ssrc + size - src < width)
 
  517                                 dst, 1, src, 0, width, 0);
 
  520                 for (i = 0; i < 
width; i++)
 
  526             for (pixels = 0; pixels < 
width;) {
 
  527                 if (ssrc + size - src < 2) {
 
  534                     if (pixels + code > width ||
 
  535                         ssrc + size - src < code) {
 
  537                                "Copy went out of bounds\n");
 
  541                                     dst, 1, src, 0, code, pixels);
 
  544                 } 
else if (code != -128) { 
 
  546                     if (pixels + code > width) {
 
  548                                "Run went out of bounds\n");
 
  553                                     dst, 0, NULL, c, code, pixels);
 
  559                 for (i = 0; i < 
width; i++)
 
  639                "This format is not supported (bpp=%d, bppcount=%d)\n",
 
  655             pal = (uint32_t *) frame->
f->
data[1];
 
  656             for (i = 0; i < 1<<s->
bpp; i++)
 
  657                 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
 
  666     s->
res[offset++] = num;
 
  670                   s->
res[2] * (uint64_t)s->
res[1], s->
res[0] * (uint64_t)s->
res[3], INT32_MAX);
 
  718                    "This format is not supported (bpp=%d, %d components)\n",
 
  732                 for (i = 0; i < 
count; i++)
 
  743                    "Samples per pixel requires a single value, many provided\n");
 
  748                    "Samples per pixel %d is too large\n", value);
 
  787         if (!value || (type == 
TIFF_LONG && value == UINT_MAX))
 
  815         set_sar(s, tag, value, value2);
 
  846                                           "PhotometricInterpretation 0x%04X",
 
  858                    "Unknown FillOrder value %d, trying default one\n", value);
 
  866         if (count / 3 > 256 ||
 
  870         pal_gb[0] = pal_gb[1] = pal_gb[2] = s->
gb;
 
  875         for (i = 0; i < count / 3; i++) {
 
  876             uint32_t p = 0xFF000000;
 
  877             p |= (
ff_tget(&pal_gb[0], type, s->
le) >> off) << 16;
 
  878             p |= (
ff_tget(&pal_gb[1], type, s->
le) >> off) << 8;
 
  879             p |=  
ff_tget(&pal_gb[2], type, s->
le) >> off;
 
  893         for (i = 0; i < 
count; i++)
 
  904 #define ADD_METADATA(count, name, sep)\ 
  905     if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\ 
  906         av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\ 
  948         if (count >= INT_MAX / 
sizeof(int64_t))
 
  957         for (i = 0; i < 
count; i++)
 
 1038                    "Unknown or unsupported tag %d/0X%0X\n",
 
 1055     int le, 
ret, plane, planes;
 
 1056     int i, j, entries, stride;
 
 1057     unsigned soff, ssize;
 
 1068     } 
else if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
 
 1087     for (i = 0; i < entries; i++) {
 
 1141     for (plane = 0; plane < planes; plane++) {
 
 1143         dst    = p->
data[plane];
 
 1144     for (i = 0; i < s->
height; i += s->
rps) {
 
 1155         if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
 
 1165         dst += s->
rps * stride;
 
 1172         dst   = p->
data[plane];
 
 1176         ssize = s->
width * soff;
 
 1181             for (i = 0; i < s->
height; i++) {
 
 1182                 for (j = soff; j < ssize; j += 2)
 
 1190             for (i = 0; i < s->
height; i++) {
 
 1191                 for (j = soff; j < ssize; j += 2)
 
 1196             for (i = 0; i < s->
height; i++) {
 
 1197                 for (j = soff; j < ssize; j++)
 
 1198                     dst[j] += dst[j - soff];
 
 1205         dst = p->
data[plane];
 
 1206         for (i = 0; i < s->
height; i++) {
 
 1207             for (j = 0; j < p->
linesize[plane]; j++)