32 #define LZMA_API_STATIC
93 #define RET_GEOKEY(TYPE, array, element)\
94 if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
95 key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_name_type_map))\
96 return ff_tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].element;
141 #define RET_GEOKEY_VAL(TYPE, array)\
142 if (val >= TIFF_##TYPE##_OFFSET &&\
143 val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
144 return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);
196 snprintf(ap, 14,
"Unknown-%d", val);
204 uint64_t component_len;
205 if (!sep) sep =
", ";
206 component_len = 24LL + strlen(sep);
207 if (count >= (INT_MAX - 1)/component_len)
209 ap =
av_malloc(component_len * count + 1);
214 for (i = 0; i <
count; i++) {
215 unsigned l =
snprintf(ap, component_len,
"%.15g%s", dp[i], sep);
216 if(l >= component_len) {
222 ap0[strlen(ap0) - strlen(sep)] =
'\0';
243 while (--width >= 0) {
244 dst[(width+
offset)*8+7] = (usePtr ? src[width] : c) & 0x1;
245 dst[(width+
offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1;
246 dst[(width+
offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1;
247 dst[(width+
offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1;
248 dst[(width+
offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1;
249 dst[(width+
offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1;
250 dst[(width+
offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1;
251 dst[(width+
offset)*8+0] = (usePtr ? src[width] : c) >> 7;
255 while (--width >= 0) {
256 dst[(width+
offset)*4+3] = (usePtr ? src[width] : c) & 0x3;
257 dst[(width+
offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3;
258 dst[(width+
offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3;
259 dst[(width+
offset)*4+0] = (usePtr ? src[width] : c) >> 6;
263 while (--width >= 0) {
264 dst[(width+
offset)*2+1] = (usePtr ? src[width] : c) & 0xF;
265 dst[(width+
offset)*2+0] = (usePtr ? src[width] : c) >> 4;
270 memcpy(dst + offset, src, width);
272 memset(dst + offset, c, width);
284 for (i = 0; i <
size; i++)
298 for (i = 0; i < w; i++) {
307 for (i = 0; i < w; i++) {
322 z_stream zstream = { 0 };
325 zstream.next_in = (
uint8_t *)src;
326 zstream.avail_in =
size;
327 zstream.next_out = dst;
328 zstream.avail_out = *
len;
329 zret = inflateInit(&zstream);
334 zret =
inflate(&zstream, Z_SYNC_FLUSH);
335 inflateEnd(&zstream);
336 *len = zstream.total_out;
337 return zret == Z_STREAM_END ? Z_OK : zret;
342 int strip_start,
int is_yuv)
345 unsigned long outlen;
347 outlen = width * lines;
358 ret = tiff_uncompress(zbuf, &outlen, src, size);
361 "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
362 (
unsigned long)width * lines, ret);
367 for (line = 0; line < lines; line++) {
371 memcpy(dst, src, width);
386 static int tiff_uncompress_lzma(
uint8_t *dst, uint64_t *len,
const uint8_t *src,
389 lzma_stream stream = LZMA_STREAM_INIT;
392 stream.next_in = (
uint8_t *)src;
393 stream.avail_in =
size;
394 stream.next_out = dst;
395 stream.avail_out = *
len;
396 ret = lzma_stream_decoder(&stream, UINT64_MAX, 0);
397 if (ret != LZMA_OK) {
401 ret = lzma_code(&stream, LZMA_RUN);
403 *len = stream.total_out;
404 return ret == LZMA_STREAM_END ? LZMA_OK : ret;
408 const uint8_t *src,
int size,
int width,
int lines,
409 int strip_start,
int is_yuv)
411 uint64_t outlen = width * lines;
423 ret = tiff_uncompress_lzma(buf, &outlen, src, size);
424 if (ret != LZMA_OK) {
426 "Uncompressing failed (%"PRIu64
" of %"PRIu64
") with error %d\n", outlen,
427 (uint64_t)width * lines, ret);
432 for (line = 0; line < lines; line++) {
436 memcpy(dst, src, width);
451 const uint8_t *src,
int size,
int width,
int lines)
460 "Error allocating temporary buffer\n");
465 memcpy(src2, src, size);
467 for (i = 0; i <
size; i++)
474 for (line = 0; line < lines; line++) {
483 const uint8_t *src,
int size,
int strip_start,
int lines)
486 int c, line,
pixels, code, ret;
488 int width = ((s->
width * s->
bpp) + 7) >> 3;
519 return tiff_unpack_zlib(s, p, dst, stride, src, size, width, lines,
520 strip_start, is_yuv);
523 "zlib support not enabled, "
524 "deflate compression not supported\n");
530 return tiff_unpack_lzma(s, p, dst, stride, src, size, width, lines,
531 strip_start, is_yuv);
534 "LZMA support not enabled\n");
544 if (size > 1 && !src[0] && (src[1]&1)) {
551 for (line = 0; line < lines; line++) {
553 if (pixels < width) {
580 for (line = 0; line < lines; line++) {
581 if (src - ssrc > size) {
591 if (ssrc + size - src < width)
596 dst, 1, src, 0, width, 0);
599 for (i = 0; i <
width; i++)
605 for (pixels = 0; pixels <
width;) {
606 if (ssrc + size - src < 2) {
613 if (pixels + code > width ||
614 ssrc + size - src < code) {
616 "Copy went out of bounds\n");
620 dst, 1, src, 0, code, pixels);
623 }
else if (code != -128) {
625 if (pixels + code > width) {
627 "Run went out of bounds\n");
632 dst, 0,
NULL, c, code, pixels);
638 for (i = 0; i <
width; i++)
655 int create_gray_palette = 0;
660 "Unsupported image parameters: bpp=%d, bppcount=%d\n",
675 create_gray_palette = 1;
734 "This format is not supported (bpp=%d, bppcount=%d)\n",
757 if (!create_gray_palette)
762 uint32_t *pal = (uint32_t *)frame->
f->
data[1];
763 for (i = 0; i < 1<<s->
bpp; i++)
764 pal[i] = 0xFFU << 24 | i * 255 / ((1<<s->
bpp) - 1) * 0x010101;
773 s->
res[offset++] = num;
777 s->
res[2] * (uint64_t)s->
res[1], s->
res[0] * (uint64_t)s->
res[3], INT32_MAX);
824 "This format is not supported (bpp=%d, %d components)\n",
839 for (i = 0; i <
count; i++)
850 "Samples per pixel requires a single value, many provided\n");
855 "Samples per pixel %d is too large\n", value);
901 if (!value || (type ==
TIFF_LONG && value == UINT_MAX))
929 set_sar(s, tag, value, value2);
960 "PhotometricInterpretation 0x%04X",
972 "Unknown FillOrder value %d, trying default one\n", value);
980 if (count / 3 > 256 ||
984 pal_gb[0] = pal_gb[1] = pal_gb[2] = s->
gb;
989 for (i = 0; i < count / 3; i++) {
990 uint32_t p = 0xFF000000;
991 p |= (
ff_tget(&pal_gb[0], type, s->
le) >> off) << 16;
992 p |= (
ff_tget(&pal_gb[1], type, s->
le) >> off) << 8;
993 p |=
ff_tget(&pal_gb[2], type, s->
le) >> off;
1007 for (i = 0; i <
count; i++) {
1023 #define ADD_METADATA(count, name, sep)\
1024 if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
1025 av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
1067 if (count >= INT_MAX /
sizeof(int64_t))
1076 for (i = 0; i <
count; i++)
1157 "Unknown or unsupported tag %d/0X%0X\n",
1165 "This format is not supported (bpp=%d, %d components)\n",
1182 int i, j, entries,
stride;
1183 unsigned soff, ssize;
1194 }
else if (off >= UINT_MAX - 14 || avpkt->
size < off + 14) {
1213 for (i = 0; i < entries; i++) {
1267 for (plane = 0; plane < planes; plane++) {
1270 for (i = 0; i < s->
height; i += s->
rps) {
1281 if (soff > avpkt->
size || ssize > avpkt->
size - soff) {
1302 ssize = s->
width * soff;
1309 for (i = 0; i < s->
height; i++) {
1310 for (j = soff; j < ssize; j += 2)
1320 for (i = 0; i < s->
height; i++) {
1321 for (j = soff; j < ssize; j += 2)
1326 for (i = 0; i < s->
height; i++) {
1327 for (j = soff; j < ssize; j++)
1328 dst[j] += dst[j - soff];
1336 for (i = 0; i < s->
height; i++) {
1337 for (j = 0; j <
stride; j++)
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...
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const TiffGeoTagKeyName ff_tiff_projection_codes[]
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
8 bits gray, 8 bits alpha
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_LOG_WARNING
Something somehow does not look correct.
static int init_thread_copy(AVCodecContext *avctx)
packed RGB 8:8:8, 24bpp, RGBRGB...
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.
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.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream2_init_writer(PutByteContext *p, uint8_t *buf, int buf_size)
av_cold void ff_lzw_decode_close(LZWState **p)
static const char * search_keyval(const TiffGeoTagKeyName *keys, int n, int id)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
av_cold void ff_lzw_decode_open(LZWState **p)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static void free_geotags(TiffContext *const s)
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...
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
unsigned int yuv_line_size
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
static av_always_inline unsigned int bytestream2_get_bufferu(GetByteContext *g, uint8_t *dst, unsigned int size)
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Macro definitions for various function/variable attributes.
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 int tiff_decode_tag(TiffContext *s, AVFrame *frame)
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
av_cold void ff_ccitt_unpack_init(void)
initialize unpacker code
planar GBRA 4:4:4:4 64bpp, big-endian
#define av_assert0(cond)
assert() equivalent, that is always enabled.
8 bits with AV_PIX_FMT_RGB32 palette
#define TIFF_GEO_KEY_USER_DEFINED
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
static av_cold int end(AVCodecContext *avctx)
Multithreading support functions.
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
static av_cold int tiff_init(AVCodecContext *avctx)
planar GBR 4:4:4 48bpp, big-endian
static void inflate(uint8_t *dst, const uint8_t *p1, int width, int threshold, const uint8_t *coordinates[], int coord)
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
16 bits gray, 16 bits alpha (big-endian)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
const uint8_t ff_reverse[256]
static av_cold int tiff_end(AVCodecContext *avctx)
unsigned ff_tget_short(GetByteContext *gb, int le)
Reads a short from the bytestream using given endianness.
static int deinvert_buffer(TiffContext *s, const uint8_t *src, int size)
unsigned ff_tget(GetByteContext *gb, int type, int le)
Reads a byte from the bytestream using given endianness.
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den)
static int tiff_unpack_fax(TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int width, int lines)
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
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
enum TiffPhotometric photometric
const TiffGeoTagKeyName ff_tiff_proj_cs_type_codes[]
uint8_t nb_components
The number of components each pixel has, (1-4)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
static void unpack_yuv(TiffContext *s, AVFrame *p, const uint8_t *src, int lnum)
#define AV_EF_EXPLODE
abort decoding on minor error detection
#define FF_ARRAY_ELEMS(a)
#define TIFF_GEO_KEY_UNDEFINED
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static av_always_inline int bytestream2_seek_p(PutByteContext *p, int offset, int whence)
static av_always_inline int bytestream2_tell(GetByteContext *g)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
static const char * get_geokey_name(int key)
TiffCompr
list of TIFF compression types
Libavcodec external API header.
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
char * av_strdup(const char *s)
Duplicate the string s.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static int get_geokey_type(int key)
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.
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static char * get_geokey_val(int key, int val)
static av_always_inline unsigned int bytestream2_get_eof(PutByteContext *p)
planar GBRA 4:4:4:4 32bpp
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t *dst, int usePtr, const uint8_t *src, uint8_t c, int width, int offset)
static char * doubles2str(double *dp, int count, const char *sep)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
int ff_lzw_decode_init(LZWState *p, int csize, const uint8_t *buf, int buf_size, int mode)
Initialize LZW decoder.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
#define RET_GEOKEY_VAL(TYPE, array)
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
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.
Y , 16bpp, little-endian.
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
16 bits gray, 16 bits alpha (little-endian)
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...
#define RET_GEOKEY(TYPE, array, element)
static void * av_mallocz_array(size_t nmemb, size_t size)
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 ...
static int init_image(TiffContext *s, ThreadFrame *frame)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
planar GBR 4:4:4 48bpp, little-endian
#define av_malloc_array(a, b)
#define FFSWAP(type, a, b)
static int cmp_id_key(const void *id, const void *k)
double ff_tget_double(GetByteContext *gb, int le)
Reads a double from the bytestream using given endianness.
planar GBRA 4:4:4:4 64bpp, little-endian
#define ADD_METADATA(count, name, sep)
This structure stores compressed data.
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
CCITT Fax Group 3 and 4 decompression.
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...