FFmpeg
Data Structures | Macros | Functions | Variables
tiffenc.c File Reference
#include "config.h"
#include "libavutil/imgutils.h"
#include "libavutil/log.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "avcodec.h"
#include "bytestream.h"
#include "internal.h"
#include "lzw.h"
#include "put_bits.h"
#include "rle.h"
#include "tiff.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
 
AVCodec 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 45 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 231 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 238 of file tiffenc.c.

◆ OFFSET

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

Definition at line 558 of file tiffenc.c.

◆ VE

Definition at line 559 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 87 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 106 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 126 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 150 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 170 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 203 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 245 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 547 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 48 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, "compression_algo" },
{ "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, "compression_algo" },
{ "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, "compression_algo" },
{ "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, "compression_algo" },
{ "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, "compression_algo" },
{ NULL },
}

Definition at line 560 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 570 of file tiffenc.c.

◆ ff_tiff_encoder

AVCodec ff_tiff_encoder
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: tiffenc.c:547
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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
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:75
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
TIFF_RAW
@ TIFF_RAW
Definition: tiff.h:121
TIFF_PACKBITS
@ TIFF_PACKBITS
Definition: tiff.h:129
add_entry1
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
Definition: tiffenc.c:150
fail
#define fail()
Definition: checkasm.h:123
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
OFFSET
#define OFFSET(x)
Definition: tiffenc.c:558
VE
#define VE
Definition: tiffenc.c:559
s
#define s(width, name)
Definition: cbs_vp9.c:257
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:276
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
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:66
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:93
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:106
AV_PIX_FMT_GRAY8A
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition: pixfmt.h:146
TIFF_LZW
@ TIFF_LZW
Definition: tiff.h:125
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:103
AV_PIX_FMT_YA16LE
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition: pixfmt.h:213
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:76
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
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:206
TiffEncoderContext
Definition: tiffenc.c:52
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:68
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
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:126
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: tiffenc.c:245
tiffenc_class
static const AVClass tiffenc_class
Definition: tiffenc.c:570
AV_PIX_FMT_PAL8
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition: pixfmt.h:77
tag
uint32_t tag
Definition: movenc.c:1532
ret
ret
Definition: filter_design.txt:187
options
static const AVOption options[]
Definition: tiffenc.c:560
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
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:71
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:98
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:70
TIFF_DEFLATE
@ TIFF_DEFLATE
Definition: tiff.h:130
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:73
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:72
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:145
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:232