annotate libvo/vo_png.c @ 4807:156482788caf

osd outside movie support for vo_sdl, patch by Fredrik Kuivinen
author atmos4
date Fri, 22 Feb 2002 15:25:11 +0000
parents b4580c55d8bc
children 36aa273ca3ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
1 #define DISP
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
2
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
3 /*
530
670d47b4ce10 changed copyroght message to correct stuff :)
atmosfear
parents: 527
diff changeset
4 * vo_png.c, Portable Network Graphics Renderer for Mplayer
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
5 *
530
670d47b4ce10 changed copyroght message to correct stuff :)
atmosfear
parents: 527
diff changeset
6 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net>
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
7 *
530
670d47b4ce10 changed copyroght message to correct stuff :)
atmosfear
parents: 527
diff changeset
8 * Uses libpng (which uses zlib), so see according licenses.
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
9 *
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
10 */
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
11
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
12 #include <stdio.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
13 #include <stdlib.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
14 #include <string.h>
612
77e0094f0cce some warnings killed
szabii
parents: 530
diff changeset
15 #include <errno.h>
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
16
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
17 #include <png.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
18 //#include "/usr/include/png.h"
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
19
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
20
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
21 #include "config.h"
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
22 #include "video_out.h"
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
23 #include "video_out_internal.h"
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
24
4060
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
25 #include "../postproc/swscale.h"
2732
ae79207a3055 Move yuv2rgb to postprocess
nick
parents: 1501
diff changeset
26 #include "../postproc/rgb2rgb.h"
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
27
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
28 LIBVO_EXTERN (png)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
29
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
30 static vo_info_t vo_info =
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
31 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
32 "PNG file",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
33 "png",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
34 "Felix Buenemann <atmosfear@users.sourceforge.net>",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
35 ""
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
36 };
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
37
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
38 #define RGB 0
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
39 #define BGR 1
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
40
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
41 extern int verbose;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
42 int z_compression = Z_NO_COMPRESSION;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
43 static int image_width;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
44 static int image_height;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
45 static int image_format;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
46 static uint8_t *image_data=NULL;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
47 //static char *image_data;
4060
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
48 static unsigned int scale_srcW = 0, scale_srcH = 0;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
49
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
50 static int bpp = 24;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
51 static int cspace = RGB;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
52 static int framenum = 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
53
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
54 struct pngdata {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
55 FILE * fp;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
56 png_structp png_ptr;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
57 png_infop info_ptr;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
58 enum {OK,ERROR} status;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
59 };
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
60
3950
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
61 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
62 vo_draw_alpha_rgb24(w, h, src, srca, stride, image_data + 3 * (y0 * image_width + x0), 3 * image_width);
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
63 }
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
64
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
65 static uint32_t
4433
df8e0f71cc3c new info for tuning
nick
parents: 4353
diff changeset
66 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info)
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
67 {
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
68 if (fullscreen&0x04 && (width != d_width || height != d_height) &&
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
69 ((format==IMGFMT_YV12) /*|| (format == IMGFMT_I420) || (format == IMGFMT_IYUV)*/)) {
4060
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
70 /* software scaling */
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
71 image_width = (d_width + 7) & ~7;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
72 image_height = d_height;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
73 scale_srcW = width;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
74 scale_srcH = height;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
75 SwScale_Init();
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
76 }
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
77 else {
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
78 image_height = height;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
79 image_width = width;
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
80 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
81 image_format = format;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
82 //printf("Verbose level is %i\n", verbose);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
83
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
84 switch(format) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
85 case IMGFMT_BGR24:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
86 bpp = 24;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
87 cspace = BGR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
88 break;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
89 case IMGFMT_RGB24:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
90 bpp = 24;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
91 cspace = RGB;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
92 break;
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
93 case IMGFMT_IYUV:
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
94 case IMGFMT_I420:
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
95 case IMGFMT_YV12:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
96 bpp = 24;
4796
b4580c55d8bc fixing scaled output
michael
parents: 4737
diff changeset
97 cspace = BGR;
b4580c55d8bc fixing scaled output
michael
parents: 4737
diff changeset
98 yuv2rgb_init(bpp,MODE_RGB);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
99 image_data = malloc(image_width*image_height*3);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
100 break;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
101 default:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
102 return 1;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
103 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
104
3950
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
105 if((z_compression >= 0) && (z_compression <= 9)) {
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
106 if(z_compression == 0) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
107 printf("PNG Warning: compression level set to 0, compression disabled!\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
108 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
109 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
110 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
111 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
112 else {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
113 printf("PNG Warning: compression level out of range setting to 1!\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
114 printf("PNG Info: Use the -z <n> switch to set compression level from 0 to 9.\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
115 printf("PNG Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
116 z_compression = Z_BEST_SPEED;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
117 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
118
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
119 if(verbose) printf("PNG Compression level %i\n", z_compression);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
120
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
121 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
122 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
123
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
124 static const vo_info_t*
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
125 get_info(void)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
126 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
127 return &vo_info;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
128 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
129
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
130
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
131 struct pngdata create_png (char * fname)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
132 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
133 struct pngdata png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
134
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
135 /*png_structp png_ptr = png_create_write_struct
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
136 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
137 user_error_fn, user_warning_fn);*/
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
138 //png_byte *row_pointers[image_height];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
139 png.png_ptr = png_create_write_struct
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
140 (PNG_LIBPNG_VER_STRING, NULL,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
141 NULL, NULL);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
142 png.info_ptr = png_create_info_struct(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
143
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
144 if (!png.png_ptr) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
145 if(verbose > 1) printf("PNG Failed to init png pointer\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
146 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
147 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
148 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
149
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
150 if (!png.info_ptr) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
151 if(verbose > 1) printf("PNG Failed to init png infopointer\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
152 png_destroy_write_struct(&png.png_ptr,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
153 (png_infopp)NULL);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
154 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
155 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
156 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
157
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
158 if (setjmp(png.png_ptr->jmpbuf)) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
159 if(verbose > 1) printf("PNG Internal error!\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
160 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
161 fclose(png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
162 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
163 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
164 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
165
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
166 png.fp = fopen (fname, "wb");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
167 if (png.fp == NULL) {
612
77e0094f0cce some warnings killed
szabii
parents: 530
diff changeset
168 printf("\nPNG Error opening %s for writing!\n", strerror(errno));
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
169 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
170 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
171 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
172
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
173 if(verbose > 1) printf("PNG Init IO\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
174 png_init_io(png.png_ptr, png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
175
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
176 /* set the zlib compression level */
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
177 png_set_compression_level(png.png_ptr, z_compression);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
178
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
179
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
180 /*png_set_IHDR(png_ptr, info_ptr, width, height,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
181 bit_depth, color_type, interlace_type,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
182 compression_type, filter_type)*/
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
183 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
184 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
185 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
186
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
187 if(verbose > 1) printf("PNG Write Info\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
188 png_write_info(png.png_ptr, png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
189
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
190 if(cspace) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
191 if(verbose > 1) printf("PNG Set BGR Conversion\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
192 png_set_bgr(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
193 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
194
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
195 png.status = OK;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
196 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
197
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
198 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
199
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
200 static uint8_t destroy_png(struct pngdata png) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
201
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
202 if(verbose > 1) printf("PNG Write End\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
203 png_write_end(png.png_ptr, png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
204
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
205 if(verbose > 1) printf("PNG Destroy Write Struct\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
206 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
207
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
208 fclose (png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
209
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
210 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
211 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
212
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
213 static uint32_t draw_frame(uint8_t * src[])
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
214 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
215 char buf[100];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
216 int k, bppmul = bpp/8;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
217 struct pngdata png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
218 png_byte *row_pointers[image_height];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
219
1078
874ba7049c1a sprintf possible buffer overflow fixes
al3x
parents: 612
diff changeset
220 snprintf (buf, 100, "%08d.png", ++framenum);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
221
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
222 png = create_png(buf);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
223
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
224 if(png.status){
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
225 printf("PNG Error in create_png\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
226 return 1;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
227 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
228
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
229 if(verbose > 1) printf("PNG Creating Row Pointers\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
230 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &src[0][image_width*k*bppmul];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
231
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
232 //png_write_flush(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
233 //png_set_flush(png.png_ptr, nrows);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
234
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
235 if(verbose > 1) printf("PNG Writing Image Data\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
236 png_write_image(png.png_ptr, row_pointers);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
237
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
238 return destroy_png(png);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
239
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
240 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
241
1501
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
242 static void draw_osd(void)
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
243 {
3950
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
244 vo_draw_text(image_width, image_height, draw_alpha);
1501
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
245 }
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
246
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
247 static void flip_page (void)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
248 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
249 char buf[100];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
250 int k, bppmul = bpp/8;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
251 struct pngdata png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
252 png_byte *row_pointers[image_height];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
253
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
254 if((image_format == IMGFMT_YV12) || (image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420)) {
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
255
1078
874ba7049c1a sprintf possible buffer overflow fixes
al3x
parents: 612
diff changeset
256 snprintf (buf, 100, "%08d.png", ++framenum);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
257
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
258 png = create_png(buf);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
259
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
260 if(png.status){
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
261 printf("PNG Error in create_png\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
262 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
263
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
264 if(verbose > 1) printf("PNG Creating Row Pointers\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
265 for ( k = 0; k < image_height; k++ ) row_pointers[k] = &image_data[image_width*k*bppmul];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
266
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
267 //png_write_flush(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
268 //png_set_flush(png.png_ptr, nrows);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
269
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
270 if(verbose > 1) printf("PNG Writing Image Data\n");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
271 png_write_image(png.png_ptr, row_pointers);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
272
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
273 destroy_png(png);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
274 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
275 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
276
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
277 static uint32_t draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
278 {
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
279 /* hack: swap planes for I420 ;) -- alex */
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
280 if ((image_format == IMGFMT_IYUV) || (image_format == IMGFMT_I420))
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
281 {
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
282 uint8_t *src_i420[3];
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
283
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
284 src_i420[0] = src[0];
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
285 src_i420[1] = src[2];
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
286 src_i420[2] = src[1];
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
287 src = src_i420;
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
288 }
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
289
4060
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
290 if (scale_srcW) {
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
291 uint8_t *dst[3] = {image_data, NULL, NULL};
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
292 SwScale_YV12slice(src,stride,y,h,
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
293 dst, image_width*((bpp+7)/8), bpp,
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
294 scale_srcW, scale_srcH, image_width, image_height);
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
295 }
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
296 else {
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
297 uint8_t *dst = image_data + (image_width * y + x) * (bpp/8);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
298 yuv2rgb(dst,src[0],src[1],src[2],w,h,image_width*(bpp/8),stride[0],stride[1]);
4060
974e028471a4 SwScaler support for vo_png by Kim Minh, SwScale w/aspecz for vo_dga by me
atmos4
parents: 3950
diff changeset
299 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
300 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
301 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
302
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
303 static uint32_t
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
304 query_format(uint32_t format)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
305 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
306 switch(format){
4353
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
307 case IMGFMT_IYUV:
8487ae6ca3f4 i420/iyuv support
alex
parents: 4352
diff changeset
308 case IMGFMT_I420:
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
309 case IMGFMT_YV12:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
310 case IMGFMT_RGB|24:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
311 case IMGFMT_BGR|24:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
312 return 1;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
313 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
314 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
315 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
316
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
317 static void
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
318 uninit(void)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
319 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
320 if(image_data){ free(image_data);image_data=NULL;}
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
321 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
322
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
323
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
324 static void check_events(void)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
325 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
326 }
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
327
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
328 static uint32_t preinit(const char *arg)
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
329 {
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
330 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
331 {
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
332 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
333 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
334 }
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
335 return 0;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
336 }
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
337
4596
c35d7ce151b3 10000hl to Holm... control MUST BE static...
arpi
parents: 4592
diff changeset
338 static uint32_t control(uint32_t request, void *data, ...)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
339 {
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
340 switch (request) {
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
341 case VOCTRL_QUERY_FORMAT:
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
342 return query_format(*((uint32_t*)data));
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
343 }
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
344 return VO_NOTIMPL;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
345 }