45 #define TIFF_MAX_ENTRY 32
49 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
111 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[type];
114 *(*p)++ = val[i ^
flip];
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);
143 tnput(s->
buf, count, ptr_val, type, 0);
156 type ==
TIFF_SHORT ? (
void *)&w : (
void *)&dw);
179 if (compress(dst, &zlen, src, n) != Z_OK) {
193 src, 1, n, 2, 0xff, -1, 0);
211 for (i = 0; i < w; i++) {
220 for (i = 0; i < w; i++) {
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;
312 "This colors format is not supported\n");
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);
383 zlen = bytes_per_row * s->
rps;
391 for (j = 0; j < s->
rps; j++) {
394 memcpy(zbuf + zn, s->
yuv_line, bytes_per_row);
397 memcpy(zbuf + j * bytes_per_row,
419 for (i = 0; i < s->
height; i++) {
434 ptr, bytes_per_row, s->
compr);
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 };
506 bytestream_put_le32(&offset, ptr - pkt->
data);
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 av_cold int encode_init(AVCodecContext *avctx)
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int num_entries
number of entries
static av_cold int encode_close(AVCodecContext *avctx)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
unsigned int bpp
bits per pixel
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define LIBAVUTIL_VERSION_INT
packed RGB 8:8:8, 24bpp, RGBRGB...
int strips
number of strips
static av_cold int init(AVCodecContext *avctx)
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
unsigned int strip_offsets_size
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
uint8_t ** buf
actual position in buffer
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
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...
int compr
compression level
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
struct LZWEncodeState * lzws
LZW encode state.
uint8_t * buf_start
pointer to first byte in buffer
#define AV_CODEC_CAP_INTRA_ONLY
Codec is intra only.
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define ADD_ENTRY1(s, tag, type, val)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
8 bits with AV_PIX_FMT_RGB32 palette
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#define AV_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int ff_lzw_encode_flush(struct LZWEncodeState *s, void(*lzw_flush_put_bits)(struct PutBitContext *))
#define ADD_ENTRY(s, tag, type, count, ptr_val)
unsigned int strip_sizes_size
static double alpha(void *priv, double x, double y)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void flip(AVCodecContext *avctx, AVFrame *frame)
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
uint8_t nb_components
The number of components each pixel has, (1-4)
enum AVPictureType pict_type
Picture type of the frame.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int width
picture width / height.
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
TiffTypes
data type identifiers for TIFF tags
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.
Libavcodec external API header.
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static AVRational av_make_q(int num, int den)
Create an AVRational.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
#define AV_OPT_FLAG_VIDEO_PARAM
main external API structure.
static const AVClass tiffenc_class
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, int flip)
Put n values to buffer.
uint16_t subsampling[2]
YUV subsampling factors.
uint8_t entries[TIFF_MAX_ENTRY *12]
entries in header
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static enum AVPixelFormat pix_fmts[]
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, uint8_t *dst, int lnum)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
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))
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
int bpp_tab_size
bpp_tab 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...
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
#define FF_ENABLE_DEPRECATION_WARNINGS
static const AVOption options[]
Y , 16bpp, little-endian.
int key_frame
1 -> keyframe, 0-> not
16 bits gray, 16 bits alpha (little-endian)
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
enum TiffPhotometric photometric_interpretation
photometric interpretation
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.
uint32_t dpi
image resolution in DPI
const int ff_lzw_encode_state_size
int depth
Number of bits in the component.
unsigned int yuv_line_size
#define AVERROR_EXTERNAL
Generic error in an external library.
AVPixelFormat
Pixel format.
This structure stores compressed data.
TiffTags
abridged list of TIFF tags
static int encode_strip(TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr)
Encode one strip in tiff file.
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...