Go to the documentation of this file.
47 #define TIFF_MAX_ENTRY 32
51 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
91 if (
s->buf_size < *
s->buf -
s->buf_start +
need) {
92 *
s->buf =
s->buf_start +
s->buf_size + 1;
113 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[
type];
131 uint8_t *entries_ptr =
s->entries + 12 *
s->num_entries;
135 bytestream_put_le16(&entries_ptr,
tag);
136 bytestream_put_le16(&entries_ptr,
type);
137 bytestream_put_le32(&entries_ptr, count);
140 tnput(&entries_ptr, count, ptr_val,
type, 0);
142 bytestream_put_le32(&entries_ptr, *
s->buf -
s->buf_start);
173 uint8_t *dst,
int n,
int compr)
180 unsigned long zlen =
s->buf_size - (*
s->buf -
s->buf_start);
181 if (compress(dst, &zlen,
src, n) != Z_OK) {
195 src, 1, n, 2, 0xff, -1, 0);
206 uint8_t *dst,
int lnum)
209 int w = (
s->width - 1) /
s->subsampling[0] + 1;
210 uint8_t *pu = &p->
data[1][lnum /
s->subsampling[1] * p->
linesize[1]];
212 if (
s->width %
s->subsampling[0] ||
s->height %
s->subsampling[1]) {
213 for (
i = 0;
i <
w;
i++) {
214 for (j = 0; j <
s->subsampling[1]; j++)
215 for (k = 0; k <
s->subsampling[0]; k++)
217 FFMIN(
i *
s->subsampling[0] + k,
s->width-1)];
222 for (
i = 0;
i <
w;
i++) {
223 for (j = 0; j <
s->subsampling[1]; j++)
224 for (k = 0; k <
s->subsampling[0]; k++)
226 i *
s->subsampling[0] + k];
233 #define ADD_ENTRY(s, tag, type, count, ptr_val) \
235 ret = add_entry(s, tag, type, count, ptr_val); \
240 #define ADD_ENTRY1(s, tag, type, val) \
242 ret = add_entry1(s, tag, type, val); \
248 const AVFrame *pict,
int *got_packet)
258 uint32_t res[2] = {
s->dpi, 1 };
261 int is_yuv = 0,
alpha = 0;
262 int shift_h, shift_v;
267 s->subsampling[0] = 1;
268 s->subsampling[1] = 1;
275 s->bpp_tab_size =
desc->nb_components;
308 s->subsampling[0] = 1 << shift_h;
309 s->subsampling[1] = 1 << shift_v;
314 "This colors format is not supported\n");
318 for (
i = 0;
i <
s->bpp_tab_size;
i++)
319 bpp_tab[
i] =
desc->comp[
i].depth;
328 s->rps =
FFMAX(8192 / (((
s->width *
s->bpp) >> 3) + 1), 1);
330 s->rps = ((
s->rps - 1) /
s->subsampling[1] + 1) *
s->subsampling[1];
332 strips = (
s->height - 1) /
s->rps + 1;
334 bytes_per_row = (((
s->width - 1) /
s->subsampling[0] + 1) *
s->bpp *
335 s->subsampling[0] *
s->subsampling[1] + 7) >> 3;
336 packet_size = avctx->
height * bytes_per_row * 2 +
352 bytestream_put_le16(&ptr, 0x4949);
353 bytestream_put_le16(&ptr, 42);
356 bytestream_put_le32(&ptr, 0);
358 if (strips > INT_MAX /
FFMAX(
sizeof(
s->strip_sizes[0]),
sizeof(
s->strip_offsets[0]))) {
365 if (!
s->strip_sizes || !
s->strip_offsets) {
372 if (
s->yuv_line ==
NULL) {
385 zlen = bytes_per_row *
s->rps;
391 s->strip_offsets[0] = ptr -
pkt->
data;
393 for (j = 0; j <
s->rps; j++) {
396 memcpy(zbuf + zn,
s->yuv_line, bytes_per_row);
397 j +=
s->subsampling[1] - 1;
399 memcpy(zbuf + j * bytes_per_row,
410 s->strip_sizes[0] = ptr -
pkt->
data -
s->strip_offsets[0];
421 for (
i = 0;
i <
s->height;
i++) {
422 if (
s->strip_sizes[
i /
s->rps] == 0) {
425 s->buf_size - (*
s->buf -
s->buf_start),
428 s->strip_offsets[
i /
s->rps] = ptr -
pkt->
data;
433 i +=
s->subsampling[1] - 1;
436 ptr, bytes_per_row,
s->compr);
441 s->strip_sizes[
i /
s->rps] +=
ret;
444 (
i ==
s->height - 1 ||
i %
s->rps ==
s->rps - 1)) {
446 s->strip_sizes[(
i /
s->rps)] +=
ret;
488 uint16_t pal[256 * 3];
489 for (
i = 0;
i < 256;
i++) {
490 uint32_t
rgb = *(uint32_t *) (p->
data[1] +
i * 4);
491 pal[
i] = ((
rgb >> 16) & 0xff) * 257;
492 pal[
i + 256] = ((
rgb >> 8) & 0xff) * 257;
493 pal[
i + 512] = (
rgb & 0xff) * 257;
501 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
514 bytestream_put_le16(&ptr,
s->num_entries);
516 bytestream_put_le32(&ptr, 0);
532 "Deflate compression needs zlib compiled in\n");
553 #define OFFSET(x) offsetof(TiffEncoderContext, x)
554 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
static av_cold int encode_close(AVCodecContext *avctx)
TiffTypes
data type identifiers for TIFF tags
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
AVPixelFormat
Pixel format.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int encode_strip(TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr)
Encode one strip in tiff file.
#define AV_OPT_FLAG_VIDEO_PARAM
uint8_t entries[TIFF_MAX_ENTRY *12]
entries in header
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int bpp_tab_size
bpp_tab size
unsigned int strip_sizes_size
This structure describes decoded (raw) audio or video data.
TiffTags
abridged list of TIFF and TIFF/EP tags
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, int little_endian)
Initialize LZW encoder.
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
uint16_t subsampling[2]
YUV subsampling factors.
@ TIFF_PHOTOMETRIC_WHITE_IS_ZERO
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
unsigned int yuv_line_size
AVCodec p
The public AVCodec.
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
int flags
AV_CODEC_FLAG_*.
static double val(void *priv, double ch)
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
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
int num_entries
number of entries
#define FF_CODEC_ENCODE_CB(func)
#define ADD_ENTRY1(s, tag, type, val)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
int strips
number of strips
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_INPUT_BUFFER_MIN_SIZE
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
must be printed separately If there s no standard function for printing the type you need
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
#define ADD_ENTRY(s, tag, type, count, ptr_val)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
uint8_t ** buf
actual position in buffer
Rational number (pair of numerator and denominator).
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ 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...
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ TIFF_PHOTOMETRIC_PALETTE
const char * av_default_item_name(void *ptr)
Return the context name.
@ 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...
uint32_t dpi
image resolution in DPI
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
struct LZWEncodeState * lzws
LZW encode state.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
static void flip(AVCodecContext *avctx, AVFrame *frame)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static AVRational av_make_q(int num, int den)
Create an AVRational.
int compr
compression level
static const AVClass tiffenc_class
#define AVERROR_EXTERNAL
Generic error in an external library.
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 offset
static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, int flip)
Put n values to buffer.
enum TiffPhotometric photometric_interpretation
photometric interpretation
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define i(width, name, range_min, range_max)
@ TIFF_PHOTOMETRIC_BLACK_IS_ZERO
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...
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
const char * name
Name of the codec implementation.
int ff_lzw_encode_flush(struct LZWEncodeState *s)
Write end code and flush bitstream.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
int ff_rle_encode(uint8_t *outbuf, int out_size, const uint8_t *ptr, int bpp, int w, int add_rep, int xor_rep, int add_raw, int xor_raw)
RLE compress the row, with maximum size of out_size.
const FFCodec ff_tiff_encoder
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
main external API structure.
unsigned int bpp
bits per pixel
static const AVOption options[]
unsigned int strip_offsets_size
void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_padded_malloc except that buffer will always be 0-initialized after call.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, uint8_t *dst, int lnum)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static const int16_t alpha[]
This structure stores compressed data.
uint8_t * buf_start
pointer to first byte in buffer
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
const int ff_lzw_encode_state_size
int width
picture width / height.
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static av_cold int encode_init(AVCodecContext *avctx)
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.