Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 18065:f275cd6c7fc8
vertical size of "Configure Equalizer" window is not enough to hold all comboboxes, based on a patch by Stanislav Maslovski <stanislav POIS maslovski AH gmail POIS com>
author | gpoirier |
---|---|
date | Sun, 09 Apr 2006 13:49:37 +0000 |
parents | 3fe3b2b3a6ce |
children | a107276371a8 |
rev | line source |
---|---|
527 | 1 /* |
12857 | 2 * vo_png.c, Portable Network Graphics Renderer for MPlayer |
527 | 3 * |
530 | 4 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net> |
527 | 5 * |
530 | 6 * Uses libpng (which uses zlib), so see according licenses. |
527 | 7 * |
8 */ | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
612 | 13 #include <errno.h> |
527 | 14 |
15 #include <png.h> | |
16 | |
17932 | 17 #include "mp_msg.h" |
527 | 18 #include "config.h" |
19 #include "video_out.h" | |
20 #include "video_out_internal.h" | |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
21 #include "subopt-helper.h" |
527 | 22 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
23 static vo_info_t info = |
527 | 24 { |
25 "PNG file", | |
26 "png", | |
27 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
28 "" | |
29 }; | |
30 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
31 LIBVO_EXTERN (png) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
32 |
527 | 33 int z_compression = Z_NO_COMPRESSION; |
34 static int framenum = 0; | |
35 | |
36 struct pngdata { | |
37 FILE * fp; | |
38 png_structp png_ptr; | |
39 png_infop info_ptr; | |
40 enum {OK,ERROR} status; | |
41 }; | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
42 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
43 static int |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14451
diff
changeset
|
44 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
527 | 45 { |
46 | |
47 if(z_compression == 0) { | |
48 printf("PNG Warning: compression level set to 0, compression disabled!\n"); | |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
49 printf("PNG Info: Use -vo png:z=<n> to set compression level from 0 to 9.\n"); |
527 | 50 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); |
51 } | |
52 | |
17932 | 53 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
54 printf("PNG Compression level %i\n", z_compression); } | |
527 | 55 |
56 return 0; | |
57 } | |
58 | |
59 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
60 struct pngdata create_png (char * fname, int image_width, int image_height, int swapped) |
527 | 61 { |
62 struct pngdata png; | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
63 |
527 | 64 /*png_structp png_ptr = png_create_write_struct |
65 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
66 user_error_fn, user_warning_fn);*/ | |
67 //png_byte *row_pointers[image_height]; | |
68 png.png_ptr = png_create_write_struct | |
69 (PNG_LIBPNG_VER_STRING, NULL, | |
70 NULL, NULL); | |
71 png.info_ptr = png_create_info_struct(png.png_ptr); | |
72 | |
73 if (!png.png_ptr) { | |
17932 | 74 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
75 printf("PNG Failed to init png pointer\n"); } | |
527 | 76 png.status = ERROR; |
77 return png; | |
78 } | |
79 | |
80 if (!png.info_ptr) { | |
17932 | 81 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
82 printf("PNG Failed to init png infopointer\n"); } | |
527 | 83 png_destroy_write_struct(&png.png_ptr, |
84 (png_infopp)NULL); | |
85 png.status = ERROR; | |
86 return png; | |
87 } | |
88 | |
89 if (setjmp(png.png_ptr->jmpbuf)) { | |
17932 | 90 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
91 printf("PNG Internal error!\n");} | |
527 | 92 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); |
93 fclose(png.fp); | |
94 png.status = ERROR; | |
95 return png; | |
96 } | |
97 | |
98 png.fp = fopen (fname, "wb"); | |
99 if (png.fp == NULL) { | |
612 | 100 printf("\nPNG Error opening %s for writing!\n", strerror(errno)); |
527 | 101 png.status = ERROR; |
102 return png; | |
103 } | |
104 | |
17932 | 105 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
106 printf("PNG Init IO\n"); } | |
527 | 107 png_init_io(png.png_ptr, png.fp); |
108 | |
109 /* set the zlib compression level */ | |
110 png_set_compression_level(png.png_ptr, z_compression); | |
111 | |
112 | |
113 /*png_set_IHDR(png_ptr, info_ptr, width, height, | |
114 bit_depth, color_type, interlace_type, | |
115 compression_type, filter_type)*/ | |
116 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, | |
117 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, | |
118 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
119 | |
17932 | 120 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
121 printf("PNG Write Info\n"); } | |
527 | 122 png_write_info(png.png_ptr, png.info_ptr); |
123 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
124 if(swapped) { |
17932 | 125 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
126 printf("PNG Set BGR Conversion\n"); } | |
527 | 127 png_set_bgr(png.png_ptr); |
128 } | |
129 | |
130 png.status = OK; | |
131 return png; | |
132 } | |
133 | |
134 static uint8_t destroy_png(struct pngdata png) { | |
135 | |
17932 | 136 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
137 printf("PNG Write End\n"); } | |
527 | 138 png_write_end(png.png_ptr, png.info_ptr); |
139 | |
17932 | 140 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
141 printf("PNG Destroy Write Struct\n"); } | |
527 | 142 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); |
143 | |
144 fclose (png.fp); | |
145 | |
146 return 0; | |
147 } | |
148 | |
7693 | 149 static uint32_t draw_image(mp_image_t* mpi){ |
527 | 150 char buf[100]; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
151 int k; |
527 | 152 struct pngdata png; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
153 png_byte *row_pointers[mpi->h]; |
7693 | 154 |
155 // if -dr or -slices then do nothing: | |
156 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | |
527 | 157 |
1078 | 158 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 159 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
160 png = create_png(buf, mpi->w, mpi->h, mpi->flags&MP_IMGFLAG_SWAPPED); |
527 | 161 |
162 if(png.status){ | |
163 printf("PNG Error in create_png\n"); | |
164 return 1; | |
165 } | |
166 | |
17932 | 167 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
168 printf("PNG Creating Row Pointers\n"); } | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
169 for ( k = 0; k < mpi->h; k++ ) |
7693 | 170 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; |
171 | |
527 | 172 //png_write_flush(png.png_ptr); |
173 //png_set_flush(png.png_ptr, nrows); | |
174 | |
17932 | 175 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
176 printf("PNG Writing Image Data\n"); } | |
527 | 177 png_write_image(png.png_ptr, row_pointers); |
178 | |
7693 | 179 destroy_png(png); |
527 | 180 |
7693 | 181 return VO_TRUE; |
527 | 182 } |
183 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
184 static void draw_osd(void){} |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
185 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
186 static void flip_page (void){} |
527 | 187 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
188 static int draw_frame(uint8_t * src[]) |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
189 { |
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
190 return -1; |
527 | 191 } |
192 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
193 static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) |
527 | 194 { |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
195 return -1; |
527 | 196 } |
197 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
198 static int |
527 | 199 query_format(uint32_t format) |
200 { | |
201 switch(format){ | |
202 case IMGFMT_RGB|24: | |
203 case IMGFMT_BGR|24: | |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
204 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
527 | 205 } |
206 return 0; | |
207 } | |
208 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
209 static void uninit(void){} |
527 | 210 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
211 static void check_events(void){} |
4352 | 212 |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
213 static int int_zero_to_nine(int *sh) |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
214 { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
215 if ( (*sh < 0) || (*sh > 9) ) |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
216 return 0; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
217 return 1; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
218 } |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
219 |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
220 static opt_t subopts[] = { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
221 {"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine}, |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
222 {NULL} |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
223 }; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
224 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
225 static int preinit(const char *arg) |
4352 | 226 { |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
227 z_compression = 0; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
228 if (subopt_parse(arg, subopts) != 0) { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
229 return -1; |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
230 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
231 return 0; |
4352 | 232 } |
233 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
234 static int control(uint32_t request, void *data, ...) |
4352 | 235 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
236 switch (request) { |
7693 | 237 case VOCTRL_DRAW_IMAGE: |
238 return draw_image(data); | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
239 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
240 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
241 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
242 return VO_NOTIMPL; |
4352 | 243 } |