[MPlayer-dev-eng] [PATCH] mf png fix

Joey Parrish joey at nicewarrior.org
Sat Mar 22 22:13:09 CET 2003


On Sat, Mar 22, 2003 at 03:10:12PM -0600, Joey Parrish wrote:
> Okay, I'm going to go through each part of this patch to explain.
Arg!  I spent so long explaining I forgot to attach the whole patch.  :)
Here it is.

--Joey
-------------- next part --------------
Index: etc/codecs.conf
===================================================================
RCS file: /cvsroot/mplayer/main/etc/codecs.conf,v
retrieving revision 1.268
diff -u -r1.268 codecs.conf
--- etc/codecs.conf	5 Mar 2003 10:38:53 -0000	1.268
+++ etc/codecs.conf	18 Mar 2003 22:10:22 -0000
@@ -58,7 +58,7 @@
   fourcc mpng,MPNG
   dll "libpng"
   driver mpng
-  out BGR32,BGR24
+  out BGR24
 
 videocodec mtga
   info "TGA images decoder"
Index: libmpcodecs/vd_mpng.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vd_mpng.c,v
retrieving revision 1.5
diff -u -r1.5 vd_mpng.c
--- libmpcodecs/vd_mpng.c	22 Dec 2002 16:31:04 -0000	1.5
+++ libmpcodecs/vd_mpng.c	18 Mar 2003 22:10:23 -0000
@@ -24,11 +24,8 @@
 
 LIBVD_EXTERN(mpng)
 
-static unsigned int out_fmt=0;
-
 static int last_w=-1;
 static int last_h=-1;
-static int last_c=-1;
 
 // to set/get/query special features/parameters
 static int control(sh_video_t *sh,int cmd,void* arg,...){
@@ -45,8 +42,6 @@
 static void uninit(sh_video_t *sh){
 }
 
-//mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
-
 static int    pngPointer;
 static int    pngLength;
 
@@ -63,7 +58,6 @@
     png_structp     png;
     png_infop       info;
     png_infop       endinfo;
-//    png_bytep       data;
     png_bytep     * row_p;
     png_uint_32     png_width=0,png_height=0;
     int             depth,color;
@@ -82,56 +76,36 @@
  png_set_sig_bytes( png,8 );
  png_read_info( png,info );
  png_get_IHDR( png,info,&png_width,&png_height,&depth,&color,NULL,NULL,NULL );
-
 png_set_bgr( png );
+ png_set_bgr( png );
 
- switch( info->color_type ) {
-   case PNG_COLOR_TYPE_GRAY_ALPHA:
-      mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
-      break;
-   case PNG_COLOR_TYPE_GRAY:
-   case PNG_COLOR_TYPE_PALETTE:
-      out_fmt=IMGFMT_BGR8;
-      break;
-   case PNG_COLOR_TYPE_RGB_ALPHA:
-      out_fmt=IMGFMT_BGR32;
-      break;
-   case PNG_COLOR_TYPE_RGB:
-      out_fmt=IMGFMT_BGR24;
-      break;
-   default:
-      mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry, unsupported PNG colorspace: %d.\n" ,info->color_type);
+ if ( info->color_type == PNG_COLOR_TYPE_PALETTE) {
+	 png_set_expand(png);
+	 png_read_update_info(png, info);
+ }
+ if ( info->color_type & PNG_COLOR_MASK_ALPHA) {
+	 png_set_strip_alpha(png);
+	 png_read_update_info(png, info);
+ }
+ if ( info->color_type == PNG_COLOR_TYPE_GRAY) {
+	 png_set_expand(png);
+	 png_read_update_info(png, info);
  }
 
  // (re)init libvo if image parameters changed (width/height/colorspace)
- if(last_w!=png_width || last_h!=png_height || last_c!=out_fmt){
-    last_w=png_width; last_h=png_height; last_c=out_fmt;
-    if(!out_fmt) return NULL;
-    if(!mpcodecs_config_vo(sh,png_width,png_height,out_fmt)) return NULL;
+ if(last_w!=png_width || last_h!=png_height){
+    last_w = png_width; last_h = png_height;
+    if(!mpcodecs_config_vo(sh,png_width,png_height,IMGFMT_BGR24)) return NULL;
  }
 
-#if 0
- switch( info->color_type )
-  {
-   case PNG_COLOR_TYPE_GRAY_ALPHA: printf( "[png] used GrayA -> stripping alpha channel\n" ); break;
-   case PNG_COLOR_TYPE_GRAY:       printf( "[png] used Gray -> rgb\n" ); break;
-   case PNG_COLOR_TYPE_PALETTE:    printf( "[png] used palette -> rgb\n" ); break;
-   case PNG_COLOR_TYPE_RGB_ALPHA:  printf( "[png] used RGBA -> stripping alpha channel\n" ); break;
-   case PNG_COLOR_TYPE_RGB:        printf( "[png] read rgb datas.\n" ); break;
-  }
-#endif
-
     mpi=mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, 
 	png_width,png_height);
     if(!mpi) return NULL;
 
 // Let's DECODE!
  row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height );
-//png_get_rowbytes( png,info ) 
  for ( i=0; i < png_height; i++ ) row_p[i]=mpi->planes[0] + mpi->stride[0]*i;
  png_read_image( png,row_p );
  free( row_p );
- 
- //png_get_PLTE( png,info,(png_colorp*)&pal,&cols );
  
  png_read_end( png,endinfo );
  png_destroy_read_struct( &png,&info,&endinfo );


More information about the MPlayer-dev-eng mailing list