You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
20KB

  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. * @file
  23. * TIFF image encoder
  24. * @author Bartlomiej Wolowiec
  25. */
  26. #include "config.h"
  27. #if CONFIG_ZLIB
  28. #include <zlib.h>
  29. #endif
  30. #include "libavutil/imgutils.h"
  31. #include "libavutil/log.h"
  32. #include "libavutil/opt.h"
  33. #include "libavutil/pixdesc.h"
  34. #include "avcodec.h"
  35. #include "bytestream.h"
  36. #include "internal.h"
  37. #include "lzw.h"
  38. #include "put_bits.h"
  39. #include "rle.h"
  40. #include "tiff.h"
  41. #define TIFF_MAX_ENTRY 32
  42. /** sizes of various TIFF field types (string size = 1)*/
  43. static const uint8_t type_sizes2[14] = {
  44. 0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4
  45. };
  46. typedef struct TiffEncoderContext {
  47. AVClass *class; ///< for private options
  48. AVCodecContext *avctx;
  49. int width; ///< picture width
  50. int height; ///< picture height
  51. unsigned int bpp; ///< bits per pixel
  52. int compr; ///< compression level
  53. int bpp_tab_size; ///< bpp_tab size
  54. enum TiffPhotometric photometric_interpretation; ///< photometric interpretation
  55. int strips; ///< number of strips
  56. uint32_t *strip_sizes;
  57. unsigned int strip_sizes_size;
  58. uint32_t *strip_offsets;
  59. unsigned int strip_offsets_size;
  60. uint8_t *yuv_line;
  61. unsigned int yuv_line_size;
  62. int rps; ///< row per strip
  63. uint8_t entries[TIFF_MAX_ENTRY * 12]; ///< entries in header
  64. int num_entries; ///< number of entries
  65. uint8_t **buf; ///< actual position in buffer
  66. uint8_t *buf_start; ///< pointer to first byte in buffer
  67. int buf_size; ///< buffer size
  68. uint16_t subsampling[2]; ///< YUV subsampling factors
  69. struct LZWEncodeState *lzws; ///< LZW encode state
  70. uint32_t dpi; ///< image resolution in DPI
  71. } TiffEncoderContext;
  72. /**
  73. * Check free space in buffer.
  74. *
  75. * @param s Tiff context
  76. * @param need Needed bytes
  77. * @return 0 - ok, 1 - no free space
  78. */
  79. static inline int check_size(TiffEncoderContext *s, uint64_t need)
  80. {
  81. if (s->buf_size < *s->buf - s->buf_start + need) {
  82. *s->buf = s->buf_start + s->buf_size + 1;
  83. av_log(s->avctx, AV_LOG_ERROR, "Buffer is too small\n");
  84. return 1;
  85. }
  86. return 0;
  87. }
  88. /**
  89. * Put n values to buffer.
  90. *
  91. * @param p pointer to pointer to output buffer
  92. * @param n number of values
  93. * @param val pointer to values
  94. * @param type type of values
  95. * @param flip = 0 - normal copy, >0 - flip
  96. */
  97. static void tnput(uint8_t **p, int n, const uint8_t *val, enum TiffTypes type,
  98. int flip)
  99. {
  100. int i;
  101. #if HAVE_BIGENDIAN
  102. flip ^= ((int[]) { 0, 0, 0, 1, 3, 3 })[type];
  103. #endif
  104. for (i = 0; i < n * type_sizes2[type]; i++)
  105. *(*p)++ = val[i ^ flip];
  106. }
  107. /**
  108. * Add entry to directory in tiff header.
  109. *
  110. * @param s Tiff context
  111. * @param tag tag that identifies the entry
  112. * @param type entry type
  113. * @param count the number of values
  114. * @param ptr_val pointer to values
  115. */
  116. static int add_entry(TiffEncoderContext *s, enum TiffTags tag,
  117. enum TiffTypes type, int count, const void *ptr_val)
  118. {
  119. uint8_t *entries_ptr = s->entries + 12 * s->num_entries;
  120. av_assert0(s->num_entries < TIFF_MAX_ENTRY);
  121. bytestream_put_le16(&entries_ptr, tag);
  122. bytestream_put_le16(&entries_ptr, type);
  123. bytestream_put_le32(&entries_ptr, count);
  124. if (type_sizes[type] * (int64_t)count <= 4) {
  125. tnput(&entries_ptr, count, ptr_val, type, 0);
  126. } else {
  127. bytestream_put_le32(&entries_ptr, *s->buf - s->buf_start);
  128. if (check_size(s, count * (int64_t)type_sizes2[type]))
  129. return AVERROR_INVALIDDATA;
  130. tnput(s->buf, count, ptr_val, type, 0);
  131. }
  132. s->num_entries++;
  133. return 0;
  134. }
  135. static int add_entry1(TiffEncoderContext *s,
  136. enum TiffTags tag, enum TiffTypes type, int val)
  137. {
  138. uint16_t w = val;
  139. uint32_t dw = val;
  140. return add_entry(s, tag, type, 1,
  141. type == TIFF_SHORT ? (void *)&w : (void *)&dw);
  142. }
  143. /**
  144. * Encode one strip in tiff file.
  145. *
  146. * @param s Tiff context
  147. * @param src input buffer
  148. * @param dst output buffer
  149. * @param n size of input buffer
  150. * @param compr compression method
  151. * @return number of output bytes. If an output error is encountered, -1 is returned
  152. */
  153. static int encode_strip(TiffEncoderContext *s, const int8_t *src,
  154. uint8_t *dst, int n, int compr)
  155. {
  156. switch (compr) {
  157. #if CONFIG_ZLIB
  158. case TIFF_DEFLATE:
  159. case TIFF_ADOBE_DEFLATE:
  160. {
  161. unsigned long zlen = s->buf_size - (*s->buf - s->buf_start);
  162. if (compress(dst, &zlen, src, n) != Z_OK) {
  163. av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n");
  164. return -1;
  165. }
  166. return zlen;
  167. }
  168. #endif
  169. case TIFF_RAW:
  170. if (check_size(s, n))
  171. return -1;
  172. memcpy(dst, src, n);
  173. return n;
  174. case TIFF_PACKBITS:
  175. return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start),
  176. src, 1, n, 2, 0xff, -1, 0);
  177. case TIFF_LZW:
  178. return ff_lzw_encode(s->lzws, src, n);
  179. default:
  180. return -1;
  181. }
  182. }
  183. static void pack_yuv(TiffEncoderContext *s, const AVFrame *p,
  184. uint8_t *dst, int lnum)
  185. {
  186. int i, j, k;
  187. int w = (s->width - 1) / s->subsampling[0] + 1;
  188. uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
  189. uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
  190. if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
  191. for (i = 0; i < w; i++) {
  192. for (j = 0; j < s->subsampling[1]; j++)
  193. for (k = 0; k < s->subsampling[0]; k++)
  194. *dst++ = p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
  195. FFMIN(i * s->subsampling[0] + k, s->width-1)];
  196. *dst++ = *pu++;
  197. *dst++ = *pv++;
  198. }
  199. }else{
  200. for (i = 0; i < w; i++) {
  201. for (j = 0; j < s->subsampling[1]; j++)
  202. for (k = 0; k < s->subsampling[0]; k++)
  203. *dst++ = p->data[0][(lnum + j) * p->linesize[0] +
  204. i * s->subsampling[0] + k];
  205. *dst++ = *pu++;
  206. *dst++ = *pv++;
  207. }
  208. }
  209. }
  210. #define ADD_ENTRY(s, tag, type, count, ptr_val) \
  211. do { \
  212. ret = add_entry(s, tag, type, count, ptr_val); \
  213. if (ret < 0) \
  214. goto fail; \
  215. } while(0);
  216. #define ADD_ENTRY1(s, tag, type, val) \
  217. do { \
  218. ret = add_entry1(s, tag, type, val); \
  219. if (ret < 0) \
  220. goto fail; \
  221. } while(0);
  222. static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  223. const AVFrame *pict, int *got_packet)
  224. {
  225. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
  226. TiffEncoderContext *s = avctx->priv_data;
  227. const AVFrame *const p = pict;
  228. int i;
  229. uint8_t *ptr;
  230. uint8_t *offset;
  231. uint32_t strips;
  232. int bytes_per_row;
  233. uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
  234. uint16_t bpp_tab[4];
  235. int ret = 0;
  236. int is_yuv = 0, alpha = 0;
  237. int shift_h, shift_v;
  238. int packet_size;
  239. s->width = avctx->width;
  240. s->height = avctx->height;
  241. s->subsampling[0] = 1;
  242. s->subsampling[1] = 1;
  243. avctx->bits_per_coded_sample =
  244. s->bpp = av_get_bits_per_pixel(desc);
  245. s->bpp_tab_size = desc->nb_components;
  246. switch (avctx->pix_fmt) {
  247. case AV_PIX_FMT_RGBA64LE:
  248. case AV_PIX_FMT_RGBA:
  249. alpha = 1;
  250. case AV_PIX_FMT_RGB48LE:
  251. case AV_PIX_FMT_RGB24:
  252. s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
  253. break;
  254. case AV_PIX_FMT_GRAY8:
  255. avctx->bits_per_coded_sample = 0x28;
  256. case AV_PIX_FMT_GRAY8A:
  257. alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A;
  258. case AV_PIX_FMT_GRAY16LE:
  259. case AV_PIX_FMT_MONOBLACK:
  260. s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
  261. break;
  262. case AV_PIX_FMT_PAL8:
  263. s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
  264. break;
  265. case AV_PIX_FMT_MONOWHITE:
  266. s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
  267. break;
  268. case AV_PIX_FMT_YUV420P:
  269. case AV_PIX_FMT_YUV422P:
  270. case AV_PIX_FMT_YUV440P:
  271. case AV_PIX_FMT_YUV444P:
  272. case AV_PIX_FMT_YUV410P:
  273. case AV_PIX_FMT_YUV411P:
  274. av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
  275. s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR;
  276. s->subsampling[0] = 1 << shift_h;
  277. s->subsampling[1] = 1 << shift_v;
  278. is_yuv = 1;
  279. break;
  280. default:
  281. av_log(s->avctx, AV_LOG_ERROR,
  282. "This colors format is not supported\n");
  283. return -1;
  284. }
  285. for (i = 0; i < s->bpp_tab_size; i++)
  286. bpp_tab[i] = desc->comp[i].depth_minus1 + 1;
  287. if (s->compr == TIFF_DEFLATE ||
  288. s->compr == TIFF_ADOBE_DEFLATE ||
  289. s->compr == TIFF_LZW)
  290. // best choice for DEFLATE
  291. s->rps = s->height;
  292. else
  293. // suggest size of strip
  294. s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1);
  295. // round rps up
  296. s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1];
  297. strips = (s->height - 1) / s->rps + 1;
  298. bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *
  299. s->subsampling[0] * s->subsampling[1] + 7) >> 3;
  300. packet_size = avctx->height * bytes_per_row * 2 +
  301. avctx->height * 4 + FF_MIN_BUFFER_SIZE;
  302. if ((ret = ff_alloc_packet2(avctx, pkt, packet_size)) < 0)
  303. return ret;
  304. ptr = pkt->data;
  305. s->buf_start = pkt->data;
  306. s->buf = &ptr;
  307. s->buf_size = pkt->size;
  308. if (check_size(s, 8)) {
  309. ret = AVERROR(EINVAL);
  310. goto fail;
  311. }
  312. // write header
  313. bytestream_put_le16(&ptr, 0x4949);
  314. bytestream_put_le16(&ptr, 42);
  315. offset = ptr;
  316. bytestream_put_le32(&ptr, 0);
  317. if (strips > INT_MAX / FFMAX(sizeof(s->strip_sizes[0]), sizeof(s->strip_offsets[0]))) {
  318. ret = AVERROR(ENOMEM);
  319. goto fail;
  320. }
  321. av_fast_padded_mallocz(&s->strip_sizes , &s->strip_sizes_size , sizeof(s->strip_sizes [0]) * strips);
  322. av_fast_padded_mallocz(&s->strip_offsets, &s->strip_offsets_size, sizeof(s->strip_offsets[0]) * strips);
  323. if (!s->strip_sizes || !s->strip_offsets) {
  324. ret = AVERROR(ENOMEM);
  325. goto fail;
  326. }
  327. if (is_yuv) {
  328. av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);
  329. if (s->yuv_line == NULL) {
  330. av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
  331. ret = AVERROR(ENOMEM);
  332. goto fail;
  333. }
  334. }
  335. #if CONFIG_ZLIB
  336. if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
  337. uint8_t *zbuf;
  338. int zlen, zn;
  339. int j;
  340. zlen = bytes_per_row * s->rps;
  341. zbuf = av_malloc(zlen);
  342. if (!zbuf) {
  343. ret = AVERROR(ENOMEM);
  344. goto fail;
  345. }
  346. s->strip_offsets[0] = ptr - pkt->data;
  347. zn = 0;
  348. for (j = 0; j < s->rps; j++) {
  349. if (is_yuv) {
  350. pack_yuv(s, p, s->yuv_line, j);
  351. memcpy(zbuf + zn, s->yuv_line, bytes_per_row);
  352. j += s->subsampling[1] - 1;
  353. } else
  354. memcpy(zbuf + j * bytes_per_row,
  355. p->data[0] + j * p->linesize[0], bytes_per_row);
  356. zn += bytes_per_row;
  357. }
  358. ret = encode_strip(s, zbuf, ptr, zn, s->compr);
  359. av_free(zbuf);
  360. if (ret < 0) {
  361. av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
  362. goto fail;
  363. }
  364. ptr += ret;
  365. s->strip_sizes[0] = ptr - pkt->data - s->strip_offsets[0];
  366. } else
  367. #endif
  368. {
  369. if (s->compr == TIFF_LZW) {
  370. s->lzws = av_malloc(ff_lzw_encode_state_size);
  371. if (!s->lzws) {
  372. ret = AVERROR(ENOMEM);
  373. goto fail;
  374. }
  375. }
  376. for (i = 0; i < s->height; i++) {
  377. if (s->strip_sizes[i / s->rps] == 0) {
  378. if (s->compr == TIFF_LZW) {
  379. ff_lzw_encode_init(s->lzws, ptr,
  380. s->buf_size - (*s->buf - s->buf_start),
  381. 12, FF_LZW_TIFF, put_bits);
  382. }
  383. s->strip_offsets[i / s->rps] = ptr - pkt->data;
  384. }
  385. if (is_yuv) {
  386. pack_yuv(s, p, s->yuv_line, i);
  387. ret = encode_strip(s, s->yuv_line, ptr, bytes_per_row, s->compr);
  388. i += s->subsampling[1] - 1;
  389. } else
  390. ret = encode_strip(s, p->data[0] + i * p->linesize[0],
  391. ptr, bytes_per_row, s->compr);
  392. if (ret < 0) {
  393. av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
  394. goto fail;
  395. }
  396. s->strip_sizes[i / s->rps] += ret;
  397. ptr += ret;
  398. if (s->compr == TIFF_LZW &&
  399. (i == s->height - 1 || i % s->rps == s->rps - 1)) {
  400. ret = ff_lzw_encode_flush(s->lzws, flush_put_bits);
  401. s->strip_sizes[(i / s->rps)] += ret;
  402. ptr += ret;
  403. }
  404. }
  405. if (s->compr == TIFF_LZW)
  406. av_freep(&s->lzws);
  407. }
  408. s->num_entries = 0;
  409. ADD_ENTRY1(s, TIFF_SUBFILE, TIFF_LONG, 0);
  410. ADD_ENTRY1(s, TIFF_WIDTH, TIFF_LONG, s->width);
  411. ADD_ENTRY1(s, TIFF_HEIGHT, TIFF_LONG, s->height);
  412. if (s->bpp_tab_size)
  413. ADD_ENTRY(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
  414. ADD_ENTRY1(s, TIFF_COMPR, TIFF_SHORT, s->compr);
  415. ADD_ENTRY1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
  416. ADD_ENTRY(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, s->strip_offsets);
  417. if (s->bpp_tab_size)
  418. ADD_ENTRY1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
  419. ADD_ENTRY1(s, TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps);
  420. ADD_ENTRY(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, s->strip_sizes);
  421. ADD_ENTRY(s, TIFF_XRES, TIFF_RATIONAL, 1, res);
  422. if (avctx->sample_aspect_ratio.num > 0 &&
  423. avctx->sample_aspect_ratio.den > 0) {
  424. AVRational y = av_mul_q(av_make_q(s->dpi, 1),
  425. avctx->sample_aspect_ratio);
  426. res[0] = y.num;
  427. res[1] = y.den;
  428. }
  429. ADD_ENTRY(s, TIFF_YRES, TIFF_RATIONAL, 1, res);
  430. ADD_ENTRY1(s, TIFF_RES_UNIT, TIFF_SHORT, 2);
  431. if (!(avctx->flags & CODEC_FLAG_BITEXACT))
  432. ADD_ENTRY(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
  433. strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT);
  434. if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
  435. uint16_t pal[256 * 3];
  436. for (i = 0; i < 256; i++) {
  437. uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
  438. pal[i] = ((rgb >> 16) & 0xff) * 257;
  439. pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
  440. pal[i + 512] = (rgb & 0xff) * 257;
  441. }
  442. ADD_ENTRY(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
  443. }
  444. if (alpha)
  445. add_entry1(s,TIFF_EXTRASAMPLES, TIFF_SHORT, 2);
  446. if (is_yuv) {
  447. /** according to CCIR Recommendation 601.1 */
  448. uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
  449. ADD_ENTRY(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling);
  450. if (avctx->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)
  451. add_entry1(s, TIFF_YCBCR_POSITIONING, TIFF_SHORT, 2);
  452. ADD_ENTRY(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw);
  453. }
  454. // write offset to dir
  455. bytestream_put_le32(&offset, ptr - pkt->data);
  456. if (check_size(s, 6 + s->num_entries * 12)) {
  457. ret = AVERROR(EINVAL);
  458. goto fail;
  459. }
  460. bytestream_put_le16(&ptr, s->num_entries); // write tag count
  461. bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12);
  462. bytestream_put_le32(&ptr, 0);
  463. pkt->size = ptr - pkt->data;
  464. pkt->flags |= AV_PKT_FLAG_KEY;
  465. *got_packet = 1;
  466. fail:
  467. return ret < 0 ? ret : 0;
  468. }
  469. static av_cold int encode_init(AVCodecContext *avctx)
  470. {
  471. TiffEncoderContext *s = avctx->priv_data;
  472. avctx->coded_frame = av_frame_alloc();
  473. if (!avctx->coded_frame)
  474. return AVERROR(ENOMEM);
  475. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  476. avctx->coded_frame->key_frame = 1;
  477. s->avctx = avctx;
  478. return 0;
  479. }
  480. static av_cold int encode_close(AVCodecContext *avctx)
  481. {
  482. TiffEncoderContext *s = avctx->priv_data;
  483. av_frame_free(&avctx->coded_frame);
  484. av_freep(&s->strip_sizes);
  485. av_freep(&s->strip_offsets);
  486. av_freep(&s->yuv_line);
  487. return 0;
  488. }
  489. #define OFFSET(x) offsetof(TiffEncoderContext, x)
  490. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  491. static const AVOption options[] = {
  492. {"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},
  493. { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" },
  494. { "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, "compression_algo" },
  495. { "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, "compression_algo" },
  496. { "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, "compression_algo" },
  497. #if CONFIG_ZLIB
  498. { "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, "compression_algo" },
  499. #endif
  500. { NULL },
  501. };
  502. static const AVClass tiffenc_class = {
  503. .class_name = "TIFF encoder",
  504. .item_name = av_default_item_name,
  505. .option = options,
  506. .version = LIBAVUTIL_VERSION_INT,
  507. };
  508. AVCodec ff_tiff_encoder = {
  509. .name = "tiff",
  510. .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
  511. .type = AVMEDIA_TYPE_VIDEO,
  512. .id = AV_CODEC_ID_TIFF,
  513. .priv_data_size = sizeof(TiffEncoderContext),
  514. .init = encode_init,
  515. .close = encode_close,
  516. .capabilities = CODEC_CAP_FRAME_THREADS | CODEC_CAP_INTRA_ONLY,
  517. .encode2 = encode_frame,
  518. .pix_fmts = (const enum AVPixelFormat[]) {
  519. AV_PIX_FMT_RGB24, AV_PIX_FMT_PAL8, AV_PIX_FMT_GRAY8,
  520. AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16LE,
  521. AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE,
  522. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  523. AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_RGB48LE,
  524. AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA64LE,
  525. AV_PIX_FMT_NONE
  526. },
  527. .priv_class = &tiffenc_class,
  528. };