FFmpeg
Loading...
Searching...
No Matches
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 "config.h"
30#if CONFIG_ZLIB
31#include <zlib.h>
32#endif
33
34#include "libavutil/log.h"
35#include "libavutil/mem.h"
36#include "libavutil/opt.h"
37#include "libavutil/pixdesc.h"
38#include "avcodec.h"
39#include "bytestream.h"
40#include "codec_internal.h"
41#include "encode.h"
42#include "lzw.h"
43#include "rle.h"
44#include "tiff.h"
45#include "tiff_common.h"
46#include "version.h"
47
48#define TIFF_MAX_ENTRY 32
49
50/** sizes of various TIFF field types (string size = 1)*/
51static const uint8_t type_sizes2[14] = {
52 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
53};
54
55typedef struct TiffEncoderContext {
56 AVClass *class; ///< for private options
58
59 int width; ///< picture width
60 int height; ///< picture height
61 unsigned int bpp; ///< bits per pixel
62 int compr; ///< compression level
63 int bpp_tab_size; ///< bpp_tab size
64 enum TiffPhotometric photometric_interpretation; ///< photometric interpretation
65 int strips; ///< number of strips
66 uint32_t *strip_sizes;
67 unsigned int strip_sizes_size;
68 uint32_t *strip_offsets;
69 unsigned int strip_offsets_size;
70 uint8_t *yuv_line;
71 unsigned int yuv_line_size;
72 int rps; ///< row per strip
73 uint8_t entries[TIFF_MAX_ENTRY * 12]; ///< entries in header
74 int num_entries; ///< number of entries
75 uint8_t **buf; ///< actual position in buffer
76 uint8_t *buf_start; ///< pointer to first byte in buffer
77 int buf_size; ///< buffer size
78 uint16_t subsampling[2]; ///< YUV subsampling factors
79 struct LZWEncodeState *lzws; ///< LZW encode state
80 uint32_t dpi; ///< image resolution in DPI
82
83/**
84 * Check free space in buffer.
85 *
86 * @param s Tiff context
87 * @param need Needed bytes
88 * @return 0 - ok, 1 - no free space
89 */
90static inline int check_size(TiffEncoderContext *s, uint64_t need)
91{
92 if (s->buf_size < *s->buf - s->buf_start + need) {
93 *s->buf = s->buf_start + s->buf_size + 1;
94 av_log(s->avctx, AV_LOG_ERROR, "Buffer is too small\n");
95 return 1;
96 }
97 return 0;
98}
99
100/**
101 * Put n values to buffer.
102 *
103 * @param p pointer to pointer to output buffer
104 * @param n number of values
105 * @param val pointer to values
106 * @param type type of values
107 * @param flip = 0 - normal copy, >0 - flip
108 */
109static void tnput(uint8_t **p, int n, const uint8_t *val, enum AVTiffDataType type,
110 int flip)
111{
112 int i;
113#if HAVE_BIGENDIAN
114 flip ^= ((int[]) { 0, 0, 0, 1, 3, 3, 0, 0, 1, 3, 3, 3, 7, 3 })[type];
115#endif
116 for (i = 0; i < n * type_sizes2[type]; i++)
117 *(*p)++ = val[i ^ flip];
118}
119
120/**
121 * Add entry to directory in tiff header.
122 *
123 * @param s Tiff context
124 * @param tag tag that identifies the entry
125 * @param type entry type
126 * @param count the number of values
127 * @param ptr_val pointer to values
128 */
130 enum AVTiffDataType type, int count, const void *ptr_val)
131{
132 uint8_t *entries_ptr = s->entries + 12 * s->num_entries;
133 int64_t data_size = count * (int64_t)type_sizes2[type];
134
135 av_assert0(s->num_entries < TIFF_MAX_ENTRY);
136
137 bytestream_put_le16(&entries_ptr, tag);
138 bytestream_put_le16(&entries_ptr, type);
139 bytestream_put_le32(&entries_ptr, count);
140
141 if (type_sizes[type] * (int64_t)count <= 4) {
142 tnput(&entries_ptr, count, ptr_val, type, 0);
143 } else {
144 int padding = (*s->buf - s->buf_start) & 1;
145
146 if (check_size(s, data_size + padding))
147 return AVERROR_INVALIDDATA;
148 if (padding)
149 bytestream_put_byte(s->buf, 0);
150 bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start);
151 tnput(s->buf, count, ptr_val, type, 0);
152 }
153
154 s->num_entries++;
155 return 0;
156}
157
159 enum TiffTags tag, enum AVTiffDataType type, int val)
160{
161 uint16_t w = val;
162 uint32_t dw = val;
163 return add_entry(s, tag, type, 1,
164 type == AV_TIFF_SHORT ? (void *)&w : (void *)&dw);
165}
166
167/**
168 * Encode one strip in tiff file.
169 *
170 * @param s Tiff context
171 * @param src input buffer
172 * @param dst output buffer
173 * @param n size of input buffer
174 * @param compr compression method
175 * @return number of output bytes. If an output error is encountered, a negative
176 * value corresponding to an AVERROR error code is returned.
177 */
178static int encode_strip(TiffEncoderContext *s, const int8_t *src,
179 uint8_t *dst, int n, int compr)
180{
181 switch (compr) {
182#if CONFIG_ZLIB
183 case TIFF_DEFLATE:
185 {
186 unsigned long zlen = s->buf_size - (*s->buf - s->buf_start);
187 if (compress(dst, &zlen, src, n) != Z_OK) {
188 av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n");
189 return AVERROR_EXTERNAL;
190 }
191 return zlen;
192 }
193#endif
194 case TIFF_RAW:
195 if (check_size(s, n))
196 return AVERROR(EINVAL);
197 memcpy(dst, src, n);
198 return n;
199 case TIFF_PACKBITS:
200 return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start),
201 src, 1, n, 2, 0xff, -1, 0);
202 case TIFF_LZW:
203 return ff_lzw_encode(s->lzws, src, n);
204 default:
205 av_log(s->avctx, AV_LOG_ERROR, "Unsupported compression method: %d\n",
206 compr);
207 return AVERROR(EINVAL);
208 }
209}
210
211static void pack_yuv(TiffEncoderContext *s, const AVFrame *p,
212 uint8_t *dst, int lnum)
213{
214 int i, j, k;
215 int w = (s->width - 1) / s->subsampling[0] + 1;
216 const uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
217 const uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
218 if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
219 for (i = 0; i < w; i++) {
220 for (j = 0; j < s->subsampling[1]; j++)
221 for (k = 0; k < s->subsampling[0]; k++)
222 *dst++ = p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
223 FFMIN(i * s->subsampling[0] + k, s->width-1)];
224 *dst++ = *pu++;
225 *dst++ = *pv++;
226 }
227 }else{
228 for (i = 0; i < w; i++) {
229 for (j = 0; j < s->subsampling[1]; j++)
230 for (k = 0; k < s->subsampling[0]; k++)
231 *dst++ = p->data[0][(lnum + j) * p->linesize[0] +
232 i * s->subsampling[0] + k];
233 *dst++ = *pu++;
234 *dst++ = *pv++;
235 }
236 }
237}
238
239#define ADD_ENTRY(s, tag, type, count, ptr_val) \
240 do { \
241 ret = add_entry(s, tag, type, count, ptr_val); \
242 if (ret < 0) \
243 goto fail; \
244 } while (0)
245
246#define ADD_ENTRY1(s, tag, type, val) \
247 do { \
248 ret = add_entry1(s, tag, type, val); \
249 if (ret < 0) \
250 goto fail; \
251 } while (0)
252
254 const AVFrame *pict, int *got_packet)
255{
258 const AVFrame *const p = pict;
259 const AVFrameSideData *icc_profile;
260 int i;
261 uint8_t *ptr;
262 uint8_t *offset;
263 uint32_t strips;
264 int64_t bytes_per_row;
265 uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
266 uint16_t bpp_tab[4];
267 int ret = 0;
268 int is_yuv = 0, alpha = 0;
269 int shift_h, shift_v;
270 int64_t packet_size;
271 int icc_size = 0;
272
273 s->width = avctx->width;
274 s->height = avctx->height;
275 s->subsampling[0] = 1;
276 s->subsampling[1] = 1;
277
278 if (!desc)
279 return AVERROR(EINVAL);
280
281 avctx->bits_per_coded_sample =
283 s->bpp_tab_size = desc->nb_components;
284
285 switch (avctx->pix_fmt) {
287 case AV_PIX_FMT_RGBA:
288 alpha = 1;
291 case AV_PIX_FMT_RGB24:
292 s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
293 break;
294 case AV_PIX_FMT_GRAY8:
295 avctx->bits_per_coded_sample = 0x28;
303 s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
304 break;
305 case AV_PIX_FMT_PAL8:
306 s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
307 break;
309 s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
310 break;
317 av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
318 s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR;
319 s->subsampling[0] = 1 << shift_h;
320 s->subsampling[1] = 1 << shift_v;
321 is_yuv = 1;
322 break;
323 default:
324 av_log(s->avctx, AV_LOG_ERROR,
325 "This colors format is not supported\n");
326 return AVERROR(EINVAL);
327 }
328
329 for (i = 0; i < s->bpp_tab_size; i++)
330 bpp_tab[i] = desc->comp[i].depth;
331
333 if (icc_profile && icc_profile->size) {
334 if (icc_profile->size > INT_MAX) {
335 av_log(avctx, AV_LOG_ERROR, "ICC profile is too large\n");
336 return AVERROR_INVALIDDATA;
337 }
338 icc_size = icc_profile->size;
339 }
340
341 if (s->compr == TIFF_DEFLATE ||
342 s->compr == TIFF_ADOBE_DEFLATE ||
343 s->compr == TIFF_LZW)
344 // best choice for DEFLATE
345 s->rps = s->height;
346 else
347 // suggest size of strip
348 s->rps = FFMAX(8192 / ((((int64_t)s->width * s->bpp) >> 3) + 1), 1);
349 // round rps up
350 s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1];
351
352 strips = (s->height - 1) / s->rps + 1;
353
354 bytes_per_row = ((((int64_t)s->width - 1) / s->subsampling[0] + 1) *
355 s->bpp * s->subsampling[0] * s->subsampling[1] + 7) >> 3;
356 if (bytes_per_row > INT_MAX)
357 return AVERROR(EINVAL);
358 if (avctx->height > (INT64_MAX - FF_INPUT_BUFFER_MIN_SIZE - icc_size -
359 !!icc_size) / (2 * bytes_per_row + 4))
360 return AVERROR(EINVAL);
361 packet_size = avctx->height * (2 * bytes_per_row + 4) +
362 FF_INPUT_BUFFER_MIN_SIZE + icc_size + !!icc_size;
363
364 if ((ret = ff_alloc_packet(avctx, pkt, packet_size)) < 0)
365 return ret;
366 ptr = pkt->data;
367 s->buf_start = pkt->data;
368 s->buf = &ptr;
369 s->buf_size = pkt->size;
370
371 if (check_size(s, 8)) {
372 ret = AVERROR(EINVAL);
373 goto fail;
374 }
375
376 // write header
377 bytestream_put_le16(&ptr, 0x4949);
378 bytestream_put_le16(&ptr, 42);
379
380 offset = ptr;
381 bytestream_put_le32(&ptr, 0);
382
383 if (strips > INT_MAX / FFMAX(sizeof(s->strip_sizes[0]), sizeof(s->strip_offsets[0]))) {
384 ret = AVERROR(ENOMEM);
385 goto fail;
386 }
387 av_fast_padded_mallocz(&s->strip_sizes , &s->strip_sizes_size , sizeof(s->strip_sizes [0]) * strips);
388 av_fast_padded_mallocz(&s->strip_offsets, &s->strip_offsets_size, sizeof(s->strip_offsets[0]) * strips);
389
390 if (!s->strip_sizes || !s->strip_offsets) {
391 ret = AVERROR(ENOMEM);
392 goto fail;
393 }
394
395 if (is_yuv) {
396 av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);
397 if (s->yuv_line == NULL) {
398 av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
399 ret = AVERROR(ENOMEM);
400 goto fail;
401 }
402 }
403
404#if CONFIG_ZLIB
405 if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
406 uint8_t *zbuf;
407 int zlen, zn;
408 int j;
409
410 zlen = bytes_per_row * s->rps;
411 zbuf = av_malloc(zlen);
412 if (!zbuf) {
413 ret = AVERROR(ENOMEM);
414 goto fail;
415 }
416 s->strip_offsets[0] = ptr - pkt->data;
417 zn = 0;
418 for (j = 0; j < s->rps; j++) {
419 if (is_yuv) {
420 pack_yuv(s, p, s->yuv_line, j);
421 memcpy(zbuf + zn, s->yuv_line, bytes_per_row);
422 j += s->subsampling[1] - 1;
423 } else
424 memcpy(zbuf + j * bytes_per_row,
425 p->data[0] + j * p->linesize[0], bytes_per_row);
426 zn += bytes_per_row;
427 }
428 ret = encode_strip(s, zbuf, ptr, zn, s->compr);
429 av_free(zbuf);
430 if (ret < 0) {
431 av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
432 goto fail;
433 }
434 ptr += ret;
435 s->strip_sizes[0] = ptr - pkt->data - s->strip_offsets[0];
436 } else
437#endif
438 {
439 if (s->compr == TIFF_LZW) {
441 if (!s->lzws) {
442 ret = AVERROR(ENOMEM);
443 goto fail;
444 }
445 }
446 for (i = 0; i < s->height; i++) {
447 if (s->strip_sizes[i / s->rps] == 0) {
448 if (s->compr == TIFF_LZW) {
449 ff_lzw_encode_init(s->lzws, ptr,
450 s->buf_size - (*s->buf - s->buf_start),
451 12, FF_LZW_TIFF, 0);
452 }
453 s->strip_offsets[i / s->rps] = ptr - pkt->data;
454 }
455 if (is_yuv) {
456 pack_yuv(s, p, s->yuv_line, i);
457 ret = encode_strip(s, s->yuv_line, ptr, bytes_per_row, s->compr);
458 i += s->subsampling[1] - 1;
459 } else
460 ret = encode_strip(s, p->data[0] + i * p->linesize[0],
461 ptr, bytes_per_row, s->compr);
462 if (ret < 0) {
463 av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
464 goto fail;
465 }
466 s->strip_sizes[i / s->rps] += ret;
467 ptr += ret;
468 if (s->compr == TIFF_LZW &&
469 (i == s->height - 1 || i % s->rps == s->rps - 1)) {
470 ret = ff_lzw_encode_flush(s->lzws);
471 s->strip_sizes[(i / s->rps)] += ret;
472 ptr += ret;
473 }
474 }
475 if (s->compr == TIFF_LZW)
476 av_freep(&s->lzws);
477 }
478
479 s->num_entries = 0;
480
484
485 if (s->bpp_tab_size)
486 ADD_ENTRY(s, TIFF_BPP, AV_TIFF_SHORT, s->bpp_tab_size, bpp_tab);
487
489 ADD_ENTRY1(s, TIFF_PHOTOMETRIC, AV_TIFF_SHORT, s->photometric_interpretation);
490 ADD_ENTRY(s, TIFF_STRIP_OFFS, AV_TIFF_LONG, strips, s->strip_offsets);
491
493 if (sd) {
494 int orientation = av_exif_matrix_to_orientation((int32_t *) sd->data);
495 if (orientation >= 1 && orientation <= 8)
497 }
498
499 if (s->bpp_tab_size)
501
503 ADD_ENTRY(s, TIFF_STRIP_SIZE, AV_TIFF_LONG, strips, s->strip_sizes);
505 if (avctx->sample_aspect_ratio.num > 0 &&
506 avctx->sample_aspect_ratio.den > 0) {
507 AVRational y = av_mul_q(av_make_q(s->dpi, 1),
508 avctx->sample_aspect_ratio);
509 res[0] = y.num;
510 res[1] = y.den;
511 }
514
515 if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT))
518
519 if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
520 uint16_t pal[256 * 3];
521 for (i = 0; i < 256; i++) {
522 uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
523 pal[i] = ((rgb >> 16) & 0xff) * 257;
524 pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
525 pal[i + 512] = (rgb & 0xff) * 257;
526 }
527 ADD_ENTRY(s, TIFF_PAL, AV_TIFF_SHORT, 256 * 3, pal);
528 }
529 if (alpha)
531 if (is_yuv) {
532 /** according to CCIR Recommendation 601.1 */
533 uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
538 }
539
540 if (icc_size)
541 ADD_ENTRY(s, TIFF_ICC_PROFILE, AV_TIFF_UNDEFINED, icc_size, icc_profile->data);
542
543 // write offset to dir
544 bytestream_put_le32(&offset, ptr - pkt->data);
545
546 if (check_size(s, 6 + s->num_entries * 12)) {
547 ret = AVERROR(EINVAL);
548 goto fail;
549 }
550 bytestream_put_le16(&ptr, s->num_entries); // write tag count
551 bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12);
552 bytestream_put_le32(&ptr, 0);
553
554 pkt->size = ptr - pkt->data;
555 *got_packet = 1;
556
557fail:
558 return ret < 0 ? ret : 0;
559}
560
562{
564
565#if !CONFIG_ZLIB
566 if (s->compr == TIFF_DEFLATE) {
567 av_log(avctx, AV_LOG_ERROR,
568 "Deflate compression needs zlib compiled in\n");
569 return AVERROR(ENOSYS);
570 }
571#endif
572
573 s->avctx = avctx;
574
575 return 0;
576}
577
579{
581
582 av_freep(&s->strip_sizes);
583 av_freep(&s->strip_offsets);
584 av_freep(&s->yuv_line);
585
586 return 0;
587}
588
589#define OFFSET(x) offsetof(TiffEncoderContext, x)
590#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
591static const AVOption options[] = {
592 {"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},
593 { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, .unit = "compression_algo" },
594 { "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, .unit = "compression_algo" },
595 { "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, .unit = "compression_algo" },
596 { "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, .unit = "compression_algo" },
597 { "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, .unit = "compression_algo" },
598 { NULL },
599};
600
601static const AVClass tiffenc_class = {
602 .class_name = "TIFF encoder",
603 .item_name = av_default_item_name,
604 .option = options,
605 .version = LIBAVUTIL_VERSION_INT,
606};
607
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
static double val(void *priv, double ch)
Definition aeval.c:77
const FFCodec ff_tiff_encoder
Definition tiffenc.c:608
#define VE
Definition amfenc_av1.c:30
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
static av_cold int encode_init(AVCodecContext *avctx)
Definition asvenc.c:373
int32_t
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition avassert.h:42
Libavcodec external API header.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
Definition bytestream.h:372
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
#define FF_CODEC_ENCODE_CB(func)
#define CODEC_LONG_NAME(str)
#define NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
static av_cold int encode_close(AVCodecContext *avctx)
Definition dcaenc.c:354
static AVPacket * pkt
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition encode.c:62
#define FF_INPUT_BUFFER_MIN_SIZE
Used by some encoders as upper bound for the length of headers.
Definition encode.h:34
int av_exif_matrix_to_orientation(const int32_t *matrix)
Convert a display matrix used by AV_FRAME_DATA_DISPLAYMATRIX into an orientation constant used by EXI...
Definition exif.c:1314
AVTiffDataType
Data type identifiers for TIFF tags.
Definition exif.h:41
@ AV_TIFF_STRING
Definition exif.h:43
@ AV_TIFF_SHORT
Definition exif.h:44
@ AV_TIFF_RATIONAL
Definition exif.h:46
@ AV_TIFF_LONG
Definition exif.h:45
@ AV_TIFF_UNDEFINED
Definition exif.h:48
static int encode_frame(OutputFile *of, OutputStream *ost, AVFrame *frame, AVPacket *pkt)
Definition ffmpeg_enc.c:694
#define fail
Definition test.h:479
#define AV_OPT_FLAG_VIDEO_PARAM
Definition opt.h:357
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition opt.h:351
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition codec.h:98
@ AV_CODEC_ID_TIFF
Definition codec_id.h:146
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition utils.c:53
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.
Definition utils.c:66
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition frame.h:85
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition frame.h:144
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
Definition rational.c:80
static AVRational av_make_q(int num, int den)
Create an AVRational.
Definition rational.h:71
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
cl_device_type type
static const int16_t alpha[]
Definition ilbcdata.h:55
unsigned offset
Definition libaomenc.c:763
static void flip(AVCodecContext *avctx, AVFrame *frame)
Definition rawdec.c:131
Libavcodec version macros.
#define LIBAVCODEC_IDENT
Definition version.h:43
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_cold
Definition attributes.h:117
const char * desc
Definition libsvtav1.c:83
uint8_t w
Definition llvidencdsp.c:39
LZW decoding routines.
void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize, int maxbits, enum FF_LZW_MODES mode, int little_endian)
Initialize LZW encoder.
Definition lzwenc.c:206
const int ff_lzw_encode_state_size
Definition lzwenc.c:68
int ff_lzw_encode(struct LZWEncodeState *s, const uint8_t *inbuf, int insize)
LZW main compress function.
Definition lzwenc.c:230
@ FF_LZW_TIFF
Definition lzw.h:39
int ff_lzw_encode_flush(struct LZWEncodeState *s)
Write end code and flush bitstream.
Definition lzwenc.c:263
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
uint32_t tag
Definition movenc.c:2087
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
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.
Definition pixdesc.c:3488
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:3412
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:806
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition pixfmt.h:75
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition pixfmt.h:106
@ AV_PIX_FMT_MONOBLACK
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:83
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_GRAY8A
alias for AV_PIX_FMT_YA8
Definition pixfmt.h:143
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_YA16LE
16 bits gray, 16 bits alpha (little-endian)
Definition pixfmt.h:210
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition pixfmt.h:79
@ AV_PIX_FMT_RGBA64LE
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:203
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition pixfmt.h:80
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition pixfmt.h:100
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ AV_PIX_FMT_RGB48LE
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:110
@ AV_PIX_FMT_GRAY16LE
Y , 16bpp, little-endian.
Definition pixfmt.h:105
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
Definition pixfmt.h:84
@ AV_PIX_FMT_MONOWHITE
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb.
Definition pixfmt.h:82
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:53
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition avcodec.h:1564
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:688
void * priv_data
Definition avcodec.h:470
Structure to hold side data for an AVFrame.
Definition frame.h:327
size_t size
Definition frame.h:330
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
LZW encode state.
Definition lzwenc.c:51
struct LZWEncodeState * lzws
LZW encode state.
Definition tiffenc.c:79
AVCodecContext * avctx
Definition tiffenc.c:57
int num_entries
number of entries
Definition tiffenc.c:74
uint8_t entries[TIFF_MAX_ENTRY *12]
entries in header
Definition tiffenc.c:73
int height
picture height
Definition tiffenc.c:60
uint32_t * strip_offsets
Definition tiffenc.c:68
uint8_t * yuv_line
Definition tiffenc.c:70
uint8_t ** buf
actual position in buffer
Definition tiffenc.c:75
int bpp_tab_size
bpp_tab size
Definition tiffenc.c:63
uint32_t * strip_sizes
Definition tiffenc.c:66
unsigned int strip_offsets_size
Definition tiffenc.c:69
unsigned int yuv_line_size
Definition tiffenc.c:71
uint32_t dpi
image resolution in DPI
Definition tiffenc.c:80
int buf_size
buffer size
Definition tiffenc.c:77
unsigned int bpp
bits per pixel
Definition tiffenc.c:61
int rps
row per strip
Definition tiffenc.c:72
uint16_t subsampling[2]
YUV subsampling factors.
Definition tiffenc.c:78
int compr
compression level
Definition tiffenc.c:62
enum TiffPhotometric photometric_interpretation
photometric interpretation
Definition tiffenc.c:64
int width
picture width
Definition tiffenc.c:59
unsigned int strip_sizes_size
Definition tiffenc.c:67
int strips
number of strips
Definition tiffenc.c:65
uint8_t * buf_start
pointer to first byte in buffer
Definition tiffenc.c:76
Definition rpzaenc.c:60
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
TIFF constants & data structures.
@ TIFF_ADOBE_DEFLATE
Definition tiff.h:134
@ TIFF_RAW
Definition tiff.h:127
@ TIFF_LZW
Definition tiff.h:131
@ TIFF_DEFLATE
Definition tiff.h:136
@ TIFF_PACKBITS
Definition tiff.h:135
TiffTags
abridged list of TIFF and TIFF/EP tags
Definition tiff.h:44
@ TIFF_ICC_PROFILE
Definition tiff.h:94
@ TIFF_WIDTH
Definition tiff.h:46
@ TIFF_COMPR
Definition tiff.h:49
@ TIFF_PAL
Definition tiff.h:77
@ TIFF_ROWSPERSTRIP
Definition tiff.h:59
@ TIFF_PHOTOMETRIC
Definition tiff.h:50
@ TIFF_YCBCR_SUBSAMPLING
Definition tiff.h:85
@ TIFF_SAMPLES_PER_PIXEL
Definition tiff.h:58
@ TIFF_STRIP_SIZE
Definition tiff.h:60
@ TIFF_RES_UNIT
Definition tiff.h:70
@ TIFF_YRES
Definition tiff.h:62
@ TIFF_REFERENCE_BW
Definition tiff.h:87
@ TIFF_XRES
Definition tiff.h:61
@ TIFF_HEIGHT
Definition tiff.h:47
@ TIFF_SOFTWARE_NAME
Definition tiff.h:72
@ TIFF_SUBFILE
Definition tiff.h:45
@ TIFF_YCBCR_POSITIONING
Definition tiff.h:86
@ TIFF_EXTRASAMPLES
Definition tiff.h:83
@ TIFF_BPP
Definition tiff.h:48
@ TIFF_ORIENTATION
Definition tiff.h:57
@ TIFF_STRIP_OFFS
Definition tiff.h:56
TiffPhotometric
list of TIFF, TIFF/AP and DNG PhotometricInterpretation (TIFF_PHOTOMETRIC) values
Definition tiff.h:189
@ TIFF_PHOTOMETRIC_RGB
Definition tiff.h:193
@ TIFF_PHOTOMETRIC_YCBCR
Definition tiff.h:197
@ TIFF_PHOTOMETRIC_PALETTE
Definition tiff.h:194
@ TIFF_PHOTOMETRIC_WHITE_IS_ZERO
Definition tiff.h:191
@ TIFF_PHOTOMETRIC_BLACK_IS_ZERO
Definition tiff.h:192
TIFF Common Routines.
static const uint8_t type_sizes[14]
sizes of various TIFF field types (string size = 100)
Definition tiff_common.h:37
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:178
static int add_entry(TiffEncoderContext *s, enum TiffTags tag, enum AVTiffDataType type, int count, const void *ptr_val)
Add entry to directory in tiff header.
Definition tiffenc.c:129
#define ADD_ENTRY1(s, tag, type, val)
Definition tiffenc.c:246
#define TIFF_MAX_ENTRY
Definition tiffenc.c:48
static const uint8_t type_sizes2[14]
sizes of various TIFF field types (string size = 1)
Definition tiffenc.c:51
static av_cold int encode_init(AVCodecContext *avctx)
Definition tiffenc.c:561
static av_cold int encode_close(AVCodecContext *avctx)
Definition tiffenc.c:578
static int add_entry1(TiffEncoderContext *s, enum TiffTags tag, enum AVTiffDataType type, int val)
Definition tiffenc.c:158
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
Definition tiffenc.c:253
static void tnput(uint8_t **p, int n, const uint8_t *val, enum AVTiffDataType type, int flip)
Put n values to buffer.
Definition tiffenc.c:109
static int check_size(TiffEncoderContext *s, uint64_t need)
Check free space in buffer.
Definition tiffenc.c:90
static void pack_yuv(TiffEncoderContext *s, const AVFrame *p, uint8_t *dst, int lnum)
Definition tiffenc.c:211
static const AVClass tiffenc_class
Definition tiffenc.c:601
#define ADD_ENTRY(s, tag, type, count, ptr_val)
Definition tiffenc.c:239
#define OFFSET(x)
Definition tiffenc.c:589