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