Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 27618:9badbf52f33c
add outdir sub-option to vo png
author | ben |
---|---|
date | Sat, 20 Sep 2008 13:13:02 +0000 |
parents | 0d255d03016f |
children | 710704af0926 |
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> |
27618 | 14 #include <sys/stat.h> |
15 #include <sys/types.h> | |
16 #include <unistd.h> | |
527 | 17 |
18 #include <png.h> | |
19 | |
26203 | 20 #include "config.h" |
17932 | 21 #include "mp_msg.h" |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
22 #include "mp_msg.h" |
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
23 #include "help_mp.h" |
527 | 24 #include "video_out.h" |
25 #include "video_out_internal.h" | |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
26 #include "subopt-helper.h" |
527 | 27 |
27618 | 28 #define BUFLENGTH 512 |
29 | |
25216 | 30 static const vo_info_t info = |
527 | 31 { |
32 "PNG file", | |
33 "png", | |
34 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
35 "" | |
36 }; | |
37 | |
25220
c9e9ac2008c2
Mark the vo_functions_t definitions as const where possible.
reimar
parents:
25216
diff
changeset
|
38 const LIBVO_EXTERN (png) |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
39 |
24669 | 40 static int z_compression = Z_NO_COMPRESSION; |
27618 | 41 static char *png_outdir = NULL; |
527 | 42 static int framenum = 0; |
43 | |
44 struct pngdata { | |
45 FILE * fp; | |
46 png_structp png_ptr; | |
47 png_infop info_ptr; | |
48 enum {OK,ERROR} status; | |
49 }; | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
50 |
27618 | 51 static void png_mkdir(char *buf, int verbose) { |
52 struct stat stat_p; | |
53 | |
54 #ifndef __MINGW32__ | |
55 if ( mkdir(buf, 0755) < 0 ) { | |
56 #else | |
57 if ( mkdir(buf) < 0 ) { | |
58 #endif | |
59 switch (errno) { /* use switch in case other errors need to be caught | |
60 and handled in the future */ | |
61 case EEXIST: | |
62 if ( stat(buf, &stat_p ) < 0 ) { | |
63 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
64 MSGTR_VO_GenericError, strerror(errno) ); | |
65 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
66 MSGTR_VO_UnableToAccess,buf); | |
67 exit_player(MSGTR_Exit_error); | |
68 } | |
69 if ( !S_ISDIR(stat_p.st_mode) ) { | |
70 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
71 buf, MSGTR_VO_ExistsButNoDirectory); | |
72 exit_player(MSGTR_Exit_error); | |
73 } | |
74 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
75 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, | |
76 buf, MSGTR_VO_DirExistsButNotWritable); | |
77 exit_player(MSGTR_Exit_error); | |
78 } | |
79 | |
80 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, | |
81 buf, MSGTR_VO_DirExistsAndIsWritable); | |
82 break; | |
83 | |
84 default: | |
85 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
86 MSGTR_VO_GenericError, strerror(errno) ); | |
87 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, | |
88 buf, MSGTR_VO_CantCreateDirectory); | |
89 exit_player(MSGTR_Exit_error); | |
90 } /* end switch */ | |
91 } else if ( verbose ) { | |
92 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, | |
93 buf, MSGTR_VO_DirectoryCreateSuccess); | |
94 } /* end if */ | |
95 } | |
96 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
97 static int |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14451
diff
changeset
|
98 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
527 | 99 { |
27618 | 100 char buf[BUFLENGTH]; |
527 | 101 |
102 if(z_compression == 0) { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
103 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning1); |
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
104 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning2); |
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
105 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3); |
527 | 106 } |
107 | |
27618 | 108 snprintf(buf, BUFLENGTH, "%s", png_outdir); |
109 png_mkdir(buf, 1); | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
110 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression); |
527 | 111 |
112 return 0; | |
113 } | |
114 | |
115 | |
18950 | 116 static struct pngdata create_png (char * fname, int image_width, int image_height, int swapped) |
527 | 117 { |
118 struct pngdata png; | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
119 |
527 | 120 /*png_structp png_ptr = png_create_write_struct |
121 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
122 user_error_fn, user_warning_fn);*/ | |
123 //png_byte *row_pointers[image_height]; | |
124 png.png_ptr = png_create_write_struct | |
125 (PNG_LIBPNG_VER_STRING, NULL, | |
126 NULL, NULL); | |
127 png.info_ptr = png_create_info_struct(png.png_ptr); | |
128 | |
129 if (!png.png_ptr) { | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
130 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png pointer\n"); |
527 | 131 png.status = ERROR; |
132 return png; | |
133 } | |
134 | |
135 if (!png.info_ptr) { | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
136 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png infopointer\n"); |
527 | 137 png_destroy_write_struct(&png.png_ptr, |
138 (png_infopp)NULL); | |
139 png.status = ERROR; | |
140 return png; | |
141 } | |
142 | |
143 if (setjmp(png.png_ptr->jmpbuf)) { | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
144 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Internal error!\n"); |
527 | 145 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); |
146 fclose(png.fp); | |
147 png.status = ERROR; | |
148 return png; | |
149 } | |
150 | |
151 png.fp = fopen (fname, "wb"); | |
152 if (png.fp == NULL) { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
153 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno)); |
527 | 154 png.status = ERROR; |
155 return png; | |
156 } | |
157 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
158 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Init IO\n"); |
527 | 159 png_init_io(png.png_ptr, png.fp); |
160 | |
161 /* set the zlib compression level */ | |
162 png_set_compression_level(png.png_ptr, z_compression); | |
163 | |
164 | |
165 /*png_set_IHDR(png_ptr, info_ptr, width, height, | |
166 bit_depth, color_type, interlace_type, | |
167 compression_type, filter_type)*/ | |
168 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height, | |
169 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, | |
170 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | |
171 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
172 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n"); |
527 | 173 png_write_info(png.png_ptr, png.info_ptr); |
174 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
175 if(swapped) { |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
176 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Set BGR Conversion\n"); |
527 | 177 png_set_bgr(png.png_ptr); |
178 } | |
179 | |
180 png.status = OK; | |
181 return png; | |
182 } | |
183 | |
184 static uint8_t destroy_png(struct pngdata png) { | |
185 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
186 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write End\n"); |
527 | 187 png_write_end(png.png_ptr, png.info_ptr); |
188 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
189 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Destroy Write Struct\n"); |
527 | 190 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); |
191 | |
192 fclose (png.fp); | |
193 | |
194 return 0; | |
195 } | |
196 | |
7693 | 197 static uint32_t draw_image(mp_image_t* mpi){ |
527 | 198 char buf[100]; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
199 int k; |
527 | 200 struct pngdata png; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
201 png_byte *row_pointers[mpi->h]; |
7693 | 202 |
203 // if -dr or -slices then do nothing: | |
204 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | |
527 | 205 |
27618 | 206 snprintf (buf, 100, "%s/%08d.png", png_outdir, ++framenum); |
527 | 207 |
24670
a2599160737c
Use IMGFMT_IS_BGR instead of mpi->flags&MP_IMGFLAG_SWAPPED, this is easier
reimar
parents:
24669
diff
changeset
|
208 png = create_png(buf, mpi->w, mpi->h, IMGFMT_IS_BGR(mpi->imgfmt)); |
527 | 209 |
210 if(png.status){ | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
211 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng); |
527 | 212 return 1; |
213 } | |
214 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
215 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Creating Row Pointers\n"); |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
216 for ( k = 0; k < mpi->h; k++ ) |
7693 | 217 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; |
218 | |
527 | 219 //png_write_flush(png.png_ptr); |
220 //png_set_flush(png.png_ptr, nrows); | |
221 | |
17932 | 222 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
223 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Writing Image Data\n"); } |
527 | 224 png_write_image(png.png_ptr, row_pointers); |
225 | |
7693 | 226 destroy_png(png); |
527 | 227 |
7693 | 228 return VO_TRUE; |
527 | 229 } |
230 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
231 static void draw_osd(void){} |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
232 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
233 static void flip_page (void){} |
527 | 234 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
235 static int draw_frame(uint8_t * src[]) |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
236 { |
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
237 return -1; |
527 | 238 } |
239 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
240 static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) |
527 | 241 { |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
242 return -1; |
527 | 243 } |
244 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
245 static int |
527 | 246 query_format(uint32_t format) |
247 { | |
248 switch(format){ | |
249 case IMGFMT_RGB|24: | |
250 case IMGFMT_BGR|24: | |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
251 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
527 | 252 } |
253 return 0; | |
254 } | |
255 | |
27618 | 256 static void uninit(void){ |
257 if (png_outdir) { | |
258 free(png_outdir); | |
259 png_outdir = NULL; | |
260 } | |
261 } | |
527 | 262 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
263 static void check_events(void){} |
4352 | 264 |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
265 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
|
266 { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
267 if ( (*sh < 0) || (*sh > 9) ) |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
268 return 0; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
269 return 1; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
270 } |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
271 |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
272 static opt_t subopts[] = { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
273 {"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine}, |
27618 | 274 {"outdir", OPT_ARG_MSTRZ, &png_outdir, NULL, 0}, |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
275 {NULL} |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
276 }; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
277 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
278 static int preinit(const char *arg) |
4352 | 279 { |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
280 z_compression = 0; |
27618 | 281 png_outdir = strdup("."); |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
282 if (subopt_parse(arg, subopts) != 0) { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
283 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
|
284 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
285 return 0; |
4352 | 286 } |
287 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
288 static int control(uint32_t request, void *data, ...) |
4352 | 289 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
290 switch (request) { |
7693 | 291 case VOCTRL_DRAW_IMAGE: |
292 return draw_image(data); | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
293 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
294 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
295 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
296 return VO_NOTIMPL; |
4352 | 297 } |