Go to the documentation of this file.
45 #define TIFF_MAX_ENTRY 32
49 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
89 if (
s->buf_size < *
s->buf -
s->buf_start +
need) {
90 *
s->buf =
s->buf_start +
s->buf_size + 1;
111 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[
type];
129 uint8_t *entries_ptr =
s->entries + 12 *
s->num_entries;
133 bytestream_put_le16(&entries_ptr,
tag);
134 bytestream_put_le16(&entries_ptr,
type);
135 bytestream_put_le32(&entries_ptr,
count);
140 bytestream_put_le32(&entries_ptr, *
s->buf -
s->buf_start);
178 unsigned long zlen =
s->buf_size - (*
s->buf -
s->buf_start);
179 if (compress(dst, &zlen,
src,
n) != Z_OK) {
193 src, 1,
n, 2, 0xff, -1, 0);
207 int w = (
s->width - 1) /
s->subsampling[0] + 1;
210 if (
s->width %
s->subsampling[0] ||
s->height %
s->subsampling[1]) {
211 for (
i = 0;
i <
w;
i++) {
212 for (j = 0; j <
s->subsampling[1]; j++)
213 for (k = 0; k <
s->subsampling[0]; k++)
215 FFMIN(
i *
s->subsampling[0] + k,
s->width-1)];
220 for (
i = 0;
i <
w;
i++) {
221 for (j = 0; j <
s->subsampling[1]; j++)
222 for (k = 0; k <
s->subsampling[0]; k++)
224 i *
s->subsampling[0] + k];
231 #define ADD_ENTRY(s, tag, type, count, ptr_val) \
233 ret = add_entry(s, tag, type, count, ptr_val); \
238 #define ADD_ENTRY1(s, tag, type, val) \
240 ret = add_entry1(s, tag, type, val); \
246 const AVFrame *pict,
int *got_packet)
256 uint32_t res[2] = {
s->dpi, 1 };
259 int is_yuv = 0,
alpha = 0;
260 int shift_h, shift_v;
265 s->subsampling[0] = 1;
266 s->subsampling[1] = 1;
273 s->bpp_tab_size =
desc->nb_components;
306 s->subsampling[0] = 1 << shift_h;
307 s->subsampling[1] = 1 << shift_v;
312 "This colors format is not supported\n");
316 for (
i = 0;
i <
s->bpp_tab_size;
i++)
317 bpp_tab[
i] =
desc->comp[
i].depth;
326 s->rps =
FFMAX(8192 / (((
s->width *
s->bpp) >> 3) + 1), 1);
328 s->rps = ((
s->rps - 1) /
s->subsampling[1] + 1) *
s->subsampling[1];
330 strips = (
s->height - 1) /
s->rps + 1;
332 bytes_per_row = (((
s->width - 1) /
s->subsampling[0] + 1) *
s->bpp *
333 s->subsampling[0] *
s->subsampling[1] + 7) >> 3;
334 packet_size = avctx->
height * bytes_per_row * 2 +
350 bytestream_put_le16(&ptr, 0x4949);
351 bytestream_put_le16(&ptr, 42);
354 bytestream_put_le32(&ptr, 0);
356 if (strips > INT_MAX /
FFMAX(
sizeof(
s->strip_sizes[0]),
sizeof(
s->strip_offsets[0]))) {
363 if (!
s->strip_sizes || !
s->strip_offsets) {
370 if (
s->yuv_line ==
NULL) {
383 zlen = bytes_per_row *
s->rps;
389 s->strip_offsets[0] = ptr -
pkt->
data;
391 for (j = 0; j <
s->rps; j++) {
394 memcpy(zbuf + zn,
s->yuv_line, bytes_per_row);
395 j +=
s->subsampling[1] - 1;
397 memcpy(zbuf + j * bytes_per_row,
408 s->strip_sizes[0] = ptr -
pkt->
data -
s->strip_offsets[0];
419 for (
i = 0;
i <
s->height;
i++) {
420 if (
s->strip_sizes[
i /
s->rps] == 0) {
423 s->buf_size - (*
s->buf -
s->buf_start),
426 s->strip_offsets[
i /
s->rps] = ptr -
pkt->
data;
431 i +=
s->subsampling[1] - 1;
434 ptr, bytes_per_row,
s->compr);
439 s->strip_sizes[
i /
s->rps] +=
ret;
442 (
i ==
s->height - 1 ||
i %
s->rps ==
s->rps - 1)) {
444 s->strip_sizes[(
i /
s->rps)] +=
ret;
486 uint16_t pal[256 * 3];
487 for (
i = 0;
i < 256;
i++) {
488 uint32_t rgb = *(uint32_t *) (p->
data[1] +
i * 4);
489 pal[
i] = ((rgb >> 16) & 0xff) * 257;
490 pal[
i + 256] = ((rgb >> 8) & 0xff) * 257;
491 pal[
i + 512] = (rgb & 0xff) * 257;
499 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
512 bytestream_put_le16(&ptr,
s->num_entries);
514 bytestream_put_le32(&ptr, 0);
531 "Deflate compression needs zlib compiled in\n");
536 #if FF_API_CODED_FRAME
558 #define OFFSET(x) offsetof(TiffEncoderContext, x)
559 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
static av_cold int encode_close(AVCodecContext *avctx)
#define FF_ENABLE_DEPRECATION_WARNINGS
TiffTypes
data type identifiers for TIFF tags
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
AVPixelFormat
Pixel format.
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, void(*lzw_put_bits)(struct PutBitContext *, int, unsigned int))
static av_cold int init(AVCodecContext *avctx)
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.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
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.
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
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
unsigned int yuv_line_size
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
int key_frame
1 -> keyframe, 0-> not
int flags
AV_CODEC_FLAG_*.
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 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.
static enum AVPixelFormat pix_fmts[]
#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...
@ AV_PICTURE_TYPE_I
Intra.
uint32_t dpi
image resolution in DPI
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
struct LZWEncodeState * lzws
LZW encode state.
enum AVPictureType pict_type
Picture type of the frame.
@ 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.
const char const char void * val
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
int flags
A combination of AV_PKT_FLAG values.
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...
const char * name
Name of the codec implementation.
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.
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
int ff_lzw_encode_flush(struct LZWEncodeState *s, void(*lzw_flush_put_bits)(struct PutBitContext *))
@ 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)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
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, size in bytes of each picture line.
@ 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_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or 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.