[FFmpeg-devel] [PATCH] allow setting png compression level

Reimar Döffinger Reimar.Doeffinger
Tue Oct 9 16:04:47 CEST 2007


Hello,
On Tue, Oct 09, 2007 at 03:33:09PM +0200, Michael Niedermayer wrote:
> > Index: libavcodec/pngenc.c
> > ===================================================================
> > --- libavcodec/pngenc.c	(revision 10668)
> > +++ libavcodec/pngenc.c	(working copy)
> > @@ -187,7 +187,8 @@
> >      s->zstream.zalloc = ff_png_zalloc;
> >      s->zstream.zfree = ff_png_zfree;
> >      s->zstream.opaque = NULL;
> > -    ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
> > +    avctx->compression_level = av_clip(avctx->compression_level, 0, 9);
> > +    ret = deflateInit2(&s->zstream, avctx->compression_level,
> >                         Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
> >      if (ret != Z_OK)
> >          return -1;
> > @@ -314,6 +315,7 @@
> >  
> >      avcodec_get_frame_defaults((AVFrame*)&s->picture);
> >      avctx->coded_frame= (AVFrame*)&s->picture;
> > +    avctx->compression_level= Z_DEFAULT_COMPRESSION;
> >  
> >      return 0;
> >  }
> 
>     /**
>      * - encoding: Set by user.
>                    ^^^^^^^^^^^^
>      * - decoding: unused
>      */
>     int compression_level;
> #define FF_COMPRESSION_DEFAULT -1
> 
> an encoder has no business setting compression_level to some custom
> default

Hm. I'd interpret that under"lined" part as it has no business setting
it at all, so it should be done as attached?

Greetings,
Reimar D?ffinger
-------------- next part --------------
Index: libavcodec/pngenc.c
===================================================================
--- libavcodec/pngenc.c	(revision 10695)
+++ libavcodec/pngenc.c	(working copy)
@@ -144,6 +144,7 @@
     AVFrame * const p= (AVFrame*)&s->picture;
     int bit_depth, color_type, y, len, row_size, ret, is_progressive;
     int bits_per_pixel, pass_row_size;
+    int compression_level;
     uint8_t *ptr;
     uint8_t *crow_buf = NULL;
     uint8_t *tmp_buf = NULL;
@@ -187,7 +188,10 @@
     s->zstream.zalloc = ff_png_zalloc;
     s->zstream.zfree = ff_png_zfree;
     s->zstream.opaque = NULL;
-    ret = deflateInit2(&s->zstream, Z_DEFAULT_COMPRESSION,
+    compression_level = avctx->compression_level == FF_COMPRESSION_DEFAULT ?
+                            Z_DEFAULT_COMPRESSION :
+                            av_clip(avctx->compression_level, 0, 9);
+    ret = deflateInit2(&s->zstream, compression_level,
                        Z_DEFLATED, 15, 8, Z_DEFAULT_STRATEGY);
     if (ret != Z_OK)
         return -1;



More information about the ffmpeg-devel mailing list