changeset 4656:04880518728d

add initial mPNG support
author pontscho
date Mon, 11 Feb 2002 09:15:59 +0000
parents 364cf7cc77be
children 610a11e4db36
files Makefile codec-cfg.c codec-cfg.h configure dec_video.c etc/codecs.conf libmpdemux/demux_mf.c mpng.c
diffstat 8 files changed, 152 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Feb 11 07:30:05 2002 +0000
+++ b/Makefile	Mon Feb 11 09:15:59 2002 +0000
@@ -34,6 +34,10 @@
 OBJS_MENCODER = $(SRCS_MENCODER:.c=.o)
 OBJS_MPLAYER = $(SRCS_MPLAYER:.c=.o)
 
+ifeq ($(PNG),yes)
+SRCS_COMMON += mpng.c
+endif
+
 ifeq ($(VO2),yes)
 VO_LIBS = -Llibvo2 -lvo2
 VO_INC = -Ilibvo2
--- a/codec-cfg.c	Mon Feb 11 07:30:05 2002 +0000
+++ b/codec-cfg.c	Mon Feb 11 09:15:59 2002 +0000
@@ -246,6 +246,7 @@
 		"ducktm1",
 		"roqvideo",
 		"qtrpza",
+		"mpng",
 		NULL
 	};
         char **drv=audioflag?audiodrv:videodrv;
--- a/codec-cfg.h	Mon Feb 11 07:30:05 2002 +0000
+++ b/codec-cfg.h	Mon Feb 11 09:15:59 2002 +0000
@@ -58,6 +58,7 @@
 #define VFM_DUCKTM1 18
 #define VFM_ROQVIDEO 19
 #define VFM_QTRPZA 20
+#define VFM_MPNG 21
 
 #ifndef GUID_TYPE
 #define GUID_TYPE
--- a/configure	Mon Feb 11 07:30:05 2002 +0000
+++ b/configure	Mon Feb 11 09:15:59 2002 +0000
@@ -1935,8 +1935,10 @@
   _ld_png='-lpng -lz'
   _vosrc="$_vosrc vo_png.c"
   _vomodules="png $_vomodules"
+  _mkf_png="yes"
 else
   _def_png='#undef HAVE_PNG'
+  _mkf_png="no"
 fi
 
 
@@ -2948,6 +2950,8 @@
 
 VO2 = $_vo2
 
+PNG = $_mkf_png
+
 EXTRA_LIB = $_ld_extra
 Z_LIB =  $_ld_static $_ld_zlib
 HAVE_MLIB = $_mlib
--- a/dec_video.c	Mon Feb 11 07:30:05 2002 +0000
+++ b/dec_video.c	Mon Feb 11 09:15:59 2002 +0000
@@ -180,6 +180,16 @@
   int height,
   int bytes_per_pixel);
 
+#ifdef HAVE_PNG
+void decode_mpng(
+  unsigned char *encoded,
+  int encoded_size,
+  unsigned char *decoded,
+  int width,
+  int height,
+  int bytes_per_pixel);
+#endif
+
 void qt_decode_rpza(
   unsigned char *encoded,
   int encoded_size,
@@ -706,6 +716,9 @@
  case VFM_FLI:
  case VFM_QTRLE:
  case VFM_DUCKTM1:
+#ifdef HAVE_PNG
+ case VFM_MPNG:
+#endif
  case VFM_QTRPZA:
    {
 #ifdef USE_MP_IMAGE
@@ -1139,6 +1152,16 @@
         ((out_fmt&255)+7)/8);
     blit_frame = 3;
     break;
+#ifdef HAVE_PNG
+ case VFM_MPNG:
+    decode_mpng(
+        start, in_size, sh_video->our_out_buffer,
+	sh_video->disp_w,sh_video->disp_h,
+	24
+    );
+    blit_frame = 3;
+    break;
+#endif
  case VFM_CYUV:
    decode_cyuv(start, in_size, sh_video->our_out_buffer,
       sh_video->disp_w, sh_video->disp_h, (out_fmt==IMGFMT_YUY2)?16:(out_fmt&255));
--- a/etc/codecs.conf	Mon Feb 11 07:30:05 2002 +0000
+++ b/etc/codecs.conf	Mon Feb 11 09:15:59 2002 +0000
@@ -347,6 +347,13 @@
   driver ducktm1
   out BGR32,BGR24,BGR16,BGR15
 
+videocodec mpng
+  info "mPNG codec"
+  status buggy
+  fourcc mpng,MPNG
+  driver mpng
+  out BGR24
+
 videocodec roqvideo
   info "Id RoQ File Video Decoder"
   status buggy
--- a/libmpdemux/demux_mf.c	Mon Feb 11 07:30:05 2002 +0000
+++ b/libmpdemux/demux_mf.c	Mon Feb 11 09:15:59 2002 +0000
@@ -76,7 +76,7 @@
 
   // go back to the beginning
   stream_reset(demuxer->stream);
-  stream_seek(demuxer->stream, 0);
+//  stream_seek(demuxer->stream, 0);
   demuxer->movi_start = 0;
   demuxer->movi_end = mf->nr_of_files - 1;
   dmf->nr_of_frames= mf->nr_of_files;
@@ -93,9 +93,11 @@
   // video_read_properties() will choke
   sh_video->ds = demuxer->video;
 
-  if ( !strcasecmp( mf_type,"jpg" ) ||
-	!(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('M', 'J', 'P', 'G');
-   else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( dmf ); return NULL; }
+  if ( !strcasecmp( mf_type,"jpg" ) || 
+        !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('M', 'J', 'P', 'G');
+   else 
+     if ( !strcasecmp( mf_type,"png" )) sh_video->format = mmioFOURCC('M', 'P', 'N', 'G' );
+       else { mp_msg(MSGT_DEMUX, MSGL_INFO, "[demux_mf] unknow input file type.\n" ); free( dmf ); return NULL; }
 
   sh_video->disp_w = mf_w;
   sh_video->disp_h = mf_h;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpng.c	Mon Feb 11 09:15:59 2002 +0000
@@ -0,0 +1,106 @@
+
+#include <stdlib.h>
+
+#include "config.h"
+#include "bswap.h"
+#include "postproc/rgb2rgb.h"
+#include "mp_msg.h"
+#include "png.h"
+
+int    pngPointer;
+
+void pngReadFN( png_structp pngstr,png_bytep buffer,png_size_t size )
+{
+ char * p = pngstr->io_ptr;
+ memcpy( buffer,(char *)&p[pngPointer],size );
+ pngPointer+=size;
+}
+
+void decode_mpng(
+  unsigned char *encoded,
+  int encoded_size,
+  unsigned char *decoded,
+  int width,
+  int height,
+  int bytes_per_pixel)
+{
+ png_structp     png;
+ png_infop       info;
+ png_infop       endinfo;
+ png_bytep       data;
+ png_bytep     * row_p;
+ png_uint_32     png_width,png_height;
+ char	       * palette = NULL;
+ int             depth,color;
+ png_uint_32     i;
+ png=png_create_read_struct( PNG_LIBPNG_VER_STRING,NULL,NULL,NULL );
+ info=png_create_info_struct( png );
+ endinfo=png_create_info_struct( png );
+
+ pngPointer=8;
+ png_set_read_fn( png,encoded,pngReadFN );
+ 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 );
+
+#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
+
+ if ( info->color_type == PNG_COLOR_TYPE_RGB ) data=decoded;
+  else data=(png_bytep)malloc( png_get_rowbytes( png,info ) * height );
+
+ row_p=(png_bytep*)malloc( sizeof( png_bytep ) * png_height );
+ for ( i=0; i < png_height; i++ ) row_p[i]=&data[png_get_rowbytes( png,info ) * i];
+ png_read_image( png,row_p );
+ free( row_p );
+						     
+ 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" );
+          free( data );
+	  break;
+   case PNG_COLOR_TYPE_GRAY:
+          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 );
+          free( data );
+	  break;
+   case PNG_COLOR_TYPE_PALETTE:
+          { 
+           int    cols;
+	   unsigned char * pal;
+           png_get_PLTE( png,info,(png_colorp*)&pal,&cols ); 
+           palette=calloc( 1,1024 );
+	   for ( i=0;i < cols;i++ )
+	    {
+	     palette[(i*4)  ]=pal[(i*3)+2];
+	     palette[(i*4)+1]=pal[(i*3)+1];
+	     palette[(i*4)+2]=pal[(i*3)  ];
+	    }
+	  }
+	  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 );
+          free( data );
+	  break;
+  }
+
+ if ( palette ) free( palette );
+
+ png_read_end( png,endinfo );
+ png_destroy_read_struct( &png,&info,&endinfo );
+}
+