]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/tiffenc.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / tiffenc.c
index d635e17aad08ea79e0348f3fa402831c05d36aa2..b9a1e20fa5ef4a9b4bea40edc2b676e8862887da 100644 (file)
@@ -29,6 +29,7 @@
 #if CONFIG_ZLIB
 #include <zlib.h>
 #endif
+#include "libavutil/opt.h"
 #include "bytestream.h"
 #include "tiff.h"
 #include "rle.h"
@@ -43,6 +44,7 @@ static const uint8_t type_sizes2[6] = {
 };
 
 typedef struct TiffEncoderContext {
+    AVClass *avclass;
     AVCodecContext *avctx;
     AVFrame picture;
 
@@ -61,6 +63,7 @@ typedef struct TiffEncoderContext {
     int buf_size;                       ///< buffer size
     uint16_t subsampling[2];            ///< YUV subsampling factors
     struct LZWEncodeState *lzws;        ///< LZW Encode state
+    uint32_t dpi;                       ///< image resolution in DPI
 } TiffEncoderContext;
 
 
@@ -210,13 +213,14 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
     uint32_t *strip_sizes = NULL;
     uint32_t *strip_offsets = NULL;
     int bytes_per_row;
-    uint32_t res[2] = { 72, 1 };        // image resolution (72/1)
+    uint32_t res[2] = { s->dpi, 1 };        // image resolution (72/1)
     uint16_t bpp_tab[] = { 8, 8, 8, 8 };
     int ret = -1;
     int is_yuv = 0;
     uint8_t *yuv_line = NULL;
     int shift_h, shift_v;
 
+    s->avctx = avctx;
     s->buf_start = buf;
     s->buf = &ptr;
     s->buf_size = buf_size;
@@ -243,6 +247,14 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
     s->subsampling[1] = 1;
 
     switch (avctx->pix_fmt) {
+    case PIX_FMT_RGB48LE:
+        s->bpp = 48;
+        s->photometric_interpretation = 2;
+        bpp_tab[0] = 16;
+        bpp_tab[1] = 16;
+        bpp_tab[2] = 16;
+        bpp_tab[3] = 16;
+        break;
     case PIX_FMT_RGB24:
         s->bpp = 24;
         s->photometric_interpretation = 2;
@@ -281,7 +293,7 @@ static int encode_frame(AVCodecContext * avctx, unsigned char *buf,
         return -1;
     }
     if (!is_yuv)
-        s->bpp_tab_size = ((s->bpp + 7) >> 3);
+        s->bpp_tab_size = (s->bpp >= 48) ? ((s->bpp + 7) >> 4):((s->bpp + 7) >> 3);
 
     if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW)
         //best choose for DEFLATE
@@ -441,6 +453,12 @@ fail:
     return ret;
 }
 
+static const AVOption options[]={
+{"dpi", "set the image resolution (in dpi)", offsetof(TiffEncoderContext, dpi), AV_OPT_TYPE_INT, {.dbl = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
+{NULL}
+};
+static const AVClass class = { "tiff", av_default_item_name, options, LIBAVUTIL_VERSION_INT };
+
 AVCodec ff_tiff_encoder = {
     .name           = "tiff",
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -452,7 +470,8 @@ AVCodec ff_tiff_encoder = {
                               PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE,
                               PIX_FMT_YUV420P, PIX_FMT_YUV422P,
                               PIX_FMT_YUV444P, PIX_FMT_YUV410P,
-                              PIX_FMT_YUV411P,
+                              PIX_FMT_YUV411P, PIX_FMT_RGB48LE,
                               PIX_FMT_NONE},
     .long_name = NULL_IF_CONFIG_SMALL("TIFF image"),
+    .priv_class= &class,
 };