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