[FFmpeg-cvslog] Read aspect ratio from tiff image files.

Carl Eugen Hoyos git at videolan.org
Mon Apr 7 19:06:47 CEST 2014


ffmpeg | branch: master | Carl Eugen Hoyos <cehoyos at ag.or.at> | Mon Apr  7 10:39:55 2014 +0200| [993a5afaada4596f6b387d0a2a7cf7ca8170f56d] | committer: Carl Eugen Hoyos

Read aspect ratio from tiff image files.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=993a5afaada4596f6b387d0a2a7cf7ca8170f56d
---

 libavcodec/tiff.c              |   21 ++++++++++++++++++++-
 tests/ref/fate/exif-image-tiff |    2 +-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
index cbc526a..e0629db 100644
--- a/libavcodec/tiff.c
+++ b/libavcodec/tiff.c
@@ -58,6 +58,7 @@ typedef struct TiffContext {
     int fax_opts;
     int predictor;
     int fill_order;
+    uint32_t res[4];
 
     int strips, rps, sstype;
     int sot;
@@ -566,9 +567,19 @@ static int init_image(TiffContext *s, ThreadFrame *frame)
     return 0;
 }
 
+static void set_sar(TiffContext *s, unsigned tag, unsigned num, unsigned den)
+{
+    int offset = tag == TIFF_YRES ? 2 : 0;
+    s->res[offset++] = num;
+    s->res[offset]   = den;
+    if (s->res[0] && s->res[1] && s->res[2] && s->res[3])
+        av_reduce(&s->avctx->sample_aspect_ratio.num, &s->avctx->sample_aspect_ratio.den,
+                  s->res[2] * (uint64_t)s->res[1], s->res[0] * (uint64_t)s->res[3], INT32_MAX);
+}
+
 static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
 {
-    unsigned tag, type, count, off, value = 0;
+    unsigned tag, type, count, off, value = 0, value2 = 0;
     int i, j, k, pos, start;
     int ret;
     uint32_t *pal;
@@ -587,6 +598,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
         case TIFF_LONG:
             value = ff_tget(&s->gb, type, s->le);
             break;
+        case TIFF_RATIONAL:
+            value  = ff_tget(&s->gb, TIFF_LONG, s->le);
+            value2 = ff_tget(&s->gb, TIFF_LONG, s->le);
+            break;
         case TIFF_STRING:
             if (count <= 4) {
                 break;
@@ -717,6 +732,10 @@ static int tiff_decode_tag(TiffContext *s, AVFrame *frame)
             return AVERROR_INVALIDDATA;
         }
         break;
+    case TIFF_XRES:
+    case TIFF_YRES:
+        set_sar(s, tag, value, value2);
+        break;
     case TIFF_TILE_BYTE_COUNTS:
     case TIFF_TILE_LENGTH:
     case TIFF_TILE_OFFSETS:
diff --git a/tests/ref/fate/exif-image-tiff b/tests/ref/fate/exif-image-tiff
index 6ccc48e..515e3f1 100644
--- a/tests/ref/fate/exif-image-tiff
+++ b/tests/ref/fate/exif-image-tiff
@@ -14,7 +14,7 @@ pkt_size=67604
 width=200
 height=112
 pix_fmt=rgb24
-sample_aspect_ratio=N/A
+sample_aspect_ratio=1:1
 pict_type=?
 coded_picture_number=0
 display_picture_number=0



More information about the ffmpeg-cvslog mailing list