annotate libvo/vo_png.c @ 27712:daff903e23e2

Move socklen_t typedef from config.h to stream/network.h.
author diego
date Sun, 12 Oct 2008 12:12:41 +0000
parents 710704af0926
children 80a16d26acda
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 /*
12857
db49cdedb88d embarassing typo
diego
parents: 8148
diff changeset
2 * vo_png.c, Portable Network Graphics Renderer for MPlayer
527
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 * Copyright 2001 by Felix Buenemann <atmosfear@users.sourceforge.net>
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 * Uses libpng (which uses zlib), so see according licenses.
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
7 *
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
8 */
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
9
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
10 #include <stdio.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
11 #include <stdlib.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
12 #include <string.h>
612
77e0094f0cce some warnings killed
szabii
parents: 530
diff changeset
13 #include <errno.h>
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
14 #include <sys/stat.h>
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
15 #include <sys/types.h>
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
16 #include <unistd.h>
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
17
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
18 #include <png.h>
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
19
26203
0d255d03016f #include config.h before all other headers.
diego
parents: 25220
diff changeset
20 #include "config.h"
17932
3fe3b2b3a6ce Convert all if(verbose>X) to mp_msg_test calls.
diego
parents: 16171
diff changeset
21 #include "mp_msg.h"
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
22 #include "mp_msg.h"
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
23 #include "help_mp.h"
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
24 #include "video_out.h"
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
25 #include "video_out_internal.h"
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
26 #include "subopt-helper.h"
27655
710704af0926 Add missing #include for mplayer.h, fixes the warning:
diego
parents: 27618
diff changeset
27 #include "mplayer.h"
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
28
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
29 #define BUFLENGTH 512
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
30
25216
3aee342be929 Make vo info structs const
reimar
parents: 24671
diff changeset
31 static const vo_info_t info =
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
32 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
33 "PNG file",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
34 "png",
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
35 "Felix Buenemann <atmosfear@users.sourceforge.net>",
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
25220
c9e9ac2008c2 Mark the vo_functions_t definitions as const where possible.
reimar
parents: 25216
diff changeset
39 const LIBVO_EXTERN (png)
8148
5b39e79af5fe removed get_info, using the same sheme as in libmpcodecs instead
alex
parents: 7926
diff changeset
40
24669
ec55ecbbd702 Make a local-only variable static in vo_png
reimar
parents: 18950
diff changeset
41 static int z_compression = Z_NO_COMPRESSION;
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
42 static char *png_outdir = NULL;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
43 static int framenum = 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
44
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
45 struct pngdata {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
46 FILE * fp;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
47 png_structp png_ptr;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
48 png_infop info_ptr;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
49 enum {OK,ERROR} status;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
50 };
3950
e92653caf5d7 osd support, zlib range fix. by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 2732
diff changeset
51
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
52 static void png_mkdir(char *buf, int verbose) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
53 struct stat stat_p;
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
54
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
55 #ifndef __MINGW32__
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
56 if ( mkdir(buf, 0755) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
57 #else
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
58 if ( mkdir(buf) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
59 #endif
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
60 switch (errno) { /* use switch in case other errors need to be caught
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
61 and handled in the future */
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
62 case EEXIST:
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
63 if ( stat(buf, &stat_p ) < 0 ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
64 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
65 MSGTR_VO_GenericError, strerror(errno) );
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
66 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
67 MSGTR_VO_UnableToAccess,buf);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
68 exit_player(MSGTR_Exit_error);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
69 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
70 if ( !S_ISDIR(stat_p.st_mode) ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
71 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
72 buf, MSGTR_VO_ExistsButNoDirectory);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
73 exit_player(MSGTR_Exit_error);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
74 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
75 if ( !(stat_p.st_mode & S_IWUSR) ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
76 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
77 buf, MSGTR_VO_DirExistsButNotWritable);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
78 exit_player(MSGTR_Exit_error);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
79 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
80
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
81 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
82 buf, MSGTR_VO_DirExistsAndIsWritable);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
83 break;
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
84
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
85 default:
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
86 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
87 MSGTR_VO_GenericError, strerror(errno) );
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
88 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
89 buf, MSGTR_VO_CantCreateDirectory);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
90 exit_player(MSGTR_Exit_error);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
91 } /* end switch */
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
92 } else if ( verbose ) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
93 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
94 buf, MSGTR_VO_DirectoryCreateSuccess);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
95 } /* end if */
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
96 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
97
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
98 static int
15212
05aa13cdf92f replace VO and VF numeric flags with #defined identifiers
henry
parents: 14451
diff changeset
99 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
100 {
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
101 char buf[BUFLENGTH];
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
102
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
103 if(z_compression == 0) {
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
104 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning1);
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
105 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning2);
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
106 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_PNG_Warning3);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
107 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
108
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
109 snprintf(buf, BUFLENGTH, "%s", png_outdir);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
110 png_mkdir(buf, 1);
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
111 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Compression level %i\n", z_compression);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
112
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
113 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
114 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
115
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
116
18950
a943bc3f26c8 Make some functions static.
uau
parents: 18234
diff changeset
117 static struct pngdata create_png (char * fname, int image_width, int image_height, int swapped)
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
118 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
119 struct pngdata png;
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
120
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
121 /*png_structp png_ptr = png_create_write_struct
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
122 (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
123 user_error_fn, user_warning_fn);*/
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
124 //png_byte *row_pointers[image_height];
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
125 png.png_ptr = png_create_write_struct
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
126 (PNG_LIBPNG_VER_STRING, NULL,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
127 NULL, NULL);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
128 png.info_ptr = png_create_info_struct(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
129
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
130 if (!png.png_ptr) {
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
131 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png pointer\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
132 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
133 return 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
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
136 if (!png.info_ptr) {
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
137 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Failed to init png infopointer\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
138 png_destroy_write_struct(&png.png_ptr,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
139 (png_infopp)NULL);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
140 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
141 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
142 }
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 (setjmp(png.png_ptr->jmpbuf)) {
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
145 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Internal error!\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
146 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
147 fclose(png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
148 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
149 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
150 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
151
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
152 png.fp = fopen (fname, "wb");
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
153 if (png.fp == NULL) {
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
154 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorOpeningForWriting, strerror(errno));
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
155 png.status = ERROR;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
156 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
157 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
158
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
159 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Init IO\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
160 png_init_io(png.png_ptr, png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
161
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
162 /* set the zlib compression level */
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
163 png_set_compression_level(png.png_ptr, z_compression);
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_set_IHDR(png_ptr, info_ptr, width, height,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
167 bit_depth, color_type, interlace_type,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
168 compression_type, filter_type)*/
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
169 png_set_IHDR(png.png_ptr, png.info_ptr, image_width, image_height,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
170 8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
171 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
172
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
173 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write Info\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
174 png_write_info(png.png_ptr, png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
175
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
176 if(swapped) {
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
177 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Set BGR Conversion\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
178 png_set_bgr(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
179 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
180
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
181 png.status = OK;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
182 return png;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
183 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
184
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
185 static uint8_t destroy_png(struct pngdata png) {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
186
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
187 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Write End\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
188 png_write_end(png.png_ptr, png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
189
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
190 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Destroy Write Struct\n");
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
191 png_destroy_write_struct(&png.png_ptr, &png.info_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
192
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
193 fclose (png.fp);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
194
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
195 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
196 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
197
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
198 static uint32_t draw_image(mp_image_t* mpi){
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
199 char buf[100];
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
200 int k;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
201 struct pngdata png;
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
202 png_byte *row_pointers[mpi->h];
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
203
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
204 // if -dr or -slices then do nothing:
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
205 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
206
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
207 snprintf (buf, 100, "%s/%08d.png", png_outdir, ++framenum);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
208
24670
a2599160737c Use IMGFMT_IS_BGR instead of mpi->flags&MP_IMGFLAG_SWAPPED, this is easier
reimar
parents: 24669
diff changeset
209 png = create_png(buf, mpi->w, mpi->h, IMGFMT_IS_BGR(mpi->imgfmt));
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
210
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
211 if(png.status){
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
212 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_PNG_ErrorInCreatePng);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
213 return 1;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
214 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
215
24671
fbcd9dcb0daf Get rid of mp_msg_test in vo_png, only reason to use it is performance and
reimar
parents: 24670
diff changeset
216 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Creating Row Pointers\n");
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
217 for ( k = 0; k < mpi->h; k++ )
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
218 row_pointers[k] = mpi->planes[0]+mpi->stride[0]*k;
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
219
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
220 //png_write_flush(png.png_ptr);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
221 //png_set_flush(png.png_ptr, nrows);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
222
17932
3fe3b2b3a6ce Convert all if(verbose>X) to mp_msg_test calls.
diego
parents: 16171
diff changeset
223 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
18234
a107276371a8 Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents: 17932
diff changeset
224 mp_msg(MSGT_VO,MSGL_DBG2, "PNG Writing Image Data\n"); }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
225 png_write_image(png.png_ptr, row_pointers);
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
226
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
227 destroy_png(png);
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
228
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
229 return VO_TRUE;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
230 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
231
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
232 static void draw_osd(void){}
1501
d40f2b686846 changes according to -utf8 option, draw_osd() function added
atlka
parents: 1078
diff changeset
233
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
234 static void flip_page (void){}
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
235
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
236 static int draw_frame(uint8_t * src[])
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
237 {
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
238 return -1;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
239 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
240
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
241 static int draw_slice( uint8_t *src[],int stride[],int w,int h,int x,int y )
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
242 {
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
243 return -1;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
244 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
245
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
246 static int
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
247 query_format(uint32_t format)
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
248 {
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
249 switch(format){
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
250 case IMGFMT_RGB|24:
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
251 case IMGFMT_BGR|24:
7694
b64f14fdadfb also set VFCAP_ACCEPT_STRIDE when draw_image() is implemented
arpi
parents: 7693
diff changeset
252 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_ACCEPT_STRIDE;
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
253 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
254 return 0;
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
255 }
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
256
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
257 static void uninit(void){
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
258 if (png_outdir) {
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
259 free(png_outdir);
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
260 png_outdir = NULL;
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
261 }
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
262 }
527
a38decaa04ec png video out renderer initial release
atmosfear
parents:
diff changeset
263
7926
7d2542838d24 - removed YV12 support (builtin yv12->rgb conversion)
arpi
parents: 7694
diff changeset
264 static void check_events(void){}
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
265
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
266 static int int_zero_to_nine(int *sh)
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
267 {
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
268 if ( (*sh < 0) || (*sh > 9) )
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
269 return 0;
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
270 return 1;
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
271 }
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
272
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
273 static opt_t subopts[] = {
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
274 {"z", OPT_ARG_INT, &z_compression, (opt_test_f)int_zero_to_nine},
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
275 {"outdir", OPT_ARG_MSTRZ, &png_outdir, NULL, 0},
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
276 {NULL}
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
277 };
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
278
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
279 static int preinit(const char *arg)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
280 {
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
281 z_compression = 0;
27618
9badbf52f33c add outdir sub-option to vo png
ben
parents: 26203
diff changeset
282 png_outdir = strdup(".");
14451
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
283 if (subopt_parse(arg, subopts) != 0) {
4a6f25e88dbb Implementation of vo_png suboption parser with subopt-helper and removal
ivo
parents: 12857
diff changeset
284 return -1;
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
285 }
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
286 return 0;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
287 }
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
288
16171
fd51fd1ff231 Fix the return types of all (six) libvo API functions. Used to be uint32_t, but
ivo
parents: 15212
diff changeset
289 static int control(uint32_t request, void *data, ...)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
290 {
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
291 switch (request) {
7693
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
292 case VOCTRL_DRAW_IMAGE:
3f218f3172f3 draw_image()
arpi
parents: 7472
diff changeset
293 return draw_image(data);
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
294 case VOCTRL_QUERY_FORMAT:
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
295 return query_format(*((uint32_t*)data));
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
296 }
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
297 return VO_NOTIMPL;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4060
diff changeset
298 }