Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 7862:013c255225d8
mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
author | arpi |
---|---|
date | Wed, 23 Oct 2002 14:46:20 +0000 |
parents | b64f14fdadfb |
children | 7d2542838d24 |
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 { | |
7693 | 202 return -1; |
203 } | |
204 | |
205 static uint32_t draw_image(mp_image_t* mpi){ | |
527 | 206 char buf[100]; |
207 int k, bppmul = bpp/8; | |
208 struct pngdata png; | |
209 png_byte *row_pointers[image_height]; | |
7693 | 210 |
211 // if -dr or -slices then do nothing: | |
212 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | |
527 | 213 |
1078 | 214 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 215 |
216 png = create_png(buf); | |
217 | |
218 if(png.status){ | |
219 printf("PNG Error in create_png\n"); | |
220 return 1; | |
221 } | |
222 | |
223 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
7693 | 224 for ( k = 0; k < image_height; k++ ) |
225 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; | |
226 | |
527 | 227 //png_write_flush(png.png_ptr); |
228 //png_set_flush(png.png_ptr, nrows); | |
229 | |
230 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
231 png_write_image(png.png_ptr, row_pointers); | |
232 | |
7693 | 233 destroy_png(png); |
527 | 234 |
7693 | 235 return VO_TRUE; |
527 | 236 } |
237 | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
238 static void draw_osd(void) |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
239 { |
6132 | 240 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
|
241 } |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
242 |
527 | 243 static void flip_page (void) |
244 { | |
245 char buf[100]; | |
246 int k, bppmul = bpp/8; | |
247 struct pngdata png; | |
248 png_byte *row_pointers[image_height]; | |
249 | |
4353 | 250 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) { |
527 | 251 |
1078 | 252 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 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 } | |
272 | |
273 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
274 { | |
4353 | 275 uint8_t *dst = image_data + (image_width * y + x) * (bpp/8); |
527 | 276 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]); |
277 return 0; | |
278 } | |
279 | |
280 static uint32_t | |
281 query_format(uint32_t format) | |
282 { | |
283 switch(format){ | |
4353 | 284 case IMGFMT_IYUV: |
285 case IMGFMT_I420: | |
527 | 286 case IMGFMT_YV12: |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
287 return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE; |
527 | 288 case IMGFMT_RGB|24: |
289 case IMGFMT_BGR|24: | |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
290 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
527 | 291 } |
292 return 0; | |
293 } | |
294 | |
295 static void | |
296 uninit(void) | |
297 { | |
298 if(image_data){ free(image_data);image_data=NULL;} | |
299 } | |
300 | |
301 | |
302 static void check_events(void) | |
303 { | |
304 } | |
4352 | 305 |
306 static uint32_t preinit(const char *arg) | |
307 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
308 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
|
309 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
310 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
|
311 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
|
312 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
313 return 0; |
4352 | 314 } |
315 | |
4596 | 316 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 317 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
318 switch (request) { |
7693 | 319 case VOCTRL_DRAW_IMAGE: |
320 return draw_image(data); | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
321 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
322 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
323 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
324 return VO_NOTIMPL; |
4352 | 325 } |