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.

588 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, a negative
  152. * value corresponding to an AVERROR error code is returned.
  153. */
  154. static int encode_strip(TiffEncoderContext *s, const int8_t *src,
  155. uint8_t *dst, int n, int compr)
  156. {
  157. switch (compr) {
  158. #if CONFIG_ZLIB
  159. case TIFF_DEFLATE:
  160. case TIFF_ADOBE_DEFLATE:
  161. {
  162. unsigned long zlen = s->buf_size - (*s->buf - s->buf_start);
  163. if (compress(dst, &zlen, src, n) != Z_OK) {
  164. av_log(s->avctx, AV_LOG_ERROR, "Compressing failed\n");
  165. return AVERROR_EXTERNAL;
  166. }
  167. return zlen;
  168. }
  169. #endif
  170. case TIFF_RAW:
  171. if (check_size(s, n))
  172. return AVERROR(EINVAL);
  173. memcpy(dst, src, n);
  174. return n;
  175. case TIFF_PACKBITS:
  176. return ff_rle_encode(dst, s->buf_size - (*s->buf - s->buf_start),
  177. src, 1, n, 2, 0xff, -1, 0);
  178. case TIFF_LZW:
  179. return ff_lzw_encode(s->lzws, src, n);
  180. default:
  181. av_log(s->avctx, AV_LOG_ERROR, "Unsupported compression method: %d\n",
  182. compr);
  183. return AVERROR(EINVAL);
  184. }
  185. }
  186. static void pack_yuv(TiffEncoderContext *s, const AVFrame *p,
  187. uint8_t *dst, int lnum)
  188. {
  189. int i, j, k;
  190. int w = (s->width - 1) / s->subsampling[0] + 1;
  191. uint8_t *pu = &p->data[1][lnum / s->subsampling[1] * p->linesize[1]];
  192. uint8_t *pv = &p->data[2][lnum / s->subsampling[1] * p->linesize[2]];
  193. if (s->width % s->subsampling[0] || s->height % s->subsampling[1]) {
  194. for (i = 0; i < w; i++) {
  195. for (j = 0; j < s->subsampling[1]; j++)
  196. for (k = 0; k < s->subsampling[0]; k++)
  197. *dst++ = p->data[0][FFMIN(lnum + j, s->height-1) * p->linesize[0] +
  198. FFMIN(i * s->subsampling[0] + k, s->width-1)];
  199. *dst++ = *pu++;
  200. *dst++ = *pv++;
  201. }
  202. }else{
  203. for (i = 0; i < w; i++) {
  204. for (j = 0; j < s->subsampling[1]; j++)
  205. for (k = 0; k < s->subsampling[0]; k++)
  206. *dst++ = p->data[0][(lnum + j) * p->linesize[0] +
  207. i * s->subsampling[0] + k];
  208. *dst++ = *pu++;
  209. *dst++ = *pv++;
  210. }
  211. }
  212. }
  213. #define ADD_ENTRY(s, tag, type, count, ptr_val) \
  214. do { \
  215. ret = add_entry(s, tag, type, count, ptr_val); \
  216. if (ret < 0) \
  217. goto fail; \
  218. } while (0)
  219. #define ADD_ENTRY1(s, tag, type, val) \
  220. do { \
  221. ret = add_entry1(s, tag, type, val); \
  222. if (ret < 0) \
  223. goto fail; \
  224. } while (0)
  225. static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
  226. const AVFrame *pict, int *got_packet)
  227. {
  228. const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
  229. TiffEncoderContext *s = avctx->priv_data;
  230. const AVFrame *const p = pict;
  231. int i;
  232. uint8_t *ptr;
  233. uint8_t *offset;
  234. uint32_t strips;
  235. int bytes_per_row;
  236. uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1)
  237. uint16_t bpp_tab[4];
  238. int ret = 0;
  239. int is_yuv = 0, alpha = 0;
  240. int shift_h, shift_v;
  241. int packet_size;
  242. s->width = avctx->width;
  243. s->height = avctx->height;
  244. s->subsampling[0] = 1;
  245. s->subsampling[1] = 1;
  246. avctx->bits_per_coded_sample =
  247. s->bpp = av_get_bits_per_pixel(desc);
  248. s->bpp_tab_size = desc->nb_components;
  249. switch (avctx->pix_fmt) {
  250. case AV_PIX_FMT_RGBA64LE:
  251. case AV_PIX_FMT_RGBA:
  252. alpha = 1;
  253. case AV_PIX_FMT_RGB48LE:
  254. case AV_PIX_FMT_RGB24:
  255. s->photometric_interpretation = TIFF_PHOTOMETRIC_RGB;
  256. break;
  257. case AV_PIX_FMT_GRAY8:
  258. avctx->bits_per_coded_sample = 0x28;
  259. case AV_PIX_FMT_GRAY8A:
  260. case AV_PIX_FMT_YA16LE:
  261. alpha = avctx->pix_fmt == AV_PIX_FMT_GRAY8A || avctx->pix_fmt == AV_PIX_FMT_YA16LE;
  262. case AV_PIX_FMT_GRAY16LE:
  263. case AV_PIX_FMT_MONOBLACK:
  264. s->photometric_interpretation = TIFF_PHOTOMETRIC_BLACK_IS_ZERO;
  265. break;
  266. case AV_PIX_FMT_PAL8:
  267. s->photometric_interpretation = TIFF_PHOTOMETRIC_PALETTE;
  268. break;
  269. case AV_PIX_FMT_MONOWHITE:
  270. s->photometric_interpretation = TIFF_PHOTOMETRIC_WHITE_IS_ZERO;
  271. break;
  272. case AV_PIX_FMT_YUV420P:
  273. case AV_PIX_FMT_YUV422P:
  274. case AV_PIX_FMT_YUV440P:
  275. case AV_PIX_FMT_YUV444P:
  276. case AV_PIX_FMT_YUV410P:
  277. case AV_PIX_FMT_YUV411P:
  278. av_pix_fmt_get_chroma_sub_sample(avctx->pix_fmt, &shift_h, &shift_v);
  279. s->photometric_interpretation = TIFF_PHOTOMETRIC_YCBCR;
  280. s->subsampling[0] = 1 << shift_h;
  281. s->subsampling[1] = 1 << shift_v;
  282. is_yuv = 1;
  283. break;
  284. default:
  285. av_log(s->avctx, AV_LOG_ERROR,
  286. "This colors format is not supported\n");
  287. return AVERROR(EINVAL);
  288. }
  289. for (i = 0; i < s->bpp_tab_size; i++)
  290. bpp_tab[i] = desc->comp[i].depth_minus1 + 1;
  291. if (s->compr == TIFF_DEFLATE ||
  292. s->compr == TIFF_ADOBE_DEFLATE ||
  293. s->compr == TIFF_LZW)
  294. // best choice for DEFLATE
  295. s->rps = s->height;
  296. else
  297. // suggest size of strip
  298. s->rps = FFMAX(8192 / (((s->width * s->bpp) >> 3) + 1), 1);
  299. // round rps up
  300. s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1];
  301. strips = (s->height - 1) / s->rps + 1;
  302. bytes_per_row = (((s->width - 1) / s->subsampling[0] + 1) * s->bpp *
  303. s->subsampling[0] * s->subsampling[1] + 7) >> 3;
  304. packet_size = avctx->height * bytes_per_row * 2 +
  305. avctx->height * 4 + AV_INPUT_BUFFER_MIN_SIZE;
  306. if ((ret = ff_alloc_packet2(avctx, pkt, packet_size, 0)) < 0)
  307. return ret;
  308. ptr = pkt->data;
  309. s->buf_start = pkt->data;
  310. s->buf = &ptr;
  311. s->buf_size = pkt->size;
  312. if (check_size(s, 8)) {
  313. ret = AVERROR(EINVAL);
  314. goto fail;
  315. }
  316. // write header
  317. bytestream_put_le16(&ptr, 0x4949);
  318. bytestream_put_le16(&ptr, 42);
  319. offset = ptr;
  320. bytestream_put_le32(&ptr, 0);
  321. if (strips > INT_MAX / FFMAX(sizeof(s->strip_sizes[0]), sizeof(s->strip_offsets[0]))) {
  322. ret = AVERROR(ENOMEM);
  323. goto fail;
  324. }
  325. av_fast_padded_mallocz(&s->strip_sizes , &s->strip_sizes_size , sizeof(s->strip_sizes [0]) * strips);
  326. av_fast_padded_mallocz(&s->strip_offsets, &s->strip_offsets_size, sizeof(s->strip_offsets[0]) * strips);
  327. if (!s->strip_sizes || !s->strip_offsets) {
  328. ret = AVERROR(ENOMEM);
  329. goto fail;
  330. }
  331. if (is_yuv) {
  332. av_fast_padded_malloc(&s->yuv_line, &s->yuv_line_size, bytes_per_row);
  333. if (s->yuv_line == NULL) {
  334. av_log(s->avctx, AV_LOG_ERROR, "Not enough memory\n");
  335. ret = AVERROR(ENOMEM);
  336. goto fail;
  337. }
  338. }
  339. #if CONFIG_ZLIB
  340. if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
  341. uint8_t *zbuf;
  342. int zlen, zn;
  343. int j;
  344. zlen = bytes_per_row * s->rps;
  345. zbuf = av_malloc(zlen);
  346. if (!zbuf) {
  347. ret = AVERROR(ENOMEM);
  348. goto fail;
  349. }
  350. s->strip_offsets[0] = ptr - pkt->data;
  351. zn = 0;
  352. for (j = 0; j < s->rps; j++) {
  353. if (is_yuv) {
  354. pack_yuv(s, p, s->yuv_line, j);
  355. memcpy(zbuf + zn, s->yuv_line, bytes_per_row);
  356. j += s->subsampling[1] - 1;
  357. } else
  358. memcpy(zbuf + j * bytes_per_row,
  359. p->data[0] + j * p->linesize[0], bytes_per_row);
  360. zn += bytes_per_row;
  361. }
  362. ret = encode_strip(s, zbuf, ptr, zn, s->compr);
  363. av_free(zbuf);
  364. if (ret < 0) {
  365. av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
  366. goto fail;
  367. }
  368. ptr += ret;
  369. s->strip_sizes[0] = ptr - pkt->data - s->strip_offsets[0];
  370. } else
  371. #endif
  372. {
  373. if (s->compr == TIFF_LZW) {
  374. s->lzws = av_malloc(ff_lzw_encode_state_size);
  375. if (!s->lzws) {
  376. ret = AVERROR(ENOMEM);
  377. goto fail;
  378. }
  379. }
  380. for (i = 0; i < s->height; i++) {
  381. if (s->strip_sizes[i / s->rps] == 0) {
  382. if (s->compr == TIFF_LZW) {
  383. ff_lzw_encode_init(s->lzws, ptr,
  384. s->buf_size - (*s->buf - s->buf_start),
  385. 12, FF_LZW_TIFF, put_bits);
  386. }
  387. s->strip_offsets[i / s->rps] = ptr - pkt->data;
  388. }
  389. if (is_yuv) {
  390. pack_yuv(s, p, s->yuv_line, i);
  391. ret = encode_strip(s, s->yuv_line, ptr, bytes_per_row, s->compr);
  392. i += s->subsampling[1] - 1;
  393. } else
  394. ret = encode_strip(s, p->data[0] + i * p->linesize[0],
  395. ptr, bytes_per_row, s->compr);
  396. if (ret < 0) {
  397. av_log(s->avctx, AV_LOG_ERROR, "Encode strip failed\n");
  398. goto fail;
  399. }
  400. s->strip_sizes[i / s->rps] += ret;
  401. ptr += ret;
  402. if (s->compr == TIFF_LZW &&
  403. (i == s->height - 1 || i % s->rps == s->rps - 1)) {
  404. ret = ff_lzw_encode_flush(s->lzws, flush_put_bits);
  405. s->strip_sizes[(i / s->rps)] += ret;
  406. ptr += ret;
  407. }
  408. }
  409. if (s->compr == TIFF_LZW)
  410. av_freep(&s->lzws);
  411. }
  412. s->num_entries = 0;
  413. ADD_ENTRY1(s, TIFF_SUBFILE, TIFF_LONG, 0);
  414. ADD_ENTRY1(s, TIFF_WIDTH, TIFF_LONG, s->width);
  415. ADD_ENTRY1(s, TIFF_HEIGHT, TIFF_LONG, s->height);
  416. if (s->bpp_tab_size)
  417. ADD_ENTRY(s, TIFF_BPP, TIFF_SHORT, s->bpp_tab_size, bpp_tab);
  418. ADD_ENTRY1(s, TIFF_COMPR, TIFF_SHORT, s->compr);
  419. ADD_ENTRY1(s, TIFF_PHOTOMETRIC, TIFF_SHORT, s->photometric_interpretation);
  420. ADD_ENTRY(s, TIFF_STRIP_OFFS, TIFF_LONG, strips, s->strip_offsets);
  421. if (s->bpp_tab_size)
  422. ADD_ENTRY1(s, TIFF_SAMPLES_PER_PIXEL, TIFF_SHORT, s->bpp_tab_size);
  423. ADD_ENTRY1(s, TIFF_ROWSPERSTRIP, TIFF_LONG, s->rps);
  424. ADD_ENTRY(s, TIFF_STRIP_SIZE, TIFF_LONG, strips, s->strip_sizes);
  425. ADD_ENTRY(s, TIFF_XRES, TIFF_RATIONAL, 1, res);
  426. if (avctx->sample_aspect_ratio.num > 0 &&
  427. avctx->sample_aspect_ratio.den > 0) {
  428. AVRational y = av_mul_q(av_make_q(s->dpi, 1),
  429. avctx->sample_aspect_ratio);
  430. res[0] = y.num;
  431. res[1] = y.den;
  432. }
  433. ADD_ENTRY(s, TIFF_YRES, TIFF_RATIONAL, 1, res);
  434. ADD_ENTRY1(s, TIFF_RES_UNIT, TIFF_SHORT, 2);
  435. if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT))
  436. ADD_ENTRY(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
  437. strlen(LIBAVCODEC_IDENT) + 1, LIBAVCODEC_IDENT);
  438. if (avctx->pix_fmt == AV_PIX_FMT_PAL8) {
  439. uint16_t pal[256 * 3];
  440. for (i = 0; i < 256; i++) {
  441. uint32_t rgb = *(uint32_t *) (p->data[1] + i * 4);
  442. pal[i] = ((rgb >> 16) & 0xff) * 257;
  443. pal[i + 256] = ((rgb >> 8) & 0xff) * 257;
  444. pal[i + 512] = (rgb & 0xff) * 257;
  445. }
  446. ADD_ENTRY(s, TIFF_PAL, TIFF_SHORT, 256 * 3, pal);
  447. }
  448. if (alpha)
  449. ADD_ENTRY1(s,TIFF_EXTRASAMPLES, TIFF_SHORT, 2);
  450. if (is_yuv) {
  451. /** according to CCIR Recommendation 601.1 */
  452. uint32_t refbw[12] = { 15, 1, 235, 1, 128, 1, 240, 1, 128, 1, 240, 1 };
  453. ADD_ENTRY(s, TIFF_YCBCR_SUBSAMPLING, TIFF_SHORT, 2, s->subsampling);
  454. if (avctx->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)
  455. ADD_ENTRY1(s, TIFF_YCBCR_POSITIONING, TIFF_SHORT, 2);
  456. ADD_ENTRY(s, TIFF_REFERENCE_BW, TIFF_RATIONAL, 6, refbw);
  457. }
  458. // write offset to dir
  459. bytestream_put_le32(&offset, ptr - pkt->data);
  460. if (check_size(s, 6 + s->num_entries * 12)) {
  461. ret = AVERROR(EINVAL);
  462. goto fail;
  463. }
  464. bytestream_put_le16(&ptr, s->num_entries); // write tag count
  465. bytestream_put_buffer(&ptr, s->entries, s->num_entries * 12);
  466. bytestream_put_le32(&ptr, 0);
  467. pkt->size = ptr - pkt->data;
  468. pkt->flags |= AV_PKT_FLAG_KEY;
  469. *got_packet = 1;
  470. fail:
  471. return ret < 0 ? ret : 0;
  472. }
  473. static av_cold int encode_init(AVCodecContext *avctx)
  474. {
  475. TiffEncoderContext *s = avctx->priv_data;
  476. #if FF_API_CODED_FRAME
  477. FF_DISABLE_DEPRECATION_WARNINGS
  478. avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
  479. avctx->coded_frame->key_frame = 1;
  480. FF_ENABLE_DEPRECATION_WARNINGS
  481. #endif
  482. s->avctx = avctx;
  483. return 0;
  484. }
  485. static av_cold int encode_close(AVCodecContext *avctx)
  486. {
  487. TiffEncoderContext *s = avctx->priv_data;
  488. av_freep(&s->strip_sizes);
  489. av_freep(&s->strip_offsets);
  490. av_freep(&s->yuv_line);
  491. return 0;
  492. }
  493. #define OFFSET(x) offsetof(TiffEncoderContext, x)
  494. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  495. static const AVOption options[] = {
  496. {"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},
  497. { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" },
  498. { "packbits", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0, 0, VE, "compression_algo" },
  499. { "raw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW }, 0, 0, VE, "compression_algo" },
  500. { "lzw", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_LZW }, 0, 0, VE, "compression_algo" },
  501. #if CONFIG_ZLIB
  502. { "deflate", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = TIFF_DEFLATE }, 0, 0, VE, "compression_algo" },
  503. #endif
  504. { NULL },
  505. };
  506. static const AVClass tiffenc_class = {
  507. .class_name = "TIFF encoder",
  508. .item_name = av_default_item_name,
  509. .option = options,
  510. .version = LIBAVUTIL_VERSION_INT,
  511. };
  512. AVCodec ff_tiff_encoder = {
  513. .name = "tiff",
  514. .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
  515. .type = AVMEDIA_TYPE_VIDEO,
  516. .id = AV_CODEC_ID_TIFF,
  517. .priv_data_size = sizeof(TiffEncoderContext),
  518. .init = encode_init,
  519. .close = encode_close,
  520. .capabilities = AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_INTRA_ONLY,
  521. .encode2 = encode_frame,
  522. .pix_fmts = (const enum AVPixelFormat[]) {
  523. AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48LE, AV_PIX_FMT_PAL8,
  524. AV_PIX_FMT_RGBA, AV_PIX_FMT_RGBA64LE,
  525. AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY8A, AV_PIX_FMT_GRAY16LE, AV_PIX_FMT_YA16LE,
  526. AV_PIX_FMT_MONOBLACK, AV_PIX_FMT_MONOWHITE,
  527. AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV440P, AV_PIX_FMT_YUV444P,
  528. AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P,
  529. AV_PIX_FMT_NONE
  530. },
  531. .priv_class = &tiffenc_class,
  532. };