43 #define TIFF_MAX_ENTRY 32
101 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[type];
104 *(*p)++ = val[i ^
flip];
116 enum TiffTypes type,
int count,
const void *ptr_val)
122 bytestream_put_le16(&entries_ptr, tag);
123 bytestream_put_le16(&entries_ptr, type);
124 bytestream_put_le32(&entries_ptr, count);
127 tnput(&entries_ptr, count, ptr_val, type, 0);
129 bytestream_put_le32(&entries_ptr, *s->
buf - s->
buf_start);
131 tnput(s->
buf, count, ptr_val, type, 0);
156 uint8_t *dst,
int n,
int compr)
164 if (compress(dst, &zlen, src, n) != Z_OK) {
178 src, 1, n, 2, 0xff, -1, 0);
193 for (i = 0; i < w; i++) {
204 const AVFrame *pict,
int *got_packet)
212 uint32_t *strip_sizes =
NULL;
213 uint32_t *strip_offsets =
NULL;
215 uint32_t res[2] = { 72, 1 };
216 uint16_t bpp_tab[] = { 8, 8, 8, 8 };
220 int shift_h, shift_v;
265 s->
bpp = 8 + (16 >> (shift_h + shift_v));
273 "This colors format is not supported\n");
306 bytestream_put_le16(&ptr, 0x4949);
307 bytestream_put_le16(&ptr, 42);
310 bytestream_put_le32(&ptr, 0);
312 strip_sizes =
av_mallocz(
sizeof(*strip_sizes) * strips);
313 strip_offsets =
av_mallocz(
sizeof(*strip_offsets) * strips);
314 if (!strip_sizes || !strip_offsets) {
323 if (yuv_line ==
NULL) {
336 zlen = bytes_per_row * s->
rps;
342 strip_offsets[0] = ptr - pkt->
data;
344 for (j = 0; j < s->
rps; j++) {
347 memcpy(zbuf + zn, yuv_line, bytes_per_row);
350 memcpy(zbuf + j * bytes_per_row,
361 strip_sizes[0] = ptr - pkt->
data - strip_offsets[0];
371 for (i = 0; i < s->
height; i++) {
372 if (strip_sizes[i / s->
rps] == 0) {
378 strip_offsets[i / s->
rps] = ptr - pkt->
data;
386 ptr, bytes_per_row, s->
compr);
391 strip_sizes[i / s->
rps] += ret;
396 strip_sizes[(i / s->
rps)] += ret;
430 uint16_t pal[256 * 3];
431 for (i = 0; i < 256; i++) {
432 uint32_t rgb = *(uint32_t *) (p->
data[1] + i * 4);
433 pal[i] = ((rgb >> 16) & 0xff) * 257;
434 pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
435 pal[i + 512] = (rgb & 0xff) * 257;
441 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
446 bytestream_put_le32(&offset, ptr - pkt->
data);
454 bytestream_put_le32(&ptr, 0);
485 #define OFFSET(x) offsetof(TiffEncoderContext, x)
486 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
int photometric_interpretation
photometric interpretation
static av_cold int encode_init(AVCodecContext *avctx)
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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)
packed RGB 8:8:8, 24bpp, RGBRGB...
int strips
number of strips
AVFrame * coded_frame
the picture in the bitstream
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
uint8_t ** buf
actual position in buffer
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static void add_entry(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int count, const void *ptr_val)
Add entry to directory in tiff header.
int compr
compression level
struct LZWEncodeState * lzws
LZW encode state.
uint8_t * buf_start
pointer to first byte in buffer
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
8 bit with 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 void add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#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 *))
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const uint8_t type_sizes2[6]
sizes of various TIFF field types (string size = 1)
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
static void put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
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 FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
int width
picture width / height.
if(ac->has_optimized_func)
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
static void close(AVCodecParserContext *s)
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.
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
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))
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
static void flip(AVCodecContext *avctx, AVPicture *picture)
FF_ENABLE_DEPRECATION_WARNINGS 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.
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
static av_cold int init(AVCodecParserContext *s)
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
static const AVOption options[]
Y , 16bpp, little-endian.
int key_frame
1 -> keyframe, 0-> not
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 int ff_lzw_encode_state_size
AVPixelFormat
Pixel format.
This structure stores compressed data.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.