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