Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 7597:363959276ef2
by cvs hephooey@fastmail.fm
author | jaf |
---|---|
date | Sat, 05 Oct 2002 10:19:07 +0000 |
parents | e60109dfc85c |
children | 5b39e79af5fe |
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 | |
25 LIBVO_EXTERN (jpeg) | |
26 | |
27 static vo_info_t vo_info= | |
28 { | |
29 "JPEG file", | |
30 "jpeg", | |
31 "Zoltan Ponekker (pontscho@makacs.poliod.hu)", | |
32 "" | |
33 }; | |
34 | |
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 const vo_info_t* | |
108 get_info(void) | |
109 { | |
110 return &vo_info; | |
111 } | |
112 | |
113 static uint32_t jpeg_write( uint8_t * name,uint8_t * buffer ) | |
114 { | |
115 FILE * o; | |
116 struct jpeg_compress_struct cinfo; | |
117 struct jpeg_error_mgr jerr; | |
118 JSAMPROW row_pointer[1]; | |
119 int row_stride; | |
120 | |
121 if ( !buffer ) return 1; | |
122 if ( (o=fopen( name,"wb" )) == NULL ) return 1; | |
123 | |
124 cinfo.err=jpeg_std_error(&jerr); | |
125 jpeg_create_compress(&cinfo); | |
126 jpeg_stdio_dest( &cinfo,o ); | |
127 | |
128 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); | |
129 | |
130 cinfo.image_width=image_width; | |
131 cinfo.image_height=image_height; | |
132 cinfo.input_components=bpp / 8; | |
133 cinfo.in_color_space=JCS_RGB; | |
134 cinfo.optimize_coding=jpeg_optimize; | |
135 cinfo.smoothing_factor=jpeg_smooth; | |
136 | |
137 jpeg_set_defaults( &cinfo ); | |
138 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); | |
139 jpeg_start_compress( &cinfo,TRUE ); | |
140 | |
141 row_stride = image_width * ( bpp / 8 ); | |
142 while ( cinfo.next_scanline < cinfo.image_height ) | |
143 { | |
144 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ]; | |
145 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 ); | |
146 } | |
147 | |
148 jpeg_finish_compress( &cinfo ); | |
149 fclose( o ); | |
150 jpeg_destroy_compress( &cinfo ); | |
151 | |
152 return 0; | |
153 } | |
154 | |
155 static uint32_t draw_frame(uint8_t * src[]) | |
156 { | |
157 char buf[256]; | |
6751 | 158 uint8_t *dst= src[0]; |
5648 | 159 |
160 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
161 | |
162 if ( image_format == IMGFMT_BGR32 ) | |
163 { | |
164 rgb32to24( src[0],image_data,image_width * image_height * 4 ); | |
165 rgb24tobgr24( image_data,image_data,image_width * image_height * 3 ); | |
6751 | 166 dst=image_data; |
5648 | 167 } |
168 if ( image_format == IMGFMT_BGR24 ) | |
169 { | |
170 rgb24tobgr24( src[0],image_data,image_width * image_height * 3 ); | |
6751 | 171 dst=image_data; |
5648 | 172 } |
6751 | 173 return jpeg_write( buf,dst ); |
5648 | 174 } |
175 | |
176 static void draw_osd(void) | |
177 { | |
178 vo_draw_text(image_width, image_height, draw_alpha); | |
179 } | |
180 | |
181 static void flip_page (void) | |
182 { | |
183 char buf[256]; | |
184 | |
185 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) | |
186 { | |
187 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
188 jpeg_write( buf,image_data ); | |
189 } | |
190 } | |
191 | |
192 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
193 { | |
194 if (scale_srcW) | |
195 { | |
196 uint8_t *dst[3]={image_data, NULL, NULL}; | |
197 SwScale_YV12slice(src,stride,y,h, | |
198 dst, image_width*((bpp+7)/8), bpp, | |
199 scale_srcW, scale_srcH, image_width, image_height); | |
200 } | |
201 else | |
202 { | |
203 uint8_t *dst=image_data + (image_width * y + x) * (bpp/8); | |
204 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
205 } | |
206 return 0; | |
207 } | |
208 | |
209 static uint32_t query_format(uint32_t format) | |
210 { | |
211 switch( format ) | |
212 { | |
213 case IMGFMT_IYUV: | |
214 case IMGFMT_I420: | |
215 case IMGFMT_YV12: | |
216 case IMGFMT_RGB|24: | |
217 case IMGFMT_BGR|24: | |
218 case IMGFMT_BGR|32: | |
219 return 1; | |
220 } | |
221 return 0; | |
222 } | |
223 | |
224 static void uninit(void) | |
225 { | |
226 if ( image_data ) | |
227 { | |
228 free( image_data ); | |
229 image_data=NULL; | |
230 } | |
231 } | |
232 | |
233 static void check_events(void) | |
234 { | |
235 } | |
236 | |
237 static uint32_t preinit(const char *arg) | |
238 { | |
239 if(arg) | |
240 { | |
241 printf("JPEG Unknown subdevice: %s\n",arg); | |
242 return ENOSYS; | |
243 } | |
244 return 0; | |
245 } | |
246 | |
247 static uint32_t control(uint32_t request, void *data, ...) | |
248 { | |
249 switch (request) | |
250 { | |
251 case VOCTRL_QUERY_FORMAT: | |
252 return query_format(*((uint32_t*)data)); | |
253 } | |
254 return VO_NOTIMPL; | |
255 } |