2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
10 * $Logfile: /Freespace2/code/AC/ac.cpp $
15 * C module for console version of anim converter
18 * Revision 1.3 2002/06/09 04:41:15 relnev
19 * added copyright header
21 * Revision 1.2 2002/05/07 03:16:43 theoddone33
22 * The Great Newline Fix
24 * Revision 1.1.1.1 2002/05/03 03:28:11 root
28 * 2 10/23/98 6:03p Dave
30 * 12 6/24/98 10:43a Hoffoss
31 * Changed default to 15 FPS instead of 30 FPS.
33 * 11 6/23/98 4:18p Hoffoss
34 * Fixed some bugs with AC release build.
36 * 10 7/20/97 6:59p Lawrance
37 * added new -i and -x switches
39 * 9 5/21/97 11:06a Lawrance
40 * enabling a user-defined transparent value
42 * 8 5/19/97 3:21p Lawrance
43 * add fps parm, version num to anim header
45 * 7 2/25/97 5:18p Lawrance
46 * add carriage return after finished, so DOS prompt at a new line
48 * 6 2/20/97 3:03p Lawrance
49 * initialize force_key_frame global to -1
51 * 5 2/20/97 1:59p Lawrance
54 * 4 2/20/97 1:58p Adam
56 * 2 2/19/97 9:26p Lawrance
57 * console version of converter working
59 * 1 2/19/97 7:26p Lawrance
70 #include "packunpack.h"
73 static const char *help_text = "AC ANI Converter Copyright (C) 1998, Volition, Inc. All Rights Reserved.\n"
74 "For exclusive use in FreeSpace missions only.\n\n"
75 "Usage: ac [-fps n] [-v] filename\n\n" \
76 "-i => display information and statistics about the ani file\n" \
77 "-x => extract pcx files from ani (named filename0000.pcx etc)\n" \
78 "-fps n => n frames per second (default 15)\n" \
79 "-v => display the version number\n" \
80 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
82 "ac test.avi => converts test.avi to test.ani\n" \
83 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n";
86 static const char *help_text = "Usage: ac [-c n] [-k n] [-ke n] [-fps n] [-to] [-v] filename\n\n" \
87 "-c n => which kind of compression to use (default is 1):\n" \
88 " -c 0 => compression using up to 255 count, takes 3 bytes for a run\n" \
89 " -c 1 => compression using up to 127 count, takes 2 bytes for a run\n" \
90 "-i => display information and statistics about the ani file\n" \
91 "-x => extract pcx files from ani (named filename0000.pcx etc)\n" \
92 "-k n => keyframe at frame n\n" \
93 "-ke n => keyframe every n frames\n" \
94 "-fps n => n frames per second (default 15)\n" \
95 "-to => transparent override. Use pixel in top-left corner of first frame as transparent color. Otherwise RGB value 0.255.0 is used.\n" \
96 "-v => display the version number\n" \
97 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
99 "ac test.avi => converts test.avi to test.ani with no keyframes\n" \
100 "ac -k 10 test.avi => converts test.avi to test.ani with keyframe at 10th frame\n" \
101 "ac -ke 10 test.avi => every 10th frame (frame 1, 10, 20 etc) is a keyframe\n" \
102 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n"\
103 "ac -k 10 test0000.pcx => same as above, but test009.pcx is a keyframe\n" \
104 "ac -ke 5 test0000.pcx => makes test0004.pcx, test0009.pcx, etc a keyframe\n";
108 static char buffer[255];
110 // Internal function prototypes
111 void ac_error(const char *msg);
112 void start_convert_with(char* filename);
114 int main(int argc, char *argv[])
118 key_frame_rate = 0; // assume no regular keyframes
119 force_key_frame = -1; // assume no force key frame
121 Default_fps = ANIM_DEFAULT_FPS; // assume default fps value
122 Use_custom_xparent_color = 0; // assume xparent RGB is 0.255.0
124 Compression_type = CUSTOM_DELTA_RLE;
126 vm_init(16*1024*1024);
129 printf("%s", help_text);
133 for ( i = 1; i < argc; i++ ) {
134 if ( !SDL_strcasecmp(argv[i], "-h" ) ) {
135 printf("%s", help_text);
139 } else if ( !SDL_strcasecmp(argv[i], "-c" ) ) {
141 if ( i+1 >= argc ) ac_error("-c switch requires a parameter\n");
142 mode = SDL_atoi(argv[i+1]);
146 Compression_type = CUSTOM_DELTA_RLE;
149 Compression_type = STD_DELTA_RLE;
152 ac_error("-c only supports compression types 0 and 1\n");
156 } else if ( !SDL_strcasecmp(argv[i], "-k" ) ) {
157 if ( i+1 >= argc ) ac_error("-k switch requires a parameter\n");
158 force_key_frame = SDL_atoi(argv[i+1]);
161 } else if ( !SDL_strcasecmp(argv[i], "-ke" ) ) {
162 if ( i+1 >= argc ) ac_error("-ke switch requires a parameter\n");
163 key_frame_rate = SDL_atoi(argv[i+1]);
166 } else if ( !SDL_strcasecmp(argv[i], "-to" ) ) {
167 Use_custom_xparent_color = 1;
170 } else if ( !SDL_strcasecmp(argv[i], "-fps" ) ) {
171 if ( i+1 >= argc ) ac_error("-fps switch requires a parameter\n");
172 Default_fps = SDL_atoi(argv[i+1]);
175 } else if ( !SDL_strcasecmp(argv[i], "-v" ) ) {
176 printf("AC version: %.2f\n", float(ANIM_VERSION));
178 } else if ( !SDL_strcasecmp(argv[i], "-i" ) ) {
179 if ( i+1 >= argc ) ac_error("-i switch requires filename of ani\n");
180 anim_display_info(argv[i+1]);
183 } else if ( !SDL_strcasecmp(argv[i], "-x" ) ) {
184 if ( i+1 >= argc ) ac_error("-x switch requires filename of ani\n");
185 anim_write_frames_out(argv[i+1]);
189 start_convert_with(argv[i]);
197 void ac_error(const char *msg)
199 fprintf(stderr, "%s", msg);
204 void start_convert_with(char* filename)
209 if (strlen(filename) < 4 || filename[strlen(filename) - 4] != '.')
210 ac_error("Extension must be specified for file to convert");
212 extension = filename + strlen(filename) - 3;
213 if (!SDL_strcasecmp(extension, "avi")) {
214 if ( key_frame_rate > 0 )
216 rc = convert_avi_to_anim(filename);
218 sprintf(buffer,"Could not convert %s to ani format\n", filename);
222 else if (!SDL_strcasecmp(extension, "pcx")) {
223 rc = convert_frames_to_anim(filename);
225 sprintf(buffer,"Could not convert %s to ani format\n", filename);
230 ac_error("Type of file to convert is not supported");