[Mplayer-cvslog] CVS: main mpng.c,1.1,1.2

Alex Beregszaszi alex at mplayer.dev.hu
Tue Feb 12 18:04:16 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv15719

Modified Files:
	mpng.c 
Log Message:
32bpp support, allocating palette based on used colors by file (possible overflow fix)

Index: mpng.c
===================================================================
RCS file: /cvsroot/mplayer/main/mpng.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- mpng.c	11 Feb 2002 09:15:59 -0000	1.1
+++ mpng.c	12 Feb 2002 17:04:13 -0000	1.2
@@ -1,9 +1,9 @@
-
 #include <stdlib.h>
 
 #include "config.h"
 #include "bswap.h"
 #include "postproc/rgb2rgb.h"
+#include "libvo/fastmemcpy.h"
 #include "mp_msg.h"
 #include "png.h"
 
@@ -33,6 +33,15 @@
  char	       * palette = NULL;
  int             depth,color;
  png_uint_32     i;
+
+ /* currently supporting only 24 and 32bpp */
+ if ((bytes_per_pixel != 3) && (bytes_per_pixel != 4))
+ {
+    /* is this memset really needed? */
+    memset(decoded, 0, width*height*bytes_per_pixel);
+    return;
+ }
+
  png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
  info=png_create_info_struct( png );
  endinfo=png_create_info_struct( png );
@@ -70,9 +79,13 @@
           free( data );
 	  break;
    case PNG_COLOR_TYPE_GRAY:
+	  /* constant 256 colors */
           palette=malloc( 1024 );
           for ( i=0;i < 256;i++ ) palette[(i*4)]=palette[(i*4)+1]=palette[(i*4)+2]=(char)i;
-	  palette8torgb24( data,decoded,png_width * png_height,palette );
+	  if (bytes_per_pixel == 4)
+	    palette8torgb32( data,decoded,png_width * png_height,palette );
+	  else
+	    palette8torgb24( data,decoded,png_width * png_height,palette );
           free( data );
 	  break;
    case PNG_COLOR_TYPE_PALETTE:
@@ -80,7 +93,8 @@
            int    cols;
 	   unsigned char * pal;
            png_get_PLTE( png,info,(png_colorp*)&pal,&cols ); 
-           palette=calloc( 1,1024 );
+           palette=calloc( 1,cols*4 );
+	   mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "[mPNG] palette. used colors: %d\n", cols);
 	   for ( i=0;i < cols;i++ )
 	    {
 	     palette[(i*4)  ]=pal[(i*3)+2];
@@ -88,11 +102,17 @@
 	     palette[(i*4)+2]=pal[(i*3)  ];
 	    }
 	  }
-	  palette8torgb24( data,decoded,png_width * png_height,palette );
+	  if (bytes_per_pixel == 4)
+	    palette8torgb32( data,decoded,png_width * png_height,palette );
+	  else
+	    palette8torgb24( data,decoded,png_width * png_height,palette );
           free( data );
 	  break;
    case PNG_COLOR_TYPE_RGB_ALPHA:
-          rgb32to24( data,decoded,png_width * png_height * 4 );
+	  if (bytes_per_pixel == 4)
+	    memcpy(decoded, data, png_width * png_height * 4);
+	  else
+            rgb32to24( data,decoded,png_width * png_height * 4 );
           free( data );
 	  break;
   }




More information about the MPlayer-cvslog mailing list