annotate libmpcodecs/vd_ijpg.c @ 5574:bdfd4b72244a

fixing vertical scaling on non mobility cards, this might have overflowed into the horizontal stuff, so perhaps it fixes the horizontal stuff too
author michael
date Fri, 12 Apr 2002 12:29:12 +0000
parents f46873b05f82
children 3e4936b52df4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
1
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
2 #include <stdio.h>
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
3 #include <stdlib.h>
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
4
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
5 #include "config.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
6 #include "mp_msg.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
7
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
8 #include <jpeglib.h>
5048
2f53b53385e2 libjpeg and loader conflict workaround
pontscho
parents: 5042
diff changeset
9 #define UINT16 IJPG_UINT16
2f53b53385e2 libjpeg and loader conflict workaround
pontscho
parents: 5042
diff changeset
10 #define INT16 IJPG_INT16
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
11
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
12 #include <setjmp.h>
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
13
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
14 #include "bswap.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
15 #include "postproc/rgb2rgb.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
16 #include "libvo/fastmemcpy.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
17
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
18 #include "vd_internal.h"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
19
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
20 static vd_info_t info = {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
21 "JPEG Images decoder",
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
22 "ijpg",
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
23 VFM_IJPG,
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
24 "Pontscho",
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
25 "based on vd_mpng.c",
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
26 "uses Indipended JPEG Group's jpeglib"
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
27 };
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
28
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
29 LIBVD_EXTERN(ijpg)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
30
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
31 static unsigned int out_fmt=0;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
32
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
33 static int last_w=-1;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
34 static int last_h=-1;
5042
75e4f695f204 kill few warning
pontscho
parents: 5033
diff changeset
35 static unsigned int last_c=-1;
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
36
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
37 // to set/get/query special features/parameters
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
38 static int control(sh_video_t *sh,int cmd,void* arg,...){
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
39 return CONTROL_UNKNOWN;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
40 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
41
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
42 // init driver
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
43 static int init(sh_video_t *sh){
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
44 last_w=-1;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
45 return 1;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
46 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
47
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
48 // uninit driver
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
49 static void uninit(sh_video_t *sh){
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
50 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
51
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
52 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
53
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
54 typedef struct
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
55 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
56 struct jpeg_source_mgr pub;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
57 unsigned char * inbuf;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
58 int bufsize;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
59 } my_source_mgr;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
60
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
61 typedef my_source_mgr * my_src_ptr;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
62
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
63 METHODDEF(void) init_source (j_decompress_ptr cinfo)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
64 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
65 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
66
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
67 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
68 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
69 my_src_ptr src = (my_src_ptr) cinfo->src;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
70 size_t nbytes;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
71 src->pub.next_input_byte = src->inbuf;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
72 src->pub.bytes_in_buffer = src->bufsize;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
73 return TRUE;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
74 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
75
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
76 METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
77 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
78 my_src_ptr src = (my_src_ptr) cinfo->src;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
79
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
80 if (num_bytes > 0)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
81 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
82 while (num_bytes > (long) src->pub.bytes_in_buffer)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
83 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
84 num_bytes -= (long) src->pub.bytes_in_buffer;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
85 (void) fill_input_buffer(cinfo);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
86 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
87 src->pub.next_input_byte += (size_t) num_bytes;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
88 src->pub.bytes_in_buffer -= (size_t) num_bytes;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
89 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
90 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
91
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
92 METHODDEF(void) term_source (j_decompress_ptr cinfo) { }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
93
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
94 GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
95 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
96 my_src_ptr src;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
97 if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
98 src = (my_src_ptr) cinfo->src;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
99 src->pub.init_source = init_source;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
100 src->pub.fill_input_buffer = fill_input_buffer;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
101 src->pub.skip_input_data = skip_input_data;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
102 src->pub.resync_to_restart = jpeg_resync_to_restart;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
103 src->pub.term_source = term_source;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
104 src->inbuf = inbuf;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
105 src->bufsize=bufsize;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
106 src->pub.bytes_in_buffer = 0;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
107 src->pub.next_input_byte = NULL;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
108 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
109
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
110 struct my_error_mgr
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
111 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
112 struct jpeg_error_mgr pub;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
113 jmp_buf setjmp_buffer;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
114 };
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
115
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
116 typedef struct my_error_mgr * my_error_ptr;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
117
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
118 METHODDEF(void) my_error_exit (j_common_ptr cinfo)
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
119 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
120 my_error_ptr myerr=(my_error_ptr) cinfo->err;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
121 (*cinfo->err->output_message) (cinfo);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
122 longjmp(myerr->setjmp_buffer, 1);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
123 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
124
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
125 static struct jpeg_decompress_struct cinfo;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
126 static struct my_error_mgr jerr;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
127 static int row_stride;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
128
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
129 // decode a frame
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
130 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
131 mp_image_t * mpi = NULL;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
132 int width,height,depth,i,j;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
133
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
134 if ( len <= 0 ) return NULL; // skipped frame
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
135
5366
f46873b05f82 eeh 10l removed too much lines :(
atmos4
parents: 5365
diff changeset
136 cinfo.err=jpeg_std_error( &jerr.pub );
f46873b05f82 eeh 10l removed too much lines :(
atmos4
parents: 5365
diff changeset
137 jerr.pub.error_exit=my_error_exit;
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
138 if( setjmp( jerr.setjmp_buffer ) )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
139 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
140 mp_msg( MSGT_DECVIDEO,MSGL_ERR,"[ijpg] setjmp error ...\n" );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
141 return NULL;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
142 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
143
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
144 jpeg_create_decompress( &cinfo );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
145 jpeg_buf_src( &cinfo,data,len );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
146 jpeg_read_header( &cinfo,TRUE );
5365
b87743434e1f Issue a warning in VDec if disp_w and disp_h weren't set by codec and try workaround.
atmos4
parents: 5124
diff changeset
147 sh->disp_w=width=cinfo.image_width;
b87743434e1f Issue a warning in VDec if disp_w and disp_h weren't set by codec and try workaround.
atmos4
parents: 5124
diff changeset
148 sh->disp_h=height=cinfo.image_height;
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
149 jpeg_start_decompress( &cinfo );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
150 depth=cinfo.output_components * 8;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
151
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
152 switch( depth ) {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
153 case 8: out_fmt=IMGFMT_BGR8; break;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
154 case 24: out_fmt=IMGFMT_BGR24; break;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
155 default: mp_msg( MSGT_DECVIDEO,MSGL_ERR,"Sorry, unsupported JPEG colorspace: %d.\n",depth ); return NULL;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
156 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
157
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
158 if ( last_w!=width || last_h!=height || last_c!=out_fmt )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
159 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
160 last_w=width; last_h=height; last_c=out_fmt;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
161 if ( !out_fmt ) return NULL;
5124
3dcbf67c0de0 handle error from mpcodecs_config_vo()
arpi
parents: 5048
diff changeset
162 if(!mpcodecs_config_vo( sh,width,height,out_fmt )) return NULL;
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
163 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
164
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
165 mpi=mpcodecs_get_image( sh,MP_IMGTYPE_TEMP,MP_IMGFLAG_ACCEPT_STRIDE,width,height );
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
166 if ( !mpi ) return NULL;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
167
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
168 row_stride=cinfo.output_width * cinfo.output_components;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
169
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
170 for ( i=0;i < height;i++ )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
171 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
172 char * row = mpi->planes[0] + mpi->stride[0] * i;
5042
75e4f695f204 kill few warning
pontscho
parents: 5033
diff changeset
173 jpeg_read_scanlines( &cinfo,(JSAMPLE**)&row,1 );
5029
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
174 #warning workaround for rgb2bgr
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
175 if ( depth == 24 )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
176 for ( j=0;j < width * 3;j+=3 )
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
177 {
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
178 char c;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
179 c=row[j];
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
180 row[j]=row[j+2];
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
181 row[j+2]=c;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
182 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
183 }
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
184
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
185 jpeg_finish_decompress(&cinfo);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
186 jpeg_destroy_decompress(&cinfo);
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
187
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
188 return mpi;
ef8a43b74075 Add IJPG decoder.
pontscho
parents:
diff changeset
189 }