[FFmpeg-devel] Enable 16 bit tiff decoding and encoding

Michael Niedermayer michaelni at gmx.at
Sun Sep 25 17:05:53 CEST 2011


Hi Jean

On Fri, Sep 23, 2011 at 11:00:00PM +0200, Jean First wrote:
> Hi Babtiste,
> 
> On Fri Sep 23 2011 22:21:12 GMT+0200 (CEST), Baptiste Coudurier wrote:
> >Hi Jean,
> >
> >On 09/23/2011 04:37 AM, Jean First wrote:
> >>On Fri Sep 23 2011 10:26:07 GMT+0200 (CEST), Jean First wrote:
> >>>Decoding testet with following compressions for RGB48LE and RGB48BE:
> >>>LZW, RLE, DEFLATE, NONE
> >>>Encoding tested with RGB48LE: PACKBITS, LZW, RAW, DEFLATE
> >>>Encoding to RGB48BE is still not supported
> >>>Jean
> >Thanks a lot for the patch !
> np
> >>Ah sorry, the patch didn't apply. New patch attached.
> >>jean
> >>
> >>0001-Enable-16-bit-encoding-and-decoding-for-tiff-files.patch
> >>
> >>
> >> From b89f691b0eb4f2b24e4b437b71befa534eedc3f6 Mon Sep 17 00:00:00 2001
> >>From: Jean First<jeanfirst at gmail.com>
> >>Date: Fri, 23 Sep 2011 02:04:11 +0200
> >>Subject: [PATCH 1/2] Enable 16-bit encoding and decoding for tiff files.
> >>
> >>---
> >>  libavcodec/tiff.c    |   15 +++++++++++++++
> >>  libavcodec/tiffenc.c |   19 +++++++++++++------
> >>  2 files changed, 28 insertions(+), 6 deletions(-)
> >>
> >>[...]
> >>
> >>diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
> >>index eaa777a..760ae36 100644
> >>--- a/libavcodec/tiffenc.c
> >>+++ b/libavcodec/tiffenc.c
> >>@@ -44,6 +44,7 @@ static const uint8_t type_sizes2[6] = {
> >>  };
> >>
> >>  typedef struct TiffEncoderContext {
> >>+    AVClass *avclass;
> >>      AVCodecContext *avctx;
> >>      AVFrame picture;
> >Did you add encoder specific options ? I don't see them.
> >Otherwise you don't need that yet.
> >
> dpi
> >>[...]
> >>
> >>-    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW)
> >>-        //best choose for DEFLATE
> >>          s->rps = s->height;
> >>-    else
> >>-        s->rps = FFMAX(8192 / (((s->width * s->bpp)>>  3) + 1), 1);     // suggest size of strip
> >>      s->rps = ((s->rps - 1) / s->subsampling[1] + 1) * s->subsampling[1]; // round rps up
> >Is this change on purpose ? Could you please explain a little more ?
> >
> I discussed it with Justin Ruggles.
> The spec from 1995 suggest: "If the entire image is one strip, the
> application may run out of memory. Recommendation: Set RowsPerStrip
> such that the size of each strip is about 8K bytes."
> but that means for big tiff files the header gets really big mainly
> because of StripByteCounts and StripOffsets each holding the hight
> of the image entries. Btw. this only happend when encoding to
> TIFF_RAW. And setting the bit_buffer_size in the transcoding
> function in ffmpeg.c to 6*width*height + 10000 was somehow too much
> overhead.
> >>      strips = (s->height - 1) / s->rps + 1;
> >>@@ -456,7 +462,8 @@ AVCodec ff_tiff_encoder = {
> >>      .priv_data_size = sizeof(TiffEncoderContext),
> >>      .encode         = encode_frame,
> >>      .pix_fmts =
> >>-        (const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8,
> >>+        (const enum PixelFormat[]) {PIX_FMT_RGB48LE, PIX_FMT_RGB24,
> >>+                              PIX_FMT_PAL8, PIX_FMT_GRAY8,
> >>                                PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE,
> >>                                PIX_FMT_YUV420P, PIX_FMT_YUV422P,
> >>                                PIX_FMT_YUV444P, PIX_FMT_YUV410P,
> >You should add the new PIX_FMT at the end of the list, the first entry
> >in that list is usually automatically picked up by applications (ffmpeg)
> >if the decoding pixel format is not in the list.
> >
> >[...]
> >
> ok new patch attached
> Jean

>  tiff.c    |   14 ++++++++++++++
>  tiffenc.c |   20 +++++++++++++-------
>  2 files changed, 27 insertions(+), 7 deletions(-)
> 619467c4d3ee583c2e270e8b983e1ab7939c37c2  0001-Enable-16-bit-encoding-and-decoding-for-tiff-files.patch
> From 8ecf3c3e15929b64efed883c1c2a5bdb8620de3b Mon Sep 17 00:00:00 2001
> From: Jean First <jeanfirst at gmail.com>
> Date: Fri, 23 Sep 2011 22:55:19 +0200
> Subject: [PATCH] Enable 16-bit encoding and decoding for tiff files

I applied the rest of the 2 patches except the strip size change
Do you know if other applications follow this 8k recommandition?

thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
then the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20110925/fa80e0f5/attachment.asc>


More information about the ffmpeg-devel mailing list