2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2007-05-16 21:45:46 +00:00
|
|
|
#include <string.h>
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
#include <jpeglib.h>
|
2002-03-11 20:13:45 +00:00
|
|
|
#define UINT16 IJPG_UINT16
|
|
|
|
#define INT16 IJPG_INT16
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
#include "vd_internal.h"
|
|
|
|
|
2010-02-12 16:29:34 +00:00
|
|
|
static const vd_info_t info = {
|
2002-03-10 22:49:18 +00:00
|
|
|
"JPEG Images decoder",
|
|
|
|
"ijpg",
|
|
|
|
"Pontscho",
|
|
|
|
"based on vd_mpng.c",
|
2006-06-06 21:22:47 +00:00
|
|
|
"uses Independent JPEG Group's jpeglib"
|
2002-03-10 22:49:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LIBVD_EXTERN(ijpg)
|
|
|
|
|
|
|
|
static int last_w=-1;
|
|
|
|
static int last_h=-1;
|
2008-01-12 15:26:24 +00:00
|
|
|
static int last_depth=-1;
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
// to set/get/query special features/parameters
|
|
|
|
static int control(sh_video_t *sh,int cmd,void* arg,...){
|
2008-01-12 15:26:24 +00:00
|
|
|
if (cmd == VDCTRL_QUERY_FORMAT) {
|
|
|
|
int format = *(int *)arg;
|
|
|
|
if ((last_depth == 24 && format == IMGFMT_RGB24) ||
|
|
|
|
(last_depth == 8 && format == IMGFMT_Y8 ))
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
return CONTROL_FALSE;
|
|
|
|
}
|
2002-03-10 22:49:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-01-12 15:01:05 +00:00
|
|
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
2002-03-10 22:49:18 +00:00
|
|
|
src->pub.next_input_byte = src->inbuf;
|
|
|
|
src->pub.bytes_in_buffer = src->bufsize;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2008-01-12 15:01:05 +00:00
|
|
|
|
|
|
|
METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
|
|
|
{
|
|
|
|
my_src_ptr src = (my_src_ptr) cinfo->src;
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 15:01:05 +00:00
|
|
|
METHODDEF(void) term_source (j_decompress_ptr cinfo) { }
|
|
|
|
|
2010-05-29 10:06:29 +00:00
|
|
|
static void jpeg_buf_src (j_decompress_ptr cinfo, char * inbuf, int bufsize)
|
2002-03-10 22:49:18 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// decode a frame
|
|
|
|
static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
|
2008-01-12 14:56:11 +00:00
|
|
|
struct jpeg_decompress_struct cinfo;
|
|
|
|
struct my_error_mgr jerr;
|
2002-03-10 22:49:18 +00:00
|
|
|
mp_image_t * mpi = NULL;
|
2002-05-15 12:53:00 +00:00
|
|
|
int width,height,depth,i;
|
2002-03-10 22:49:18 +00:00
|
|
|
|
|
|
|
if ( len <= 0 ) return NULL; // skipped frame
|
|
|
|
|
2008-01-12 14:56:11 +00:00
|
|
|
memset(&cinfo, 0, sizeof(cinfo));
|
|
|
|
memset(&jerr, 0, sizeof(jerr));
|
2002-03-27 03:07:07 +00:00
|
|
|
cinfo.err=jpeg_std_error( &jerr.pub );
|
|
|
|
jerr.pub.error_exit=my_error_exit;
|
2002-03-10 22:49:18 +00:00
|
|
|
if( setjmp( jerr.setjmp_buffer ) )
|
|
|
|
{
|
|
|
|
mp_msg( MSGT_DECVIDEO,MSGL_ERR,"[ijpg] setjmp error ...\n" );
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-01-12 15:01:05 +00:00
|
|
|
|
2002-03-10 22:49:18 +00:00
|
|
|
jpeg_create_decompress( &cinfo );
|
|
|
|
jpeg_buf_src( &cinfo,data,len );
|
|
|
|
jpeg_read_header( &cinfo,TRUE );
|
2002-03-27 02:58:55 +00:00
|
|
|
sh->disp_w=width=cinfo.image_width;
|
|
|
|
sh->disp_h=height=cinfo.image_height;
|
2002-03-10 22:49:18 +00:00
|
|
|
jpeg_start_decompress( &cinfo );
|
|
|
|
depth=cinfo.output_components * 8;
|
|
|
|
|
|
|
|
switch( depth ) {
|
2002-05-15 12:53:00 +00:00
|
|
|
case 8:
|
|
|
|
case 24: break;
|
2002-03-10 22:49:18 +00:00
|
|
|
default: mp_msg( MSGT_DECVIDEO,MSGL_ERR,"Sorry, unsupported JPEG colorspace: %d.\n",depth ); return NULL;
|
|
|
|
}
|
|
|
|
|
2008-01-12 15:26:24 +00:00
|
|
|
if ( last_w!=width || last_h!=height || last_depth != depth )
|
2002-03-10 22:49:18 +00:00
|
|
|
{
|
2008-01-12 15:26:24 +00:00
|
|
|
last_depth = depth;
|
|
|
|
if(!mpcodecs_config_vo( sh,width,height, depth == 8 ? IMGFMT_Y8 : IMGFMT_RGB24 )) return NULL;
|
2002-05-15 12:53:00 +00:00
|
|
|
last_w=width; last_h=height;
|
2002-03-10 22:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mpi=mpcodecs_get_image( sh,MP_IMGTYPE_TEMP,MP_IMGFLAG_ACCEPT_STRIDE,width,height );
|
|
|
|
if ( !mpi ) return NULL;
|
|
|
|
|
|
|
|
for ( i=0;i < height;i++ )
|
|
|
|
{
|
2002-05-15 12:53:00 +00:00
|
|
|
unsigned char * drow = mpi->planes[0] + mpi->stride[0] * i;
|
2008-01-12 15:26:24 +00:00
|
|
|
jpeg_read_scanlines( &cinfo,(JSAMPLE**)&drow,1 );
|
2002-03-10 22:49:18 +00:00
|
|
|
}
|
2008-01-12 15:01:05 +00:00
|
|
|
|
|
|
|
jpeg_finish_decompress(&cinfo);
|
|
|
|
jpeg_destroy_decompress(&cinfo);
|
|
|
|
|
2002-03-10 22:49:18 +00:00
|
|
|
return mpi;
|
|
|
|
}
|