527
|
1 #define DISP
|
|
2
|
|
3 /*
|
530
|
4 * vo_png.c, Portable Network Graphics Renderer for Mplayer
|
527
|
5 *
|
530
|
6 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net>
|
527
|
7 *
|
530
|
8 * Uses libpng (which uses zlib), so see according licenses.
|
527
|
9 *
|
|
10 */
|
|
11
|
|
12 #include <stdio.h>
|
|
13 #include <stdlib.h>
|
|
14 #include <string.h>
|
612
|
15 #include <errno.h>
|
527
|
16
|
|
17 #include <png.h>
|
|
18 //#include "/usr/include/png.h"
|
|
19
|
|
20
|
|
21 #include "config.h"
|
|
22 #include "video_out.h"
|
|
23 #include "video_out_internal.h"
|
|
24
|
|
25 #include "yuv2rgb.h"
|
|
26
|
|
27 LIBVO_EXTERN (png)
|
|
28
|
|
29 static vo_info_t vo_info =
|
|
30 {
|
|
31 "PNG file",
|
|
32 "png",
|
|
33 "Felix Buenemann <atmosfear@users.sourceforge.net>",
|
|
34 ""
|
|
35 };
|
|
36
|
|
37 #define RGB 0
|
|
38 #define BGR 1
|
|
39
|
|
40 extern int verbose;
|
|
41 int z_compression = Z_NO_COMPRESSION;
|
|
42 static int image_width;
|
|
43 static int image_height;
|
|
44 static int image_format;
|
|
45 static uint8_t *image_data=NULL;
|
|
46 //static char *image_data;
|
|
47
|
|
48 static int bpp = 24;
|
|
49 static int cspace = RGB;
|
|
50 static int framenum = 0;
|
|
51
|
|
52 struct pngdata {
|
|
53 FILE * fp;
|
|
54 png_structp png_ptr;
|
|
55 png_infop info_ptr;
|
|
56 enum {OK,ERROR} status;
|
|
57 };
|
|
58
|
|
59 static uint32_t
|
|
60 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
|
|
61 {
|
|
62 image_height = height;
|
|
63 image_width = width;
|
|
64 image_format = format;
|
|
65
|
|
66 //printf("Verbose level is %i\n", verbose);
|
|
67
|
|
68 switch(format) {
|
|
69 case IMGFMT_BGR24:
|
|
70 bpp = 24;
|
|
71 cspace = BGR;
|
|
72 break;
|
|
73 case IMGFMT_RGB24:
|
|
74 bpp = 24;
|
|
75 cspace = RGB;
|
|
76 break;
|
|
77 case IMGFMT_YV12:
|
|
78 bpp = 24;
|
|
79 cspace = RGB;
|
|
80 yuv2rgb_init(bpp,MODE_BGR);
|
|
81 image_data = malloc(image_width*image_height*3);
|
|
82 break;
|
|
83 default:
|
|
84 return 1;
|
|
85 }
|
|
86
|
|
87 if((z_compression < 0) || (z_compression < 9)) {
|
|
88 if(z_compression == 0) {
|
|
89 printf("PNG Warning: compression level set to 0, compression disabled!\n");
|
|
90 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n");
|
|
91 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n");
|
|
92 }
|
|
93 }
|
|
94 else {
|
|
95 printf("PNG Warning: compression level out of range setting to 1!\n");
|
|
96 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n");
|
|
97 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n");
|
|
98 z_compression = Z_BEST_SPEED;
|
|
99 }
|
|
100
|
|
101 if(verbose) printf("PNG Compression level %i\n", z_compression);
|
|
102
|
|
103 return 0;
|
|
104 }
|
|
105
|
|
106 static const vo_info_t*
|
|
107 get_info(void)
|
|
108 {
|
|
109 return &vo_info;
|
|
110 }
|
|
111
|
|
112
|
|
113 struct pngdata create_png (char * fname)
|
|
114 {
|
|
115 struct pngdata png;
|
|
116
|
|
117 /*png_structp png_ptr = png_create_write_struct
|
|
118 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
|
119 user_error_fn, user_warning_fn);*/
|
|
120 //png_byte *row_pointers[image_height];
|
|
121 png.png_ptr = png_create_write_struct
|
|
122 (PNG_LIBPNG_VER_STRING, NULL,
|
|
123 NULL, NULL);
|
|
124 png.info_ptr = png_create_info_struct(png.png_ptr);
|
|
125
|
|
126 if (!png.png_ptr) {
|
|
127 if(verbose > 1) printf("PNG Failed to init png pointer\n");
|
|
128 png.status = ERROR;
|
|
129 return png;
|
|
130 }
|
|
131
|
|
132 if (!png.info_ptr) {
|
|
133 if(verbose > 1) printf("PNG Failed to init png infopointer\n");
|
|
134 png_destroy_write_struct(&png.png_ptr,
|
|
135 (png_infopp)NULL);
|
|
136 png.status = ERROR;
|
|
137 return png;
|
|
138 }
|
|
139
|
|
140 if (setjmp(png.png_ptr->jmpbuf)) {
|
|
141 if(verbose > 1) printf("PNG Internal error!\n");
|
|
142 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
|
|
143 fclose(png.fp);
|
|
144 png.status = ERROR;
|
|
145 return png;
|
|
146 }
|
|
147
|
|
148 png.fp = fopen (fname, "wb");
|
|
149 if (png.fp == NULL) {
|
612
|
150 printf("\nPNG Error opening %s for writing!\n", strerror(errno));
|
527
|
151 png.status = ERROR;
|
|
152 return png;
|
|
153 }
|
|
154
|
|
155 if(verbose > 1) printf("PNG Init IO\n");
|
|
156 png_init_io(png.png_ptr, png.fp);
|
|
157
|
|
158 /* set the zlib compression level */
|
|
159 png_set_compression_level(png.png_ptr, z_compression);
|
|
160
|
|
161
|
|
162 /*png_set_IHDR(png_ptr, info_ptr, width, height,
|
|
163 bit_depth, color_type, interlace_type,
|
|
164 compression_type, filter_type)*/
|
|
165 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height,
|
|
166 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
|
|
167 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
|
168
|
|
169 if(verbose > 1) printf("PNG Write Info\n");
|
|
170 png_write_info(png.png_ptr, png.info_ptr);
|
|
171
|
|
172 if(cspace) {
|
|
173 if(verbose > 1) printf("PNG Set BGR Conversion\n");
|
|
174 png_set_bgr(png.png_ptr);
|
|
175 }
|
|
176
|
|
177 png.status = OK;
|
|
178 return png;
|
|
179
|
|
180 }
|
|
181
|
|
182 static uint8_t destroy_png(struct pngdata png) {
|
|
183
|
|
184 if(verbose > 1) printf("PNG Write End\n");
|
|
185 png_write_end(png.png_ptr, png.info_ptr);
|
|
186
|
|
187 if(verbose > 1) printf("PNG Destroy Write Struct\n");
|
|
188 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
|
|
189
|
|
190 fclose (png.fp);
|
|
191
|
|
192 return 0;
|
|
193 }
|
|
194
|
|
195 static uint32_t draw_frame(uint8_t * src[])
|
|
196 {
|
|
197 char buf[100];
|
|
198 int k, bppmul = bpp/8;
|
|
199 struct pngdata png;
|
|
200 png_byte *row_pointers[image_height];
|
|
201
|
|
202 sprintf (buf, "%08d.png", ++framenum);
|
|
203 //printf("%s\n", buf);
|
|
204
|
|
205 png = create_png(buf);
|
|
206
|
|
207 if(png.status){
|
|
208 printf("PNG Error in create_png\n");
|
|
209 return 1;
|
|
210 }
|
|
211
|
|
212 if(verbose > 1) printf("PNG Creating Row Pointers\n");
|
|
213 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul];
|
|
214
|
|
215 //png_write_flush(png.png_ptr);
|
|
216 //png_set_flush(png.png_ptr, nrows);
|
|
217
|
|
218 if(verbose > 1) printf("PNG Writing Image Data\n");
|
|
219 png_write_image(png.png_ptr, row_pointers);
|
|
220
|
|
221 return destroy_png(png);
|
|
222
|
|
223 }
|
|
224
|
|
225 static void flip_page (void)
|
|
226 {
|
|
227 char buf[100];
|
|
228 int k, bppmul = bpp/8;
|
|
229 struct pngdata png;
|
|
230 png_byte *row_pointers[image_height];
|
|
231
|
|
232 if(image_format == IMGFMT_YV12) {
|
|
233
|
|
234 sprintf (buf, "%08d.png", ++framenum);
|
|
235 //printf("%s\n", buf);
|
|
236
|
|
237 png = create_png(buf);
|
|
238
|
|
239 if(png.status){
|
|
240 printf("PNG Error in create_png\n");
|
|
241 }
|
|
242
|
|
243 if(verbose > 1) printf("PNG Creating Row Pointers\n");
|
|
244 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul];
|
|
245
|
|
246 //png_write_flush(png.png_ptr);
|
|
247 //png_set_flush(png.png_ptr, nrows);
|
|
248
|
|
249 if(verbose > 1) printf("PNG Writing Image Data\n");
|
|
250 png_write_image(png.png_ptr, row_pointers);
|
|
251
|
|
252 destroy_png(png);
|
|
253 }
|
|
254 }
|
|
255
|
|
256 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
|
|
257 {
|
|
258 uint8_t *dst;
|
|
259
|
|
260 dst = image_data + (image_width * y + x) * (bpp/8);
|
|
261 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]);
|
|
262
|
|
263 return 0;
|
|
264 }
|
|
265
|
|
266 static uint32_t
|
|
267 query_format(uint32_t format)
|
|
268 {
|
|
269 switch(format){
|
|
270 case IMGFMT_YV12:
|
|
271 case IMGFMT_RGB|24:
|
|
272 case IMGFMT_BGR|24:
|
|
273 return 1;
|
|
274 }
|
|
275 return 0;
|
|
276 }
|
|
277
|
|
278 static void
|
|
279 uninit(void)
|
|
280 {
|
|
281 if(image_data){ free(image_data);image_data=NULL;}
|
|
282 }
|
|
283
|
|
284
|
|
285 static void check_events(void)
|
|
286 {
|
|
287 }
|
|
288
|
|
289
|
|
290
|