Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 7535:37bc382a61e6
no fix window size
author | pontscho |
---|---|
date | Sat, 28 Sep 2002 19:00:50 +0000 |
parents | c4434bdf6e51 |
children | 3f218f3172f3 |
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" | |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
7124
diff
changeset
|
24 #include "sub.h" |
527 | 25 |
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 | |
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 | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
59 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
|
60 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
|
61 } |
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
62 |
527 | 63 static uint32_t |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6132
diff
changeset
|
64 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
527 | 65 { |
6132 | 66 image_height = height; |
67 image_width = width; | |
527 | 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; | |
4353 | 80 case IMGFMT_IYUV: |
81 case IMGFMT_I420: | |
527 | 82 case IMGFMT_YV12: |
83 bpp = 24; | |
4796 | 84 cspace = BGR; |
85 yuv2rgb_init(bpp,MODE_RGB); | |
527 | 86 image_data = malloc(image_width*image_height*3); |
87 break; | |
88 default: | |
89 return 1; | |
90 } | |
91 | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
92 if((z_compression >= 0) && (z_compression <= 9)) { |
527 | 93 if(z_compression == 0) { |
94 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"); | |
96 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
97 } | |
98 } | |
99 else { | |
100 printf("PNG Warning: compression level out of range setting to 1!\n"); | |
101 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
102 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
103 z_compression = Z_BEST_SPEED; | |
104 } | |
105 | |
106 if(verbose) printf("PNG Compression level %i\n", z_compression); | |
107 | |
108 return 0; | |
109 } | |
110 | |
111 static const vo_info_t* | |
112 get_info(void) | |
113 { | |
114 return &vo_info; | |
115 } | |
116 | |
117 | |
118 struct pngdata create_png (char * fname) | |
119 { | |
120 struct pngdata png; | |
121 | |
122 /*png_structp png_ptr = png_create_write_struct | |
123 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
124 user_error_fn, user_warning_fn);*/ | |
125 //png_byte *row_pointers[image_height]; | |
126 png.png_ptr = png_create_write_struct | |
127 (PNG_LIBPNG_VER_STRING, NULL, | |
128 NULL, NULL); | |
129 png.info_ptr = png_create_info_struct(png.png_ptr); | |
130 | |
131 if (!png.png_ptr) { | |
132 if(verbose > 1) printf("PNG Failed to init png pointer\n"); | |
133 png.status = ERROR; | |
134 return png; | |
135 } | |
136 | |
137 if (!png.info_ptr) { | |
138 if(verbose > 1) printf("PNG Failed to init png infopointer\n"); | |
139 png_destroy_write_struct(&png.png_ptr, | |
140 (png_infopp)NULL); | |
141 png.status = ERROR; | |
142 return png; | |
143 } | |
144 | |
145 if (setjmp(png.png_ptr->jmpbuf)) { | |
146 if(verbose > 1) printf("PNG Internal error!\n"); | |
147 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
148 fclose(png.fp); | |
149 png.status = ERROR; | |
150 return png; | |
151 } | |
152 | |
153 png.fp = fopen (fname, "wb"); | |
154 if (png.fp == NULL) { | |
612 | 155 printf("\nPNG Error opening %s for writing!\n", strerror(errno)); |
527 | 156 png.status = ERROR; |
157 return png; | |
158 } | |
159 | |
160 if(verbose > 1) printf("PNG Init IO\n"); | |
161 png_init_io(png.png_ptr, png.fp); | |
162 | |
163 /* set the zlib compression level */ | |
164 png_set_compression_level(png.png_ptr, z_compression); | |
165 | |
166 | |
167 /*png_set_IHDR(png_ptr, info_ptr, width, height, | |
168 bit_depth, color_type, interlace_type, | |
169 compression_type, filter_type)*/ | |
170 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, | |
171 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, | |
172 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
173 | |
174 if(verbose > 1) printf("PNG Write Info\n"); | |
175 png_write_info(png.png_ptr, png.info_ptr); | |
176 | |
177 if(cspace) { | |
178 if(verbose > 1) printf("PNG Set BGR Conversion\n"); | |
179 png_set_bgr(png.png_ptr); | |
180 } | |
181 | |
182 png.status = OK; | |
183 return png; | |
184 | |
185 } | |
186 | |
187 static uint8_t destroy_png(struct pngdata png) { | |
188 | |
189 if(verbose > 1) printf("PNG Write End\n"); | |
190 png_write_end(png.png_ptr, png.info_ptr); | |
191 | |
192 if(verbose > 1) printf("PNG Destroy Write Struct\n"); | |
193 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
194 | |
195 fclose (png.fp); | |
196 | |
197 return 0; | |
198 } | |
199 | |
200 static uint32_t draw_frame(uint8_t * src[]) | |
201 { | |
202 char buf[100]; | |
203 int k, bppmul = bpp/8; | |
204 struct pngdata png; | |
205 png_byte *row_pointers[image_height]; | |
206 | |
1078 | 207 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 208 |
209 png = create_png(buf); | |
210 | |
211 if(png.status){ | |
212 printf("PNG Error in create_png\n"); | |
213 return 1; | |
214 } | |
215 | |
216 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
217 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul]; | |
218 | |
219 //png_write_flush(png.png_ptr); | |
220 //png_set_flush(png.png_ptr, nrows); | |
221 | |
222 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
223 png_write_image(png.png_ptr, row_pointers); | |
224 | |
225 return destroy_png(png); | |
226 | |
227 } | |
228 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
229 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
230 { |
6132 | 231 if(image_data) 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
|
232 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
233 |
527 | 234 static void flip_page (void) |
235 { | |
236 char buf[100]; | |
237 int k, bppmul = bpp/8; | |
238 struct pngdata png; | |
239 png_byte *row_pointers[image_height]; | |
240 | |
4353 | 241 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) { |
527 | 242 |
1078 | 243 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 244 |
245 png = create_png(buf); | |
246 | |
247 if(png.status){ | |
248 printf("PNG Error in create_png\n"); | |
249 } | |
250 | |
251 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
252 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul]; | |
253 | |
254 //png_write_flush(png.png_ptr); | |
255 //png_set_flush(png.png_ptr, nrows); | |
256 | |
257 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
258 png_write_image(png.png_ptr, row_pointers); | |
259 | |
260 destroy_png(png); | |
261 } | |
262 } | |
263 | |
264 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
265 { | |
4353 | 266 uint8_t *dst = image_data + (image_width * y + x) * (bpp/8); |
527 | 267 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); |
268 return 0; | |
269 } | |
270 | |
271 static uint32_t | |
272 query_format(uint32_t format) | |
273 { | |
274 switch(format){ | |
4353 | 275 case IMGFMT_IYUV: |
276 case IMGFMT_I420: | |
527 | 277 case IMGFMT_YV12: |
6132 | 278 return VFCAP_CSP_SUPPORTED|VFCAP_OSD; |
527 | 279 case IMGFMT_RGB|24: |
280 case IMGFMT_BGR|24: | |
6132 | 281 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW; |
527 | 282 } |
283 return 0; | |
284 } | |
285 | |
286 static void | |
287 uninit(void) | |
288 { | |
289 if(image_data){ free(image_data);image_data=NULL;} | |
290 } | |
291 | |
292 | |
293 static void check_events(void) | |
294 { | |
295 } | |
4352 | 296 |
297 static uint32_t preinit(const char *arg) | |
298 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
299 if(arg) |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
300 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
301 printf("PNG Unknown subdevice: %s\n",arg); |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
302 return ENOSYS; |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
303 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
304 return 0; |
4352 | 305 } |
306 | |
4596 | 307 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 308 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
309 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
310 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
311 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
312 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
313 return VO_NOTIMPL; |
4352 | 314 } |