annotate libvo/vo_pnm.c @ 13565:d8808729d3fd

unsinged 32 and 24bit types
author alex
date Tue, 05 Oct 2004 19:18:22 +0000
parents 455a5056801f
children e394a9cfaf3f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13394
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
1 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
2
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
3 /*
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
4 * vo_pnm.c, PPM/PGM/PGMYUV Video Output Driver for MPlayer
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
5 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
6 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
7 * Written by Ivo van Poorten. (GPL)2004
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
8 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
9 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
10 * Changelog
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
11 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
12 * 2004-09-09 First draft.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
13 * 2004-09-16 Second draft. It now acts on VOCTRL_DRAW_IMAGE and does not
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
14 * maintain a local copy of the image if the format is YV12.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
15 * Speed improvement and uses less memory.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
16 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
17 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
18 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
19
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
20 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
21
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
22 /* Global Includes */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
23
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
24 #include <stdio.h>
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
25 #include <stdlib.h>
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
26 #include <string.h>
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
27 #include <errno.h>
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
28 #include <sys/stat.h>
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
29 #include <math.h> /* for log10() */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
30
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
31 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
32
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
33 /* Local Includes */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
34
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
35 #include "config.h"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
36 #include "mp_msg.h"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
37 #include "video_out.h"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
38 #include "video_out_internal.h"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
39 #include "mplayer.h" /* for exit_player() */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
40 #include "help_mp.h"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
41
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
42 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
43
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
44 /* Defines */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
45
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
46 /* Used for temporary buffers to store file- and pathnames */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
47 #define BUFLENGTH 512
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
48
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
49 #define PNM_ASCII_MODE 0
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
50 #define PNM_RAW_MODE 1
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
51 #define PNM_TYPE_PPM 0
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
52 #define PNM_TYPE_PGM 1
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
53 #define PNM_TYPE_PGMYUV 2
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
54
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
55 #define PNM_LINE_OF_ASCII "%03d %03d %03d %03d %03d %03d %03d %03d %03d %03d %03d %03d %03d %03d %03d\n"
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
56 #define PNM_LINE15(a,b) a[b], a[b+1], a[b+2], a[b+3], a[b+4], a[b+5], a[b+6], \
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
57 a[b+7], a[b+8], a[b+9], a[b+10], a[b+11], a[b+12], \
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
58 a[b+13], a[b+14]
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
59
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
60 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
61
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
62 /* Info */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
63
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
64 static vo_info_t info=
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
65 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
66 "PPM/PGM/PGMYUV file",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
67 "pnm",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
68 "Ivo van Poorten (ivop@euronet.nl)",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
69 ""
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
70 };
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
71
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
72 LIBVO_EXTERN (pnm)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
73
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
74 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
75
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
76 /* Global Variables */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
77
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
78 int pnm_type = PNM_TYPE_PPM;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
79 int pnm_mode = PNM_RAW_MODE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
80
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
81 char *pnm_outdir = NULL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
82 char *pnm_subdirs = NULL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
83 int pnm_maxfiles = 1000;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
84 char *pnm_file_extension = NULL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
85
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
86 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
87
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
88 /** \brief Memory allocation failed.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
89 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
90 * The video output driver failed to allocate a block of memory it needed.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
91 * It displays a message and exits the player.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
92 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
93 * \return nothing It does not return.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
94 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
95
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
96 void pnm_malloc_failed(void) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
97 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
98 MSGTR_MemAllocFailed);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
99 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
100 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
101
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
102 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
103
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
104 /** \brief An error occured while writing to a file.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
105 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
106 * The program failed to write data to a file.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
107 * It displays a message and exits the player.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
108 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
109 * \return nothing It does not return.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
110 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
111
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
112 void pnm_write_error(void) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
113 mp_msg(MSGT_VO, MSGL_ERR, MSGTR_ErrorWritingFile, info.short_name);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
114 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
115 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
116
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
117 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
118
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
119 /** \brief Pre-initialisation.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
120 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
121 * This function is called before initialising the video output driver. It
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
122 * parses all suboptions and sets variables accordingly. If an error occurs
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
123 * (like an option being out of range, not having any value or an unknown
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
124 * option is stumbled upon) the player will exit.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
125 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
126 * \param arg A string containing all the suboptions passed to the video
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
127 * output driver.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
128 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
129 * \return 0 All went well.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
130 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
131
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
132 static uint32_t preinit(const char *arg)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
133 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
134 char *buf; /* buf is used to store parsed string values */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
135 int value; /* storage for parsed integer values */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
136
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
137 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
138 MSGTR_VO_ParsingSuboptions);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
139
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
140 if (arg) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
141
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
142 while (*arg != '\0') {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
143 if (!strncmp(arg, ":", 1)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
144 arg++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
145 continue; /* multiple ':' is not really an error */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
146 } if (!strncmp(arg, "ascii", 5)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
147 arg += 5;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
148 pnm_mode = PNM_ASCII_MODE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
149 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
150 MSGTR_VO_PNM_ASCIIMode);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
151 } else if (!strncmp(arg, "raw", 3)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
152 arg += 3;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
153 pnm_mode = PNM_RAW_MODE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
154 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
155 MSGTR_VO_PNM_RawMode);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
156 } else if (!strncmp(arg, "ppm", 3)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
157 arg += 3;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
158 pnm_type = PNM_TYPE_PPM;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
159 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
160 MSGTR_VO_PNM_PPMType);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
161 } else if (!strncmp(arg, "pgmyuv", 6)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
162 arg += 6;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
163 pnm_type = PNM_TYPE_PGMYUV;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
164 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
165 MSGTR_VO_PNM_PGMYUVType);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
166 } else if (!strncmp(arg, "pgm", 3)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
167 arg += 3;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
168 pnm_type = PNM_TYPE_PGM;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
169 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
170 MSGTR_VO_PNM_PGMType);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
171 } else if (!strncmp(arg, "outdir=", 7)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
172 arg += 7;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
173 buf = malloc(strlen(arg)+1); /* maximum length possible */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
174 if (!buf) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
175 pnm_malloc_failed(); /* message and exit_player! */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
176 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
177 if (sscanf(arg, "%[^:]", buf) == 1) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
178 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
179 info.short_name, "outdir", buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
180 arg += strlen(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
181 pnm_outdir = strdup(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
182 if (!pnm_outdir) pnm_malloc_failed();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
183 free(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
184 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
185 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
186 info.short_name, "outdir",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
187 MSGTR_VO_NoValueSpecified);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
188 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
189 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
190 } else if (!strncmp(arg, "subdirs=", 8)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
191 arg += 8;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
192 buf = malloc(strlen(arg)+1); /* maximum length possible */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
193 if (!buf) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
194 pnm_malloc_failed();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
195 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
196 if (sscanf(arg, "%[^:]", buf) == 1) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
197 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
198 info.short_name, "subdirs", buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
199 arg += strlen(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
200 pnm_subdirs = strdup(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
201 if (!pnm_subdirs) pnm_malloc_failed();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
202 free(buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
203 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
204 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
205 info.short_name, "subdirs",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
206 MSGTR_VO_NoValueSpecified);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
207 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
208 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
209 } else if (!strncmp(arg, "maxfiles=", 9)) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
210 arg += 9;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
211 if (sscanf(arg, "%d", &value) == 1) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
212 if (value < 1) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
213 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s %s.\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
214 info.short_name, "maxfiles",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
215 MSGTR_VO_ValueOutOfRange, ">=1");
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
216 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
217 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
218 pnm_maxfiles = value;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
219 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s --> %d\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
220 info.short_name, "maxfiles", value);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
221 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
222 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
223 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
224 info.short_name, "maxfiles",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
225 MSGTR_VO_NoValueSpecified);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
226 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
227 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
228 /* only here if value is set and sane */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
229 if (value) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
230 arg += (int)log10(value) + 1;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
231 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
232 arg++; /* log10(0) fails */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
233 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
234 } else {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
235 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %-20s...\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
236 MSGTR_VO_UnknownSuboptions, arg);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
237 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
238 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
239 } /* end while */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
240 } /* endif */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
241
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
242 /* If pnm_outdir is not set by an option, resort to default of "." */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
243 if (!pnm_outdir) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
244 pnm_outdir = strdup(".");
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
245 if (!pnm_outdir) pnm_malloc_failed();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
246 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
247
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
248 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
249 MSGTR_VO_SuboptionsParsedOK);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
250 return 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
251 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
252
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
253 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
254
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
255 /** \brief Create a directory.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
256 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
257 * This function creates a directory. If it already exists, it tests if
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
258 * it's a directory and not something else, and if it is, it tests whether
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
259 * the directory is writable or not.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
260 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
261 * \param buf Pointer to directory name.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
262 * \param verbose Verbose on success. If verbose is non-zero, it will print
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
263 * a message if it was successful in creating the directory.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
264 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
265 * \return nothing In case anything fails, the player will exit. If it
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
266 * returns, everything went well.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
267 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
268
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
269 void pnm_mkdir(char *buf, int verbose) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
270 struct stat stat_p;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
271
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
272 /* Silly MING32 bug workaround */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
273 #ifndef __MINGW32__
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
274 if ( mkdir(buf, 0755) < 0 ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
275 #else
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
276 if ( mkdir(buf) < 0 ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
277 #endif
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
278 switch (errno) { /* use switch in case other errors need to be caught
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
279 and handled in the future */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
280 case EEXIST:
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
281 if ( stat(buf, &stat_p ) < 0 ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
282 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
283 MSGTR_VO_GenericError, strerror(errno) );
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
284 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
285 MSGTR_VO_UnableToAccess,buf);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
286 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
287 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
288 if ( !S_ISDIR(stat_p.st_mode) ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
289 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
290 buf, MSGTR_VO_ExistsButNoDirectory);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
291 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
292 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
293 if ( !(stat_p.st_mode & S_IWUSR) ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
294 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
295 buf, MSGTR_VO_DirExistsButNotWritable);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
296 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
297 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
298
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
299 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
300 buf, MSGTR_VO_DirExistsAndIsWritable);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
301 break;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
302
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
303 default:
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
304 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
305 MSGTR_VO_GenericError, strerror(errno) );
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
306 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s - %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
307 buf, MSGTR_VO_CantCreateDirectory);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
308 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
309 } /* end switch */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
310 } else if ( verbose ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
311 mp_msg(MSGT_VO, MSGL_INFO, "%s: %s - %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
312 buf, MSGTR_VO_DirectoryCreateSuccess);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
313 } /* end if */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
314 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
315
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
316 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
317
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
318 /** \brief Configure the video output driver.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
319 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
320 * This functions configures the video output driver. It determines the
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
321 * width and height of the image(s) and creates the output directory.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
322 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
323 * \return 0 All went well.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
324 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
325
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
326 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
327 uint32_t d_height, uint32_t fullscreen, char *title,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
328 uint32_t format)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
329 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
330 char buf[BUFLENGTH];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
331
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
332 if (vo_config_count > 0 ) { /* Already configured */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
333 return 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
334 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
335
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
336 /* Create outdir. */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
337
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
338 snprintf(buf, BUFLENGTH, "%s", pnm_outdir);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
339 pnm_mkdir(buf, 1); /* This function only returns if creation was
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
340 successful. If not, the player will exit. */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
341
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
342 if (pnm_type == PNM_TYPE_PPM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
343 pnm_file_extension = strdup("ppm");
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
344 } else if (pnm_type == PNM_TYPE_PGM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
345 pnm_file_extension = strdup("pgm");
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
346 } else if (pnm_type == PNM_TYPE_PGMYUV) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
347 pnm_file_extension = strdup("pgmyuv");
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
348 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
349 if (!pnm_file_extension) pnm_malloc_failed();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
350
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
351 return 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
352 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
353
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
354 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
355
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
356 /** \brief Write PNM file to output file
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
357 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
358 * This function writes PPM, PGM or PGMYUV data to an output file, depending
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
359 * on which type was selected on the commandline. pnm_type and pnm_mode are
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
360 * global variables. Depending on which mode was selected, it will write
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
361 * a RAW or an ASCII file.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
362 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
363 * \param outfile Filedescriptor of output file.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
364 * \param mpi The image to write.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
365 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
366 * \return none The player will exit if anything goes wrong.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
367 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
368
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
369 void pnm_write_pnm(FILE *outfile, mp_image_t *mpi)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
370 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
371 uint32_t w = mpi->w;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
372 uint32_t h = mpi->h;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
373 uint8_t *rgbimage = mpi->planes[0];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
374 uint8_t *planeY = mpi->planes[0];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
375 uint8_t *planeU = mpi->planes[1];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
376 uint8_t *planeV = mpi->planes[2];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
377 uint8_t *curline;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
378 uint32_t strideY = mpi->stride[0];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
379 uint32_t strideU = mpi->stride[1];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
380 uint32_t strideV = mpi->stride[2];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
381
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
382 int i, j;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
383
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
384 if (pnm_mode == PNM_RAW_MODE) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
385
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
386 if (pnm_type == PNM_TYPE_PPM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
387 if ( fprintf(outfile, "P6\n%d %d\n255\n", w, h) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
388 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
389 if ( fwrite(rgbimage, w * 3, h, outfile) < h ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
390 } else if (pnm_type == PNM_TYPE_PGM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
391 if ( fprintf(outfile, "P5\n%d %d\n255\n", w, h) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
392 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
393 for (i=0; i<h; i++) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
394 if ( fwrite(planeY + i * strideY, w, 1, outfile) < 1 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
395 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
396 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
397 } else if (pnm_type == PNM_TYPE_PGMYUV) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
398 if ( fprintf(outfile, "P5\n%d %d\n255\n", w, h*3/2) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
399 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
400 for (i=0; i<h; i++) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
401 if ( fwrite(planeY + i * strideY, w, 1, outfile) < 1 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
402 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
403 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
404 w = w / 2;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
405 h = h / 2;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
406 for (i=0; i<h; i++) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
407 if ( fwrite(planeU + i * strideU, w, 1, outfile) < 1 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
408 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
409 if ( fwrite(planeV + i * strideV, w, 1, outfile) < 1 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
410 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
411 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
412 } /* end if pnm_type */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
413
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
414 } else if (pnm_mode == PNM_ASCII_MODE) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
415
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
416 if (pnm_type == PNM_TYPE_PPM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
417 if ( fprintf(outfile, "P3\n%d %d\n255\n", w, h) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
418 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
419 for (i=0; i <= w * h * 3 - 16 ; i += 15) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
420 if ( fprintf(outfile, PNM_LINE_OF_ASCII,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
421 PNM_LINE15(rgbimage,i) ) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
422 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
423 while (i < (w * h * 3) ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
424 if ( fprintf(outfile, "%03d ", rgbimage[i]) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
425 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
426 i++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
427 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
428 if ( fputc('\n', outfile) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
429 } else if ( (pnm_type == PNM_TYPE_PGM) ||
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
430 (pnm_type == PNM_TYPE_PGMYUV) ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
431
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
432 /* different header for pgm and pgmyuv. pgmyuv is 'higher' */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
433 if (pnm_type == PNM_TYPE_PGM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
434 if ( fprintf(outfile, "P2\n%d %d\n255\n", w, h) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
435 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
436 } else { /* PNM_TYPE_PGMYUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
437 if ( fprintf(outfile, "P2\n%d %d\n255\n", w, h*3/2) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
438 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
439 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
440
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
441 /* output Y plane for both PGM and PGMYUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
442 for (j=0; j<h; j++) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
443 curline = planeY + strideY * j;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
444 for (i=0; i <= w - 16; i+=15) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
445 if ( fprintf(outfile, PNM_LINE_OF_ASCII,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
446 PNM_LINE15(curline,i) ) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
447 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
448 while (i < w ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
449 if ( fprintf(outfile, "%03d ", curline[i]) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
450 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
451 i++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
452 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
453 if ( fputc('\n', outfile) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
454 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
455
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
456 /* also output U and V planes fpr PGMYUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
457 if (pnm_type == PNM_TYPE_PGMYUV) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
458 w = w / 2;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
459 h = h / 2;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
460 for (j=0; j<h; j++) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
461 curline = planeU + strideU * j;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
462 for (i=0; i<= w-16; i+=15) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
463 if ( fprintf(outfile, PNM_LINE_OF_ASCII,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
464 PNM_LINE15(curline,i) ) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
465 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
466 while (i < w ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
467 if ( fprintf(outfile, "%03d ", curline[i]) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
468 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
469 i++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
470 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
471 if ( fputc('\n', outfile) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
472
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
473 curline = planeV + strideV * j;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
474 for (i=0; i<= w-16; i+=15) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
475 if ( fprintf(outfile, PNM_LINE_OF_ASCII,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
476 PNM_LINE15(curline,i) ) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
477 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
478 while (i < w ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
479 if ( fprintf(outfile, "%03d ", curline[i]) < 0 )
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
480 pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
481 i++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
482 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
483 if ( fputc('\n', outfile) < 0 ) pnm_write_error();
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
484 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
485 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
486
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
487 } /* end if pnm_type */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
488 } /* end if pnm_mode */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
489 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
490
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
491 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
492
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
493 /** \brief Write a PNM image.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
494 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
495 * This function gets called first if a PNM image has to be written to disk.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
496 * It contains the subdirectory framework and it calls pnm_write_pnm() to
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
497 * actually write the image to disk.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
498 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
499 * \param mpi The image to write.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
500 *
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
501 * \return none The player will exit if anything goes wrong.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
502 */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
503
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
504 void pnm_write_image(mp_image_t *mpi)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
505 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
506 static uint32_t framenum = 0, framecounter = 0, subdircounter = 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
507 char buf[BUFLENGTH];
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
508 static char subdirname[BUFLENGTH] = "";
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
509 FILE *outfile;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
510
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
511 if (!mpi) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
512 mp_msg(MSGT_VO, MSGL_ERR, "%s: No image data suplied to video output driver\n", info.short_name );
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
513 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
514 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
515
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
516 /* Start writing to new subdirectory after a certain amount of frames */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
517 if ( framecounter == pnm_maxfiles ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
518 framecounter = 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
519 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
520
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
521 /* If framecounter is zero (or reset to zero), increment subdirectory
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
522 * number and create the subdirectory.
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
523 * If pnm_subdirs is not set, do nothing. */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
524 if ( !framecounter && pnm_subdirs ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
525 subdircounter++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
526 snprintf(subdirname, BUFLENGTH, "%s%08d", pnm_subdirs, subdircounter);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
527 snprintf(buf, BUFLENGTH, "%s/%s", pnm_outdir, subdirname);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
528 pnm_mkdir(buf, 0); /* This function only returns if creation was
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
529 successful. If not, the player will exit. */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
530 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
531
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
532 framenum++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
533 framecounter++;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
534
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
535 /* snprintf the full pathname of the outputfile */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
536 snprintf(buf, BUFLENGTH, "%s/%s/%08d.%s", pnm_outdir, subdirname,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
537 framenum, pnm_file_extension);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
538
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
539 if ( (outfile = fopen(buf, "wb") ) == NULL ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
540 mp_msg(MSGT_VO, MSGL_ERR, "\n%s: %s\n", info.short_name,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
541 MSGTR_VO_CantCreateFile);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
542 mp_msg(MSGT_VO, MSGL_ERR, "%s: %s: %s\n",
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
543 info.short_name, MSGTR_VO_GenericError,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
544 strerror(errno) );
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
545 exit_player(MSGTR_Exit_error);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
546 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
547
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
548 pnm_write_pnm(outfile, mpi);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
549
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
550 fclose(outfile);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
551 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
552
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
553 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
554
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
555 static uint32_t draw_image(mp_image_t *mpi)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
556 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
557 if (mpi->flags & MP_IMGFLAG_PLANAR) { /* Planar */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
558 if (mpi->flags & MP_IMGFLAG_YUV) { /* Planar YUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
559 pnm_write_image(mpi);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
560 return VO_TRUE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
561 } else { /* Planar RGB */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
562 return VO_FALSE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
563 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
564 } else { /* Packed */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
565 if (mpi->flags & MP_IMGFLAG_YUV) { /* Packed YUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
566 return VO_FALSE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
567 } else { /* Packed RGB */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
568 pnm_write_image(mpi);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
569 return VO_TRUE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
570 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
571 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
572
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
573 return VO_FALSE;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
574 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
575
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
576 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
577
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
578 static uint32_t draw_frame(uint8_t *src[])
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
579 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
580 mp_msg(MSGT_VO, MSGL_V, "%s: draw_frame() is called!\n", info.short_name);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
581 return -1;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
582 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
583
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
584 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
585
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
586 static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h,
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
587 int x, int y)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
588 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
589 return 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
590 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
591
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
592 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
593
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
594 static uint32_t query_format(uint32_t format)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
595 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
596 /* Ensure that for PPM we get Packed RGB and for PGM(YUV) we get
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
597 * Planar YUV */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
598 if (pnm_type == PNM_TYPE_PPM) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
599 if (format == IMGFMT_RGB24) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
600 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
601 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
602 } else if ( (pnm_type == PNM_TYPE_PGM) || (pnm_type == PNM_TYPE_PGMYUV) ) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
603 if (format == IMGFMT_YV12) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
604 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
605 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
606 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
607
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
608 return 0;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
609 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
610
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
611 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
612
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
613 static uint32_t control(uint32_t request, void *data, ...)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
614 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
615 switch (request) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
616 case VOCTRL_QUERY_FORMAT:
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
617 return query_format(*((uint32_t*)data));
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
618 case VOCTRL_DRAW_IMAGE:
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
619 return draw_image(data);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
620 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
621 return VO_NOTIMPL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
622 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
623
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
624 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
625
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
626 static void uninit(void)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
627 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
628 if (pnm_subdirs) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
629 free(pnm_subdirs);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
630 pnm_subdirs = NULL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
631 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
632 if (pnm_outdir) {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
633 free(pnm_outdir);
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
634 pnm_outdir = NULL;
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
635 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
636 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
637
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
638 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
639
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
640 static void check_events(void)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
641 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
642 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
643
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
644 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
645
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
646 static void draw_osd(void)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
647 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
648 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
649
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
650 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
651
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
652 static void flip_page (void)
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
653 {
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
654 }
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
655
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
656 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
657
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
658 #undef BUFLENGTH
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
659 #undef PNM_RAW_MODE
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
660 #undef PNM_ASCII_MODE
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
661 #undef PNM_TYPE_PPM
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
662 #undef PNM_TYPE_PGM
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
663 #undef PNM_TYPE_PGMYUV
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
664
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
665 /* ------------------------------------------------------------------------- */
455a5056801f New generic 'portable anymap' video output driver. It supports portable
ivo
parents:
diff changeset
666