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