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