]> icculus.org git repositories - taylor/freespace2.git/blob - src/ac/ac.cpp
Initial revision
[taylor/freespace2.git] / src / ac / ac.cpp
1 /*
2  * $Logfile: /Freespace2/code/AC/ac.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C module for console version of anim converter
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:11  root
11  * Initial revision
12  *
13  * 
14  * 2     10/23/98 6:03p Dave
15  * 
16  * 12    6/24/98 10:43a Hoffoss
17  * Changed default to 15 FPS instead of 30 FPS.
18  * 
19  * 11    6/23/98 4:18p Hoffoss
20  * Fixed some bugs with AC release build.
21  * 
22  * 10    7/20/97 6:59p Lawrance
23  * added new -i and -x switches
24  * 
25  * 9     5/21/97 11:06a Lawrance
26  * enabling a user-defined transparent value
27  * 
28  * 8     5/19/97 3:21p Lawrance
29  * add fps parm, version num to anim header
30  * 
31  * 7     2/25/97 5:18p Lawrance
32  * add carriage return after finished, so DOS prompt at a new line
33  * 
34  * 6     2/20/97 3:03p Lawrance
35  * initialize force_key_frame global to -1
36  * 
37  * 5     2/20/97 1:59p Lawrance
38  * sourcesafe sucks
39  * 
40  * 4     2/20/97 1:58p Adam
41  * 
42  * 2     2/19/97 9:26p Lawrance
43  * console version of converter working
44  * 
45  * 1     2/19/97 7:26p Lawrance
46  *
47  * $NoKeywords: $
48  */
49
50 #include <windows.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <string.h>
54 #include "convert.h"
55 #include "ac.h"
56 #include "animplay.h"
57 #include "packunpack.h"
58
59 #ifdef NDEBUG
60 char *help_text = "AC ANI Converter Copyright (C) 1998, Volition, Inc.  All Rights Reserved.\n"
61                                                 "For exclusive use in FreeSpace missions only.\n\n"
62                                                 "Usage: ac [-fps n] [-v] filename\n\n" \
63                                                 "-i     => display information and statistics about the ani file\n" \
64                                                 "-x     => extract pcx files from ani (named filename0000.pcx etc)\n" \
65                   "-fps n => n frames per second (default 15)\n" \
66                                                 "-v     => display the version number\n" \
67                                                 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
68                                                 "Examples:\n" \
69                                                 "ac test.avi => converts test.avi to test.ani\n" \
70                                                 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n";
71
72 #else
73 char *help_text = "Usage: ac [-c n] [-k n] [-ke n] [-fps n] [-to] [-v] filename\n\n" \
74                                                 "-c   n => which kind of compression to use (default is 1):\n" \
75                                                 "     -c 0 => compression using up to 255 count, takes 3 bytes for a run\n" \
76                                                 "     -c 1 => compression using up to 127 count, takes 2 bytes for a run\n" \
77                                                 "-i     => display information and statistics about the ani file\n" \
78                                                 "-x     => extract pcx files from ani (named filename0000.pcx etc)\n" \
79                                                 "-k   n => keyframe at frame n\n" \
80                   "-ke  n => keyframe every n frames\n" \
81                   "-fps n => n frames per second (default 15)\n" \
82                   "-to    => transparent override.  Use pixel in top-left corner of first frame as transparent color.  Otherwise RGB value 0.255.0 is used.\n" \
83                                                 "-v     => display the version number\n" \
84                                                 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
85                                                 "Examples:\n" \
86                                                 "ac test.avi => converts test.avi to test.ani with no keyframes\n" \
87                                                 "ac -k 10 test.avi => converts test.avi to test.ani with keyframe at 10th frame\n" \
88                                                 "ac -ke 10 test.avi => every 10th frame (frame 1, 10, 20 etc) is a keyframe\n" \
89                                                 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n"\
90                                                 "ac -k 10 test0000.pcx => same as above, but test009.pcx is a keyframe\n" \
91                                                 "ac -ke 5 test0000.pcx => makes test0004.pcx, test0009.pcx, etc a keyframe\n";
92 #endif
93
94 // Global to file
95 static char buffer[255];
96
97 // Internal function prototypes
98 void ac_error(char *msg);
99 void start_convert_with(char* filename);
100
101 int main(int argc, char *argv[])
102 {
103         int i;
104
105         key_frame_rate = 0;             // assume no regular keyframes
106         force_key_frame = -1;   // assume no force key frame
107
108         Default_fps = ANIM_DEFAULT_FPS; // assume default fps value
109         Use_custom_xparent_color = 0;           // assume xparent RGB is 0.255.0
110
111         Compression_type = CUSTOM_DELTA_RLE;
112
113         vm_init(16*1024*1024);
114
115         if ( argc <= 1 ) {
116                 printf(help_text);
117                 exit(0);
118         }
119
120         for ( i = 1; i < argc; i++ ) {
121                 if ( !stricmp(argv[i], "-h" ) ) {
122                         printf(help_text);
123                         exit(0);
124
125 #ifndef NDEBUG
126                 } else if ( !stricmp(argv[i], "-c" ) ) {
127                         int mode;
128                         if ( i+1 >= argc ) ac_error("-c switch requires a parameter\n");
129                         mode = atoi(argv[i+1]);
130                         i++;
131                         switch ( mode ) {
132                                 case 0:
133                                         Compression_type = CUSTOM_DELTA_RLE;
134                                         break;
135                                 case 1:
136                                         Compression_type = STD_DELTA_RLE;
137                                         break;
138                                 default:
139                                         ac_error("-c only supports compression types 0 and 1\n");
140                                         break;
141                         }       // end switch
142
143                 } else if ( !stricmp(argv[i], "-k" ) ) {
144                         if ( i+1 >= argc ) ac_error("-k switch requires a parameter\n");
145                         force_key_frame = atoi(argv[i+1]);
146                         i++;
147
148                 } else if ( !stricmp(argv[i], "-ke" ) ) {
149                         if ( i+1 >= argc ) ac_error("-ke switch requires a parameter\n");
150                         key_frame_rate = atoi(argv[i+1]);
151                         i++;
152
153                 } else if ( !stricmp(argv[i], "-to" ) ) {
154                         Use_custom_xparent_color = 1;
155 #endif
156
157                 } else if ( !stricmp(argv[i], "-fps" ) ) {
158                         if ( i+1 >= argc ) ac_error("-fps switch requires a parameter\n");
159                         Default_fps = atoi(argv[i+1]);
160                         i++;
161
162                 } else if ( !stricmp(argv[i], "-v" ) ) {
163                         printf("AC version: %.2f\n", float(ANIM_VERSION));
164
165                 } else if ( !stricmp(argv[i], "-i" ) ) {
166                         if ( i+1 >= argc ) ac_error("-i switch requires filename of ani\n");
167                         anim_display_info(argv[i+1]);
168                         exit(0);
169
170                 } else if ( !stricmp(argv[i], "-x" ) ) {
171                         if ( i+1 >= argc ) ac_error("-x switch requires filename of ani\n");
172                         anim_write_frames_out(argv[i+1]);
173                         exit(0);
174
175                 } else {
176                         start_convert_with(argv[i]);
177                 }
178
179         }
180
181         return 0;
182 }
183
184 void ac_error(char *msg)
185 {
186         fprintf(stderr, msg);
187         exit(1);
188 }
189
190
191 void start_convert_with(char* filename)
192 {
193         char *extension;
194         int rc;
195
196         if (strlen(filename) < 4 || filename[strlen(filename) - 4] != '.')
197                 ac_error("Extension must be specified for file to convert");
198
199         extension = filename + strlen(filename) - 3;
200         if (!stricmp(extension, "avi")) {
201                 if ( key_frame_rate > 0 )
202                         key_frame_rate--;
203                 rc = convert_avi_to_anim(filename);
204                 if (rc) {
205                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
206                         ac_error(buffer);
207                 }
208         }
209         else if (!stricmp(extension, "pcx")) {
210                 rc = convert_frames_to_anim(filename);
211                 if (rc) {
212                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
213                         ac_error(buffer);
214                 }
215         }
216         else
217                 ac_error("Type of file to convert is not supported");
218 }