FFmpeg
Data Structures | Macros | Functions | Variables
tiff.c File Reference
#include "config.h"
#include "libavutil/attributes.h"
#include "libavutil/avstring.h"
#include "libavutil/error.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/imgutils.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "bytestream.h"
#include "faxcompr.h"
#include "internal.h"
#include "lzw.h"
#include "mathops.h"
#include "tiff.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(TYPE, array, element)
 
#define RET_GEOKEY_VAL(TYPE, array)
 
#define ADD_METADATA(count, name, sep)
 
#define OFFSET(x)   offsetof(TiffContext, 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 char * get_geokey_val (int key, int 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 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 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_strip (AVCodecContext *avctx, AVFrame *frame)
 
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 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) More...
 
static uint16_t av_always_inline dng_process_color8 (uint16_t value, const uint16_t *lut, uint16_t black_level, float scale_factor)
 
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 dng_decode_tiles (AVCodecContext *avctx, AVFrame *frame, AVPacket *avpkt)
 
static int init_image (TiffContext *s, ThreadFrame *frame)
 
static void set_sar (TiffContext *s, unsigned tag, unsigned num, unsigned den)
 
static int tiff_decode_tag (TiffContext *s, AVFrame *frame)
 
static int decode_frame (AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
 
static av_cold int tiff_init (AVCodecContext *avctx)
 
static av_cold int tiff_end (AVCodecContext *avctx)
 

Variables

static const AVOption tiff_options []
 
static const AVClass tiff_decoder_class
 
AVCodec ff_tiff_decoder
 

Detailed Description

TIFF image decoder

Author
Konstantin Shishkov

Definition in file tiff.c.

Macro Definition Documentation

◆ RET_GEOKEY

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

Definition at line 133 of file tiff.c.

◆ RET_GEOKEY_VAL

#define RET_GEOKEY_VAL (   TYPE,
  array 
)
Value:
if (val >= TIFF_##TYPE##_OFFSET &&\
val - TIFF_##TYPE##_OFFSET < FF_ARRAY_ELEMS(ff_tiff_##array##_codes))\
return av_strdup(ff_tiff_##array##_codes[val - TIFF_##TYPE##_OFFSET]);

◆ 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;\
}

◆ OFFSET

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

Definition at line 2201 of file tiff.c.

Function Documentation

◆ tiff_set_type()

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

Definition at line 117 of file tiff.c.

Referenced by tiff_decode_tag().

◆ free_geotags()

static void free_geotags ( TiffContext *const  s)
static

Definition at line 122 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 138 of file tiff.c.

Referenced by decode_frame().

◆ get_geokey_type()

static int get_geokey_type ( int  key)
static

Definition at line 148 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 158 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 163 of file tiff.c.

Referenced by get_geokey_val().

◆ get_geokey_val()

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

Definition at line 172 of file tiff.c.

Referenced by tiff_decode_tag().

◆ doubles2str()

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

Definition at line 240 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 266 of file tiff.c.

◆ dng_blit()

static void 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

Definition at line 813 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 281 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 336 of file tiff.c.

Referenced by 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 349 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 362 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 522 of file tiff.c.

Referenced by tiff_unpack_strip().

◆ dng_decode_strip()

static int dng_decode_strip ( AVCodecContext avctx,
AVFrame frame 
)
static

Definition at line 1042 of file tiff.c.

Referenced by 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 557 of file tiff.c.

Referenced by decode_frame().

◆ dng_process_color16()

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

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

Definition at line 785 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,
uint16_t  black_level,
float  scale_factor 
)
static

Definition at line 806 of file tiff.c.

Referenced by dng_blit().

◆ 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 876 of file tiff.c.

Referenced by dng_decode_strip(), and dng_decode_tiles().

◆ dng_decode_tiles()

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

Definition at line 967 of file tiff.c.

Referenced by decode_frame().

◆ init_image()

static int init_image ( TiffContext s,
ThreadFrame frame 
)
static

Definition at line 1055 of file tiff.c.

Referenced by decode_frame().

◆ set_sar()

static void set_sar ( TiffContext s,
unsigned  tag,
unsigned  num,
unsigned  den 
)
static

Definition at line 1228 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 1247 of file tiff.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
void *  data,
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 1780 of file tiff.c.

◆ tiff_init()

static av_cold int tiff_init ( AVCodecContext avctx)
static

Definition at line 2143 of file tiff.c.

◆ tiff_end()

static av_cold int tiff_end ( AVCodecContext avctx)
static

Definition at line 2183 of file tiff.c.

Variable Documentation

◆ 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 },
}

Definition at line 2202 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,
}

Definition at line 2209 of file tiff.c.

◆ ff_tiff_decoder

AVCodec ff_tiff_decoder
Initial value:
= {
.name = "tiff",
.long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
.priv_data_size = sizeof(TiffContext),
.close = tiff_end,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.priv_class = &tiff_decoder_class,
}

Definition at line 2216 of file tiff.c.

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:279
OFFSET
#define OFFSET(x)
Definition: tiff.c:2201
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
tiff_end
static av_cold int tiff_end(AVCodecContext *avctx)
Definition: tiff.c:2183
tiff_options
static const AVOption tiff_options[]
Definition: tiff.c:2202
val
static double val(void *priv, double ch)
Definition: aeval.c:76
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
s
#define s(width, name)
Definition: cbs_vp9.c:257
key
const char * key
Definition: hwcontext_opencl.c:168
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:106
tiff_init
static av_cold int tiff_init(AVCodecContext *avctx)
Definition: tiff.c:2143
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: tiff.c:1780
NULL
#define NULL
Definition: coverity.c:32
TiffContext
Definition: tiff.c:54
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
TYPE
#define TYPE
Definition: ffv1.h:195
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
tiff_decoder_class
static const AVClass tiff_decoder_class
Definition: tiff.c:2209
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:48
AV_OPT_FLAG_DECODING_PARAM
#define AV_OPT_FLAG_DECODING_PARAM
a generic parameter which can be set by the user for demuxing or decoding
Definition: opt.h:277
array
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:253
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:240
add_metadata
static int add_metadata(int count, int type, const char *name, const char *sep, TiffContext *s, AVFrame *frame)
Definition: tiff.c:266
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:145