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