32 #define LZMA_API_STATIC
118 if (
s->tiff_type < tiff_type)
119 s->tiff_type = tiff_type;
125 for (
i = 0;
i <
s->geotag_count;
i++) {
126 if (
s->geotags[
i].val)
133 #define RET_GEOKEY(TYPE, array, element)\
134 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
135 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
136 return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
181 #define RET_GEOKEY_VAL(TYPE, array)\
182 if (val >= TIFF_##TYPE##_OFFSET &&\
183 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_codes))\
184 return av_strdup(tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
244 uint64_t component_len;
245 if (!sep) sep =
", ";
246 component_len = 24LL + strlen(sep);
247 if (count >= (INT_MAX - 1)/component_len)
249 ap =
av_malloc(component_len * count + 1);
254 for (
i = 0;
i < count;
i++) {
255 unsigned l =
snprintf(ap, component_len,
"%.15g%s", dp[
i], sep);
256 if(l >= component_len) {
262 ap0[strlen(ap0) - strlen(sep)] =
'\0';
282 uint16_t black_level,
295 value_norm = (float)
value * scale_factor;
304 uint16_t black_level,
312 int is_single_comp,
int is_u16)
317 scale_factor = 1.0f / (
s->white_level -
s->black_level);
319 if (is_single_comp) {
326 uint16_t *dst_u16 = (uint16_t *)dst;
327 uint16_t *src_u16 = (uint16_t *)
src;
330 for (col = 0; col <
width; col++)
334 dst += dst_stride *
sizeof(uint16_t);
335 dst_u16 = (uint16_t *)dst;
338 for (col = 0; col <
width; col++)
341 dst += dst_stride *
sizeof(uint16_t);
342 src += src_stride *
sizeof(uint16_t);
349 uint16_t *dst_u16 = (uint16_t *)dst;
350 uint16_t *src_u16 = (uint16_t *)
src;
352 for (col = 0; col <
width; col++)
355 dst += dst_stride *
sizeof(uint16_t);
356 src += src_stride *
sizeof(uint16_t);
363 for (col = 0; col <
width; col++)
374 unsigned int bpp,
uint8_t* dst,
380 while (--
width >= 0) {
392 while (--
width >= 0) {
400 while (--
width >= 0) {
408 uint16_t *dst16 = (uint16_t *)dst;
414 for (
int i = 0;
i <
s->width;
i++) {
433 if (!
s->deinvert_buf)
445 uint16_t *dst = (uint16_t *)(p->
data[0] + lnum * p->
linesize[0]);
449 for (
int i = 0;
i <
s->width;
i++) {
458 int w = (
s->width - 1) /
s->subsampling[0] + 1;
461 if (
s->width %
s->subsampling[0] ||
s->height %
s->subsampling[1]) {
462 for (
i = 0;
i <
w;
i++) {
463 for (j = 0; j <
s->subsampling[1]; j++)
464 for (k = 0; k <
s->subsampling[0]; k++)
466 FFMIN(
i *
s->subsampling[0] + k,
s->width-1)] = *
src++;
471 for (
i = 0;
i <
w;
i++) {
472 for (j = 0; j <
s->subsampling[1]; j++)
473 for (k = 0; k <
s->subsampling[0]; k++)
475 i *
s->subsampling[0] + k] = *
src++;
486 z_stream zstream = { 0 };
489 zstream.next_in =
src;
490 zstream.avail_in =
size;
491 zstream.next_out = dst;
492 zstream.avail_out = *
len;
493 zret = inflateInit(&zstream);
498 zret =
inflate(&zstream, Z_SYNC_FLUSH);
499 inflateEnd(&zstream);
500 *
len = zstream.total_out;
501 return zret == Z_STREAM_END ? Z_OK : zret;
506 int strip_start,
int is_yuv)
509 unsigned long outlen;
511 outlen =
width * lines;
520 src =
s->deinvert_buf;
522 ret = tiff_uncompress(zbuf, &outlen,
src,
size);
525 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
526 (
unsigned long)
width * lines, ret);
539 line +=
s->subsampling[1] - 1;
553 lzma_stream stream = LZMA_STREAM_INIT;
557 stream.avail_in =
size;
558 stream.next_out = dst;
559 stream.avail_out = *
len;
560 ret = lzma_stream_decoder(&stream, UINT64_MAX, 0);
561 if (ret != LZMA_OK) {
565 ret = lzma_code(&stream, LZMA_RUN);
567 *
len = stream.total_out;
568 return ret == LZMA_STREAM_END ? LZMA_OK : ret;
573 int strip_start,
int is_yuv)
575 uint64_t outlen =
width * (uint64_t)lines;
585 src =
s->deinvert_buf;
587 ret = tiff_uncompress_lzma(buf, &outlen,
src,
size);
588 if (ret != LZMA_OK) {
590 "Uncompressing failed (%"PRIu64
" of %"PRIu64
") with error %d\n", outlen,
591 (uint64_t)
width * lines, ret);
604 line +=
s->subsampling[1] - 1;
622 src2 =
s->fax_buffer;
626 "Error allocating temporary buffer\n");
630 if (!
s->fill_order) {
638 s->compr,
s->fax_opts);
648 int tile_byte_count,
int dst_x,
int dst_y,
int w,
int h)
653 int is_single_comp, is_u16, pixel_size;
662 s->jpkt->size = tile_byte_count;
668 mjpegdecctx->
bayer = 1;
688 is_u16 = (
s->bpp > 8);
692 if (
s->jpgframe->width !=
s->avctx_mjpeg->width ||
693 s->jpgframe->height !=
s->avctx_mjpeg->height ||
694 s->jpgframe->format !=
s->avctx_mjpeg->pix_fmt)
698 if (
s->avctx_mjpeg->width ==
w * 2 &&
699 s->avctx_mjpeg->height ==
h / 2 &&
702 }
else if (
s->avctx_mjpeg->width >=
w &&
703 s->avctx_mjpeg->height >=
h &&
710 pixel_size = (is_u16 ?
sizeof(uint16_t) :
sizeof(
uint8_t));
712 if (is_single_comp && !is_u16) {
718 dst_offset = dst_x +
frame->
linesize[0] * dst_y / pixel_size;
719 dst_data =
frame->
data[0] + dst_offset * pixel_size;
720 src_data =
s->jpgframe->data[0];
726 s->jpgframe->linesize[0] / pixel_size,
743 int width = ((
s->width *
s->bpp) + 7) >> 3;
747 desc->nb_components >= 3;
757 int bytes_per_row = (((
s->width - 1) /
s->subsampling[0] + 1) *
s->bpp *
758 s->subsampling[0] *
s->subsampling[1] + 7) >> 3;
760 if (
s->yuv_line ==
NULL) {
767 width = (
s->width - 1) /
s->subsampling[0] + 1;
778 if (
s->yuv_line ==
NULL) {
789 strip_start, is_yuv);
792 "zlib support not enabled, "
793 "deflate compression not supported\n");
800 strip_start, is_yuv);
803 "LZMA support not enabled\n");
811 ssrc =
src =
s->deinvert_buf;
822 if (pixels <
width) {
831 line +=
s->subsampling[1] - 1;
866 if (is_dng &&
stride == 0)
883 if (!
s->fill_order) {
894 int is_u16, pixel_size_bytes, pixel_size_bits,
elements;
896 is_u16 = (
s->bpp /
s->bppcount > 8);
897 pixel_size_bits = (is_u16 ? 16 : 8);
898 pixel_size_bytes = (is_u16 ?
sizeof(uint16_t) :
sizeof(
uint8_t));
900 elements =
width / pixel_size_bytes * pixel_size_bits /
s->bpp *
s->bppcount;
916 for (pixels = 0; pixels <
width;) {
927 "Copy went out of bounds\n");
934 }
else if (
code != -128) {
938 "Run went out of bounds\n");
956 line +=
s->subsampling[1] - 1;
970 int tile_offset_offset, tile_offset;
971 int tile_byte_count_offset, tile_byte_count;
972 int tile_count_x, tile_count_y;
973 int tile_width, tile_length;
974 int has_width_leftover, has_height_leftover;
975 int tile_x = 0, tile_y = 0;
976 int pos_x = 0, pos_y = 0;
979 if (
s->tile_width <= 0 ||
s->tile_length <= 0)
982 has_width_leftover = (
s->width %
s->tile_width != 0);
983 has_height_leftover = (
s->height %
s->tile_length != 0);
986 tile_count_x = (
s->width +
s->tile_width - 1) /
s->tile_width;
987 tile_count_y = (
s->height +
s->tile_length - 1) /
s->tile_length;
990 for (tile_idx = 0; tile_idx < tile_count_x * tile_count_y; tile_idx++) {
991 tile_x = tile_idx % tile_count_x;
992 tile_y = tile_idx / tile_count_x;
994 if (has_width_leftover && tile_x == tile_count_x - 1)
995 tile_width =
s->width %
s->tile_width;
997 tile_width =
s->tile_width;
999 if (has_height_leftover && tile_y == tile_count_y - 1)
1000 tile_length =
s->height %
s->tile_length;
1002 tile_length =
s->tile_length;
1005 tile_offset_offset =
s->tile_offsets_offset + tile_idx *
sizeof(
int);
1010 tile_byte_count_offset =
s->tile_byte_counts_offset + tile_idx *
sizeof(
int);
1024 pos_x += tile_width;
1025 if (tile_x == tile_count_x - 1) {
1027 pos_y += tile_length;
1041 int create_gray_palette = 0;
1044 if (
s->bpp >= 100 ||
s->bppcount >= 10) {
1046 "Unsupported image parameters: bpp=%d, bppcount=%d\n",
1047 s->bpp,
s->bppcount);
1051 switch (
s->planar * 1000 +
s->bpp * 10 +
s->bppcount +
s->is_bayer * 10000) {
1053 if (!
s->palette_is_set) {
1060 if (!
s->palette_is_set) {
1061 create_gray_palette = 1;
1115 if (
s->subsampling[0] == 1 &&
s->subsampling[1] == 1) {
1117 }
else if (
s->subsampling[0] == 2 &&
s->subsampling[1] == 1) {
1119 }
else if (
s->subsampling[0] == 4 &&
s->subsampling[1] == 1) {
1121 }
else if (
s->subsampling[0] == 1 &&
s->subsampling[1] == 2) {
1123 }
else if (
s->subsampling[0] == 2 &&
s->subsampling[1] == 2) {
1125 }
else if (
s->subsampling[0] == 4 &&
s->subsampling[1] == 4) {
1151 "bpp=40 without PHOTOMETRIC_SEPARATED is unsupported\n");
1175 "This format is not supported (bpp=%d, bppcount=%d)\n",
1176 s->bpp,
s->bppcount);
1184 desc->nb_components < 3) {
1190 if (
s->width !=
s->avctx->width ||
s->height !=
s->avctx->height) {
1198 if (!create_gray_palette)
1199 memcpy(
frame->f->
data[1],
s->palette,
sizeof(
s->palette));
1203 uint32_t *pal = (uint32_t *)
frame->f->
data[1];
1204 for (
i = 0;
i < 1<<
s->bpp;
i++)
1205 pal[
i] = 0xFFU << 24 |
i * 255 / ((1<<
s->bpp) - 1) * 0x010101;
1216 if (
s->res[0] &&
s->res[1] &&
s->res[2] &&
s->res[3]) {
1217 uint64_t num =
s->res[2] * (uint64_t)
s->res[1];
1218 uint64_t den =
s->res[0] * (uint64_t)
s->res[3];
1219 if (num > INT64_MAX || den > INT64_MAX) {
1223 av_reduce(&
s->avctx->sample_aspect_ratio.num, &
s->avctx->sample_aspect_ratio.den,
1224 num, den, INT32_MAX);
1225 if (!
s->avctx->sample_aspect_ratio.den)
1226 s->avctx->sample_aspect_ratio = (
AVRational) {0, 1};
1244 if (tag <= s->last_tag)
1279 s->is_thumbnail = (
value != 0);
1288 if (count > 5 || count <= 0) {
1290 "This format is not supported (bpp=%d, %d components)\n",
1294 s->bppcount = count;
1305 for (
i = 0;
i < count;
i++)
1316 "Samples per pixel requires a single value, many provided\n");
1321 "Invalid samples per pixel %d\n",
value);
1324 if (
s->bppcount == 1)
1374 if (
value > INT_MAX) {
1376 "strippos %u too large\n",
value);
1390 if (
value > INT_MAX) {
1392 "stripsize %u too large\n",
value);
1395 s->stripsizesoff = 0;
1399 s->stripsizesoff = off;
1409 s->tile_offsets_offset = off;
1413 s->tile_byte_counts_offset = off;
1433 for (
int i = 0;
i < count;
i++)
1446 s->black_level =
value / value2;
1451 s->black_level =
value / value2;
1490 "PhotometricInterpretation 0x%04X",
1495 "unknown\n",
value);
1500 if (value < 1 || value > 2) {
1502 "Unknown FillOrder value %d, trying default one\n",
value);
1505 s->fill_order =
value - 1;
1510 if (count / 3 > 256 ||
1514 pal_gb[0] = pal_gb[1] = pal_gb[2] =
s->gb;
1524 for (
i = 0;
i < count / 3;
i++) {
1525 uint32_t p = 0xFF000000;
1531 s->palette_is_set = 1;
1542 for (
i = 0;
i < count;
i++) {
1544 if (
s->subsampling[
i] <= 0) {
1546 s->subsampling[
i] = 1;
1559 #define ADD_METADATA(count, name, sep)\
1560 if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
1561 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
1574 if (
s->geotag_count) {
1581 if (
s->geotag_count > count / 4 - 1) {
1582 s->geotag_count = count / 4 - 1;
1586 ||
s->geotag_count == 0) {
1587 s->geotag_count = 0;
1593 s->geotag_count = 0;
1596 for (
i = 0;
i <
s->geotag_count;
i++) {
1601 if (!
s->geotags[
i].type)
1608 if (count >= INT_MAX /
sizeof(int64_t))
1617 for (
i = 0;
i < count;
i++)
1619 for (
i = 0;
i <
s->geotag_count;
i++) {
1621 if (
s->geotags[
i].count == 0
1622 ||
s->geotags[
i].offset +
s->geotags[
i].count > count) {
1624 }
else if (
s->geotags[
i].val) {
1627 char *ap =
doubles2str(&dp[
s->geotags[
i].offset],
s->geotags[
i].count,
", ");
1633 s->geotags[
i].val = ap;
1641 for (
i = 0;
i <
s->geotag_count;
i++) {
1643 if (
s->geotags[
i].count == 0
1644 ||
s->geotags[
i].offset +
s->geotags[
i].count > count) {
1652 if (
s->geotags[
i].val)
1660 ap[
s->geotags[
i].count - 1] =
'\0';
1661 s->geotags[
i].val = ap;
1713 bytestream2_seek(&
s->gb, count *
sizeof(uint16_t) -
sizeof(uint16_t), SEEK_CUR);
1720 unsigned int ver[4];
1727 ver[0], ver[1], ver[2], ver[3]);
1742 "Unknown or unsupported tag %d/0x%0X\n",
1750 "This format is not supported (bpp=%d, %d components)\n",
1765 unsigned off, last_off = 0;
1766 int le, ret, plane,
planes;
1768 unsigned soff, ssize;
1772 int retry_for_subifd, retry_for_page;
1774 int has_tile_bits, has_strip_bits;
1782 }
else if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1791 s->is_thumbnail = 0;
1792 s->bppcount =
s->bpp = 1;
1803 for (
i = 0;
i < 65536;
i++)
1809 s->stripsizesoff =
s->strippos = 0;
1815 for (
i = 0;
i < entries;
i++) {
1820 if (
s->get_thumbnail && !
s->is_thumbnail) {
1826 retry_for_subifd =
s->sub_ifd && (
s->get_subimage || (!
s->get_thumbnail &&
s->is_thumbnail));
1828 retry_for_page =
s->get_page &&
s->cur_page + 1 <
s->get_page;
1830 if (retry_for_page) {
1833 }
else if (retry_for_subifd) {
1838 if (retry_for_subifd || retry_for_page) {
1843 if (off <= last_off) {
1848 if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1860 for (
i = 0;
i<
s->geotag_count;
i++) {
1880 if (
s->bpp %
s->bppcount)
1882 bps =
s->bpp /
s->bppcount;
1883 if (bps < 8 || bps > 32)
1886 if (
s->white_level == 0)
1887 s->white_level = (1LL <<
bps) - 1;
1889 if (
s->white_level <=
s->black_level) {
1890 av_log(avctx,
AV_LOG_ERROR,
"BlackLevel (%"PRId32
") must be less than WhiteLevel (%"PRId32
")\n",
1891 s->black_level,
s->white_level);
1899 if (!
s->is_tiled && !
s->strippos && !
s->stripoff) {
1904 has_tile_bits =
s->is_tiled ||
s->tile_byte_counts_offset ||
s->tile_offsets_offset ||
s->tile_width ||
s->tile_length;
1905 has_strip_bits =
s->strippos ||
s->strips ||
s->stripoff ||
s->rps ||
s->sot ||
s->sstype ||
s->stripsize ||
s->stripsizesoff;
1907 if (has_tile_bits && has_strip_bits) {
1908 int tiled_dng =
s->is_tiled && is_dng;
1918 if (!
s->is_tiled || has_strip_bits) {
1919 if (
s->strips == 1 && !
s->stripsize) {
1921 s->stripsize = avpkt->
size -
s->stripoff;
1924 if (
s->stripsizesoff) {
1925 if (
s->stripsizesoff >= (
unsigned)avpkt->
size)
1928 avpkt->
size -
s->stripsizesoff);
1931 if (
s->strippos >= (
unsigned)avpkt->
size)
1934 avpkt->
size -
s->strippos);
1937 if (
s->rps <= 0 ||
s->rps %
s->subsampling[1]) {
1952 if (is_dng &&
s->is_tiled) {
1956 }
else if (!
s->is_bayer) {
1968 planes =
s->planar ?
s->bppcount : 1;
1969 for (plane = 0; plane <
planes; plane++) {
1971 int remaining = avpkt->
size;
1974 dst = p->
data[plane];
1983 for (
i = 0;
i <
s->height;
i +=
s->rps) {
1986 if (
s->stripsizesoff)
1987 ssize =
ff_tget(&stripsizes,
s->sstype, le);
1989 ssize =
s->stripsize;
1992 soff =
ff_tget(&stripdata,
s->sot, le);
1996 if (soff > avpkt->
size || ssize > avpkt->
size - soff || ssize > remaining) {
2003 FFMIN(
s->rps,
s->height -
i))) < 0) {
2011 decoded_height =
FFMIN(
i,
s->height);
2013 if (
s->predictor == 2) {
2018 dst = five_planes ? five_planes : p->
data[plane];
2021 soff =
FFMAX(soff /
s->bppcount, 1);
2022 ssize =
s->width * soff;
2029 for (
i = 0;
i < decoded_height;
i++) {
2030 for (j = soff; j < ssize; j += 2)
2040 for (
i = 0;
i < decoded_height;
i++) {
2041 for (j = soff; j < ssize; j += 2)
2046 for (
i = 0;
i < decoded_height;
i++) {
2047 for (j = soff; j < ssize; j++)
2048 dst[j] += dst[j - soff];
2056 dst = p->
data[plane];
2057 for (
i = 0;
i <
s->height;
i++) {
2058 for (j = 0; j <
stride; j++)
2059 dst[j] =
c - dst[j];
2068 dst = p->
data[plane];
2069 for (
i = 0;
i <
s->height;
i++) {
2070 for (j = 0; j <
s->width; j++) {
2071 int k = 255 -
src[x * j + 3];
2072 int r = (255 -
src[x * j ]) * k;
2073 int g = (255 -
src[x * j + 1]) * k;
2074 int b = (255 -
src[x * j + 2]) * k;
2075 dst[4 * j ] =
r * 257 >> 16;
2076 dst[4 * j + 1] =
g * 257 >> 16;
2077 dst[4 * j + 2] =
b * 257 >> 16;
2086 dst = p->
data[plane];
2087 for (
i = 0;
i <
s->height;
i++) {
2088 for (j = 0; j <
s->width; j++) {
2089 uint64_t k = 65535 -
AV_RB16(dst + 8 * j + 6);
2090 uint64_t
r = (65535 -
AV_RB16(dst + 8 * j )) * k;
2091 uint64_t
g = (65535 -
AV_RB16(dst + 8 * j + 2)) * k;
2092 uint64_t
b = (65535 -
AV_RB16(dst + 8 * j + 4)) * k;
2093 AV_WB16(dst + 8 * j ,
r * 65537 >> 32);
2094 AV_WB16(dst + 8 * j + 2,
g * 65537 >> 32);
2095 AV_WB16(dst + 8 * j + 4,
b * 65537 >> 32);
2096 AV_WB16(dst + 8 * j + 6, 65535);
2103 if (
s->planar &&
s->bppcount > 2) {
2110 if (
s->is_bayer &&
s->white_level &&
s->bpp == 16 && !is_dng) {
2111 uint16_t *dst = (uint16_t *)p->
data[0];
2112 for (
i = 0;
i <
s->height;
i++) {
2113 for (j = 0; j <
s->width; j++)
2114 dst[j] =
FFMIN((dst[j] / (
float)
s->white_level) * 65535, 65535);
2133 s->subsampling[1] = 1;
2143 if (!
s->jpgframe || !
s->jpkt)
2151 if (!
s->avctx_mjpeg)
2153 s->avctx_mjpeg->flags = avctx->
flags;
2154 s->avctx_mjpeg->flags2 = avctx->
flags2;
2155 s->avctx_mjpeg->dct_algo = avctx->
dct_algo;
2156 s->avctx_mjpeg->idct_algo = avctx->
idct_algo;
2174 s->deinvert_buf_size = 0;
2176 s->yuv_line_size = 0;
2178 s->fax_buffer_size = 0;
2185 #define OFFSET(x) offsetof(TiffContext, x)
static double val(void *priv, double ch)
Macro definitions for various function/variable attributes.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
#define FFSWAP(type, a, b)
static av_always_inline av_const uint16_t av_clip_uint16_c(int a)
Clip a signed integer value into the 0-65535 range.
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
av_cold void ff_ccitt_unpack_init(void)
initialize unpacker code
int ff_ccitt_unpack(AVCodecContext *avctx, const uint8_t *src, int srcsize, uint8_t *dst, int height, int stride, enum TiffCompr compr, int opts)
unpack data compressed with CCITT Group 3 1/2-D or Group 4 method
CCITT Fax Group 3 and 4 decompression.
bitstream reader API header.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, buffer_size_t size)
Add a new side data to a frame.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
char * av_strdup(const char *s)
Duplicate a string.
void * av_mallocz_array(size_t nmemb, size_t size)
Allocate a memory block for an array with av_mallocz().
@ AV_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
const uint8_t ff_reverse[256]
static const struct @322 planes[]
av_cold void ff_lzw_decode_close(LZWState **p)
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
int ff_lzw_decode(LZWState *p, uint8_t *buf, int len)
Decode given number of bytes NOTE: the algorithm here is inspired from the LZW GIF decoder written by...
av_cold void ff_lzw_decode_open(LZWState **p)
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
#define AV_OPT_FLAG_VIDEO_PARAM
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_PIX_FMT_BAYER_GRBG16
#define AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_BAYER_BGGR16
#define AV_PIX_FMT_BAYER_RGGB16
@ AV_PIX_FMT_BAYER_GBRG8
bayer, GBGB..(odd line), RGRG..(even line), 8-bit samples
@ AV_PIX_FMT_GRAY16BE
Y , 16bpp, big-endian.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YA16BE
16 bits gray, 16 bits alpha (big-endian)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
@ AV_PIX_FMT_RGB48BE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ AV_PIX_FMT_RGBA64BE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_RGBA64LE
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_GBRAP16BE
planar GBRA 4:4:4:4 64bpp, big-endian
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_BAYER_GRBG8
bayer, GRGR..(odd line), BGBG..(even line), 8-bit samples
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
@ AV_PIX_FMT_GBRP16BE
planar GBR 4:4:4 48bpp, big-endian
@ AV_PIX_FMT_RGB48LE
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
@ AV_PIX_FMT_GBRAP16LE
planar GBRA 4:4:4:4 64bpp, little-endian
@ AV_PIX_FMT_YA8
8 bits gray, 8 bits alpha
@ AV_PIX_FMT_BAYER_RGGB8
bayer, RGRG..(odd line), GBGB..(even line), 8-bit samples
@ AV_PIX_FMT_GBRP16LE
planar GBR 4:4:4 48bpp, little-endian
@ AV_PIX_FMT_BAYER_BGGR8
bayer, BGBG..(odd line), GRGR..(even line), 8-bit samples
#define AV_PIX_FMT_BAYER_GBRG16
#define AV_PIX_FMT_GRAY16
@ AVCOL_TRC_GAMMA22
also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM
@ AVCOL_TRC_LINEAR
"Linear transfer characteristics"
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static const ElemCat * elements[ELEMENT_COUNT]
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
main external API structure.
int flags2
AV_CODEC_FLAG2_*.
int64_t max_pixels
The number of pixels per image to maximally accept.
int dct_algo
DCT algorithm, see FF_DCT_* below.
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int flags
AV_CODEC_FLAG_*.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
AVDictionary * metadata
metadata.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVColorTransferCharacteristic color_trc
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
AVCodecContext * avctx_mjpeg
unsigned int yuv_line_size
unsigned int fax_buffer_size
enum TiffPhotometric photometric
int tile_byte_counts_offset
#define av_malloc_array(a, b)
#define avpriv_request_sample(...)
#define ADD_METADATA(count, name, sep)
static const AVOption tiff_options[]
static int get_geokey_type(int key)
static void unpack_yuv(TiffContext *s, AVFrame *p, const uint8_t *src, int lnum)
static uint16_t av_always_inline dng_process_color8(uint16_t value, const uint16_t *lut, uint16_t black_level, float scale_factor)
static uint16_t av_always_inline dng_process_color16(uint16_t value, const uint16_t *lut, uint16_t black_level, float scale_factor)
Map stored raw sensor values into linear reference values (see: DNG Specification - Chapter 5)
static int init_image(TiffContext *s, ThreadFrame *frame)
static av_cold int tiff_end(AVCodecContext *avctx)
#define RET_GEOKEY(TYPE, array, element)
static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
static char * doubles2str(double *dp, int count, const char *sep)
static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int stride, const uint8_t *src, int size, int strip_start, int lines)
static const char * search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
static char * get_geokey_val(int key, int val)
static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den)
static int cmp_id_key(const void *id, const void *k)
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
static av_cold int tiff_init(AVCodecContext *avctx)
static void av_always_inline dng_blit(TiffContext *s, uint8_t *dst, int dst_stride, const uint8_t *src, int src_stride, int width, int height, int is_single_comp, int is_u16)
static int dng_decode_tiles(AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt)
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int width, int lines)
static int deinvert_buffer(TiffContext *s, const uint8_t *src, int size)
static const char * get_geokey_name(int key)
static void unpack_gray(TiffContext *s, AVFrame *p, const uint8_t *src, int lnum, int width, int bpp)
static const AVClass tiff_decoder_class
static void free_geotags(TiffContext *const s)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
static int dng_decode_jpeg(AVCodecContext *avctx, AVFrame *frame, int tile_byte_count, int dst_x, int dst_y, int w, int h)
#define RET_GEOKEY_VAL(TYPE, array)
static void av_always_inline horizontal_fill(TiffContext *s, unsigned int bpp, uint8_t *dst, int usePtr, const uint8_t *src, uint8_t c, int width, int offset)
static void tiff_set_type(TiffContext *s, enum TiffType tiff_type)
TIFF constants & data structures.
TiffCompr
list of TIFF, TIFF/EP and DNG compression types
@ TIFF_MODEL_TRANSFORMATION
@ TIFF_VERTICAL_CS_TYPE_GEOKEY
@ TIFF_GEOG_GEODETIC_DATUM_GEOKEY
@ TIFF_GEOG_ELLIPSOID_GEOKEY
@ TIFF_GEOG_ANGULAR_UNITS_GEOKEY
@ TIFF_GT_MODEL_TYPE_GEOKEY
@ TIFF_PROJ_LINEAR_UNITS_GEOKEY
@ TIFF_GT_RASTER_TYPE_GEOKEY
@ TIFF_GEOG_PRIME_MERIDIAN_GEOKEY
@ TIFF_GEOG_AZIMUTH_UNITS_GEOKEY
@ TIFF_GEOG_LINEAR_UNITS_GEOKEY
@ TIFF_GEOGRAPHIC_TYPE_GEOKEY
@ TIFF_PROJECTED_CS_TYPE_GEOKEY
@ TIFF_VERTICAL_UNITS_GEOKEY
@ TIFF_PROJ_COORD_TRANS_GEOKEY
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
@ TIFF_PHOTOMETRIC_ICC_LAB
@ TIFF_PHOTOMETRIC_SEPARATED
@ TIFF_PHOTOMETRIC_LINEAR_RAW
@ TIFF_PHOTOMETRIC_CIE_LAB
@ TIFF_PHOTOMETRIC_PALETTE
@ TIFF_PHOTOMETRIC_WHITE_IS_ZERO
@ TIFF_PHOTOMETRIC_LOG_LUV
@ TIFF_PHOTOMETRIC_ALPHA_MASK
@ TIFF_PHOTOMETRIC_BLACK_IS_ZERO
@ TIFF_PHOTOMETRIC_ITU_LAB
@ DNG_LINEARIZATION_TABLE
TiffType
TIFF types in ascenting priority (last in the list is highest)
@ TIFF_TYPE_CINEMADNG
Digital Negative (DNG) image part of an CinemaDNG image sequence.
@ TIFF_TYPE_TIFF
TIFF image based on the TIFF 6.0 or TIFF/EP (ISO 12234-2) specifications.
@ TIFF_TYPE_DNG
Digital Negative (DNG) image.
unsigned ff_tget(GetByteContext *gb, int type, int le)
Reads a byte from the bytestream using given endianness.
int ff_tadd_shorts_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, int is_signed, AVDictionary **metadata)
Adds count shorts converted to a string into the metadata dictionary.
int ff_tadd_string_metadata(int count, const char *name, GetByteContext *gb, int le, AVDictionary **metadata)
Adds a string of count characters into the metadata dictionary.
int ff_tread_tag(GetByteContext *gb, int le, unsigned *tag, unsigned *type, unsigned *count, int *next)
Reads the first 3 fields of a TIFF tag, which are the tag id, the tag type and the count of values fo...
int ff_tdecode_header(GetByteContext *gb, int *le, int *ifd_offset)
Decodes a TIFF header from the input bytestream and sets the endianness in *le and the offset to the ...
unsigned ff_tget_short(GetByteContext *gb, int le)
Reads a short from the bytestream using given endianness.
int ff_tadd_doubles_metadata(int count, const char *name, const char *sep, GetByteContext *gb, int le, AVDictionary **metadata)
Adds count doubles converted to a string into the metadata dictionary.
double ff_tget_double(GetByteContext *gb, int le)
Reads a double from the bytestream using given endianness.
unsigned ff_tget_long(GetByteContext *gb, int le)
Reads a long from the bytestream using given endianness.
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
static const TiffGeoTagKeyName tiff_projection_codes[]
#define TIFF_GEO_KEY_USER_DEFINED
static const TiffGeoTagKeyName tiff_proj_cs_type_codes[]
#define TIFF_GEO_KEY_UNDEFINED
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord, int maxc)
static const uint8_t offset[127][2]