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);
132 tnput(s->
buf, count, ptr_val, type, 0);
145 type ==
TIFF_SHORT ? (
void *)&w : (
void *)&dw);
168 if (compress(dst, &zlen, src, n) != Z_OK) {
182 src, 1, n, 2, 0xff, -1, 0);
197 for (i = 0; i < w; i++) {
207 #define ADD_ENTRY(s, tag, type, count, ptr_val) \ 209 ret = add_entry(s, tag, type, count, ptr_val); \ 214 #define ADD_ENTRY1(s, tag, type, val) \ 216 ret = add_entry1(s, tag, type, val); \ 222 const AVFrame *pict,
int *got_packet)
230 uint32_t *strip_sizes =
NULL;
231 uint32_t *strip_offsets =
NULL;
233 uint32_t res[2] = { 72, 1 };
234 uint16_t bpp_tab[] = { 8, 8, 8, 8 };
238 int shift_h, shift_v;
288 s->
bpp = 8 + (16 >> (shift_h + shift_v));
296 "This colors format is not supported\n");
313 packet_size = avctx->
height * ((avctx->
width * s->
bpp + 7) >> 3) * 2 +
332 bytestream_put_le16(&ptr, 0x4949);
333 bytestream_put_le16(&ptr, 42);
336 bytestream_put_le32(&ptr, 0);
340 if (!strip_sizes || !strip_offsets) {
362 zlen = bytes_per_row * s->
rps;
368 strip_offsets[0] = ptr - pkt->
data;
370 for (j = 0; j < s->
rps; j++) {
373 memcpy(zbuf + zn, yuv_line, bytes_per_row);
376 memcpy(zbuf + j * bytes_per_row,
387 strip_sizes[0] = ptr - pkt->
data - strip_offsets[0];
397 for (i = 0; i < s->
height; i++) {
398 if (strip_sizes[i / s->
rps] == 0) {
404 strip_offsets[i / s->
rps] = ptr - pkt->
data;
412 ptr, bytes_per_row, s->
compr);
417 strip_sizes[i / s->
rps] += ret;
422 strip_sizes[(i / s->
rps)] += ret;
456 uint16_t pal[256 * 3];
457 for (i = 0; i < 256; i++) {
458 uint32_t rgb = *(uint32_t *) (p->
data[1] + i * 4);
459 pal[i] = ((rgb >> 16) & 0xff) * 257;
460 pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
461 pal[i + 512] = (rgb & 0xff) * 257;
467 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
472 bytestream_put_le32(&offset, ptr - pkt->
data);
480 bytestream_put_le32(&ptr, 0);
500 "Deflate compression needs zlib compiled in\n");
505 #if FF_API_CODED_FRAME 515 #define OFFSET(x) offsetof(TiffEncoderContext, x) 516 #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.
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 ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int num_entries
number of entries
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
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_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
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.
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
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 ADD_ENTRY1(s, tag, type, val)
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_sizes[6]
sizes of various TIFF field types (string size = 100)
#define AV_INPUT_BUFFER_MIN_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
#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 ADD_ENTRY(s, tag, type, count, ptr_val)
#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(). ...
static void flip(AVCodecContext *avctx, AVFrame *frame)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
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. ...
static const uint8_t type_sizes2[6]
sizes of various TIFF field types (string size = 1)
int flags
AV_CODEC_FLAG_*.
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.
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)
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
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.
if(ac->has_optimized_func)
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
static const AVClass tiffenc_class
#define AVERROR_BUG
Bug detected, please report the issue.
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
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
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
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
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)
#define FF_ENABLE_DEPRECATION_WARNINGS
static const AVOption options[]
Y , 16bpp, little-endian.
int key_frame
1 -> keyframe, 0-> not
static void * av_mallocz_array(size_t nmemb, size_t size)
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.
const int ff_lzw_encode_state_size
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...