Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 28063:a318969a4f45
Set the base size window manager hint, otherwise some subtract the minimum
size of 4x4 from the numbers displayed to the user which might be confusing.
Based on patch by Bert Wesarg [bert wesarg googlemail com].
author | reimar |
---|---|
date | Fri, 05 Dec 2008 19:01:49 +0000 |
parents | 80a16d26acda |
children | 77c7b422a49d |
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" |
27655
710704af0926
Add missing #include for mplayer.h, fixes the warning:
diego
parents:
27618
diff
changeset
|
27 #include "mplayer.h" |
527 | 28 |
27618 | 29 #define BUFLENGTH 512 |
30 | |
25216 | 31 static const vo_info_t info = |
527 | 32 { |
33 "PNG file", | |
34 "png", | |
35 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
36 "" | |
37 }; | |
38 | |
25220
c9e9ac2008c2
Mark the vo_functions_t definitions as const where possible.
reimar
parents:
25216
diff
changeset
|
39 const LIBVO_EXTERN (png) |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
40 |
24669 | 41 static int z_compression = Z_NO_COMPRESSION; |
27618 | 42 static char *png_outdir = NULL; |
527 | 43 static int framenum = 0; |
44 | |
45 struct pngdata { | |
46 FILE * fp; | |
47 png_structp png_ptr; | |
48 png_infop info_ptr; | |
49 enum {OK,ERROR} status; | |
50 }; | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
51 |
27618 | 52 static void png_mkdir(char *buf, int verbose) { |
53 struct stat stat_p; | |
54 | |
55 #ifndef __MINGW32__ | |
56 if ( mkdir(buf, 0755) < 0 ) { | |
57 #else | |
58 if ( mkdir(buf) < 0 ) { | |
59 #endif | |
60 switch (errno) { /* use switch in case other errors need to be caught | |
61 and handled in the future */ | |
62 case EEXIST: | |
63 if ( stat(buf, &stat_p ) < 0 ) { | |
64 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
65 MSGTR_VO_GenericError, strerror(errno) ); | |
66 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
67 MSGTR_VO_UnableToAccess,buf); | |
68 exit_player(MSGTR_Exit_error); | |
69 } | |
70 if ( !S_ISDIR(stat_p.st_mode) ) { | |
71 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name, | |
72 buf, MSGTR_VO_ExistsButNoDirectory); | |
73 exit_player(MSGTR_Exit_error); | |
74 } | |
75 if ( !(stat_p.st_mode & S_IWUSR) ) { | |
76 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, | |
77 buf, MSGTR_VO_DirExistsButNotWritable); | |
78 exit_player(MSGTR_Exit_error); | |
79 } | |
80 | |
81 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, | |
82 buf, MSGTR_VO_DirExistsAndIsWritable); | |
83 break; | |
84 | |
85 default: | |
86 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name, | |
87 MSGTR_VO_GenericError, strerror(errno) ); | |
88 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name, | |
89 buf, MSGTR_VO_CantCreateDirectory); | |
90 exit_player(MSGTR_Exit_error); | |
91 } /* end switch */ | |
92 } else if ( verbose ) { | |
93 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name, | |
94 buf, MSGTR_VO_DirectoryCreateSuccess); | |
95 } /* end if */ | |
96 } | |
97 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
98 static int |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
14451
diff
changeset
|
99 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
527 | 100 { |
27618 | 101 char buf[BUFLENGTH]; |
527 | 102 |
103 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
|
104 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
|
105 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
|
106 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3); |
527 | 107 } |
108 | |
27618 | 109 snprintf(buf, BUFLENGTH, "%s", png_outdir); |
110 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
|
111 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression); |
527 | 112 |
113 return 0; | |
114 } | |
115 | |
116 | |
18950 | 117 static struct pngdata create_png (char * fname, int image_width, int image_height, int swapped) |
527 | 118 { |
119 struct pngdata png; | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
120 |
527 | 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) { | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
131 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png pointer\n"); |
527 | 132 png.status = ERROR; |
133 return png; | |
134 } | |
135 | |
136 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
|
137 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png infopointer\n"); |
527 | 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)) { | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
145 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Internal error!\n"); |
527 | 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) { | |
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
|
154 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno)); |
527 | 155 png.status = ERROR; |
156 return png; | |
157 } | |
158 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
159 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Init IO\n"); |
527 | 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 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
173 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n"); |
527 | 174 png_write_info(png.png_ptr, png.info_ptr); |
175 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
176 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
|
177 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Set BGR Conversion\n"); |
527 | 178 png_set_bgr(png.png_ptr); |
179 } | |
180 | |
181 png.status = OK; | |
182 return png; | |
183 } | |
184 | |
185 static uint8_t destroy_png(struct pngdata png) { | |
186 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
187 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write End\n"); |
527 | 188 png_write_end(png.png_ptr, png.info_ptr); |
189 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
190 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Destroy Write Struct\n"); |
527 | 191 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); |
192 | |
193 fclose (png.fp); | |
194 | |
195 return 0; | |
196 } | |
197 | |
7693 | 198 static uint32_t draw_image(mp_image_t* mpi){ |
527 | 199 char buf[100]; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
200 int k; |
527 | 201 struct pngdata png; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
202 png_byte *row_pointers[mpi->h]; |
7693 | 203 |
204 // if -dr or -slices then do nothing: | |
205 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | |
527 | 206 |
27618 | 207 snprintf (buf, 100, "%s/%08d.png", png_outdir, ++framenum); |
527 | 208 |
24670
a2599160737c
Use IMGFMT_IS_BGR instead of mpi->flags&MP_IMGFLAG_SWAPPED, this is easier
reimar
parents:
24669
diff
changeset
|
209 png = create_png(buf, mpi->w, mpi->h, IMGFMT_IS_BGR(mpi->imgfmt)); |
527 | 210 |
211 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
|
212 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng); |
527 | 213 return 1; |
214 } | |
215 | |
24671
fbcd9dcb0daf
Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents:
24670
diff
changeset
|
216 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
|
217 for ( k = 0; k < mpi->h; k++ ) |
7693 | 218 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; |
219 | |
527 | 220 //png_write_flush(png.png_ptr); |
221 //png_set_flush(png.png_ptr, nrows); | |
222 | |
17932 | 223 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
|
224 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Writing Image Data\n"); } |
527 | 225 png_write_image(png.png_ptr, row_pointers); |
226 | |
7693 | 227 destroy_png(png); |
527 | 228 |
7693 | 229 return VO_TRUE; |
527 | 230 } |
231 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
232 static void draw_osd(void){} |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
233 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
234 static void flip_page (void){} |
527 | 235 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
236 static int draw_frame(uint8_t * src[]) |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
237 { |
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
238 return -1; |
527 | 239 } |
240 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
241 static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) |
527 | 242 { |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
243 return -1; |
527 | 244 } |
245 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
246 static int |
527 | 247 query_format(uint32_t format) |
248 { | |
249 switch(format){ | |
27873
80a16d26acda
Use the proper IMGFMT_RGB24 and IMGFMT_BGR24 defines instead of
reimar
parents:
27655
diff
changeset
|
250 case IMGFMT_RGB24: |
80a16d26acda
Use the proper IMGFMT_RGB24 and IMGFMT_BGR24 defines instead of
reimar
parents:
27655
diff
changeset
|
251 case IMGFMT_BGR24: |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
252 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
527 | 253 } |
254 return 0; | |
255 } | |
256 | |
27618 | 257 static void uninit(void){ |
258 if (png_outdir) { | |
259 free(png_outdir); | |
260 png_outdir = NULL; | |
261 } | |
262 } | |
527 | 263 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
264 static void check_events(void){} |
4352 | 265 |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
266 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
|
267 { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
268 if ( (*sh < 0) || (*sh > 9) ) |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
269 return 0; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
270 return 1; |
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 |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
273 static opt_t subopts[] = { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
274 {"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine}, |
27618 | 275 {"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
|
276 {NULL} |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
277 }; |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
278 |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
279 static int preinit(const char *arg) |
4352 | 280 { |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
281 z_compression = 0; |
27618 | 282 png_outdir = strdup("."); |
14451
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
283 if (subopt_parse(arg, subopts) != 0) { |
4a6f25e88dbb
Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents:
12857
diff
changeset
|
284 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
|
285 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
286 return 0; |
4352 | 287 } |
288 | |
16171
fd51fd1ff231
Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents:
15212
diff
changeset
|
289 static int control(uint32_t request, void *data, ...) |
4352 | 290 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
291 switch (request) { |
7693 | 292 case VOCTRL_DRAW_IMAGE: |
293 return draw_image(data); | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
294 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
295 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
296 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
297 return VO_NOTIMPL; |
4352 | 298 } |