changeset 15502:ef7349907cf4

8bit palette mode support (and spurious ^M removal)
author henry
date Wed, 18 May 2005 10:44:45 +0000
parents 7cdc07507650
children 4b25392ecfa0
files libmpcodecs/vd_mpng.c
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/vd_mpng.c	Tue May 17 21:49:48 2005 +0000
+++ b/libmpcodecs/vd_mpng.c	Wed May 18 10:44:45 2005 +0000
@@ -76,6 +76,10 @@
     png_uint_32     i;
     mp_image_t* mpi;
 
+    int cols;
+    png_colorp pal;
+    unsigned char *p;
+
     if(len<=0) return NULL; // skipped frame
     
  png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
@@ -88,7 +92,6 @@
  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 );
 
  switch( info->color_type ) {
@@ -96,6 +99,8 @@
       mp_msg( MSGT_DECVIDEO,MSGL_INFO,"Sorry gray scaled png with alpha channel not supported at moment.\n" );
       break;
    case PNG_COLOR_TYPE_GRAY:
+      out_fmt=IMGFMT_Y800;
+      break;
    case PNG_COLOR_TYPE_PALETTE:
       out_fmt=IMGFMT_BGR8;
       break;
@@ -137,8 +142,18 @@
  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 );
+
+ if (out_fmt==IMGFMT_BGR8) {
+     png_get_PLTE( png,info,&pal,&cols );
+     mpi->planes[1] = (char*)realloc(mpi->planes[1], 4*cols);
+     p = mpi->planes[1];
+     for (i = 0; i < cols; i++) {
+	 *p++ = pal[i].blue;
+	 *p++ = pal[i].green;
+	 *p++ = pal[i].red;
+	 *p++ = 0;
+     }
+ }
  
  png_read_end( png,endinfo );
  png_destroy_read_struct( &png,&info,&endinfo );