Mercurial > mplayer.hg
annotate libvo/vo_jpeg.c @ 8538:6973e76d95b2
In this situation it was easier to fix yours. I applied these 3 points
(fixed locking echo, removed excessive cut to make script a bit faster
and shortened grep) and changed copy mark from "x" to "" in order to use
-z and -n tests.
patch by GoTaR <priv0.onet.pl->gotar>
author | arpi |
---|---|
date | Mon, 23 Dec 2002 17:28:19 +0000 |
parents | 1ac2523775ad |
children | 555d64fc02b8 |
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 | |
123 cinfo.image_width=image_width; | |
124 cinfo.image_height=image_height; | |
125 cinfo.input_components=bpp / 8; | |
126 cinfo.in_color_space=JCS_RGB; | |
8267 | 127 |
128 jpeg_set_defaults( &cinfo ); | |
129 jpeg_set_quality( &cinfo,jpeg_quality,jpeg_baseline ); | |
5648 | 130 cinfo.optimize_coding=jpeg_optimize; |
131 cinfo.smoothing_factor=jpeg_smooth; | |
8267 | 132 |
5648 | 133 if ( jpeg_progressive_mode ) jpeg_simple_progression( &cinfo ); |
134 jpeg_start_compress( &cinfo,TRUE ); | |
135 | |
136 row_stride = image_width * ( bpp / 8 ); | |
137 while ( cinfo.next_scanline < cinfo.image_height ) | |
138 { | |
139 row_pointer[0]=&buffer[ cinfo.next_scanline * row_stride ]; | |
140 (void)jpeg_write_scanlines( &cinfo,row_pointer,1 ); | |
141 } | |
142 | |
143 jpeg_finish_compress( &cinfo ); | |
144 fclose( o ); | |
145 jpeg_destroy_compress( &cinfo ); | |
146 | |
147 return 0; | |
148 } | |
149 | |
150 static uint32_t draw_frame(uint8_t * src[]) | |
151 { | |
152 char buf[256]; | |
6751 | 153 uint8_t *dst= src[0]; |
5648 | 154 |
155 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
156 | |
157 if ( image_format == IMGFMT_BGR32 ) | |
158 { | |
159 rgb32to24( src[0],image_data,image_width * image_height * 4 ); | |
160 rgb24tobgr24( image_data,image_data,image_width * image_height * 3 ); | |
6751 | 161 dst=image_data; |
5648 | 162 } |
163 if ( image_format == IMGFMT_BGR24 ) | |
164 { | |
165 rgb24tobgr24( src[0],image_data,image_width * image_height * 3 ); | |
6751 | 166 dst=image_data; |
5648 | 167 } |
6751 | 168 return jpeg_write( buf,dst ); |
5648 | 169 } |
170 | |
171 static void draw_osd(void) | |
172 { | |
173 vo_draw_text(image_width, image_height, draw_alpha); | |
174 } | |
175 | |
176 static void flip_page (void) | |
177 { | |
178 char buf[256]; | |
179 | |
180 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) | |
181 { | |
182 snprintf (buf, 256, "%s/%08d.jpg", jpeg_outdir, ++framenum); | |
183 jpeg_write( buf,image_data ); | |
184 } | |
185 } | |
186 | |
187 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
188 { | |
189 if (scale_srcW) | |
190 { | |
191 uint8_t *dst[3]={image_data, NULL, NULL}; | |
192 SwScale_YV12slice(src,stride,y,h, | |
193 dst, image_width*((bpp+7)/8), bpp, | |
194 scale_srcW, scale_srcH, image_width, image_height); | |
195 } | |
196 else | |
197 { | |
198 uint8_t *dst=image_data + (image_width * y + x) * (bpp/8); | |
199 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
200 } | |
201 return 0; | |
202 } | |
203 | |
204 static uint32_t query_format(uint32_t format) | |
205 { | |
206 switch( format ) | |
207 { | |
208 case IMGFMT_IYUV: | |
209 case IMGFMT_I420: | |
210 case IMGFMT_YV12: | |
211 case IMGFMT_RGB|24: | |
212 case IMGFMT_BGR|24: | |
213 case IMGFMT_BGR|32: | |
214 return 1; | |
215 } | |
216 return 0; | |
217 } | |
218 | |
219 static void uninit(void) | |
220 { | |
221 if ( image_data ) | |
222 { | |
223 free( image_data ); | |
224 image_data=NULL; | |
225 } | |
226 } | |
227 | |
228 static void check_events(void) | |
229 { | |
230 } | |
231 | |
232 static uint32_t preinit(const char *arg) | |
233 { | |
234 if(arg) | |
235 { | |
236 printf("JPEG Unknown subdevice: %s\n",arg); | |
237 return ENOSYS; | |
238 } | |
239 return 0; | |
240 } | |
241 | |
242 static uint32_t control(uint32_t request, void *data, ...) | |
243 { | |
244 switch (request) | |
245 { | |
246 case VOCTRL_QUERY_FORMAT: | |
247 return query_format(*((uint32_t*)data)); | |
248 } | |
249 return VO_NOTIMPL; | |
250 } |