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);
138 tnput(&entries_ptr, count, ptr_val,
type, 0);
140 bytestream_put_le32(&entries_ptr, *
s->buf -
s->buf_start);
171 uint8_t *dst,
int n,
int compr)
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);
521 return ret < 0 ? ret : 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
static double val(void *priv, double ch)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
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 AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#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.
@ AV_PICTURE_TYPE_I
Intra.
#define LIBAVUTIL_VERSION_INT
static const int16_t alpha[]
static void flip(AVCodecContext *avctx, AVFrame *frame)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FF_DISABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
static enum AVPixelFormat pix_fmts[]
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.
#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
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.
AVPixelFormat
Pixel format.
@ 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.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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).
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
int flags
AV_CODEC_FLAG_*.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int key_frame
1 -> keyframe, 0-> not
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
enum AVPictureType pict_type
Picture type of the frame.
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
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
TiffTypes
data type identifiers for TIFF tags
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.
#define ADD_ENTRY1(s, tag, type, val)
static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, int flip)
Put n values to buffer.
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
static const AVOption options[]
static av_cold int encode_init(AVCodecContext *avctx)
static av_cold int encode_close(AVCodecContext *avctx)
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
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
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
#define ADD_ENTRY(s, tag, type, count, ptr_val)
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 const uint8_t offset[127][2]