tiffenc.c
Go to the documentation of this file.
1 /*
2  * TIFF image encoder
3  * Copyright (c) 2007 Bartlomiej Wolowiec
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * TIFF image encoder
25  * @author Bartlomiej Wolowiec
26  */
27 
28 #include "libavutil/imgutils.h"
29 #include "libavutil/log.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 
33 #include "avcodec.h"
34 #include "config.h"
35 #if CONFIG_ZLIB
36 #include <zlib.h>
37 #endif
38 #include "bytestream.h"
39 #include "internal.h"
40 #include "tiff.h"
41 #include "rle.h"
42 #include "lzw.h"
43 #include "put_bits.h"
44 
45 #define TIFF_MAX_ENTRY 32
46 
47 /** sizes of various TIFF field types (string size = 1)*/
48 static const uint8_t type_sizes2[14] = {
49  0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
50 };
51 
52 typedef struct TiffEncoderContext {
53  AVClass *class; ///< for private options
56 
57  int width; ///< picture width
58  int height; ///< picture height
59  unsigned int bpp; ///< bits per pixel
60  int compr; ///< compression level
61  int bpp_tab_size; ///< bpp_tab size
62  int photometric_interpretation; ///< photometric interpretation
63  int strips; ///< number of strips
64  uint32_t *strip_sizes;
65  unsigned int strip_sizes_size;
66  uint32_t *strip_offsets;
67  unsigned int strip_offsets_size;
69  unsigned int yuv_line_size;
70  int rps; ///< row per strip
71  uint8_t entries[TIFF_MAX_ENTRY*12]; ///< entires in header
72  int num_entries; ///< number of entires
73  uint8_t **buf; ///< actual position in buffer
74  uint8_t *buf_start; ///< pointer to first byte in buffer
75  int buf_size; ///< buffer size
76  uint16_t subsampling[2]; ///< YUV subsampling factors
77  struct LZWEncodeState *lzws; ///< LZW Encode state
78  uint32_t dpi; ///< image resolution in DPI
80 
81 
82 /**
83  * Check free space in buffer.
84  *
85  * @param s Tiff context
86  * @param need Needed bytes
87  * @return 0 - ok, 1 - no free space
88  */
89 static inline int check_size(TiffEncoderContext * s, uint64_t need)
90 {
91  if (s->buf_size < *s->buf - s->buf_start + need) {
92  *s->buf = s->buf_start + s->buf_size + 1;
93  av_log(s->avctx, AV_LOG_ERROR, "Buffer is too small\n");
94  return 1;
95  }
96  return 0;
97 }
98 
99 /**
100  * Put n values to buffer.
101  *
102  * @param p pointer to pointer to output buffer
103  * @param n number of values
104  * @param val pointer to values
105  * @param type type of values
106  * @param flip = 0 - normal copy, >0 - flip
107  */
108 static void tnput(uint8_t ** p, int n, const uint8_t * val, enum TiffTypes type,
109  int flip)
110 {
111  int i;
112 #if HAVE_BIGENDIAN
113  flip ^= ((int[]) {0, 0, 0, 1, 3, 3})[type];
114 #endif
115  for (i = 0; i < n * type_sizes2[type]; i++)
116  *(*p)++ = val[i ^ flip];
117 }
118 
119 /**
120  * Add entry to directory in tiff header.
121  *
122  * @param s Tiff context
123  * @param tag tag that identifies the entry
124  * @param type entry type
125  * @param count the number of values
126  * @param ptr_val pointer to values
127  */
129  enum TiffTags tag, enum TiffTypes type, int count,
130  const void *ptr_val)
131 {
132  uint8_t *entries_ptr = s->entries + 12 * s->num_entries;
133 
135 
136  bytestream_put_le16(&entries_ptr, tag);
137  bytestream_put_le16(&entries_ptr, type);
138  bytestream_put_le32(&entries_ptr, count);
139 
140  if (type_sizes[type] * (int64_t)count <= 4) {
141  tnput(&entries_ptr, count, ptr_val, type, 0);
142  } else {
143  bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start);
144  check_size(s, count * (int64_t)type_sizes2[type]);
145  tnput(s->buf, count, ptr_val, type, 0);
146  }
147 
148  s->num_entries++;
149 }
150 
152  enum TiffTags tag, enum TiffTypes type, int val){
153  uint16_t w = val;
154  uint32_t dw= val;
155  add_entry(s, tag, type, 1, type == TIFF_SHORT ? (void *)&w : (void *)&dw);
156 }
157 
158 /**
159  * Encode one strip in tiff file.
160  *
161  * @param s Tiff context
162  * @param src input buffer
163  * @param dst output buffer
164  * @param n size of input buffer
165  * @param compr compression method
166  * @return number of output bytes. If an output error is encountered, -1 is returned
167  */
168 static int encode_strip(TiffEncoderContext * s, const int8_t * src,
169  uint8_t * dst, int n, int compr)
170 {
171 
172  switch (compr) {
173 #if CONFIG_ZLIB
174  case TIFF_DEFLATE:
175  case TIFF_ADOBE_DEFLATE:
176  {
177  unsigned long zlen = s->buf_size - (*s->buf - s->buf_start);
178  if (compress(dst, &zlen, src, n) != Z_OK) {
179  av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n");
180  return -1;
181  }
182  return zlen;
183  }
184 #endif
185  case TIFF_RAW:
186  if (check_size(s, n))
187  return -1;
188  memcpy(dst, src, n);
189  return n;
190  case TIFF_PACKBITS:
191  return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start), src, 1, n, 2, 0xff, -1, 0);
192  case TIFF_LZW:
193  return ff_lzw_encode(s->lzws, src, n);
194  default:
195  return -1;
196  }
197 }
198 
199 static void pack_yuv(TiffEncoderContext * s, uint8_t * dst, int lnum)
200 {
201  AVFrame *p = &s->picture;
202  int i, j, k;
203  int w = (s->width - 1) / s->subsampling[0] + 1;
204  uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
205  uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
206  if(s->width % s->subsampling[0] || s->height % s->subsampling[1]){
207  for (i = 0; i < w; i++){
208  for (j = 0; j < s->subsampling[1]; j++)
209  for (k = 0; k < s->subsampling[0]; k++)
210  *dst++ = p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
211  FFMIN(i * s->subsampling[0] + k, s->width-1)];
212  *dst++ = *pu++;
213  *dst++ = *pv++;
214  }
215  }else{
216  for (i = 0; i < w; i++){
217  for (j = 0; j < s->subsampling[1]; j++)
218  for (k = 0; k < s->subsampling[0]; k++)
219  *dst++ = p->data[0][(lnum + j) * p->linesize[0] +
220  i * s->subsampling[0] + k];
221  *dst++ = *pu++;
222  *dst++ = *pv++;
223  }
224  }
225 }
226 
228 {
229  TiffEncoderContext *s = avctx->priv_data;
230 
231  avctx->coded_frame= &s->picture;
233  avctx->coded_frame->key_frame = 1;
234  s->avctx = avctx;
235 
236  return 0;
237 }
238 
240  const AVFrame *pict, int *got_packet)
241 {
242  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
243  TiffEncoderContext *s = avctx->priv_data;
244  AVFrame *const p = &s->picture;
245  int i;
246  uint8_t *ptr;
247  uint8_t *offset;
248  uint32_t strips;
249  int bytes_per_row;
250  uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
251  uint16_t bpp_tab[4];
252  int ret = -1;
253  int is_yuv = 0, alpha = 0;
254  int shift_h, shift_v;
255 
256  *p = *pict;
257 
258  s->width = avctx->width;
259  s->height = avctx->height;
260  s->subsampling[0] = 1;
261  s->subsampling[1] = 1;
262 
263  avctx->bits_per_coded_sample =
264  s->bpp = av_get_bits_per_pixel(desc);
265  s->bpp_tab_size = desc->nb_components;
266 
267  switch (avctx->pix_fmt) {
268  case AV_PIX_FMT_RGBA64LE:
269  case AV_PIX_FMT_RGBA:
270  alpha = 1;
271  case AV_PIX_FMT_RGB48LE:
272  case AV_PIX_FMT_RGB24:
274  break;
275  case AV_PIX_FMT_GRAY8:
276  avctx->bits_per_coded_sample = 0x28;
277  case AV_PIX_FMT_GRAY8A:
278  alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A;
279  case AV_PIX_FMT_GRAY16LE:
282  break;
283  case AV_PIX_FMT_PAL8:
285  break;
288  break;
289  case AV_PIX_FMT_YUV420P:
290  case AV_PIX_FMT_YUV422P:
291  case AV_PIX_FMT_YUV440P:
292  case AV_PIX_FMT_YUV444P:
293  case AV_PIX_FMT_YUV410P:
294  case AV_PIX_FMT_YUV411P:
296  avcodec_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
297  s->subsampling[0] = 1 << shift_h;
298  s->subsampling[1] = 1 << shift_v;
299  is_yuv = 1;
300  break;
301  default:
303  "This colors format is not supported\n");
304  return -1;
305  }
306 
307  for (i = 0; i < s->bpp_tab_size; i++)
308  bpp_tab[i] = desc->comp[i].depth_minus1 + 1;
309 
310  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW)
311  //best choose for DEFLATE
312  s->rps = s->height;
313  else
314  s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1); // suggest size of strip
315  s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // round rps up
316 
317  strips = (s->height - 1) / s->rps + 1;
318 
319  if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * s->bpp * 2 +
320  avctx->height * 4 + FF_MIN_BUFFER_SIZE)) < 0)
321  return ret;
322  ptr = pkt->data;
323  s->buf_start = pkt->data;
324  s->buf = &ptr;
325  s->buf_size = pkt->size;
326 
327  if (check_size(s, 8))
328  goto fail;
329 
330  // write header
331  bytestream_put_le16(&ptr, 0x4949);
332  bytestream_put_le16(&ptr, 42);
333 
334  offset = ptr;
335  bytestream_put_le32(&ptr, 0);
336 
337  av_fast_padded_mallocz(&s->strip_sizes, &s->strip_sizes_size, sizeof(s->strip_sizes[0]) * strips);
338  av_fast_padded_mallocz(&s->strip_offsets, &s->strip_offsets_size, sizeof(s->strip_offsets[0]) * strips);
339 
340  if (!s->strip_sizes || !s->strip_offsets) {
341  ret = AVERROR(ENOMEM);
342  goto fail;
343  }
344 
345  bytes_per_row = (((s->width - 1)/s->subsampling[0] + 1) * s->bpp
346  * s->subsampling[0] * s->subsampling[1] + 7) >> 3;
347  if (is_yuv){
348  av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);
349  if (s->yuv_line == NULL){
350  av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
351  ret = AVERROR(ENOMEM);
352  goto fail;
353  }
354  }
355 
356 #if CONFIG_ZLIB
357  if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
358  uint8_t *zbuf;
359  int zlen, zn;
360  int j;
361 
362  zlen = bytes_per_row * s->rps;
363  zbuf = av_malloc(zlen);
364  if (!zbuf) {
365  ret = AVERROR(ENOMEM);
366  goto fail;
367  }
368  s->strip_offsets[0] = ptr - pkt->data;
369  zn = 0;
370  for (j = 0; j < s->rps; j++) {
371  if (is_yuv){
372  pack_yuv(s, s->yuv_line, j);
373  memcpy(zbuf + zn, s->yuv_line, bytes_per_row);
374  j += s->subsampling[1] - 1;
375  }
376  else
377  memcpy(zbuf + j * bytes_per_row,
378  p->data[0] + j * p->linesize[0], bytes_per_row);
379  zn += bytes_per_row;
380  }
381  ret = encode_strip(s, zbuf, ptr, zn, s->compr);
382  av_free(zbuf);
383  if (ret < 0) {
384  av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
385  goto fail;
386  }
387  ptr += ret;
388  s->strip_sizes[0] = ptr - pkt->data - s->strip_offsets[0];
389  } else
390 #endif
391  {
392  if (s->compr == TIFF_LZW) {
394  if (!s->lzws) {
395  ret = AVERROR(ENOMEM);
396  goto fail;
397  }
398  }
399  for (i = 0; i < s->height; i++) {
400  if (s->strip_sizes[i / s->rps] == 0) {
401  if(s->compr == TIFF_LZW){
402  ff_lzw_encode_init(s->lzws, ptr, s->buf_size - (*s->buf - s->buf_start),
403  12, FF_LZW_TIFF, put_bits);
404  }
405  s->strip_offsets[i / s->rps] = ptr - pkt->data;
406  }
407  if (is_yuv){
408  pack_yuv(s, s->yuv_line, i);
409  ret = encode_strip(s, s->yuv_line, ptr, bytes_per_row, s->compr);
410  i += s->subsampling[1] - 1;
411  }
412  else
413  ret = encode_strip(s, p->data[0] + i * p->linesize[0],
414  ptr, bytes_per_row, s->compr);
415  if (ret < 0) {
416  av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
417  goto fail;
418  }
419  s->strip_sizes[i / s->rps] += ret;
420  ptr += ret;
421  if(s->compr == TIFF_LZW && (i==s->height-1 || i%s->rps == s->rps-1)){
423  s->strip_sizes[(i / s->rps )] += ret ;
424  ptr += ret;
425  }
426  }
427  if(s->compr == TIFF_LZW)
428  av_free(s->lzws);
429  }
430 
431  s->num_entries = 0;
432 
436 
437  if (s->bpp_tab_size)
438  add_entry(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
439 
443 
444  if (s->bpp_tab_size)
446 
449  add_entry(s, TIFF_XRES, TIFF_RATIONAL, 1, res);
450  add_entry(s, TIFF_YRES, TIFF_RATIONAL, 1, res);
452 
453  if(!(avctx->flags & CODEC_FLAG_BITEXACT))
455  strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT);
456 
457  if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
458  uint16_t pal[256 * 3];
459  for (i = 0; i < 256; i++) {
460  uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
461  pal[i] = ((rgb >> 16) & 0xff) * 257;
462  pal[i + 256] = ((rgb >> 8 ) & 0xff) * 257;
463  pal[i + 512] = ( rgb & 0xff) * 257;
464  }
465  add_entry(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
466  }
467  if (alpha)
469  if (is_yuv){
470  /** according to CCIR Recommendation 601.1 */
471  uint32_t refbw[12] = {15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1};
476  }
477  bytestream_put_le32(&offset, ptr - pkt->data); // write offset to dir
478 
479  if (check_size(s, 6 + s->num_entries * 12)) {
480  ret = AVERROR(EINVAL);
481  goto fail;
482  }
483  bytestream_put_le16(&ptr, s->num_entries); // write tag count
484  bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12);
485  bytestream_put_le32(&ptr, 0);
486 
487  pkt->size = ptr - pkt->data;
488  pkt->flags |= AV_PKT_FLAG_KEY;
489  *got_packet = 1;
490 
491 fail:
492  return ret < 0 ? ret : 0;
493 }
494 
496 {
497  TiffEncoderContext *s = avctx->priv_data;
498 
499  av_freep(&s->strip_sizes);
500  av_freep(&s->strip_offsets);
501  av_freep(&s->yuv_line);
502 
503  return 0;
504 }
505 
506 #define OFFSET(x) offsetof(TiffEncoderContext, x)
507 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
508 static const AVOption options[] = {
509  {"dpi", "set the image resolution (in dpi)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
510  { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, {.i64 = TIFF_PACKBITS}, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" },
511  { "packbits", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_PACKBITS}, 0, 0, VE, "compression_algo" },
512  { "raw", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_RAW}, 0, 0, VE, "compression_algo" },
513  { "lzw", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_LZW}, 0, 0, VE, "compression_algo" },
514 #if CONFIG_ZLIB
515  { "deflate", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = TIFF_DEFLATE}, 0, 0, VE, "compression_algo" },
516 #endif
517  { NULL },
518 };
519 
520 static const AVClass tiffenc_class = {
521  .class_name = "TIFF encoder",
522  .item_name = av_default_item_name,
523  .option = options,
524  .version = LIBAVUTIL_VERSION_INT,
525 };
526 
528  .name = "tiff",
529  .type = AVMEDIA_TYPE_VIDEO,
530  .id = AV_CODEC_ID_TIFF,
531  .priv_data_size = sizeof(TiffEncoderContext),
532  .init = encode_init,
533  .encode2 = encode_frame,
534  .close = encode_close,
535  .pix_fmts = (const enum AVPixelFormat[]) {
543  },
544  .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
545  .priv_class = &tiffenc_class,
546 };
int photometric_interpretation
photometric interpretation
Definition: tiffenc.c:62
Definition: tiff.h:53
static av_cold int encode_init(AVCodecContext *avctx)
Definition: tiffenc.c:227
Definition: tiff.h:88
const char * s
Definition: avisynth_c.h:668
int num_entries
number of entires
Definition: tiffenc.c:72
static av_cold int encode_close(AVCodecContext *avctx)
Definition: tiffenc.c:495
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
unsigned int bpp
bits per pixel
Definition: tiffenc.c:59
AVOption.
Definition: opt.h:251
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
Definition: tiffenc.c:89
av_default_item_name
Definition: tiff.h:52
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:73
misc image utilities
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:70
int strips
number of strips
Definition: tiffenc.c:63
AVFrame * coded_frame
the picture in the bitstream
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
Definition: pixdesc.c:1731
unsigned int strip_offsets_size
Definition: tiffenc.c:67
AVCodec ff_tiff_encoder
Definition: tiffenc.c:527
TIFF tables.
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
Definition: lzwenc.c:226
uint8_t ** buf
actual position in buffer
Definition: tiffenc.c:73
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.
Definition: tiffenc.c:128
int height
picture height
Definition: tiffenc.c:58
struct TiffEncoderContext TiffEncoderContext
uint8_t * yuv_line
Definition: tiffenc.c:68
int compr
compression level
Definition: tiffenc.c:60
struct LZWEncodeState * lzws
LZW Encode state.
Definition: tiffenc.c:77
Definition: tiff.h:92
uint8_t * buf_start
pointer to first byte in buffer
Definition: tiffenc.c:74
output residual component w
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
#define OFFSET(x)
Definition: tiffenc.c:506
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:55
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:86
uint8_t
#define av_cold
Definition: attributes.h:78
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:79
AVOptions.
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:112
static AVPacket pkt
Definition: demuxing.c:56
static void add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum TiffTypes type, int val)
Definition: tiffenc.c:151
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
Definition: tiffenc.c:48
uint8_t * data
LZW encode state.
Definition: lzwenc.c:49
static void pack_yuv(TiffEncoderContext *s, uint8_t *dst, int lnum)
Definition: tiffenc.c:199
uint32_t tag
Definition: movenc.c:894
#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).
uint32_t * strip_sizes
Definition: tiffenc.c:64
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
Definition: opt.h:281
Definition: tiff.h:67
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define VE
Definition: tiffenc.c:507
int ff_lzw_encode_flush(struct LZWEncodeState *s, void(*lzw_flush_put_bits)(struct PutBitContext *))
int buf_size
buffer size
Definition: tiffenc.c:75
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:43
unsigned int strip_sizes_size
Definition: tiffenc.c:65
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:86
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:183
#define pv
Definition: regdef.h:60
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
Definition: tiff.h:171
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
CODEC_FLAG_*.
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
uint32_t * strip_offsets
Definition: tiffenc.c:66
static void put_bits(J2kEncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:160
static const uint8_t offset[127][2]
Definition: vf_spp.c:70
#define FFMAX(a, b)
Definition: common.h:56
external API header
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:97
AVFrame picture
Definition: tiffenc.c:55
int flags
A combination of AV_PKT_FLAG values.
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:72
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
8bit gray, 8bit alpha
Definition: pixfmt.h:141
#define FFMIN(a, b)
Definition: common.h:58
#define FF_MIN_BUFFER_SIZE
minimum encoding buffer size Used to avoid some checks during header writing.
ret
Definition: avfilter.c:821
int width
picture width / height.
int width
picture width
Definition: tiffenc.c:57
void avcodec_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.
Definition: imgconvert.c:65
LIBAVUTIL_VERSION_INT
Definition: eval.c:55
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size)
Check AVPacket size and/or allocate data.
for k
NULL
Definition: eval.c:55
Definition: tiff.h:40
AVS_Value src
Definition: avisynth_c.h:523
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition: tiffenc.c:239
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
#define AV_OPT_FLAG_VIDEO_PARAM
Definition: opt.h:285
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static const AVClass tiffenc_class
Definition: tiffenc.c:520
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:74
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Describe the class of an AVClass context structure.
Definition: log.h:50
synthesis window for stochastic i
#define TIFF_MAX_ENTRY
Definition: tiffenc.c:45
static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type, int flip)
Put n values to buffer.
Definition: tiffenc.c:108
must be printed separately If there s no standard function for printing the type you need
Definition: tablegen.txt:45
uint16_t subsampling[2]
YUV subsampling factors.
Definition: tiffenc.c:76
uint8_t entries[TIFF_MAX_ENTRY *12]
entires in header
Definition: tiffenc.c:71
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define type
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
LZW decoding routines.
TiffTypes
Definition: tiff.h:100
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:78
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
Y , 8bpp.
Definition: pixfmt.h:76
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))
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:81
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:77
int bpp_tab_size
bpp_tab size
Definition: tiffenc.c:61
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...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:75
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition: bytestream.h:337
static const AVOption options[]
Definition: tiffenc.c:508
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
Y , 16bpp, little-endian.
Definition: pixfmt.h:102
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
#define LIBAVCODEC_IDENT
AVCodecContext * avctx
Definition: tiffenc.c:54
void INT64 INT64 count
Definition: avisynth_c.h:594
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:103
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.
Definition: rle.c:58
uint32_t dpi
image resolution in DPI
Definition: tiffenc.c:78
const int ff_lzw_encode_state_size
Definition: lzwenc.c:66
int rps
row per strip
Definition: tiffenc.c:70
unsigned int yuv_line_size
Definition: tiffenc.c:69
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
This structure stores compressed data.
TiffTags
abridged list of TIFF tags
Definition: tiff.h:36
static int encode_strip(TiffEncoderContext *s, const int8_t *src, uint8_t *dst, int n, int compr)
Encode one strip in tiff file.
Definition: tiffenc.c:168
packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is st...
Definition: pixfmt.h:210
bitstream writer API