FFmpeg
Data Structures | Macros | Functions | Variables
tiffenc.c File Reference
#include "config.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "encode.h"
#include "lzw.h"
#include "rle.h"
#include "tiff.h"
#include "tiff_common.h"
#include "version.h"

Go to the source code of this file.

Data Structures

struct  TiffEncoderContext
 

Macros

#define TIFF_MAX_ENTRY   32
 
#define ADD_ENTRY(s, tag, type, count, ptr_val)
 
#define ADD_ENTRY1(s, tag, type, val)
 
#define OFFSET(x)   offsetof(TiffEncoderContext, x)
 
#define VE   AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static int check_size (TiffEncoderContext *s, uint64_t need)
 Check free space in buffer. More...
 
static void tnput (uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, int flip)
 Put n values to buffer. More...
 
static int add_entry (TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int count, const void *ptr_val)
 Add entry to directory in tiff header. More...
 
static int add_entry1 (TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
 
static int encode_strip (TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr)
 Encode one strip in tiff file. More...
 
static void pack_yuv (TiffEncoderContext *s, const AVFrame *p, uint8_t *dst, int lnum)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
 
static av_cold int encode_init (AVCodecContext *avctx)
 
static av_cold int encode_close (AVCodecContext *avctx)
 

Variables

static const uint8_t type_sizes2 [14]
 sizes of various TIFF field types (string size = 1) More...
 
static const AVOption options []
 
static const AVClass tiffenc_class
 
const FFCodec ff_tiff_encoder
 

Detailed Description

TIFF image encoder

Author
Bartlomiej Wolowiec

Definition in file tiffenc.c.

Macro Definition Documentation

◆ TIFF_MAX_ENTRY

#define TIFF_MAX_ENTRY   32

Definition at line 46 of file tiffenc.c.

◆ ADD_ENTRY

#define ADD_ENTRY (   s,
  tag,
  type,
  count,
  ptr_val 
)
Value:
do { \
ret = add_entry(s, tag, type, count, ptr_val); \
if (ret < 0) \
goto fail; \
} while (0)

Definition at line 232 of file tiffenc.c.

◆ ADD_ENTRY1

#define ADD_ENTRY1 (   s,
  tag,
  type,
  val 
)
Value:
do { \
ret = add_entry1(s, tag, type, val); \
if (ret < 0) \
goto fail; \
} while (0)

Definition at line 239 of file tiffenc.c.

◆ OFFSET

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

Definition at line 552 of file tiffenc.c.

◆ VE

Definition at line 553 of file tiffenc.c.

Function Documentation

◆ check_size()

static int check_size ( TiffEncoderContext s,
uint64_t  need 
)
inlinestatic

Check free space in buffer.

Parameters
sTiff context
needNeeded bytes
Returns
0 - ok, 1 - no free space

Definition at line 88 of file tiffenc.c.

Referenced by add_entry(), decode_format80(), encode_frame(), and encode_strip().

◆ tnput()

static void tnput ( uint8_t **  p,
int  n,
const uint8_t *  val,
enum TiffTypes  type,
int  flip 
)
static

Put n values to buffer.

Parameters
ppointer to pointer to output buffer
nnumber of values
valpointer to values
typetype of values
flip= 0 - normal copy, >0 - flip

Definition at line 107 of file tiffenc.c.

Referenced by add_entry().

◆ add_entry()

static int add_entry ( TiffEncoderContext s,
enum TiffTags  tag,
enum TiffTypes  type,
int  count,
const void *  ptr_val 
)
static

Add entry to directory in tiff header.

Parameters
sTiff context
tagtag that identifies the entry
typeentry type
countthe number of values
ptr_valpointer to values

Definition at line 127 of file tiffenc.c.

Referenced by add_entry1().

◆ add_entry1()

static int add_entry1 ( TiffEncoderContext s,
enum TiffTags  tag,
enum TiffTypes  type,
int  val 
)
static

Definition at line 151 of file tiffenc.c.

◆ encode_strip()

static int encode_strip ( TiffEncoderContext s,
const int8_t *  src,
uint8_t *  dst,
int  n,
int  compr 
)
static

Encode one strip in tiff file.

Parameters
sTiff context
srcinput buffer
dstoutput buffer
nsize of input buffer
comprcompression method
Returns
number of output bytes. If an output error is encountered, a negative value corresponding to an AVERROR error code is returned.

Definition at line 171 of file tiffenc.c.

Referenced by encode_frame().

◆ pack_yuv()

static void pack_yuv ( TiffEncoderContext s,
const AVFrame p,
uint8_t *  dst,
int  lnum 
)
static

Definition at line 204 of file tiffenc.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( AVCodecContext avctx,
AVPacket pkt,
const AVFrame pict,
int got_packet 
)
static

according to CCIR Recommendation 601.1

Definition at line 246 of file tiffenc.c.

◆ encode_init()

static av_cold int encode_init ( AVCodecContext avctx)
static

Definition at line 524 of file tiffenc.c.

◆ encode_close()

static av_cold int encode_close ( AVCodecContext avctx)
static

Definition at line 541 of file tiffenc.c.

Variable Documentation

◆ type_sizes2

const uint8_t type_sizes2[14]
static
Initial value:
= {
0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
}

sizes of various TIFF field types (string size = 1)

Definition at line 49 of file tiffenc.c.

Referenced by add_entry(), and tnput().

◆ options

const AVOption options[]
static
Initial value:
= {
{"dpi", "set the image resolution (in dpi)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
{ "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, .unit = "compression_algo" },
{ "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, .unit = "compression_algo" },
{ "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, .unit = "compression_algo" },
{ "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, .unit = "compression_algo" },
{ "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, .unit = "compression_algo" },
{ NULL },
}

Definition at line 554 of file tiffenc.c.

◆ tiffenc_class

const AVClass tiffenc_class
static
Initial value:
= {
.class_name = "TIFF encoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 564 of file tiffenc.c.

◆ ff_tiff_encoder

const FFCodec ff_tiff_encoder
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: tiffenc.c:541
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_PIX_FMT_MONOWHITE
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:82
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
TIFF_RAW
@ TIFF_RAW
Definition: tiff.h:126
TIFF_PACKBITS
@ TIFF_PACKBITS
Definition: tiff.h:134
add_entry1
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
Definition: tiffenc.c:151
fail
#define fail()
Definition: checkasm.h:179
val
static double val(void *priv, double ch)
Definition: aeval.c:78
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
OFFSET
#define OFFSET(x)
Definition: tiffenc.c:552
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:296
VE
#define VE
Definition: tiffenc.c:553
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
AV_PIX_FMT_GRAY8A
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:143
TIFF_LZW
@ TIFF_LZW
Definition: tiff.h:130
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
AV_PIX_FMT_RGB48LE
@ 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...
Definition: pixfmt.h:110
AV_PIX_FMT_YA16LE
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:210
AV_PIX_FMT_MONOBLACK
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition: pixfmt.h:83
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_RGBA64LE
@ 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...
Definition: pixfmt.h:203
TiffEncoderContext
Definition: tiffenc.c:53
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:269
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
add_entry
static int add_entry(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int count, const void *ptr_val)
Add entry to directory in tiff header.
Definition: tiffenc.c:127
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: tiffenc.c:246
tiffenc_class
static const AVClass tiffenc_class
Definition: tiffenc.c:564
AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:275
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:84
tag
uint32_t tag
Definition: movenc.c:1791
ret
ret
Definition: filter_design.txt:187
options
static const AVOption options[]
Definition: tiffenc.c:554
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_GRAY16LE
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition: pixfmt.h:105
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
TIFF_DEFLATE
@ TIFF_DEFLATE
Definition: tiff.h:135
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
encode_init
static av_cold int encode_init(AVCodecContext *avctx)
Definition: tiffenc.c:524
AV_CODEC_ID_TIFF
@ AV_CODEC_ID_TIFF
Definition: codec_id.h:148
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244