[FFmpeg-devel] [PATCH]Write tiff aspect ratio by default instead of dpi

Carl Eugen Hoyos cehoyos at ag.or.at
Tue Apr 1 12:15:25 CEST 2014


Hi!

Attached patch changes the tiff encoder to write the sample 
aspect ratio instead of the dpi by default, this is what other 
FFmpeg image decoders do.
Tested with xv.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/Changelog b/Changelog
index 0e38ec8..9d40e53 100644
--- a/Changelog
+++ b/Changelog
@@ -13,6 +13,7 @@ version <next>:
 - QTKit input device
 - improvments to OpenEXR image decoder
 - support decoding 16-bit RLE SGI images
+- Write tiff aspect ratio instead of dpi by default
 
 
 version 2.2:
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index 7b1e510..cccc4bc 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -233,7 +233,8 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     uint8_t *offset;
     uint32_t strips;
     int bytes_per_row;
-    uint32_t res[2] = { s->dpi, 1 };    // image resolution (72/1)
+    uint32_t resx[2] = { s->dpi ? s->dpi : avctx->sample_aspect_ratio.den, 1 };
+    uint32_t resy[2] = { s->dpi ? s->dpi : avctx->sample_aspect_ratio.num, 1 };
     uint16_t bpp_tab[4];
     int ret = -1;
     int is_yuv = 0, alpha = 0;
@@ -435,9 +436,9 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 
     add_entry1(s, TIFF_ROWSPERSTRIP, TIFF_LONG,     s->rps);
     add_entry(s,  TIFF_STRIP_SIZE,   TIFF_LONG,     strips, s->strip_sizes);
-    add_entry(s,  TIFF_XRES,         TIFF_RATIONAL, 1,      res);
-    add_entry(s,  TIFF_YRES,         TIFF_RATIONAL, 1,      res);
-    add_entry1(s, TIFF_RES_UNIT,     TIFF_SHORT,    2);
+    add_entry(s,  TIFF_XRES,         TIFF_RATIONAL, 1,      resx);
+    add_entry(s,  TIFF_YRES,         TIFF_RATIONAL, 1,      resy);
+    add_entry1(s, TIFF_RES_UNIT,     TIFF_SHORT,    s->dpi ? 2 : 1);
 
     if (!(avctx->flags & CODEC_FLAG_BITEXACT))
         add_entry(s, TIFF_SOFTWARE_NAME, TIFF_STRING,
@@ -512,7 +513,7 @@ static av_cold int encode_close(AVCodecContext *avctx)
 #define OFFSET(x) offsetof(TiffEncoderContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-    {"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},
+    {"dpi", "set the image resolution (in dpi)", OFFSET(dpi), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM},
     { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT,   { .i64 = TIFF_PACKBITS }, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" },
     { "packbits",         NULL, 0,             AV_OPT_TYPE_CONST, { .i64 = TIFF_PACKBITS }, 0,        0,            VE, "compression_algo" },
     { "raw",              NULL, 0,             AV_OPT_TYPE_CONST, { .i64 = TIFF_RAW      }, 0,        0,            VE, "compression_algo" },
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 21f5dea..1907aea 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -30,7 +30,7 @@
 
 #define LIBAVCODEC_VERSION_MAJOR 55
 #define LIBAVCODEC_VERSION_MINOR  55
-#define LIBAVCODEC_VERSION_MICRO 107
+#define LIBAVCODEC_VERSION_MICRO 108
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
                                                LIBAVCODEC_VERSION_MINOR, \
diff --git a/tests/ref/lavf/tiff b/tests/ref/lavf/tiff
index 4b0b985..1a806e6 100644
--- a/tests/ref/lavf/tiff
+++ b/tests/ref/lavf/tiff
@@ -1,3 +1,3 @@
-b3299346a8959553a437e486d8f3bf76 *./tests/data/images/tiff/02.tiff
+3e55f370921733949fd72aad1feee574 *./tests/data/images/tiff/02.tiff
 ./tests/data/images/tiff/%02d.tiff CRC=0x6da01946
 307131 ./tests/data/images/tiff/02.tiff


More information about the ffmpeg-devel mailing list