]> icculus.org git repositories - taylor/freespace2.git/blob - src/ac/ac.cpp
added copyright header
[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 #include <windows.h>
65 #include <stdio.h>
66 #include <stdlib.h>
67 #include <string.h>
68 #include "convert.h"
69 #include "ac.h"
70 #include "animplay.h"
71 #include "packunpack.h"
72
73 #ifdef NDEBUG
74 char *help_text = "AC ANI Converter Copyright (C) 1998, Volition, Inc.  All Rights Reserved.\n"
75                                                 "For exclusive use in FreeSpace missions only.\n\n"
76                                                 "Usage: ac [-fps n] [-v] filename\n\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                   "-fps n => n frames per second (default 15)\n" \
80                                                 "-v     => display the version number\n" \
81                                                 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
82                                                 "Examples:\n" \
83                                                 "ac test.avi => converts test.avi to test.ani\n" \
84                                                 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n";
85
86 #else
87 char *help_text = "Usage: ac [-c n] [-k n] [-ke n] [-fps n] [-to] [-v] filename\n\n" \
88                                                 "-c   n => which kind of compression to use (default is 1):\n" \
89                                                 "     -c 0 => compression using up to 255 count, takes 3 bytes for a run\n" \
90                                                 "     -c 1 => compression using up to 127 count, takes 2 bytes for a run\n" \
91                                                 "-i     => display information and statistics about the ani file\n" \
92                                                 "-x     => extract pcx files from ani (named filename0000.pcx etc)\n" \
93                                                 "-k   n => keyframe at frame n\n" \
94                   "-ke  n => keyframe every n frames\n" \
95                   "-fps n => n frames per second (default 15)\n" \
96                   "-to    => transparent override.  Use pixel in top-left corner of first frame as transparent color.  Otherwise RGB value 0.255.0 is used.\n" \
97                                                 "-v     => display the version number\n" \
98                                                 "filename => a Microsoft RLE AVI || PCX file in form nameXXXX.pcx\n\n" \
99                                                 "Examples:\n" \
100                                                 "ac test.avi => converts test.avi to test.ani with no keyframes\n" \
101                                                 "ac -k 10 test.avi => converts test.avi to test.ani with keyframe at 10th frame\n" \
102                                                 "ac -ke 10 test.avi => every 10th frame (frame 1, 10, 20 etc) is a keyframe\n" \
103                                                 "ac test0000.pcx => converts test0000.pcx up to highest testxxxx.pcx to test.ani\n"\
104                                                 "ac -k 10 test0000.pcx => same as above, but test009.pcx is a keyframe\n" \
105                                                 "ac -ke 5 test0000.pcx => makes test0004.pcx, test0009.pcx, etc a keyframe\n";
106 #endif
107
108 // Global to file
109 static char buffer[255];
110
111 // Internal function prototypes
112 void ac_error(char *msg);
113 void start_convert_with(char* filename);
114
115 int main(int argc, char *argv[])
116 {
117         int i;
118
119         key_frame_rate = 0;             // assume no regular keyframes
120         force_key_frame = -1;   // assume no force key frame
121
122         Default_fps = ANIM_DEFAULT_FPS; // assume default fps value
123         Use_custom_xparent_color = 0;           // assume xparent RGB is 0.255.0
124
125         Compression_type = CUSTOM_DELTA_RLE;
126
127         vm_init(16*1024*1024);
128
129         if ( argc <= 1 ) {
130                 printf(help_text);
131                 exit(0);
132         }
133
134         for ( i = 1; i < argc; i++ ) {
135                 if ( !stricmp(argv[i], "-h" ) ) {
136                         printf(help_text);
137                         exit(0);
138
139 #ifndef NDEBUG
140                 } else if ( !stricmp(argv[i], "-c" ) ) {
141                         int mode;
142                         if ( i+1 >= argc ) ac_error("-c switch requires a parameter\n");
143                         mode = atoi(argv[i+1]);
144                         i++;
145                         switch ( mode ) {
146                                 case 0:
147                                         Compression_type = CUSTOM_DELTA_RLE;
148                                         break;
149                                 case 1:
150                                         Compression_type = STD_DELTA_RLE;
151                                         break;
152                                 default:
153                                         ac_error("-c only supports compression types 0 and 1\n");
154                                         break;
155                         }       // end switch
156
157                 } else if ( !stricmp(argv[i], "-k" ) ) {
158                         if ( i+1 >= argc ) ac_error("-k switch requires a parameter\n");
159                         force_key_frame = atoi(argv[i+1]);
160                         i++;
161
162                 } else if ( !stricmp(argv[i], "-ke" ) ) {
163                         if ( i+1 >= argc ) ac_error("-ke switch requires a parameter\n");
164                         key_frame_rate = atoi(argv[i+1]);
165                         i++;
166
167                 } else if ( !stricmp(argv[i], "-to" ) ) {
168                         Use_custom_xparent_color = 1;
169 #endif
170
171                 } else if ( !stricmp(argv[i], "-fps" ) ) {
172                         if ( i+1 >= argc ) ac_error("-fps switch requires a parameter\n");
173                         Default_fps = atoi(argv[i+1]);
174                         i++;
175
176                 } else if ( !stricmp(argv[i], "-v" ) ) {
177                         printf("AC version: %.2f\n", float(ANIM_VERSION));
178
179                 } else if ( !stricmp(argv[i], "-i" ) ) {
180                         if ( i+1 >= argc ) ac_error("-i switch requires filename of ani\n");
181                         anim_display_info(argv[i+1]);
182                         exit(0);
183
184                 } else if ( !stricmp(argv[i], "-x" ) ) {
185                         if ( i+1 >= argc ) ac_error("-x switch requires filename of ani\n");
186                         anim_write_frames_out(argv[i+1]);
187                         exit(0);
188
189                 } else {
190                         start_convert_with(argv[i]);
191                 }
192
193         }
194
195         return 0;
196 }
197
198 void ac_error(char *msg)
199 {
200         fprintf(stderr, msg);
201         exit(1);
202 }
203
204
205 void start_convert_with(char* filename)
206 {
207         char *extension;
208         int rc;
209
210         if (strlen(filename) < 4 || filename[strlen(filename) - 4] != '.')
211                 ac_error("Extension must be specified for file to convert");
212
213         extension = filename + strlen(filename) - 3;
214         if (!stricmp(extension, "avi")) {
215                 if ( key_frame_rate > 0 )
216                         key_frame_rate--;
217                 rc = convert_avi_to_anim(filename);
218                 if (rc) {
219                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
220                         ac_error(buffer);
221                 }
222         }
223         else if (!stricmp(extension, "pcx")) {
224                 rc = convert_frames_to_anim(filename);
225                 if (rc) {
226                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
227                         ac_error(buffer);
228                 }
229         }
230         else
231                 ac_error("Type of file to convert is not supported");
232 }