Mercurial > mplayer.hg
annotate libvo/vo_png.c @ 11757:a9dd06d780b8
updated -pass examples
author | gabucino |
---|---|
date | Tue, 06 Jan 2004 13:37:55 +0000 |
parents | 5b39e79af5fe |
children | db49cdedb88d |
rev | line source |
---|---|
527 | 1 /* |
530 | 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 | |
17 #include "config.h" | |
18 #include "video_out.h" | |
19 #include "video_out_internal.h" | |
20 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
21 static vo_info_t info = |
527 | 22 { |
23 "PNG file", | |
24 "png", | |
25 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
26 "" | |
27 }; | |
28 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
29 LIBVO_EXTERN (png) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7926
diff
changeset
|
30 |
527 | 31 extern int verbose; |
32 int z_compression = Z_NO_COMPRESSION; | |
33 static int framenum = 0; | |
34 | |
35 struct pngdata { | |
36 FILE * fp; | |
37 png_structp png_ptr; | |
38 png_infop info_ptr; | |
39 enum {OK,ERROR} status; | |
40 }; | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
41 |
527 | 42 static uint32_t |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
6132
diff
changeset
|
43 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) |
527 | 44 { |
45 | |
3950
e92653caf5d7
osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents:
2732
diff
changeset
|
46 if((z_compression >= 0) && (z_compression <= 9)) { |
527 | 47 if(z_compression == 0) { |
48 printf("PNG Warning: compression level set to 0, compression disabled!\n"); | |
49 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
50 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
51 } | |
52 } | |
53 else { | |
54 printf("PNG Warning: compression level out of range setting to 1!\n"); | |
55 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n"); | |
56 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n"); | |
57 z_compression = Z_BEST_SPEED; | |
58 } | |
59 | |
60 if(verbose) printf("PNG Compression level %i\n", z_compression); | |
61 | |
62 return 0; | |
63 } | |
64 | |
65 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
66 struct pngdata create_png (char * fname, int image_width, int image_height, int swapped) |
527 | 67 { |
68 struct pngdata png; | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
69 |
527 | 70 /*png_structp png_ptr = png_create_write_struct |
71 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr, | |
72 user_error_fn, user_warning_fn);*/ | |
73 //png_byte *row_pointers[image_height]; | |
74 png.png_ptr = png_create_write_struct | |
75 (PNG_LIBPNG_VER_STRING, NULL, | |
76 NULL, NULL); | |
77 png.info_ptr = png_create_info_struct(png.png_ptr); | |
78 | |
79 if (!png.png_ptr) { | |
80 if(verbose > 1) printf("PNG Failed to init png pointer\n"); | |
81 png.status = ERROR; | |
82 return png; | |
83 } | |
84 | |
85 if (!png.info_ptr) { | |
86 if(verbose > 1) printf("PNG Failed to init png infopointer\n"); | |
87 png_destroy_write_struct(&png.png_ptr, | |
88 (png_infopp)NULL); | |
89 png.status = ERROR; | |
90 return png; | |
91 } | |
92 | |
93 if (setjmp(png.png_ptr->jmpbuf)) { | |
94 if(verbose > 1) printf("PNG Internal error!\n"); | |
95 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
96 fclose(png.fp); | |
97 png.status = ERROR; | |
98 return png; | |
99 } | |
100 | |
101 png.fp = fopen (fname, "wb"); | |
102 if (png.fp == NULL) { | |
612 | 103 printf("\nPNG Error opening %s for writing!\n", strerror(errno)); |
527 | 104 png.status = ERROR; |
105 return png; | |
106 } | |
107 | |
108 if(verbose > 1) printf("PNG Init IO\n"); | |
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 | |
122 if(verbose > 1) printf("PNG Write Info\n"); | |
123 png_write_info(png.png_ptr, png.info_ptr); | |
124 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
125 if(swapped) { |
527 | 126 if(verbose > 1) printf("PNG Set BGR Conversion\n"); |
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 | |
136 if(verbose > 1) printf("PNG Write End\n"); | |
137 png_write_end(png.png_ptr, png.info_ptr); | |
138 | |
139 if(verbose > 1) printf("PNG Destroy Write Struct\n"); | |
140 png_destroy_write_struct(&png.png_ptr, &png.info_ptr); | |
141 | |
142 fclose (png.fp); | |
143 | |
144 return 0; | |
145 } | |
146 | |
7693 | 147 static uint32_t draw_image(mp_image_t* mpi){ |
527 | 148 char buf[100]; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
149 int k; |
527 | 150 struct pngdata png; |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
151 png_byte *row_pointers[mpi->h]; |
7693 | 152 |
153 // if -dr or -slices then do nothing: | |
154 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE; | |
527 | 155 |
1078 | 156 snprintf (buf, 100, "%08d.png", ++framenum); |
527 | 157 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
158 png = create_png(buf, mpi->w, mpi->h, mpi->flags&MP_IMGFLAG_SWAPPED); |
527 | 159 |
160 if(png.status){ | |
161 printf("PNG Error in create_png\n"); | |
162 return 1; | |
163 } | |
164 | |
165 if(verbose > 1) printf("PNG Creating Row Pointers\n"); | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
166 for ( k = 0; k < mpi->h; k++ ) |
7693 | 167 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k; |
168 | |
527 | 169 //png_write_flush(png.png_ptr); |
170 //png_set_flush(png.png_ptr, nrows); | |
171 | |
172 if(verbose > 1) printf("PNG Writing Image Data\n"); | |
173 png_write_image(png.png_ptr, row_pointers); | |
174 | |
7693 | 175 destroy_png(png); |
527 | 176 |
7693 | 177 return VO_TRUE; |
527 | 178 } |
179 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
180 static void draw_osd(void){} |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1078
diff
changeset
|
181 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
182 static void flip_page (void){} |
527 | 183 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
184 static uint32_t draw_frame(uint8_t * src[]) |
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
185 { |
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
186 return -1; |
527 | 187 } |
188 | |
189 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y ) | |
190 { | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
191 return -1; |
527 | 192 } |
193 | |
194 static uint32_t | |
195 query_format(uint32_t format) | |
196 { | |
197 switch(format){ | |
198 case IMGFMT_RGB|24: | |
199 case IMGFMT_BGR|24: | |
7694
b64f14fdadfb
also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents:
7693
diff
changeset
|
200 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE; |
527 | 201 } |
202 return 0; | |
203 } | |
204 | |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
205 static void uninit(void){} |
527 | 206 |
7926
7d2542838d24
- removed YV12 support (builtin yv12->rgb conversion)
arpi
parents:
7694
diff
changeset
|
207 static void check_events(void){} |
4352 | 208 |
209 static uint32_t preinit(const char *arg) | |
210 { | |
4737
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
211 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
|
212 { |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
213 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
|
214 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
|
215 } |
32e1f5042f65
I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents:
4596
diff
changeset
|
216 return 0; |
4352 | 217 } |
218 | |
4596 | 219 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 220 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
221 switch (request) { |
7693 | 222 case VOCTRL_DRAW_IMAGE: |
223 return draw_image(data); | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
224 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
225 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
226 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4433
diff
changeset
|
227 return VO_NOTIMPL; |
4352 | 228 } |