# HG changeset patch # User pontscho # Date 1015800558 0 # Node ID ef8a43b7407517816a7a5dc8ff4182f016a9d50d # Parent ddc28e9aa72607eaade1522f43b5eb76411efcfb Add IJPG decoder. diff -r ddc28e9aa726 -r ef8a43b74075 Makefile --- a/Makefile Sun Mar 10 17:51:52 2002 +0000 +++ b/Makefile Sun Mar 10 22:49:18 2002 +0000 @@ -55,7 +55,7 @@ VO_LIBS = -Llibvo -lvo VO_INC = -Ilibvo endif -V_LIBS = $(X_LIB) $(MP1E_LIB) $(GGI_LIB) $(MLIB_LIB) $(PNG_LIB) $(SDL_LIB) $(SVGA_LIB) $(AA_LIB) $(DIRECTFB_LIB) +V_LIBS = $(X_LIB) $(MP1E_LIB) $(GGI_LIB) $(MLIB_LIB) $(JPEG_LIB) $(PNG_LIB) $(SDL_LIB) $(SVGA_LIB) $(AA_LIB) $(DIRECTFB_LIB) AO_LIBS = -Llibao2 -lao2 A_LIBS = $(ALSA_LIB) $(NAS_LIB) $(MAD_LIB) $(VORBIS_LIB) $(SGIAUDIO_LIB) diff -r ddc28e9aa726 -r ef8a43b74075 codec-cfg.c --- a/codec-cfg.c Sun Mar 10 17:51:52 2002 +0000 +++ b/codec-cfg.c Sun Mar 10 22:49:18 2002 +0000 @@ -252,6 +252,7 @@ "roqvideo", "qtrpza", "mpng", + "ijpg", NULL }; char **drv=audioflag?audiodrv:videodrv; diff -r ddc28e9aa726 -r ef8a43b74075 codec-cfg.h --- a/codec-cfg.h Sun Mar 10 17:51:52 2002 +0000 +++ b/codec-cfg.h Sun Mar 10 22:49:18 2002 +0000 @@ -60,6 +60,7 @@ #define VFM_ROQVIDEO 19 #define VFM_QTRPZA 20 #define VFM_MPNG 21 +#define VFM_IJPG 22 #ifndef GUID_TYPE #define GUID_TYPE diff -r ddc28e9aa726 -r ef8a43b74075 configure --- a/configure Sun Mar 10 17:51:52 2002 +0000 +++ b/configure Sun Mar 10 22:49:18 2002 +0000 @@ -120,6 +120,8 @@ --enable-termcap use termcap database for key codes [autodetect] --enable-lirc enable LIRC (remote control) support [autodetect] --enable-gui enable GUI [disable] + --enable-png enable png support [autodetect] + --enable-jpeg enable jpeg support [autodetect] --disable-tv disable TV Interface (tv/dvb grabbers) [enable] --disable-tv-v4l disable Video 4 Linux TV Interface support [autodetect] --disable-win32 disable Win32 DLL support [autodetect] @@ -737,6 +739,7 @@ _sdl=auto _nas=auto _png=auto +_jpg=auto _gl=auto _ggi=auto _aa=auto @@ -816,6 +819,8 @@ --disable-nas) _nas=no ;; --enable-png) _png=yes ;; --disable-png) _png=no ;; + --enable-jpeg) _jpg=yes ;; + --disable-jpeg) _jpg=no ;; --enable-gl) _gl=yes ;; --disable-gl) _gl=no ;; --enable-ggi) _ggi=yes ;; @@ -1978,6 +1983,39 @@ _mkf_png="no" fi +echocheck "JPEG support" +if test "$_jpg" = auto ; then + _jpg=no +cat > $TMPC << EOF +#include +#include +#include +#include +#include +int main(void) { + return 0; +} +EOF + if cc_check -ljpeg -lm ; then + if "$TMPO" >> "$TMPLOG" ; then + _jpg=yes + echores yes + fi + else + echores no + fi +else + echores "$_jpg" +fi +if test "$_jpg" = yes ; then + _def_jpg='#define HAVE_JPEG 1' + _ld_jpg='-ljpeg' + _mkf_jpg="yes" +else + _def_jpg='#undef HAVE_JPEG' + _mkf_jpg="no" +fi + if test "$_vesa" != no ; then echocheck "VESA support" @@ -3061,6 +3099,7 @@ VO2 = $_vo2 PNG = $_mkf_png +JPEG = $_mkf_jpg EXTRA_LIB = $_ld_extra Z_LIB = $_ld_static $_ld_zlib @@ -3076,6 +3115,7 @@ MLIB_LIB = $_ld_mlib MLIB_INC = $_inc_mlib PNG_LIB = $_ld_png +JPEG_LIB = $_ld_jpg SDL_LIB = $_ld_sdl SVGA_LIB = $_ld_svga AA_LIB = $_ld_aa @@ -3359,6 +3399,9 @@ /* enable PNG support */ $_def_png +/* enable JPEG support */ +$_def_jpg + /* libmad support */ $_def_mad diff -r ddc28e9aa726 -r ef8a43b74075 etc/codecs.conf --- a/etc/codecs.conf Sun Mar 10 17:51:52 2002 +0000 +++ b/etc/codecs.conf Sun Mar 10 22:49:18 2002 +0000 @@ -361,6 +361,14 @@ driver mpng out BGR32,BGR24 +videocodec ijpg + info "IJPG codec" + status working + comment "Hm." + fourcc ijpg,IJPG + driver ijpg + out BGR24,BGR8 + videocodec roqvideo info "Id RoQ File Video Decoder" status buggy diff -r ddc28e9aa726 -r ef8a43b74075 libmpcodecs/Makefile --- a/libmpcodecs/Makefile Sun Mar 10 17:51:52 2002 +0000 +++ b/libmpcodecs/Makefile Sun Mar 10 22:49:18 2002 +0000 @@ -3,7 +3,15 @@ LIBNAME = libmpcodecs.a -SRCS=dec_video.c vd.c vd_null.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_rle.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_mpng.c vd_libmpeg2.c +SRCS=dec_video.c vd.c vd_null.c vd_cinepak.c vd_qtrpza.c vd_ffmpeg.c vd_dshow.c vd_vfw.c vd_odivx.c vd_divx4.c vd_raw.c vd_xanim.c vd_rle.c vd_msvidc.c vd_fli.c vd_qtrle.c vd_qtsmc.c vd_roqvideo.c vd_cyuv.c vd_nuv.c vd_libmpeg2.c + +ifeq ($(PNG),yes) +SRCS += vd_mpng.c +endif + +ifeq ($(JPEG),yes) +SRCS += vd_ijpg.c +endif OBJS=$(SRCS:.c=.o) diff -r ddc28e9aa726 -r ef8a43b74075 libmpcodecs/vd.c --- a/libmpcodecs/vd.c Sun Mar 10 17:51:52 2002 +0000 +++ b/libmpcodecs/vd.c Sun Mar 10 22:49:18 2002 +0000 @@ -41,6 +41,7 @@ extern vd_functions_t mpcodecs_vd_cyuv; extern vd_functions_t mpcodecs_vd_nuv; extern vd_functions_t mpcodecs_vd_mpng; +extern vd_functions_t mpcodecs_vd_ijpg; extern vd_functions_t mpcodecs_vd_libmpeg2; vd_functions_t* mpcodecs_vd_drivers[] = { @@ -78,6 +79,9 @@ #ifdef HAVE_PNG &mpcodecs_vd_mpng, #endif +#ifdef HAVE_JPEG + &mpcodecs_vd_ijpg, +#endif &mpcodecs_vd_libmpeg2, NULL }; diff -r ddc28e9aa726 -r ef8a43b74075 libmpcodecs/vd_ijpg.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libmpcodecs/vd_ijpg.c Sun Mar 10 22:49:18 2002 +0000 @@ -0,0 +1,192 @@ + +#include +#include + +#include "config.h" +#include "mp_msg.h" + +#include +#include +#include +#include +#include + +#include + +#include "bswap.h" +#include "postproc/rgb2rgb.h" +#include "libvo/fastmemcpy.h" + +#include "vd_internal.h" + +static vd_info_t info = { + "JPEG Images decoder", + "ijpg", + VFM_IJPG, + "Pontscho", + "based on vd_mpng.c", + "uses Indipended JPEG Group's jpeglib" +}; + +LIBVD_EXTERN(ijpg) + +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,...){ + return CONTROL_UNKNOWN; +} + +// init driver +static int init(sh_video_t *sh){ + last_w=-1; + return 1; +} + +// uninit driver +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); + +typedef struct +{ + struct jpeg_source_mgr pub; + unsigned char * inbuf; + int bufsize; +} my_source_mgr; + +typedef my_source_mgr * my_src_ptr; + +METHODDEF(void) init_source (j_decompress_ptr cinfo) +{ +} + +METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + size_t nbytes; + src->pub.next_input_byte = src->inbuf; + src->pub.bytes_in_buffer = src->bufsize; + return TRUE; +} + +METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes) +{ + my_src_ptr src = (my_src_ptr) cinfo->src; + + if (num_bytes > 0) + { + while (num_bytes > (long) src->pub.bytes_in_buffer) + { + num_bytes -= (long) src->pub.bytes_in_buffer; + (void) fill_input_buffer(cinfo); + } + src->pub.next_input_byte += (size_t) num_bytes; + src->pub.bytes_in_buffer -= (size_t) num_bytes; + } +} + +METHODDEF(void) term_source (j_decompress_ptr cinfo) { } + +GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize ) +{ + my_src_ptr src; + if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) ); + src = (my_src_ptr) cinfo->src; + src->pub.init_source = init_source; + src->pub.fill_input_buffer = fill_input_buffer; + src->pub.skip_input_data = skip_input_data; + src->pub.resync_to_restart = jpeg_resync_to_restart; + src->pub.term_source = term_source; + src->inbuf = inbuf; + src->bufsize=bufsize; + src->pub.bytes_in_buffer = 0; + src->pub.next_input_byte = NULL; +} + +struct my_error_mgr +{ + struct jpeg_error_mgr pub; + jmp_buf setjmp_buffer; +}; + +typedef struct my_error_mgr * my_error_ptr; + +METHODDEF(void) my_error_exit (j_common_ptr cinfo) +{ + my_error_ptr myerr=(my_error_ptr) cinfo->err; + (*cinfo->err->output_message) (cinfo); + longjmp(myerr->setjmp_buffer, 1); +} + +static struct jpeg_decompress_struct cinfo; +static struct my_error_mgr jerr; +static int row_stride; +static int count; + +// decode a frame +static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ + mp_image_t * mpi = NULL; + int width,height,depth,i,j; + + if ( len <= 0 ) return NULL; // skipped frame + + cinfo.err=jpeg_std_error( &jerr.pub ); + jerr.pub.error_exit=my_error_exit; + if( setjmp( jerr.setjmp_buffer ) ) + { + mp_msg( MSGT_DECVIDEO,MSGL_ERR,"[ijpg] setjmp error ...\n" ); + return NULL; + } + + jpeg_create_decompress( &cinfo ); + jpeg_buf_src( &cinfo,data,len ); + jpeg_read_header( &cinfo,TRUE ); + width=cinfo.image_width; + height=cinfo.image_height; + jpeg_start_decompress( &cinfo ); + depth=cinfo.output_components * 8; + + switch( depth ) { + case 8: out_fmt=IMGFMT_BGR8; break; + case 24: out_fmt=IMGFMT_BGR24; break; + default: mp_msg( MSGT_DECVIDEO,MSGL_ERR,"Sorry, unsupported JPEG colorspace: %d.\n",depth ); return NULL; + } + + if ( last_w!=width || last_h!=height || last_c!=out_fmt ) + { + last_w=width; last_h=height; last_c=out_fmt; + if ( !out_fmt ) return NULL; + mpcodecs_config_vo( sh,width,height,out_fmt ); + } + + mpi=mpcodecs_get_image( sh,MP_IMGTYPE_TEMP,MP_IMGFLAG_ACCEPT_STRIDE,width,height ); + if ( !mpi ) return NULL; + + row_stride=cinfo.output_width * cinfo.output_components; + + for ( i=0;i < height;i++ ) + { + char * row = mpi->planes[0] + mpi->stride[0] * i; + jpeg_read_scanlines( &cinfo,&row,1 ); +#warning workaround for rgb2bgr + if ( depth == 24 ) + for ( j=0;j < width * 3;j+=3 ) + { + char c; + c=row[j]; + row[j]=row[j+2]; + row[j+2]=c; + } + } + + jpeg_finish_decompress(&cinfo); + jpeg_destroy_decompress(&cinfo); + + return mpi; +} diff -r ddc28e9aa726 -r ef8a43b74075 libmpdemux/demux_mf.c --- a/libmpdemux/demux_mf.c Sun Mar 10 17:51:52 2002 +0000 +++ b/libmpdemux/demux_mf.c Sun Mar 10 22:49:18 2002 +0000 @@ -94,7 +94,7 @@ sh_video->ds = demuxer->video; if ( !strcasecmp( mf_type,"jpg" ) || - !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('M', 'J', 'P', 'G'); + !(strcasecmp(mf_type, "jpeg"))) sh_video->format = mmioFOURCC('I', '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; }