33 #include "libavutil/imgutils.h"
34 #include "libavutil/log.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/pixdesc.h"
45 #define TIFF_MAX_ENTRY 32
49 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
112 flip ^= ((
int[]) { 0, 0, 0, 1, 3, 3 })[type];
115 *(*p)++ = val[i ^
flip];
134 bytestream_put_le16(&entries_ptr, tag);
135 bytestream_put_le16(&entries_ptr, type);
136 bytestream_put_le32(&entries_ptr, count);
139 tnput(&entries_ptr, count, ptr_val, type, 0);
141 bytestream_put_le32(&entries_ptr, *s->
buf - s->
buf_start);
143 tnput(s->
buf, count, ptr_val, type, 0);
176 if (compress(dst, &zlen, src, n) != Z_OK) {
190 src, 1, n, 2, 0xff, -1, 0);
206 for (i = 0; i < w; i++) {
215 for (i = 0; i < w; i++) {
239 const AVFrame *pict,
int *got_packet)
249 uint32_t
res[2] = { s->
dpi, 1 };
252 int is_yuv = 0,
alpha = 0;
253 int shift_h, shift_v;
302 "This colors format is not supported\n");
335 bytestream_put_le16(&ptr, 0x4949);
336 bytestream_put_le16(&ptr, 42);
339 bytestream_put_le32(&ptr, 0);
366 zlen = bytes_per_row * s->
rps;
374 for (j = 0; j < s->
rps; j++) {
377 memcpy(zbuf + zn, s->
yuv_line, bytes_per_row);
380 memcpy(zbuf + j * bytes_per_row,
402 for (i = 0; i < s->
height; i++) {
417 ptr, bytes_per_row, s->
compr);
462 uint16_t pal[256 * 3];
463 for (i = 0; i < 256; i++) {
464 uint32_t rgb = *(uint32_t *) (p->
data[1] + i * 4);
465 pal[i] = ((rgb >> 16) & 0xff) * 257;
466 pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
467 pal[i + 512] = (rgb & 0xff) * 257;
475 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
482 bytestream_put_le32(&offset, ptr - pkt->
data);
490 bytestream_put_le32(&ptr, 0);
497 return ret < 0 ? ret : 0;
511 #define OFFSET(x) offsetof(TiffEncoderContext, x)
512 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
int photometric_interpretation
photometric interpretation
static av_cold int encode_init(AVCodecContext *avctx)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and/or allocate data.
const char const char void * val
int num_entries
number of entries
static av_cold int encode_close(AVCodecContext *avctx)
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.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define LIBAVUTIL_VERSION_INT
int strips
number of strips
static av_cold int init(AVCodecContext *avctx)
unsigned int strip_offsets_size
packed RGB 8:8:8, 24bpp, RGBRGB...
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
uint8_t ** buf
actual position in buffer
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
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 FF_INPUT_BUFFER_PADDING_SIZE at the end w...
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
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static const uint8_t offset[511][2]
const char * name
Name of the codec implementation.
static void add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
#define AV_OPT_FLAG_VIDEO_PARAM
static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum)
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
const OptionDef options[]
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
#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 *))
uint16_t depth_minus1
number of bits in the component minus 1
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Libavcodec external API header.
AVPixelFormat
Pixel format.
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 flags
A combination of AV_PKT_FLAG values.
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.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
TiffTypes
data type identifiers for TIFF tags
int AC3_NAME() encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
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
Describe the class of an AVClass context structure.
AVFrame * coded_frame
the picture in the bitstream
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
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Y , 16bpp, little-endian.
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
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))
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.
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int bpp_tab_size
bpp_tab size
static void flip(AVCodecContext *avctx, AVPicture *picture)
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_OPT_FLAG_ENCODING_PARAM
a generic parameter which can be set by the user for muxing or encoding
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
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.
uint32_t dpi
image resolution in DPI
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const int ff_lzw_encode_state_size
8 bit with PIX_FMT_RGB32 palette
unsigned int yuv_line_size
This structure stores compressed data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
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 RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...