2 * $Logfile: /Freespace2/code/AC/ac.cpp $
7 * C module for console version of anim converter
10 * Revision 1.1 2002/05/03 03:28:11 root
14 * 2 10/23/98 6:03p Dave
16 * 12 6/24/98 10:43a Hoffoss
17 * Changed default to 15 FPS instead of 30 FPS.
19 * 11 6/23/98 4:18p Hoffoss
20 * Fixed some bugs with AC release build.
22 * 10 7/20/97 6:59p Lawrance
23 * added new -i and -x switches
25 * 9 5/21/97 11:06a Lawrance
26 * enabling a user-defined transparent value
28 * 8 5/19/97 3:21p Lawrance
29 * add fps parm, version num to anim header
31 * 7 2/25/97 5:18p Lawrance
32 * add carriage return after finished, so DOS prompt at a new line
34 * 6 2/20/97 3:03p Lawrance
35 * initialize force_key_frame global to -1
37 * 5 2/20/97 1:59p Lawrance
40 * 4 2/20/97 1:58p Adam
42 * 2 2/19/97 9:26p Lawrance
43 * console version of converter working
45 * 1 2/19/97 7:26p Lawrance
57 #include "packunpack.h"
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" \
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";
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" \
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";
95 static char buffer[255];
97 // Internal function prototypes
98 void ac_error(char *msg);
99 void start_convert_with(char* filename);
101 int main(int argc, char *argv[])
105 key_frame_rate = 0; // assume no regular keyframes
106 force_key_frame = -1; // assume no force key frame
108 Default_fps = ANIM_DEFAULT_FPS; // assume default fps value
109 Use_custom_xparent_color = 0; // assume xparent RGB is 0.255.0
111 Compression_type = CUSTOM_DELTA_RLE;
113 vm_init(16*1024*1024);
120 for ( i = 1; i < argc; i++ ) {
121 if ( !stricmp(argv[i], "-h" ) ) {
126 } else if ( !stricmp(argv[i], "-c" ) ) {
128 if ( i+1 >= argc ) ac_error("-c switch requires a parameter\n");
129 mode = atoi(argv[i+1]);
133 Compression_type = CUSTOM_DELTA_RLE;
136 Compression_type = STD_DELTA_RLE;
139 ac_error("-c only supports compression types 0 and 1\n");
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]);
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]);
153 } else if ( !stricmp(argv[i], "-to" ) ) {
154 Use_custom_xparent_color = 1;
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]);
162 } else if ( !stricmp(argv[i], "-v" ) ) {
163 printf("AC version: %.2f\n", float(ANIM_VERSION));
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]);
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]);
176 start_convert_with(argv[i]);
184 void ac_error(char *msg)
186 fprintf(stderr, msg);
191 void start_convert_with(char* filename)
196 if (strlen(filename) < 4 || filename[strlen(filename) - 4] != '.')
197 ac_error("Extension must be specified for file to convert");
199 extension = filename + strlen(filename) - 3;
200 if (!stricmp(extension, "avi")) {
201 if ( key_frame_rate > 0 )
203 rc = convert_avi_to_anim(filename);
205 sprintf(buffer,"Could not convert %s to ani format\n", filename);
209 else if (!stricmp(extension, "pcx")) {
210 rc = convert_frames_to_anim(filename);
212 sprintf(buffer,"Could not convert %s to ani format\n", filename);
217 ac_error("Type of file to convert is not supported");