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