[MPlayer-dev-eng] PATCH - PNG transparency in vo_png.c

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Thu Nov 13 20:20:21 CET 2008


On Thu, Nov 13, 2008 at 08:08:30PM +0100, Reimar Döffinger wrote:
> On Thu, Nov 13, 2008 at 11:47:46AM -0500, it at tidetamerboatlifts.com wrote:
> > @@ -193,6 +193,7 @@
> >      switch(format){
> >      case IMGFMT_RGB|24:
> >      case IMGFMT_BGR|24:
> > +    case IMGFMT_RGBA|32:
> >          return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
> 
> And this should be just IMGFMT_RGBA (without |32). Ideally someone
> should check on little- and big-endian that is is the right one and not
> e.g. IMGFMT_RGB32.

Testing is still very welcome, but please try the attached patch
instead.
Most people probably will not want that useless alpha-channel (for most
sources it is useless) in their png files, so this is optional, you will
have to use -vo png:alpha
-------------- next part --------------
Index: libvo/vo_png.c
===================================================================
--- libvo/vo_png.c	(revision 27907)
+++ libvo/vo_png.c	(working copy)
@@ -41,6 +41,7 @@
 static int z_compression = Z_NO_COMPRESSION;
 static char *png_outdir = NULL;
 static int framenum = 0;
+static int use_alpha;
 
 struct pngdata {
 	FILE * fp;
@@ -167,7 +168,7 @@
        bit_depth, color_type, interlace_type,
        compression_type, filter_type)*/
     png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height,
-       8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
+       8, use_alpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
        PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
     
     mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n");
@@ -246,10 +247,14 @@
 static int
 query_format(uint32_t format)
 {
+    const int supported_flags = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
     switch(format){
     case IMGFMT_RGB24:
     case IMGFMT_BGR24:
-        return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
+        return use_alpha ? 0 : supported_flags;
+    case IMGFMT_RGBA:
+    case IMGFMT_BGRA:
+        return use_alpha ? supported_flags : 0;
     }
     return 0;
 }
@@ -271,6 +276,7 @@
 }
 
 static opt_t subopts[] = {
+    {"alpha", OPT_ARG_BOOL, &use_alpha, NULL, 0},
     {"z",   OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine},
     {"outdir",      OPT_ARG_MSTRZ,  &png_outdir,           NULL, 0},
     {NULL}
@@ -280,6 +286,7 @@
 {
     z_compression = 0;
     png_outdir = strdup(".");
+    use_alpha = 0;
     if (subopt_parse(arg, subopts) != 0) {
         return -1;
     }


More information about the MPlayer-dev-eng mailing list