Mercurial > mplayer.hg
annotate libmpcodecs/vd_ijpg.c @ 25944:8a1c062707ff
Do not uselessly erase background, OpenGL will take care of drawing everything.
author | reimar |
---|---|
date | Sun, 10 Feb 2008 19:47:54 +0000 |
parents | a9fd64f3d166 |
children | b21e1506e50b |
rev | line source |
---|---|
5029 | 1 |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
23305
22d3d12c6dfb
Include string.h for memcpy, fastmemcpy.h alone is not enough.
reimar
parents:
21507
diff
changeset
|
4 #include <string.h> |
5029 | 5 |
6 #include "config.h" | |
7 #include "mp_msg.h" | |
8 | |
9 #include <jpeglib.h> | |
5048 | 10 #define UINT16 IJPG_UINT16 |
11 #define INT16 IJPG_INT16 | |
5029 | 12 |
13 #include <setjmp.h> | |
14 | |
21372 | 15 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
16 #include "mpbswap.h" |
5029 | 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", | |
18604 | 25 "uses Independent JPEG Group's jpeglib" |
5029 | 26 }; |
27 | |
28 LIBVD_EXTERN(ijpg) | |
29 | |
30 static int last_w=-1; | |
31 static int last_h=-1; | |
25667
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
32 static int last_depth=-1; |
5029 | 33 |
34 // to set/get/query special features/parameters | |
35 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
25667
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
36 if (cmd == VDCTRL_QUERY_FORMAT) { |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
37 int format = *(int *)arg; |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
38 if ((last_depth == 24 && format == IMGFMT_RGB24) || |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
39 (last_depth == 8 && format == IMGFMT_Y8 )) |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
40 return CONTROL_TRUE; |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
41 return CONTROL_FALSE; |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
42 } |
5029 | 43 return CONTROL_UNKNOWN; |
44 } | |
45 | |
46 // init driver | |
47 static int init(sh_video_t *sh){ | |
48 last_w=-1; | |
49 return 1; | |
50 } | |
51 | |
52 // uninit driver | |
53 static void uninit(sh_video_t *sh){ | |
54 } | |
55 | |
56 //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); | |
57 | |
58 typedef struct | |
59 { | |
60 struct jpeg_source_mgr pub; | |
61 unsigned char * inbuf; | |
62 int bufsize; | |
63 } my_source_mgr; | |
64 | |
65 typedef my_source_mgr * my_src_ptr; | |
66 | |
67 METHODDEF(void) init_source (j_decompress_ptr cinfo) | |
68 { | |
69 } | |
70 | |
71 METHODDEF(boolean) fill_input_buffer (j_decompress_ptr cinfo) | |
72 { | |
25666
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
73 my_src_ptr src = (my_src_ptr) cinfo->src; |
5029 | 74 src->pub.next_input_byte = src->inbuf; |
75 src->pub.bytes_in_buffer = src->bufsize; | |
76 return TRUE; | |
77 } | |
25666
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
78 |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
79 METHODDEF(void) skip_input_data (j_decompress_ptr cinfo, long num_bytes) |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
80 { |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
81 my_src_ptr src = (my_src_ptr) cinfo->src; |
5029 | 82 |
83 if (num_bytes > 0) | |
84 { | |
85 while (num_bytes > (long) src->pub.bytes_in_buffer) | |
86 { | |
87 num_bytes -= (long) src->pub.bytes_in_buffer; | |
88 (void) fill_input_buffer(cinfo); | |
89 } | |
90 src->pub.next_input_byte += (size_t) num_bytes; | |
91 src->pub.bytes_in_buffer -= (size_t) num_bytes; | |
92 } | |
93 } | |
94 | |
25666
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
95 METHODDEF(void) term_source (j_decompress_ptr cinfo) { } |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
96 |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
97 GLOBAL(void) jpeg_buf_src ( j_decompress_ptr cinfo, char * inbuf,int bufsize ) |
5029 | 98 { |
99 my_src_ptr src; | |
100 if (cinfo->src == NULL) cinfo->src=malloc( sizeof( my_source_mgr ) ); | |
101 src = (my_src_ptr) cinfo->src; | |
102 src->pub.init_source = init_source; | |
103 src->pub.fill_input_buffer = fill_input_buffer; | |
104 src->pub.skip_input_data = skip_input_data; | |
105 src->pub.resync_to_restart = jpeg_resync_to_restart; | |
106 src->pub.term_source = term_source; | |
107 src->inbuf = inbuf; | |
108 src->bufsize=bufsize; | |
109 src->pub.bytes_in_buffer = 0; | |
110 src->pub.next_input_byte = NULL; | |
111 } | |
112 | |
113 struct my_error_mgr | |
114 { | |
115 struct jpeg_error_mgr pub; | |
116 jmp_buf setjmp_buffer; | |
117 }; | |
118 | |
119 typedef struct my_error_mgr * my_error_ptr; | |
120 | |
121 METHODDEF(void) my_error_exit (j_common_ptr cinfo) | |
122 { | |
123 my_error_ptr myerr=(my_error_ptr) cinfo->err; | |
124 (*cinfo->err->output_message) (cinfo); | |
125 longjmp(myerr->setjmp_buffer, 1); | |
126 } | |
127 | |
128 // decode a frame | |
129 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
25664 | 130 struct jpeg_decompress_struct cinfo; |
131 struct my_error_mgr jerr; | |
5029 | 132 mp_image_t * mpi = NULL; |
6097 | 133 int width,height,depth,i; |
5029 | 134 |
135 if ( len <= 0 ) return NULL; // skipped frame | |
136 | |
25664 | 137 memset(&cinfo, 0, sizeof(cinfo)); |
138 memset(&jerr, 0, sizeof(jerr)); | |
5366 | 139 cinfo.err=jpeg_std_error( &jerr.pub ); |
140 jerr.pub.error_exit=my_error_exit; | |
5029 | 141 if( setjmp( jerr.setjmp_buffer ) ) |
142 { | |
143 mp_msg( MSGT_DECVIDEO,MSGL_ERR,"[ijpg] setjmp error ...\n" ); | |
144 return NULL; | |
145 } | |
25666
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
146 |
5029 | 147 jpeg_create_decompress( &cinfo ); |
148 jpeg_buf_src( &cinfo,data,len ); | |
149 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
|
150 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
|
151 sh->disp_h=height=cinfo.image_height; |
5029 | 152 jpeg_start_decompress( &cinfo ); |
153 depth=cinfo.output_components * 8; | |
154 | |
155 switch( depth ) { | |
6097 | 156 case 8: |
157 case 24: break; | |
5029 | 158 default: mp_msg( MSGT_DECVIDEO,MSGL_ERR,"Sorry, unsupported JPEG colorspace: %d.\n",depth ); return NULL; |
159 } | |
160 | |
25667
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
161 if ( last_w!=width || last_h!=height || last_depth != depth ) |
5029 | 162 { |
25667
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
163 last_depth = depth; |
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
164 if(!mpcodecs_config_vo( sh,width,height, depth == 8 ? IMGFMT_Y8 : IMGFMT_RGB24 )) return NULL; |
6097 | 165 last_w=width; last_h=height; |
5029 | 166 } |
167 | |
168 mpi=mpcodecs_get_image( sh,MP_IMGTYPE_TEMP,MP_IMGFLAG_ACCEPT_STRIDE,width,height ); | |
169 if ( !mpi ) return NULL; | |
170 | |
171 for ( i=0;i < height;i++ ) | |
172 { | |
6097 | 173 unsigned char * drow = mpi->planes[0] + mpi->stride[0] * i; |
25667
a9fd64f3d166
Colourspace conversions do _not_ belong into a decoder!
reimar
parents:
25666
diff
changeset
|
174 jpeg_read_scanlines( &cinfo,(JSAMPLE**)&drow,1 ); |
5029 | 175 } |
25666
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
176 |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
177 jpeg_finish_decompress(&cinfo); |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
178 jpeg_destroy_decompress(&cinfo); |
79fee31fb216
Cosmetics: get rid of huge amounts of trailing whitespace
reimar
parents:
25665
diff
changeset
|
179 |
5029 | 180 return mpi; |
181 } |