add initial mPNG support

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4657 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
pontscho 2002-02-11 09:15:59 +00:00
parent 8db2a741bb
commit 97654ce7f3
8 changed files with 152 additions and 4 deletions

View File

@ -34,6 +34,10 @@ SRCS_MPLAYER = mplayer.c $(SRCS_COMMON) find_sub.c subreader.c lirc_mp.c mixer.c
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

View File

@ -246,6 +246,7 @@ static short get_driver(char *s,int audioflag)
"ducktm1",
"roqvideo",
"qtrpza",
"mpng",
NULL
};
char **drv=audioflag?audiodrv:videodrv;

View File

@ -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

4
configure vendored
View File

@ -1935,8 +1935,10 @@ if test "$_png" = yes ; then
_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 @@ OPENDIVX = $_opendivx
VO2 = $_vo2
PNG = $_mkf_png
EXTRA_LIB = $_ld_extra
Z_LIB = $_ld_static $_ld_zlib
HAVE_MLIB = $_mlib

View File

@ -180,6 +180,16 @@ void decode_duck_tm1(
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 @@ switch(sh_video->codec->driver){
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 @@ if(verbose>1){
((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));

View File

@ -347,6 +347,13 @@ videocodec ducktm1
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

View File

@ -76,7 +76,7 @@ demuxer_t* demux_open_mf(demuxer_t* demuxer){
// 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 @@ demuxer_t* demux_open_mf(demuxer_t* demuxer){
// 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;

106
mpng.c Normal file
View File

@ -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 );
}