Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 7137:9a44c38d388c
Fixed some breakages of single-buffer rendering of tdfx
author | mark |
---|---|
date | Thu, 29 Aug 2002 12:04:21 +0000 |
parents | eca7dbad0166 |
children | c4434bdf6e51 |
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" | |
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; | |
5659 | 49 char * jpeg_outdir = "."; |
5648 | 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 | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6751
diff
changeset
|
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) |
5648 | 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]; | |
6751 | 157 uint8_t *dst= src[0]; |
5648 | 158 |
159 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
160 | |
161 if ( image_format == IMGFMT_BGR32 ) | |
162 { | |
163 rgb32to24( src[0],image_data,image_width * image_height * 4 ); | |
164 rgb24tobgr24( image_data,image_data,image_width * image_height * 3 ); | |
6751 | 165 dst=image_data; |
5648 | 166 } |
167 if ( image_format == IMGFMT_BGR24 ) | |
168 { | |
169 rgb24tobgr24( src[0],image_data,image_width * image_height * 3 ); | |
6751 | 170 dst=image_data; |
5648 | 171 } |
6751 | 172 return jpeg_write( buf,dst ); |
5648 | 173 } |
174 | |
175 static void draw_osd(void) | |
176 { | |
177 vo_draw_text(image_width, image_height, draw_alpha); | |
178 } | |
179 | |
180 static void flip_page (void) | |
181 { | |
182 char buf[256]; | |
183 | |
184 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) | |
185 { | |
186 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
187 jpeg_write( buf,image_data ); | |
188 } | |
189 } | |
190 | |
191 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
192 { | |
193 // hack: swap planes for I420 ;) -- alex | |
194 if ((image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) | |
195 { | |
196 uint8_t *src_i420[3]; | |
197 | |
198 src_i420[0]=src[0]; | |
199 src_i420[1]=src[2]; | |
200 src_i420[2]=src[1]; | |
201 src=src_i420; | |
202 } | |
203 | |
204 if (scale_srcW) | |
205 { | |
206 uint8_t *dst[3]={image_data, NULL, NULL}; | |
207 SwScale_YV12slice(src,stride,y,h, | |
208 dst, image_width*((bpp+7)/8), bpp, | |
209 scale_srcW, scale_srcH, image_width, image_height); | |
210 } | |
211 else | |
212 { | |
213 uint8_t *dst=image_data + (image_width * y + x) * (bpp/8); | |
214 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
215 } | |
216 return 0; | |
217 } | |
218 | |
219 static uint32_t query_format(uint32_t format) | |
220 { | |
221 switch( format ) | |
222 { | |
223 case IMGFMT_IYUV: | |
224 case IMGFMT_I420: | |
225 case IMGFMT_YV12: | |
226 case IMGFMT_RGB|24: | |
227 case IMGFMT_BGR|24: | |
228 case IMGFMT_BGR|32: | |
229 return 1; | |
230 } | |
231 return 0; | |
232 } | |
233 | |
234 static void uninit(void) | |
235 { | |
236 if ( image_data ) | |
237 { | |
238 free( image_data ); | |
239 image_data=NULL; | |
240 } | |
241 } | |
242 | |
243 static void check_events(void) | |
244 { | |
245 } | |
246 | |
247 static uint32_t preinit(const char *arg) | |
248 { | |
249 if(arg) | |
250 { | |
251 printf("JPEG Unknown subdevice: %s\n",arg); | |
252 return ENOSYS; | |
253 } | |
254 return 0; | |
255 } | |
256 | |
257 static uint32_t control(uint32_t request, void *data, ...) | |
258 { | |
259 switch (request) | |
260 { | |
261 case VOCTRL_QUERY_FORMAT: | |
262 return query_format(*((uint32_t*)data)); | |
263 } | |
264 return VO_NOTIMPL; | |
265 } |