Mercurial > mplayer.hg
comparison libvo/vo_png.c @ 7926:7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
- removed built-in OSD rendering
author | arpi |
---|---|
date | Sat, 26 Oct 2002 16:05:47 +0000 |
parents | b64f14fdadfb |
children | 5b39e79af5fe |
comparison
equal
deleted
inserted
replaced
7925:6e937de68683 | 7926:7d2542838d24 |
---|---|
1 #define DISP | |
2 | |
3 /* | 1 /* |
4 * vo_png.c, Portable Network Graphics Renderer for Mplayer | 2 * vo_png.c, Portable Network Graphics Renderer for Mplayer |
5 * | 3 * |
6 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net> | 4 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net> |
7 * | 5 * |
13 #include <stdlib.h> | 11 #include <stdlib.h> |
14 #include <string.h> | 12 #include <string.h> |
15 #include <errno.h> | 13 #include <errno.h> |
16 | 14 |
17 #include <png.h> | 15 #include <png.h> |
18 //#include "/usr/include/png.h" | |
19 | |
20 | 16 |
21 #include "config.h" | 17 #include "config.h" |
22 #include "video_out.h" | 18 #include "video_out.h" |
23 #include "video_out_internal.h" | 19 #include "video_out_internal.h" |
24 #include "sub.h" | |
25 | |
26 #include "../postproc/rgb2rgb.h" | |
27 | 20 |
28 LIBVO_EXTERN (png) | 21 LIBVO_EXTERN (png) |
29 | 22 |
30 static vo_info_t vo_info = | 23 static vo_info_t vo_info = |
31 { | 24 { |
33 "png", | 26 "png", |
34 "Felix Buenemann <atmosfear@users.sourceforge.net>", | 27 "Felix Buenemann <atmosfear@users.sourceforge.net>", |
35 "" | 28 "" |
36 }; | 29 }; |
37 | 30 |
38 #define RGB 0 | |
39 #define BGR 1 | |
40 | |
41 extern int verbose; | 31 extern int verbose; |
42 int z_compression = Z_NO_COMPRESSION; | 32 int z_compression = Z_NO_COMPRESSION; |
43 static int image_width; | |
44 static int image_height; | |
45 static int image_format; | |
46 static uint8_t *image_data=NULL; | |
47 | |
48 static int bpp = 24; | |
49 static int cspace = RGB; | |
50 static int framenum = 0; | 33 static int framenum = 0; |
51 | 34 |
52 struct pngdata { | 35 struct pngdata { |
53 FILE * fp; | 36 FILE * fp; |
54 png_structp png_ptr; | 37 png_structp png_ptr; |
55 png_infop info_ptr; | 38 png_infop info_ptr; |
56 enum {OK,ERROR} status; | 39 enum {OK,ERROR} status; |
57 }; | 40 }; |
58 | |
59 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
60 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width); | |
61 } | |
62 | 41 |
63 static uint32_t | 42 static uint32_t |
64 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | 43 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
65 { | 44 { |
66 image_height = height; | |
67 image_width = width; | |
68 image_format = format; | |
69 //printf("Verbose level is %i\n", verbose); | |
70 | |
71 switch(format) { | |
72 case IMGFMT_BGR24: | |
73 bpp = 24; | |
74 cspace = BGR; | |
75 break; | |
76 case IMGFMT_RGB24: | |
77 bpp = 24; | |
78 cspace = RGB; | |
79 break; | |
80 case IMGFMT_IYUV: | |
81 case IMGFMT_I420: | |
82 case IMGFMT_YV12: | |
83 bpp = 24; | |
84 cspace = BGR; | |
85 yuv2rgb_init(bpp,MODE_RGB); | |
86 image_data = malloc(image_width*image_height*3); | |
87 break; | |
88 default: | |
89 return 1; | |
90 } | |
91 | 45 |
92 if((z_compression >= 0) && (z_compression <= 9)) { | 46 if((z_compression >= 0) && (z_compression <= 9)) { |
93 if(z_compression == 0) { | 47 if(z_compression == 0) { |
94 printf("PNG Warning: compression level set to 0, compression disabled!\n"); | 48 printf("PNG Warning: compression level set to 0, compression disabled!\n"); |
95 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | 49 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); |
113 { | 67 { |
114 return &vo_info; | 68 return &vo_info; |
115 } | 69 } |
116 | 70 |
117 | 71 |
118 struct pngdata create_png (char * fname) | 72 struct pngdata create_png (char * fname, int image_width, int image_height, int swapped) |
119 { | 73 { |
120 struct pngdata png; | 74 struct pngdata png; |
121 | 75 |
122 /*png_structp png_ptr = png_create_write_struct | 76 /*png_structp png_ptr = png_create_write_struct |
123 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | 77 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, |
124 user_error_fn, user_warning_fn);*/ | 78 user_error_fn, user_warning_fn);*/ |
125 //png_byte *row_pointers[image_height]; | 79 //png_byte *row_pointers[image_height]; |
126 png.png_ptr = png_create_write_struct | 80 png.png_ptr = png_create_write_struct |
172 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 126 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
173 | 127 |
174 if(verbose > 1) printf("PNG Write Info\n"); | 128 if(verbose > 1) printf("PNG Write Info\n"); |
175 png_write_info(png.png_ptr, png.info_ptr); | 129 png_write_info(png.png_ptr, png.info_ptr); |
176 | 130 |
177 if(cspace) { | 131 if(swapped) { |
178 if(verbose > 1) printf("PNG Set BGR Conversion\n"); | 132 if(verbose > 1) printf("PNG Set BGR Conversion\n"); |
179 png_set_bgr(png.png_ptr); | 133 png_set_bgr(png.png_ptr); |
180 } | 134 } |
181 | 135 |
182 png.status = OK; | 136 png.status = OK; |
183 return png; | 137 return png; |
184 | |
185 } | 138 } |
186 | 139 |
187 static uint8_t destroy_png(struct pngdata png) { | 140 static uint8_t destroy_png(struct pngdata png) { |
188 | 141 |
189 if(verbose > 1) printf("PNG Write End\n"); | 142 if(verbose > 1) printf("PNG Write End\n"); |
195 fclose (png.fp); | 148 fclose (png.fp); |
196 | 149 |
197 return 0; | 150 return 0; |
198 } | 151 } |
199 | 152 |
200 static uint32_t draw_frame(uint8_t * src[]) | |
201 { | |
202 return -1; | |
203 } | |
204 | |
205 static uint32_t draw_image(mp_image_t* mpi){ | 153 static uint32_t draw_image(mp_image_t* mpi){ |
206 char buf[100]; | 154 char buf[100]; |
207 int k, bppmul = bpp/8; | 155 int k; |
208 struct pngdata png; | 156 struct pngdata png; |
209 png_byte *row_pointers[image_height]; | 157 png_byte *row_pointers[mpi->h]; |
210 | 158 |
211 // if -dr or -slices then do nothing: | 159 // if -dr or -slices then do nothing: |
212 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | 160 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; |
213 | 161 |
214 snprintf (buf, 100, "%08d.png", ++framenum); | 162 snprintf (buf, 100, "%08d.png", ++framenum); |
215 | 163 |
216 png = create_png(buf); | 164 png = create_png(buf, mpi->w, mpi->h, mpi->flags&MP_IMGFLAG_SWAPPED); |
217 | 165 |
218 if(png.status){ | 166 if(png.status){ |
219 printf("PNG Error in create_png\n"); | 167 printf("PNG Error in create_png\n"); |
220 return 1; | 168 return 1; |
221 } | 169 } |
222 | 170 |
223 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | 171 if(verbose > 1) printf("PNG Creating Row Pointers\n"); |
224 for ( k = 0; k < image_height; k++ ) | 172 for ( k = 0; k < mpi->h; k++ ) |
225 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; | 173 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; |
226 | 174 |
227 //png_write_flush(png.png_ptr); | 175 //png_write_flush(png.png_ptr); |
228 //png_set_flush(png.png_ptr, nrows); | 176 //png_set_flush(png.png_ptr, nrows); |
229 | 177 |
233 destroy_png(png); | 181 destroy_png(png); |
234 | 182 |
235 return VO_TRUE; | 183 return VO_TRUE; |
236 } | 184 } |
237 | 185 |
238 static void draw_osd(void) | 186 static void draw_osd(void){} |
239 { | 187 |
240 if(image_data) vo_draw_text(image_width, image_height, draw_alpha); | 188 static void flip_page (void){} |
241 } | 189 |
242 | 190 static uint32_t draw_frame(uint8_t * src[]) |
243 static void flip_page (void) | 191 { |
244 { | 192 return -1; |
245 char buf[100]; | |
246 int k, bppmul = bpp/8; | |
247 struct pngdata png; | |
248 png_byte *row_pointers[image_height]; | |
249 | |
250 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) { | |
251 | |
252 snprintf (buf, 100, "%08d.png", ++framenum); | |
253 | |
254 png = create_png(buf); | |
255 | |
256 if(png.status){ | |
257 printf("PNG Error in create_png\n"); | |
258 } | |
259 | |
260 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
261 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul]; | |
262 | |
263 //png_write_flush(png.png_ptr); | |
264 //png_set_flush(png.png_ptr, nrows); | |
265 | |
266 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
267 png_write_image(png.png_ptr, row_pointers); | |
268 | |
269 destroy_png(png); | |
270 } | |
271 } | 193 } |
272 | 194 |
273 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | 195 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) |
274 { | 196 { |
275 uint8_t *dst = image_data + (image_width * y + x) * (bpp/8); | 197 return -1; |
276 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
277 return 0; | |
278 } | 198 } |
279 | 199 |
280 static uint32_t | 200 static uint32_t |
281 query_format(uint32_t format) | 201 query_format(uint32_t format) |
282 { | 202 { |
283 switch(format){ | 203 switch(format){ |
284 case IMGFMT_IYUV: | |
285 case IMGFMT_I420: | |
286 case IMGFMT_YV12: | |
287 return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE; | |
288 case IMGFMT_RGB|24: | 204 case IMGFMT_RGB|24: |
289 case IMGFMT_BGR|24: | 205 case IMGFMT_BGR|24: |
290 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; | 206 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
291 } | 207 } |
292 return 0; | 208 return 0; |
293 } | 209 } |
294 | 210 |
295 static void | 211 static void uninit(void){} |
296 uninit(void) | 212 |
297 { | 213 static void check_events(void){} |
298 if(image_data){ free(image_data);image_data=NULL;} | |
299 } | |
300 | |
301 | |
302 static void check_events(void) | |
303 { | |
304 } | |
305 | 214 |
306 static uint32_t preinit(const char *arg) | 215 static uint32_t preinit(const char *arg) |
307 { | 216 { |
308 if(arg) | 217 if(arg) |
309 { | 218 { |