41 #define TIFF_MAX_ENTRY 32
96 static void tnput(uint8_t ** p,
int n,
const uint8_t * val,
enum TiffTypes type,
101 flip ^= ((
int[]) {0, 0, 0, 1, 3, 3})[type];
104 *(*p)++ = val[i ^
flip];
123 bytestream_put_le16(&entries_ptr, tag);
124 bytestream_put_le16(&entries_ptr, type);
125 bytestream_put_le32(&entries_ptr, count);
128 tnput(&entries_ptr, count, ptr_val, type, 0);
130 bytestream_put_le32(&entries_ptr, *s->
buf - s->
buf_start);
132 tnput(s->
buf, count, ptr_val, type, 0);
156 uint8_t * dst,
int n,
int compr)
165 if (compress(dst, &zlen, src, n) != Z_OK) {
193 for (i = 0; i < w; i++){
204 int buf_size,
void *
data)
214 uint32_t *strip_sizes =
NULL;
215 uint32_t *strip_offsets =
NULL;
217 uint32_t res[2] = { 72, 1 };
218 static const uint16_t bpp_tab[] = { 8, 8, 8, 8 };
221 uint8_t *yuv_line =
NULL;
222 int shift_h, shift_v;
227 s->buf_size = buf_size;
232 avctx->coded_frame= &s->picture;
234 #if FF_API_TIFFENC_COMPLEVEL
237 "algorithm is deprecated. Please use the compression_algo private "
238 "option instead.\n");
239 if (avctx->compression_level == 0) {
241 }
else if(avctx->compression_level == 2) {
244 }
else if ((avctx->compression_level >= 3)) {
250 s->width = avctx->width;
251 s->height = avctx->height;
252 s->subsampling[0] = 1;
253 s->subsampling[1] = 1;
255 switch (avctx->pix_fmt) {
258 s->photometric_interpretation = 2;
262 s->photometric_interpretation = 1;
266 s->photometric_interpretation = 3;
270 s->photometric_interpretation = 1;
274 s->photometric_interpretation = 0;
281 s->photometric_interpretation = 6;
284 s->bpp = 8 + (16 >> (shift_h + shift_v));
285 s->subsampling[0] = 1 << shift_h;
286 s->subsampling[1] = 1 << shift_v;
292 "This colors format is not supported\n");
296 s->bpp_tab_size = (s->bpp >> 3);
302 s->rps =
FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1);
303 s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1];
305 strips = (s->height - 1) / s->rps + 1;
311 bytestream_put_le16(&ptr, 0x4949);
312 bytestream_put_le16(&ptr, 42);
315 bytestream_put_le32(&ptr, 0);
317 strip_sizes =
av_mallocz(
sizeof(*strip_sizes) * strips);
318 strip_offsets =
av_mallocz(
sizeof(*strip_offsets) * strips);
319 if (!strip_sizes || !strip_offsets) {
324 bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp
325 * s->subsampling[0] * s->subsampling[1] + 7) >> 3;
328 if (yuv_line ==
NULL){
341 zlen = bytes_per_row * s->rps;
347 strip_offsets[0] = ptr - buf;
349 for (j = 0; j < s->rps; j++) {
352 memcpy(zbuf + zn, yuv_line, bytes_per_row);
353 j += s->subsampling[1] - 1;
356 memcpy(zbuf + j * bytes_per_row,
357 p->data[0] + j * p->linesize[0], bytes_per_row);
367 strip_sizes[0] = ptr - buf - strip_offsets[0];
378 for (i = 0; i < s->height; i++) {
379 if (strip_sizes[i / s->rps] == 0) {
384 strip_offsets[i / s->rps] = ptr - buf;
388 n =
encode_strip(s, yuv_line, ptr, bytes_per_row, s->compr);
389 i += s->subsampling[1] - 1;
393 ptr, bytes_per_row, s->compr);
398 strip_sizes[i / s->rps] += n;
400 if(s->compr ==
TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){
403 strip_sizes[(i / s->rps )] += ret ;
438 uint16_t pal[256 * 3];
439 for (i = 0; i < 256; i++) {
440 uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
441 pal[i] = ((rgb >> 16) & 0xff) * 257;
442 pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257;
443 pal[i + 512] = ( rgb & 0xff) * 257;
449 uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1};
453 bytestream_put_le32(&offset, ptr - buf);
457 bytestream_put_le16(&ptr, s->num_entries);
459 bytestream_put_le32(&ptr, 0);
470 #define OFFSET(x) offsetof(TiffEncoderContext, x)
471 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
int photometric_interpretation
photometric interpretation
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int num_entries
number of entires
#define FF_COMPRESSION_DEFAULT
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
unsigned int bpp
bits per pixel
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
int strips
number of strips
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
uint8_t ** buf
actual position in buffer
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
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.
struct TiffEncoderContext TiffEncoderContext
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...
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static void add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum)
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
static const uint8_t type_sizes[6]
sizes of various TIFF field types (string size = 100)
int ff_lzw_encode_flush(struct LZWEncodeState *s, void(*lzw_flush_put_bits)(struct PutBitContext *))
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
#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.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift)
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
main external API structure.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const AVClass tiffenc_class
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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]
entires in header
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
int bpp_tab_size
bpp_tab size
static void flip(AVCodecContext *avctx, AVPicture *picture)
8 bit with PIX_FMT_RGB32 palette
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
packed RGB 8:8:8, 24bpp, RGBRGB...
static const AVOption options[]
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
#define CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
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.