Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 8148:5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
author | alex |
---|---|
date | Mon, 11 Nov 2002 15:22:10 +0000 |
parents | e60109dfc85c |
children | 1ac2523775ad |
rev | line source |
---|---|
5648 | 1 #define DISP |
2 | |
3 /* | |
4 * vo_jpeg.c, JPEG Renderer for Mplayer | |
5 * | |
5649 | 6 * Copyright 2002 by Pontscho (pontscho@makacs.poliod.hu) |
5648 | 7 * |
8 */ | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <errno.h> | |
14 | |
15 #include <jpeglib.h> | |
16 | |
17 #include "config.h" | |
18 #include "video_out.h" | |
19 #include "video_out_internal.h" | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7124
diff
changeset
|
20 #include "sub.h" |
5648 | 21 |
22 #include "../postproc/swscale.h" | |
23 #include "../postproc/rgb2rgb.h" | |
24 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
25 static vo_info_t info= |
5648 | 26 { |
27 "JPEG file", | |
28 "jpeg", | |
29 "Zoltan Ponekker (pontscho@makacs.poliod.hu)", | |
30 "" | |
31 }; | |
32 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
33 LIBVO_EXTERN (jpeg) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7487
diff
changeset
|
34 |
5648 | 35 #define RGB 0 |
36 #define BGR 1 | |
37 | |
38 extern int verbose; | |
39 static int image_width; | |
40 static int image_height; | |
41 static int image_format; | |
42 static uint8_t *image_data=NULL; | |
43 static unsigned int scale_srcW=0, scale_srcH=0; | |
44 | |
45 int jpeg_baseline = 1; | |
46 int jpeg_progressive_mode = 0; | |
47 int jpeg_optimize = 100; | |
48 int jpeg_smooth = 0; | |
49 int jpeg_quality = 75; | |
5659 | 50 char * jpeg_outdir = "."; |
5648 | 51 |
52 #define bpp 24 | |
53 | |
54 static int cspace=RGB; | |
55 static int framenum=0; | |
56 | |
57 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
58 { | |
59 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width); | |
60 } | |
61 | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6751
diff
changeset
|
62 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
5648 | 63 { |
64 if ( fullscreen&0x04 && ( width != d_width || height != d_height )&&( ( format == IMGFMT_YV12 ) ) ) | |
65 { | |
66 // software scaling | |
67 image_width=(d_width + 7) & ~7; | |
68 image_height=d_height; | |
69 scale_srcW=width; | |
70 scale_srcH=height; | |
71 SwScale_Init(); | |
72 } | |
73 else | |
74 { | |
75 image_height=height; | |
76 image_width=width; | |
77 } | |
78 | |
79 image_format=format; | |
80 switch(format) | |
81 { | |
82 case IMGFMT_BGR32: | |
83 cspace=BGR; | |
84 image_data=malloc( image_width * image_height * 3 ); | |
85 break; | |
86 case IMGFMT_BGR24: | |
87 cspace=BGR; | |
88 image_data=malloc( image_width * image_height * 3 ); | |
89 break; | |
90 case IMGFMT_RGB24: | |
91 cspace=RGB; | |
92 break; | |
93 case IMGFMT_IYUV: | |
94 case IMGFMT_I420: | |
95 case IMGFMT_YV12: | |
96 cspace=BGR; | |
97 yuv2rgb_init( bpp,MODE_BGR ); | |
98 image_data=malloc( image_width * image_height * 3 ); | |
99 break; | |
100 default: | |
101 return 1; | |
102 } | |
103 | |
104 return 0; | |
105 } | |
106 | |
107 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) | |
108 { | |
109 FILE * o; | |
110 struct jpeg_compress_struct cinfo; | |
111 struct jpeg_error_mgr jerr; | |
112 JSAMPROW row_pointer[1]; | |
113 int row_stride; | |
114 | |
115 if ( !buffer ) return 1; | |
116 if ( (o=fopen( name,"wb" )) == NULL ) return 1; | |
117 | |
118 cinfo.err=jpeg_std_error(&jerr); | |
119 jpeg_create_compress(&cinfo); | |
120 jpeg_stdio_dest( &cinfo,o ); | |
121 | |
122 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); | |
123 | |
124 cinfo.image_width=image_width; | |
125 cinfo.image_height=image_height; | |
126 cinfo.input_components=bpp / 8; | |
127 cinfo.in_color_space=JCS_RGB; | |
128 cinfo.optimize_coding=jpeg_optimize; | |
129 cinfo.smoothing_factor=jpeg_smooth; | |
130 | |
131 jpeg_set_defaults( &cinfo ); | |
132 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); | |
133 jpeg_start_compress( &cinfo,TRUE ); | |
134 | |
135 row_stride = image_width * ( bpp / 8 ); | |
136 while ( cinfo.next_scanline < cinfo.image_height ) | |
137 { | |
138 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ]; | |
139 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 ); | |
140 } | |
141 | |
142 jpeg_finish_compress( &cinfo ); | |
143 fclose( o ); | |
144 jpeg_destroy_compress( &cinfo ); | |
145 | |
146 return 0; | |
147 } | |
148 | |
149 static uint32_t draw_frame(uint8_t * src[]) | |
150 { | |
151 char buf[256]; | |
6751 | 152 uint8_t *dst= src[0]; |
5648 | 153 |
154 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
155 | |
156 if ( image_format == IMGFMT_BGR32 ) | |
157 { | |
158 rgb32to24( src[0],image_data,image_width * image_height * 4 ); | |
159 rgb24tobgr24( image_data,image_data,image_width * image_height * 3 ); | |
6751 | 160 dst=image_data; |
5648 | 161 } |
162 if ( image_format == IMGFMT_BGR24 ) | |
163 { | |
164 rgb24tobgr24( src[0],image_data,image_width * image_height * 3 ); | |
6751 | 165 dst=image_data; |
5648 | 166 } |
6751 | 167 return jpeg_write( buf,dst ); |
5648 | 168 } |
169 | |
170 static void draw_osd(void) | |
171 { | |
172 vo_draw_text(image_width, image_height, draw_alpha); | |
173 } | |
174 | |
175 static void flip_page (void) | |
176 { | |
177 char buf[256]; | |
178 | |
179 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) | |
180 { | |
181 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
182 jpeg_write( buf,image_data ); | |
183 } | |
184 } | |
185 | |
186 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
187 { | |
188 if (scale_srcW) | |
189 { | |
190 uint8_t *dst[3]={image_data, NULL, NULL}; | |
191 SwScale_YV12slice(src,stride,y,h, | |
192 dst, image_width*((bpp+7)/8), bpp, | |
193 scale_srcW, scale_srcH, image_width, image_height); | |
194 } | |
195 else | |
196 { | |
197 uint8_t *dst=image_data + (image_width * y + x) * (bpp/8); | |
198 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
199 } | |
200 return 0; | |
201 } | |
202 | |
203 static uint32_t query_format(uint32_t format) | |
204 { | |
205 switch( format ) | |
206 { | |
207 case IMGFMT_IYUV: | |
208 case IMGFMT_I420: | |
209 case IMGFMT_YV12: | |
210 case IMGFMT_RGB|24: | |
211 case IMGFMT_BGR|24: | |
212 case IMGFMT_BGR|32: | |
213 return 1; | |
214 } | |
215 return 0; | |
216 } | |
217 | |
218 static void uninit(void) | |
219 { | |
220 if ( image_data ) | |
221 { | |
222 free( image_data ); | |
223 image_data=NULL; | |
224 } | |
225 } | |
226 | |
227 static void check_events(void) | |
228 { | |
229 } | |
230 | |
231 static uint32_t preinit(const char *arg) | |
232 { | |
233 if(arg) | |
234 { | |
235 printf("JPEG Unknown subdevice: %s\n",arg); | |
236 return ENOSYS; | |
237 } | |
238 return 0; | |
239 } | |
240 | |
241 static uint32_t control(uint32_t request, void *data, ...) | |
242 { | |
243 switch (request) | |
244 { | |
245 case VOCTRL_QUERY_FORMAT: | |
246 return query_format(*((uint32_t*)data)); | |
247 } | |
248 return VO_NOTIMPL; | |
249 } |