Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 4221:401149ba73fd
Fixed bug with benchmark option
author | albeu |
---|---|
date | Thu, 17 Jan 2002 20:25:55 +0000 |
parents | 974e028471a4 |
children | ed5b85b713a3 |
rev | line source |
---|---|
527 | 1 #define DISP |
2 | |
3 /* | |
530 | 4 * vo_png.c, Portable Network Graphics Renderer for Mplayer |
527 | 5 * |
530 | 6 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net> |
527 | 7 * |
530 | 8 * Uses libpng (which uses zlib), so see according licenses. |
527 | 9 * |
10 */ | |
11 | |
12 #include <stdio.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
612 | 15 #include <errno.h> |
527 | 16 |
17 #include <png.h> | |
18 //#include "/usr/include/png.h" | |
19 | |
20 | |
21 #include "config.h" | |
22 #include "video_out.h" | |
23 #include "video_out_internal.h" | |
24 | |
4060
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
25 #include "../postproc/swscale.h" |
2732 | 26 #include "../postproc/rgb2rgb.h" |
527 | 27 |
28 LIBVO_EXTERN (png) | |
29 | |
30 static vo_info_t vo_info = | |
31 { | |
32 "PNG file", | |
33 "png", | |
34 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
35 "" | |
36 }; | |
37 | |
38 #define RGB 0 | |
39 #define BGR 1 | |
40 | |
41 extern int verbose; | |
42 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 //static char *image_data; | |
4060
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
48 static unsigned int scale_srcW = 0, scale_srcH = 0; |
527 | 49 |
50 static int bpp = 24; | |
51 static int cspace = RGB; | |
52 static int framenum = 0; | |
53 | |
54 struct pngdata { | |
55 FILE * fp; | |
56 png_structp png_ptr; | |
57 png_infop info_ptr; | |
58 enum {OK,ERROR} status; | |
59 }; | |
60 | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
61 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
62 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width); |
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
63 } |
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
64 |
527 | 65 static uint32_t |
66 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | |
67 { | |
4060
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
68 if (fullscreen&0x04 && (width != d_width || height != d_height) && format==IMGFMT_YV12) { |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
69 /* software scaling */ |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
70 image_width = (d_width + 7) & ~7; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
71 image_height = d_height; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
72 scale_srcW = width; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
73 scale_srcH = height; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
74 SwScale_Init(); |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
75 } |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
76 else { |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
77 image_height = height; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
78 image_width = width; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
79 } |
527 | 80 image_format = format; |
81 //printf("Verbose level is %i\n", verbose); | |
82 | |
83 switch(format) { | |
84 case IMGFMT_BGR24: | |
85 bpp = 24; | |
86 cspace = BGR; | |
87 break; | |
88 case IMGFMT_RGB24: | |
89 bpp = 24; | |
90 cspace = RGB; | |
91 break; | |
92 case IMGFMT_YV12: | |
93 bpp = 24; | |
94 cspace = RGB; | |
95 yuv2rgb_init(bpp,MODE_BGR); | |
96 image_data = malloc(image_width*image_height*3); | |
97 break; | |
98 default: | |
99 return 1; | |
100 } | |
101 | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
102 if((z_compression >= 0) && (z_compression <= 9)) { |
527 | 103 if(z_compression == 0) { |
104 printf("PNG Warning: compression level set to 0, compression disabled!\n"); | |
105 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
106 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
107 } | |
108 } | |
109 else { | |
110 printf("PNG Warning: compression level out of range setting to 1!\n"); | |
111 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
112 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
113 z_compression = Z_BEST_SPEED; | |
114 } | |
115 | |
116 if(verbose) printf("PNG Compression level %i\n", z_compression); | |
117 | |
118 return 0; | |
119 } | |
120 | |
121 static const vo_info_t* | |
122 get_info(void) | |
123 { | |
124 return &vo_info; | |
125 } | |
126 | |
127 | |
128 struct pngdata create_png (char * fname) | |
129 { | |
130 struct pngdata png; | |
131 | |
132 /*png_structp png_ptr = png_create_write_struct | |
133 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
134 user_error_fn, user_warning_fn);*/ | |
135 //png_byte *row_pointers[image_height]; | |
136 png.png_ptr = png_create_write_struct | |
137 (PNG_LIBPNG_VER_STRING, NULL, | |
138 NULL, NULL); | |
139 png.info_ptr = png_create_info_struct(png.png_ptr); | |
140 | |
141 if (!png.png_ptr) { | |
142 if(verbose > 1) printf("PNG Failed to init png pointer\n"); | |
143 png.status = ERROR; | |
144 return png; | |
145 } | |
146 | |
147 if (!png.info_ptr) { | |
148 if(verbose > 1) printf("PNG Failed to init png infopointer\n"); | |
149 png_destroy_write_struct(&png.png_ptr, | |
150 (png_infopp)NULL); | |
151 png.status = ERROR; | |
152 return png; | |
153 } | |
154 | |
155 if (setjmp(png.png_ptr->jmpbuf)) { | |
156 if(verbose > 1) printf("PNG Internal error!\n"); | |
157 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
158 fclose(png.fp); | |
159 png.status = ERROR; | |
160 return png; | |
161 } | |
162 | |
163 png.fp = fopen (fname, "wb"); | |
164 if (png.fp == NULL) { | |
612 | 165 printf("\nPNG Error opening %s for writing!\n", strerror(errno)); |
527 | 166 png.status = ERROR; |
167 return png; | |
168 } | |
169 | |
170 if(verbose > 1) printf("PNG Init IO\n"); | |
171 png_init_io(png.png_ptr, png.fp); | |
172 | |
173 /* set the zlib compression level */ | |
174 png_set_compression_level(png.png_ptr, z_compression); | |
175 | |
176 | |
177 /*png_set_IHDR(png_ptr, info_ptr, width, height, | |
178 bit_depth, color_type, interlace_type, | |
179 compression_type, filter_type)*/ | |
180 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, | |
181 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, | |
182 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
183 | |
184 if(verbose > 1) printf("PNG Write Info\n"); | |
185 png_write_info(png.png_ptr, png.info_ptr); | |
186 | |
187 if(cspace) { | |
188 if(verbose > 1) printf("PNG Set BGR Conversion\n"); | |
189 png_set_bgr(png.png_ptr); | |
190 } | |
191 | |
192 png.status = OK; | |
193 return png; | |
194 | |
195 } | |
196 | |
197 static uint8_t destroy_png(struct pngdata png) { | |
198 | |
199 if(verbose > 1) printf("PNG Write End\n"); | |
200 png_write_end(png.png_ptr, png.info_ptr); | |
201 | |
202 if(verbose > 1) printf("PNG Destroy Write Struct\n"); | |
203 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
204 | |
205 fclose (png.fp); | |
206 | |
207 return 0; | |
208 } | |
209 | |
210 static uint32_t draw_frame(uint8_t * src[]) | |
211 { | |
212 char buf[100]; | |
213 int k, bppmul = bpp/8; | |
214 struct pngdata png; | |
215 png_byte *row_pointers[image_height]; | |
216 | |
1078 | 217 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 218 |
219 png = create_png(buf); | |
220 | |
221 if(png.status){ | |
222 printf("PNG Error in create_png\n"); | |
223 return 1; | |
224 } | |
225 | |
226 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
227 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul]; | |
228 | |
229 //png_write_flush(png.png_ptr); | |
230 //png_set_flush(png.png_ptr, nrows); | |
231 | |
232 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
233 png_write_image(png.png_ptr, row_pointers); | |
234 | |
235 return destroy_png(png); | |
236 | |
237 } | |
238 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
239 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
240 { |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
241 vo_draw_text(image_width, image_height, draw_alpha); |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
242 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
243 |
527 | 244 static void flip_page (void) |
245 { | |
246 char buf[100]; | |
247 int k, bppmul = bpp/8; | |
248 struct pngdata png; | |
249 png_byte *row_pointers[image_height]; | |
250 | |
251 if(image_format == IMGFMT_YV12) { | |
252 | |
1078 | 253 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 254 |
255 png = create_png(buf); | |
256 | |
257 if(png.status){ | |
258 printf("PNG Error in create_png\n"); | |
259 } | |
260 | |
261 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
262 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul]; | |
263 | |
264 //png_write_flush(png.png_ptr); | |
265 //png_set_flush(png.png_ptr, nrows); | |
266 | |
267 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
268 png_write_image(png.png_ptr, row_pointers); | |
269 | |
270 destroy_png(png); | |
271 } | |
272 } | |
273 | |
274 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
275 { | |
4060
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
276 if (scale_srcW) { |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
277 uint8_t *dst[3] = {image_data, NULL, NULL}; |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
278 SwScale_YV12slice(src,stride,y,h, |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
279 dst, image_width*((bpp+7)/8), bpp, |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
280 scale_srcW, scale_srcH, image_width, image_height); |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
281 } |
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
282 else { |
527 | 283 uint8_t *dst; |
284 dst = image_data + (image_width * y + x) * (bpp/8); | |
285 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
4060
974e028471a4
SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents:
3950
diff
changeset
|
286 } |
527 | 287 return 0; |
288 } | |
289 | |
290 static uint32_t | |
291 query_format(uint32_t format) | |
292 { | |
293 switch(format){ | |
294 case IMGFMT_YV12: | |
295 case IMGFMT_RGB|24: | |
296 case IMGFMT_BGR|24: | |
297 return 1; | |
298 } | |
299 return 0; | |
300 } | |
301 | |
302 static void | |
303 uninit(void) | |
304 { | |
305 if(image_data){ free(image_data);image_data=NULL;} | |
306 } | |
307 | |
308 | |
309 static void check_events(void) | |
310 { | |
311 } |