Mercurial > mplayer.hg
annotate libmpcodecs/vd_ijpg.c @ 7365:822923446b66
Removed authors and maintainers section, now in txt format.
author | diego |
---|---|
date | Tue, 10 Sep 2002 21:56:05 +0000 |
parents | 28677d779205 |
children | c4434bdf6e51 |
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 "Pontscho", | |
24 "based on vd_mpng.c", | |
25 "uses Indipended JPEG Group's jpeglib" | |
26 }; | |
27 | |
28 LIBVD_EXTERN(ijpg) | |
29 | |
30 static int last_w=-1; | |
31 static int last_h=-1; | |
32 | |
33 // to set/get/query special features/parameters | |
34 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
35 return CONTROL_UNKNOWN; | |
36 } | |
37 | |
38 // init driver | |
39 static int init(sh_video_t *sh){ | |
40 last_w=-1; | |
41 return 1; | |
42 } | |
43 | |
44 // uninit driver | |
45 static void uninit(sh_video_t *sh){ | |
46 } | |
47 | |
48 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
49 | |
50 typedef struct | |
51 { | |
52 struct jpeg_source_mgr pub; | |
53 unsigned char * inbuf; | |
54 int bufsize; | |
55 } my_source_mgr; | |
56 | |
57 typedef my_source_mgr * my_src_ptr; | |
58 | |
59 METHODDEF(void) init_source (j_decompress_ptr cinfo) | |
60 { | |
61 } | |
62 | |
63 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) | |
64 { | |
65 my_src_ptr src = (my_src_ptr) cinfo->src; | |
66 size_t nbytes; | |
67 src->pub.next_input_byte = src->inbuf; | |
68 src->pub.bytes_in_buffer = src->bufsize; | |
69 return TRUE; | |
70 } | |
71 | |
72 METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes) | |
73 { | |
74 my_src_ptr src = (my_src_ptr) cinfo->src; | |
75 | |
76 if (num_bytes > 0) | |
77 { | |
78 while (num_bytes > (long) src->pub.bytes_in_buffer) | |
79 { | |
80 num_bytes -= (long) src->pub.bytes_in_buffer; | |
81 (void) fill_input_buffer(cinfo); | |
82 } | |
83 src->pub.next_input_byte += (size_t) num_bytes; | |
84 src->pub.bytes_in_buffer -= (size_t) num_bytes; | |
85 } | |
86 } | |
87 | |
88 METHODDEF(void) term_source (j_decompress_ptr cinfo) { } | |
89 | |
90 GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize ) | |
91 { | |
92 my_src_ptr src; | |
93 if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) ); | |
94 src = (my_src_ptr) cinfo->src; | |
95 src->pub.init_source = init_source; | |
96 src->pub.fill_input_buffer = fill_input_buffer; | |
97 src->pub.skip_input_data = skip_input_data; | |
98 src->pub.resync_to_restart = jpeg_resync_to_restart; | |
99 src->pub.term_source = term_source; | |
100 src->inbuf = inbuf; | |
101 src->bufsize=bufsize; | |
102 src->pub.bytes_in_buffer = 0; | |
103 src->pub.next_input_byte = NULL; | |
104 } | |
105 | |
106 struct my_error_mgr | |
107 { | |
108 struct jpeg_error_mgr pub; | |
109 jmp_buf setjmp_buffer; | |
110 }; | |
111 | |
112 typedef struct my_error_mgr * my_error_ptr; | |
113 | |
114 METHODDEF(void) my_error_exit (j_common_ptr cinfo) | |
115 { | |
116 my_error_ptr myerr=(my_error_ptr) cinfo->err; | |
117 (*cinfo->err->output_message) (cinfo); | |
118 longjmp(myerr->setjmp_buffer, 1); | |
119 } | |
120 | |
121 static struct jpeg_decompress_struct cinfo; | |
122 static struct my_error_mgr jerr; | |
123 static int row_stride; | |
6097 | 124 static unsigned char *temp_row=NULL; |
125 | |
5029 | 126 // decode a frame |
127 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
128 mp_image_t * mpi = NULL; | |
6097 | 129 int width,height,depth,i; |
5029 | 130 |
131 if ( len <= 0 ) return NULL; // skipped frame | |
132 | |
5366 | 133 cinfo.err=jpeg_std_error( &jerr.pub ); |
134 jerr.pub.error_exit=my_error_exit; | |
5029 | 135 if( setjmp( jerr.setjmp_buffer ) ) |
136 { | |
137 mp_msg( MSGT_DECVIDEO,MSGL_ERR,"[ijpg] setjmp error ...\n" ); | |
138 return NULL; | |
139 } | |
140 | |
141 jpeg_create_decompress( &cinfo ); | |
142 jpeg_buf_src( &cinfo,data,len ); | |
143 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
|
144 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
|
145 sh->disp_h=height=cinfo.image_height; |
5029 | 146 jpeg_start_decompress( &cinfo ); |
147 depth=cinfo.output_components * 8; | |
148 | |
149 switch( depth ) { | |
6097 | 150 case 8: |
151 case 24: break; | |
5029 | 152 default: mp_msg( MSGT_DECVIDEO,MSGL_ERR,"Sorry, unsupported JPEG colorspace: %d.\n",depth ); return NULL; |
153 } | |
154 | |
6097 | 155 if ( last_w!=width || last_h!=height ) |
5029 | 156 { |
6097 | 157 if(!mpcodecs_config_vo( sh,width,height, IMGFMT_RGB24 )) return NULL; |
158 if(temp_row) free(temp_row); | |
159 temp_row=malloc(3*width+16); | |
160 last_w=width; last_h=height; | |
5029 | 161 } |
162 | |
163 mpi=mpcodecs_get_image( sh,MP_IMGTYPE_TEMP,MP_IMGFLAG_ACCEPT_STRIDE,width,height ); | |
164 if ( !mpi ) return NULL; | |
165 | |
166 row_stride=cinfo.output_width * cinfo.output_components; | |
167 | |
168 for ( i=0;i < height;i++ ) | |
169 { | |
6097 | 170 unsigned char * drow = mpi->planes[0] + mpi->stride[0] * i; |
171 unsigned char * row = (mpi->imgfmt==IMGFMT_RGB24 && depth==24) ? drow : temp_row; | |
5042 | 172 jpeg_read_scanlines( &cinfo,(JSAMPLE**)&row,1 ); |
6097 | 173 if(depth==8){ |
174 // grayscale -> rgb/bgr 24/32 | |
175 int x; | |
176 if(mpi->bpp==32) | |
177 for(x=0;x<width;x++) drow[4*x]=0x010101*row[x]; | |
178 else | |
179 for(x=0;x<width;x++) drow[3*x+0]=drow[3*x+1]=drow[3*x+2]=row[x]; | |
180 } else { | |
181 int x; | |
182 switch(mpi->imgfmt){ | |
183 // rgb24 -> bgr24 | |
184 case IMGFMT_BGR24: | |
185 for(x=0;x<3*width;x+=3){ | |
186 drow[x+0]=row[x+2]; | |
187 drow[x+1]=row[x+1]; | |
188 drow[x+2]=row[x+0]; | |
189 } | |
190 break; | |
191 // rgb24 -> bgr32 | |
192 case IMGFMT_BGR32: | |
193 for(x=0;x<width;x++){ | |
194 drow[4*x+0]=row[3*x+2]; | |
195 drow[4*x+1]=row[3*x+1]; | |
196 drow[4*x+2]=row[3*x+0]; | |
197 } | |
198 break; | |
199 } | |
200 } | |
5029 | 201 } |
202 | |
203 jpeg_finish_decompress(&cinfo); | |
204 jpeg_destroy_decompress(&cinfo); | |
205 | |
206 return mpi; | |
207 } |