FFmpeg
Loading...
Searching...
No Matches
tiff.c File Reference

TIFF image decoder. More...

#include "config.h"
#include <float.h>
#include "libavutil/attributes.h"
#include "libavutil/attributes_internal.h"
#include "libavutil/avstring.h"
#include "libavutil/error.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/reverse.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "decode.h"
#include "exif_internal.h"
#include "faxcompr.h"
#include "lzw.h"
#include "tiff.h"
#include "tiff_common.h"
#include "tiff_data.h"
#include "mjpegdec.h"
#include "thread.h"
#include "get_bits.h"

Go to the source code of this file.

Data Structures

struct  TiffContext
 

Macros

#define RET_GEOKEY_STR(TYPE, array)
 
#define RET_GEOKEY_TYPE(TYPE, array)
 
#define RET_GEOKEY_VAL(TYPE, array)
 
#define ADD_METADATA(count, name, sep)
 
#define OFFSET(x)
 

Functions

static void tiff_set_type (TiffContext *s, enum TiffType tiff_type)
 
static void free_geotags (TiffContext *const s)
 
static const char * get_geokey_name (int key)
 
static int get_geokey_type (int key)
 
static int cmp_id_key (const void *id, const void *k)
 
static const char * search_keyval (const TiffGeoTagKeyName *keys, int n, int id)
 
static const char * get_geokey_val (int key, uint16_t val)
 
static char * doubles2str (double *dp, int count, const char *sep)
 
static int add_metadata (int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
 
static uint16_t av_always_inline dng_process_color16 (uint16_t value, const uint16_t *lut, float black_level, float scale_factor)
 Map stored raw sensor values into linear reference values (see: DNG Specification - Chapter 5)
 
static uint16_t av_always_inline dng_process_color8 (uint16_t value, const uint16_t *lut, float black_level, float scale_factor)
 
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, int odd_line)
 
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 int deinvert_buffer (TiffContext *s, const uint8_t *src, int size)
 
static void unpack_gray (TiffContext *s, AVFrame *p, const uint8_t *src, int lnum, int width, int bpp)
 
static void unpack_yuv (TiffContext *s, AVFrame *p, const uint8_t *src, int lnum)
 
static int tiff_unpack_fax (TiffContext *s, uint8_t *dst, int stride, const uint8_t *src, int size, int width, int lines)
 
static int dng_decode_jpeg (AVCodecContext *avctx, AVFrame *frame, int tile_byte_count, int dst_x, int dst_y, int w, int h)
 
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 dng_decode_tiles (AVCodecContext *avctx, AVFrame *frame, const AVPacket *avpkt)
 
static int init_image (TiffContext *s, AVFrame *frame)
 
static void set_sar (TiffContext *s, unsigned tag, unsigned numerator, unsigned denumerator)
 
static int tiff_decode_tag (TiffContext *s, AVFrame *frame)
 
static void camera_xyz_coeff (TiffContext *s, float rgb2cam[3][4], double cam2xyz[4][3])
 
static int decode_frame (AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
 
static av_cold int tiff_init (AVCodecContext *avctx)
 
static av_cold int tiff_end (AVCodecContext *avctx)
 

Variables

static const float d65_white [3] = { 0.950456f, 1.f, 1.088754f }
 
static const float xyz2rgb [3][3]
 
static const AVOption tiff_options []
 
static const AVClass tiff_decoder_class
 
const FFCodec ff_tiff_decoder
 

Detailed Description

TIFF image decoder.

Author
Konstantin Shishkov

Definition in file tiff.c.

Macro Definition Documentation

◆ RET_GEOKEY_STR

#define RET_GEOKEY_STR ( TYPE,
array )
Value:
if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
return tiff_##array##_name_type_string + tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].offset;
const char * key
#define TYPE
Definition ffv1dec.c:90
#define FF_ARRAY_ELEMS(a)
static int array[MAX_W *MAX_W]

Referenced by get_geokey_name().

◆ RET_GEOKEY_TYPE

#define RET_GEOKEY_TYPE ( TYPE,
array )
Value:
if (key >= TIFF_##TYPE##_KEY_ID_OFFSET &&\
key - TIFF_##TYPE##_KEY_ID_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_name_type_map))\
return tiff_##array##_name_type_map[key - TIFF_##TYPE##_KEY_ID_OFFSET].type;

Referenced by get_geokey_type().

◆ RET_GEOKEY_VAL

#define RET_GEOKEY_VAL ( TYPE,
array )
Value:
if (val >= TIFF_##TYPE##_OFFSET &&\
val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(tiff_##array##_codes))\
return tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET];
static double val(void *priv, double ch)
Definition aeval.c:77

Referenced by get_geokey_val().

◆ ADD_METADATA

#define ADD_METADATA ( count,
name,
sep )
Value:
if ((ret = add_metadata(count, type, name, sep, s, frame)) < 0) {\
av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");\
goto end;\
}
#define s(width, name)
Definition cbs_vp9.c:198
static AVFrame * frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
cl_device_type type
const char * name
Definition qsvenc.c:142
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition tiff.c:275

Referenced by tiff_decode_tag().

◆ OFFSET

#define OFFSET ( x)
Value:
offsetof(TiffContext, x)

Definition at line 2494 of file tiff.c.

Function Documentation

◆ tiff_set_type()

static void tiff_set_type ( TiffContext * s,
enum TiffType tiff_type )
static

Definition at line 134 of file tiff.c.

Referenced by tiff_decode_tag().

◆ free_geotags()

static void free_geotags ( TiffContext *const s)
static

Definition at line 139 of file tiff.c.

Referenced by decode_frame(), and tiff_end().

◆ get_geokey_name()

static const char * get_geokey_name ( int key)
static

Definition at line 147 of file tiff.c.

Referenced by decode_frame().

◆ get_geokey_type()

static int get_geokey_type ( int key)
static

Definition at line 162 of file tiff.c.

Referenced by decode_frame().

◆ cmp_id_key()

static int cmp_id_key ( const void * id,
const void * k )
static

Definition at line 176 of file tiff.c.

Referenced by search_keyval().

◆ search_keyval()

static const char * search_keyval ( const TiffGeoTagKeyName * keys,
int n,
int id )
static

Definition at line 181 of file tiff.c.

Referenced by get_geokey_val().

◆ get_geokey_val()

static const char * get_geokey_val ( int key,
uint16_t val )
static

Definition at line 190 of file tiff.c.

Referenced by tiff_decode_tag().

◆ doubles2str()

static char * doubles2str ( double * dp,
int count,
const char * sep )
static

Definition at line 249 of file tiff.c.

Referenced by tiff_decode_tag().

◆ add_metadata()

static int add_metadata ( int count,
int type,
const char * name,
const char * sep,
TiffContext * s,
AVFrame * frame )
static

Definition at line 275 of file tiff.c.

◆ dng_process_color16()

static uint16_t av_always_inline dng_process_color16 ( uint16_t value,
const uint16_t * lut,
float black_level,
float scale_factor )
static

Map stored raw sensor values into linear reference values (see: DNG Specification - Chapter 5)

Definition at line 289 of file tiff.c.

Referenced by dng_blit(), and dng_process_color8().

◆ dng_process_color8()

static uint16_t av_always_inline dng_process_color8 ( uint16_t value,
const uint16_t * lut,
float black_level,
float scale_factor )
static

Definition at line 308 of file tiff.c.

Referenced by dng_blit().

◆ dng_blit()

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,
int odd_line )
static

Definition at line 316 of file tiff.c.

Referenced by dng_decode_jpeg(), and tiff_unpack_strip().

◆ horizontal_fill()

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

Definition at line 389 of file tiff.c.

Referenced by tiff_unpack_fax(), and tiff_unpack_strip().

◆ deinvert_buffer()

static int deinvert_buffer ( TiffContext * s,
const uint8_t * src,
int size )
static

Definition at line 445 of file tiff.c.

Referenced by tiff_unpack_fax(), and tiff_unpack_strip().

◆ unpack_gray()

static void unpack_gray ( TiffContext * s,
AVFrame * p,
const uint8_t * src,
int lnum,
int width,
int bpp )
static

Definition at line 458 of file tiff.c.

Referenced by tiff_unpack_strip().

◆ unpack_yuv()

static void unpack_yuv ( TiffContext * s,
AVFrame * p,
const uint8_t * src,
int lnum )
static

Definition at line 472 of file tiff.c.

Referenced by tiff_unpack_strip().

◆ tiff_unpack_fax()

static int tiff_unpack_fax ( TiffContext * s,
uint8_t * dst,
int stride,
const uint8_t * src,
int size,
int width,
int lines )
static

Definition at line 646 of file tiff.c.

Referenced by tiff_unpack_strip().

◆ dng_decode_jpeg()

static int dng_decode_jpeg ( AVCodecContext * avctx,
AVFrame * frame,
int tile_byte_count,
int dst_x,
int dst_y,
int w,
int h )
static

Definition at line 667 of file tiff.c.

Referenced by dng_decode_tiles(), and tiff_unpack_strip().

◆ tiff_unpack_strip()

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

Definition at line 757 of file tiff.c.

Referenced by decode_frame().

◆ dng_decode_tiles()

static int dng_decode_tiles ( AVCodecContext * avctx,
AVFrame * frame,
const AVPacket * avpkt )
static

Definition at line 986 of file tiff.c.

Referenced by decode_frame().

◆ init_image()

static int init_image ( TiffContext * s,
AVFrame * frame )
static

Definition at line 1059 of file tiff.c.

Referenced by decode_frame().

◆ set_sar()

static void set_sar ( TiffContext * s,
unsigned tag,
unsigned numerator,
unsigned denumerator )
static

Definition at line 1249 of file tiff.c.

Referenced by tiff_decode_tag().

◆ tiff_decode_tag()

static int tiff_decode_tag ( TiffContext * s,
AVFrame * frame )
static

Only get the first SubIFD

Definition at line 1268 of file tiff.c.

Referenced by decode_frame().

◆ camera_xyz_coeff()

static void camera_xyz_coeff ( TiffContext * s,
float rgb2cam[3][4],
double cam2xyz[4][3] )
static

Definition at line 1918 of file tiff.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext * avctx,
AVFrame * p,
int * got_frame,
AVPacket * avpkt )
static

whether we should process this IFD's SubIFD

whether we should process this multi-page IFD's next page

Definition at line 1944 of file tiff.c.

◆ tiff_init()

static av_cold int tiff_init ( AVCodecContext * avctx)
static

Definition at line 2438 of file tiff.c.

◆ tiff_end()

static av_cold int tiff_end ( AVCodecContext * avctx)
static

Definition at line 2476 of file tiff.c.

Variable Documentation

◆ d65_white

const float d65_white[3] = { 0.950456f, 1.f, 1.088754f }
static

Definition at line 132 of file tiff.c.

Referenced by tiff_decode_tag().

◆ xyz2rgb

const float xyz2rgb[3][3]
static
Initial value:
= {
{ 0.412453f, 0.357580f, 0.180423f },
{ 0.212671f, 0.715160f, 0.072169f },
{ 0.019334f, 0.119193f, 0.950227f },
}

Definition at line 1912 of file tiff.c.

Referenced by camera_xyz_coeff(), create_filtergraph(), ff_sws_get_adaptation(), and get_rgb2rgb_matrix().

◆ tiff_options

const AVOption tiff_options[]
static
Initial value:
= {
{ "subimage", "decode subimage instead if available", OFFSET(get_subimage), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
{ "thumbnail", "decode embedded thumbnail subimage instead if available", OFFSET(get_thumbnail), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
{ "page", "page number of multi-page image to decode (starting from 1)", OFFSET(get_page), AV_OPT_TYPE_INT, {.i64=0}, 0, UINT16_MAX, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM },
{ NULL },
}
#define NULL
Definition coverity.c:32
#define OFFSET(x)
#define AV_OPT_FLAG_DECODING_PARAM
A generic parameter which can be set by the user for demuxing or decoding.
Definition opt.h:355
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326

Definition at line 2495 of file tiff.c.

◆ tiff_decoder_class

const AVClass tiff_decoder_class
static
Initial value:
= {
.class_name = "TIFF decoder",
.item_name = av_default_item_name,
.option = tiff_options,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const AVOption tiff_options[]
Definition tiff.c:2495

Definition at line 2502 of file tiff.c.

◆ ff_tiff_decoder

const FFCodec ff_tiff_decoder
Initial value:
= {
.p.name = "tiff",
CODEC_LONG_NAME("TIFF image"),
.p.type = AVMEDIA_TYPE_VIDEO,
.priv_data_size = sizeof(TiffContext),
.p.priv_class = &tiff_decoder_class,
}
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_TIFF
Definition codec_id.h:146
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
static av_cold int tiff_end(AVCodecContext *avctx)
Definition tiff.c:2476
static av_cold int tiff_init(AVCodecContext *avctx)
Definition tiff.c:2438
static const AVClass tiff_decoder_class
Definition tiff.c:2502

Definition at line 2509 of file tiff.c.