Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 1661:7a7beab9d7c6
preliminary linuxdoc version of docs in polish. this is not only unfinished
but there are some technical problems ( polish national characters in many outputs
- dvi, info, html! )
author | eyck |
---|---|
date | Thu, 23 Aug 2001 13:31:58 +0000 |
parents | d40f2b686846 |
children | ae79207a3055 |
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 | |
25 #include "yuv2rgb.h" | |
26 | |
27 LIBVO_EXTERN (png) | |
28 | |
29 static vo_info_t vo_info = | |
30 { | |
31 "PNG file", | |
32 "png", | |
33 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
34 "" | |
35 }; | |
36 | |
37 #define RGB 0 | |
38 #define BGR 1 | |
39 | |
40 extern int verbose; | |
41 int z_compression = Z_NO_COMPRESSION; | |
42 static int image_width; | |
43 static int image_height; | |
44 static int image_format; | |
45 static uint8_t *image_data=NULL; | |
46 //static char *image_data; | |
47 | |
48 static int bpp = 24; | |
49 static int cspace = RGB; | |
50 static int framenum = 0; | |
51 | |
52 struct pngdata { | |
53 FILE * fp; | |
54 png_structp png_ptr; | |
55 png_infop info_ptr; | |
56 enum {OK,ERROR} status; | |
57 }; | |
58 | |
59 static uint32_t | |
60 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) | |
61 { | |
62 image_height = height; | |
63 image_width = width; | |
64 image_format = format; | |
65 | |
66 //printf("Verbose level is %i\n", verbose); | |
67 | |
68 switch(format) { | |
69 case IMGFMT_BGR24: | |
70 bpp = 24; | |
71 cspace = BGR; | |
72 break; | |
73 case IMGFMT_RGB24: | |
74 bpp = 24; | |
75 cspace = RGB; | |
76 break; | |
77 case IMGFMT_YV12: | |
78 bpp = 24; | |
79 cspace = RGB; | |
80 yuv2rgb_init(bpp,MODE_BGR); | |
81 image_data = malloc(image_width*image_height*3); | |
82 break; | |
83 default: | |
84 return 1; | |
85 } | |
86 | |
87 if((z_compression < 0) || (z_compression < 9)) { | |
88 if(z_compression == 0) { | |
89 printf("PNG Warning: compression level set to 0, compression disabled!\n"); | |
90 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
91 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
92 } | |
93 } | |
94 else { | |
95 printf("PNG Warning: compression level out of range setting to 1!\n"); | |
96 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
97 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
98 z_compression = Z_BEST_SPEED; | |
99 } | |
100 | |
101 if(verbose) printf("PNG Compression level %i\n", z_compression); | |
102 | |
103 return 0; | |
104 } | |
105 | |
106 static const vo_info_t* | |
107 get_info(void) | |
108 { | |
109 return &vo_info; | |
110 } | |
111 | |
112 | |
113 struct pngdata create_png (char * fname) | |
114 { | |
115 struct pngdata png; | |
116 | |
117 /*png_structp png_ptr = png_create_write_struct | |
118 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
119 user_error_fn, user_warning_fn);*/ | |
120 //png_byte *row_pointers[image_height]; | |
121 png.png_ptr = png_create_write_struct | |
122 (PNG_LIBPNG_VER_STRING, NULL, | |
123 NULL, NULL); | |
124 png.info_ptr = png_create_info_struct(png.png_ptr); | |
125 | |
126 if (!png.png_ptr) { | |
127 if(verbose > 1) printf("PNG Failed to init png pointer\n"); | |
128 png.status = ERROR; | |
129 return png; | |
130 } | |
131 | |
132 if (!png.info_ptr) { | |
133 if(verbose > 1) printf("PNG Failed to init png infopointer\n"); | |
134 png_destroy_write_struct(&png.png_ptr, | |
135 (png_infopp)NULL); | |
136 png.status = ERROR; | |
137 return png; | |
138 } | |
139 | |
140 if (setjmp(png.png_ptr->jmpbuf)) { | |
141 if(verbose > 1) printf("PNG Internal error!\n"); | |
142 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
143 fclose(png.fp); | |
144 png.status = ERROR; | |
145 return png; | |
146 } | |
147 | |
148 png.fp = fopen (fname, "wb"); | |
149 if (png.fp == NULL) { | |
612 | 150 printf("\nPNG Error opening %s for writing!\n", strerror(errno)); |
527 | 151 png.status = ERROR; |
152 return png; | |
153 } | |
154 | |
155 if(verbose > 1) printf("PNG Init IO\n"); | |
156 png_init_io(png.png_ptr, png.fp); | |
157 | |
158 /* set the zlib compression level */ | |
159 png_set_compression_level(png.png_ptr, z_compression); | |
160 | |
161 | |
162 /*png_set_IHDR(png_ptr, info_ptr, width, height, | |
163 bit_depth, color_type, interlace_type, | |
164 compression_type, filter_type)*/ | |
165 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, | |
166 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, | |
167 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
168 | |
169 if(verbose > 1) printf("PNG Write Info\n"); | |
170 png_write_info(png.png_ptr, png.info_ptr); | |
171 | |
172 if(cspace) { | |
173 if(verbose > 1) printf("PNG Set BGR Conversion\n"); | |
174 png_set_bgr(png.png_ptr); | |
175 } | |
176 | |
177 png.status = OK; | |
178 return png; | |
179 | |
180 } | |
181 | |
182 static uint8_t destroy_png(struct pngdata png) { | |
183 | |
184 if(verbose > 1) printf("PNG Write End\n"); | |
185 png_write_end(png.png_ptr, png.info_ptr); | |
186 | |
187 if(verbose > 1) printf("PNG Destroy Write Struct\n"); | |
188 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
189 | |
190 fclose (png.fp); | |
191 | |
192 return 0; | |
193 } | |
194 | |
195 static uint32_t draw_frame(uint8_t * src[]) | |
196 { | |
197 char buf[100]; | |
198 int k, bppmul = bpp/8; | |
199 struct pngdata png; | |
200 png_byte *row_pointers[image_height]; | |
201 | |
1078 | 202 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 203 |
204 png = create_png(buf); | |
205 | |
206 if(png.status){ | |
207 printf("PNG Error in create_png\n"); | |
208 return 1; | |
209 } | |
210 | |
211 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
212 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul]; | |
213 | |
214 //png_write_flush(png.png_ptr); | |
215 //png_set_flush(png.png_ptr, nrows); | |
216 | |
217 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
218 png_write_image(png.png_ptr, row_pointers); | |
219 | |
220 return destroy_png(png); | |
221 | |
222 } | |
223 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
224 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
225 { |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
226 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
227 |
527 | 228 static void flip_page (void) |
229 { | |
230 char buf[100]; | |
231 int k, bppmul = bpp/8; | |
232 struct pngdata png; | |
233 png_byte *row_pointers[image_height]; | |
234 | |
235 if(image_format == IMGFMT_YV12) { | |
236 | |
1078 | 237 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 238 |
239 png = create_png(buf); | |
240 | |
241 if(png.status){ | |
242 printf("PNG Error in create_png\n"); | |
243 } | |
244 | |
245 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
246 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul]; | |
247 | |
248 //png_write_flush(png.png_ptr); | |
249 //png_set_flush(png.png_ptr, nrows); | |
250 | |
251 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
252 png_write_image(png.png_ptr, row_pointers); | |
253 | |
254 destroy_png(png); | |
255 } | |
256 } | |
257 | |
258 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
259 { | |
260 uint8_t *dst; | |
261 | |
262 dst = image_data + (image_width * y + x) * (bpp/8); | |
263 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); | |
264 | |
265 return 0; | |
266 } | |
267 | |
268 static uint32_t | |
269 query_format(uint32_t format) | |
270 { | |
271 switch(format){ | |
272 case IMGFMT_YV12: | |
273 case IMGFMT_RGB|24: | |
274 case IMGFMT_BGR|24: | |
275 return 1; | |
276 } | |
277 return 0; | |
278 } | |
279 | |
280 static void | |
281 uninit(void) | |
282 { | |
283 if(image_data){ free(image_data);image_data=NULL;} | |
284 } | |
285 | |
286 | |
287 static void check_events(void) | |
288 { | |
289 } |