48#define TIFF_MAX_ENTRY 32
52 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
92 if (
s->buf_size < *
s->buf -
s->buf_start + need) {
93 *
s->buf =
s->buf_start +
s->buf_size + 1;
114 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[
type];
132 uint8_t *entries_ptr =
s->entries + 12 *
s->num_entries;
136 bytestream_put_le16(&entries_ptr,
tag);
137 bytestream_put_le16(&entries_ptr,
type);
138 bytestream_put_le32(&entries_ptr, count);
141 tnput(&entries_ptr, count, ptr_val,
type, 0);
143 bytestream_put_le32(&entries_ptr, *
s->buf -
s->buf_start);
174 uint8_t *
dst,
int n,
int compr)
181 unsigned long zlen =
s->buf_size - (*
s->buf -
s->buf_start);
182 if (compress(
dst, &zlen,
src, n) != Z_OK) {
196 src, 1, n, 2, 0xff, -1, 0);
207 uint8_t *
dst,
int lnum)
210 int w = (
s->width - 1) /
s->subsampling[0] + 1;
211 const uint8_t *pu = &p->data[1][lnum /
s->subsampling[1] * p->linesize[1]];
212 const uint8_t *pv = &p->data[2][lnum /
s->subsampling[1] * p->linesize[2]];
213 if (
s->width %
s->subsampling[0] ||
s->height %
s->subsampling[1]) {
214 for (
i = 0;
i <
w;
i++) {
215 for (j = 0; j <
s->subsampling[1]; j++)
216 for (k = 0; k <
s->subsampling[0]; k++)
217 *
dst++ = p->data[0][
FFMIN(lnum + j,
s->height-1) * p->linesize[0] +
218 FFMIN(
i *
s->subsampling[0] + k,
s->width-1)];
223 for (
i = 0;
i <
w;
i++) {
224 for (j = 0; j <
s->subsampling[1]; j++)
225 for (k = 0; k <
s->subsampling[0]; k++)
226 *
dst++ = p->data[0][(lnum + j) * p->linesize[0] +
227 i *
s->subsampling[0] + k];
234#define ADD_ENTRY(s, tag, type, count, ptr_val) \
236 ret = add_entry(s, tag, type, count, ptr_val); \
241#define ADD_ENTRY1(s, tag, type, val) \
243 ret = add_entry1(s, tag, type, val); \
249 const AVFrame *pict,
int *got_packet)
259 uint32_t res[2] = {
s->dpi, 1 };
262 int is_yuv = 0,
alpha = 0;
263 int shift_h, shift_v;
268 s->subsampling[0] = 1;
269 s->subsampling[1] = 1;
276 s->bpp_tab_size =
desc->nb_components;
312 s->subsampling[0] = 1 << shift_h;
313 s->subsampling[1] = 1 << shift_v;
318 "This colors format is not supported\n");
322 for (
i = 0;
i <
s->bpp_tab_size;
i++)
323 bpp_tab[
i] =
desc->comp[
i].depth;
332 s->rps =
FFMAX(8192 / (((
s->width *
s->bpp) >> 3) + 1), 1);
334 s->rps = ((
s->rps - 1) /
s->subsampling[1] + 1) *
s->subsampling[1];
336 strips = (
s->height - 1) /
s->rps + 1;
338 bytes_per_row = (((
s->width - 1) /
s->subsampling[0] + 1) *
s->bpp *
339 s->subsampling[0] *
s->subsampling[1] + 7) >> 3;
340 packet_size = avctx->
height * bytes_per_row * 2 +
346 s->buf_start =
pkt->data;
348 s->buf_size =
pkt->size;
356 bytestream_put_le16(&ptr, 0x4949);
357 bytestream_put_le16(&ptr, 42);
360 bytestream_put_le32(&ptr, 0);
362 if (strips > INT_MAX /
FFMAX(
sizeof(
s->strip_sizes[0]),
sizeof(
s->strip_offsets[0]))) {
369 if (!
s->strip_sizes || !
s->strip_offsets) {
376 if (
s->yuv_line ==
NULL) {
389 zlen = bytes_per_row *
s->rps;
395 s->strip_offsets[0] = ptr -
pkt->data;
397 for (j = 0; j <
s->rps; j++) {
400 memcpy(zbuf + zn,
s->yuv_line, bytes_per_row);
401 j +=
s->subsampling[1] - 1;
403 memcpy(zbuf + j * bytes_per_row,
404 p->data[0] + j * p->linesize[0], bytes_per_row);
414 s->strip_sizes[0] = ptr -
pkt->data -
s->strip_offsets[0];
425 for (
i = 0;
i <
s->height;
i++) {
426 if (
s->strip_sizes[
i /
s->rps] == 0) {
429 s->buf_size - (*
s->buf -
s->buf_start),
432 s->strip_offsets[
i /
s->rps] = ptr -
pkt->data;
437 i +=
s->subsampling[1] - 1;
440 ptr, bytes_per_row,
s->compr);
445 s->strip_sizes[
i /
s->rps] += ret;
448 (
i ==
s->height - 1 ||
i %
s->rps ==
s->rps - 1)) {
450 s->strip_sizes[(
i /
s->rps)] += ret;
474 if (orientation >= 1 && orientation <= 8)
499 uint16_t pal[256 * 3];
500 for (
i = 0;
i < 256;
i++) {
501 uint32_t
rgb = *(uint32_t *) (p->data[1] +
i * 4);
502 pal[
i] = ((
rgb >> 16) & 0xff) * 257;
503 pal[
i + 256] = ((
rgb >> 8) & 0xff) * 257;
504 pal[
i + 512] = (
rgb & 0xff) * 257;
512 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
519 bytestream_put_le32(&
offset, ptr -
pkt->data);
525 bytestream_put_le16(&ptr,
s->num_entries);
527 bytestream_put_le32(&ptr, 0);
529 pkt->size = ptr -
pkt->data;
533 return ret < 0 ? ret : 0;
543 "Deflate compression needs zlib compiled in\n");
564#define OFFSET(x) offsetof(TiffEncoderContext, x)
565#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
577 .class_name =
"TIFF encoder",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_tiff_encoder
static av_cold void close(AVCodecParserContext *s)
static av_cold int encode_init(AVCodecContext *avctx)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
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)
#define CODEC_PIXFMTS(...)
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
static av_cold int encode_close(AVCodecContext *avctx)
int(* init)(AVBSFContext *ctx)
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
int av_exif_matrix_to_orientation(const int32_t *matrix)
Convert a display matrix used by AV_FRAME_DATA_DISPLAYMATRIX into an orientation constant used by EXI...
AVTiffDataType
Data type identifiers for TIFF tags.
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
#define AV_OPT_FLAG_VIDEO_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
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...
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.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
static AVRational av_make_q(int num, int den)
Create an AVRational.
#define LIBAVUTIL_VERSION_INT
static const int16_t alpha[]
static void flip(AVCodecContext *avctx, AVFrame *frame)
Libavcodec version macros.
Macro definitions for various function/variable attributes.
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.
const int ff_lzw_encode_state_size
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
int ff_lzw_encode_flush(struct LZWEncodeState *s)
Write end code and flush bitstream.
Memory handling functions.
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.
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
@ 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_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
@ 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_GRAY16LE
Y , 16bpp, little-endian.
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ 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 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.
Describe the class of an AVClass context structure.
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int flags
AV_CODEC_FLAG_*.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Structure to hold side data for an AVFrame.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
struct LZWEncodeState * lzws
LZW encode state.
int num_entries
number of entries
uint8_t entries[TIFF_MAX_ENTRY *12]
entries in header
uint8_t ** buf
actual position in buffer
int bpp_tab_size
bpp_tab size
unsigned int strip_offsets_size
unsigned int yuv_line_size
uint32_t dpi
image resolution in DPI
unsigned int bpp
bits per pixel
uint16_t subsampling[2]
YUV subsampling factors.
int compr
compression level
enum TiffPhotometric photometric_interpretation
photometric interpretation
unsigned int strip_sizes_size
int strips
number of strips
uint8_t * buf_start
pointer to first byte in buffer
TIFF constants & data structures.
TiffTags
abridged list of TIFF and TIFF/EP tags
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
@ TIFF_PHOTOMETRIC_PALETTE
@ TIFF_PHOTOMETRIC_WHITE_IS_ZERO
@ TIFF_PHOTOMETRIC_BLACK_IS_ZERO
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
static int encode_strip(TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr)
Encode one strip in tiff file.
static int add_entry(TiffEncoderContext *s, enum TiffTags tag, enum AVTiffDataType type, int count, const void *ptr_val)
Add entry to directory in tiff header.
#define ADD_ENTRY1(s, tag, type, val)
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
static av_cold int encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum AVTiffDataType type, int val)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
static void tnput(uint8_t **p, int n, const uint8_t *val, enum AVTiffDataType type, int flip)
Put n values to buffer.
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, uint8_t *dst, int lnum)
static const AVClass tiffenc_class
#define ADD_ENTRY(s, tag, type, count, ptr_val)