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

Clément Bœsch u at pkh.me
Sat Apr 5 14:39:18 CEST 2014


On Sat, Apr 05, 2014 at 02:37:08PM +0200, Carl Eugen Hoyos wrote:
> On Thursday 03 April 2014 05:29:09 am Michael Niedermayer wrote:
> > > -    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 };
> >
> > i think this is wrong
> > shouldnt the dpi be adjusted when the aspect differs from 1:1
> 
> New patch attached which is supported by more image viewers 
> on my system.
> It's now: Consider aspect ratio when writing tiff dpi.
> 
> Please comment, Carl Eugen

> diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
> index 7b1e510..01e6168 100644
> --- a/libavcodec/tiffenc.c
> +++ b/libavcodec/tiffenc.c
> @@ -436,6 +436,13 @@ 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);
> +    if (avctx->sample_aspect_ratio.num > 0 &&
> +        avctx->sample_aspect_ratio.den > 0) {
> +        AVRational y = av_mul_q((AVRational) { s->dpi, 1 },
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^
                                    av_make_q()

> +                                avctx->sample_aspect_ratio);
> +        res[0] = y.num;
> +        res[1] = y.den;
> +    }
>      add_entry(s,  TIFF_YRES,         TIFF_RATIONAL, 1,      res);
>      add_entry1(s, TIFF_RES_UNIT,     TIFF_SHORT,    2);
>  
[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140405/26bc0f61/attachment.asc>


More information about the ffmpeg-devel mailing list