]> icculus.org git repositories - taylor/freespace2.git/blob - src/ac/ac.cpp
clean up Windows #include's and use winsock2
[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 <stdio.h>
65 #include <stdlib.h>
66 #include <string.h>
67 #include "convert.h"
68 #include "ac.h"
69 #include "animplay.h"
70 #include "packunpack.h"
71
72 #ifdef NDEBUG
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" \
81                                                 "Examples:\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";
84
85 #else
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" \
98                                                 "Examples:\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";
105 #endif
106
107 // Global to file
108 static char buffer[255];
109
110 // Internal function prototypes
111 void ac_error(const char *msg);
112 void start_convert_with(char* filename);
113
114 int main(int argc, char *argv[])
115 {
116         int i;
117
118         key_frame_rate = 0;             // assume no regular keyframes
119         force_key_frame = -1;   // assume no force key frame
120
121         Default_fps = ANIM_DEFAULT_FPS; // assume default fps value
122         Use_custom_xparent_color = 0;           // assume xparent RGB is 0.255.0
123
124         Compression_type = CUSTOM_DELTA_RLE;
125
126         vm_init(16*1024*1024);
127
128         if ( argc <= 1 ) {
129                 printf("%s", help_text);
130                 exit(0);
131         }
132
133         for ( i = 1; i < argc; i++ ) {
134                 if ( !SDL_strcasecmp(argv[i], "-h" ) ) {
135                         printf("%s", help_text);
136                         exit(0);
137
138 #ifndef NDEBUG
139                 } else if ( !SDL_strcasecmp(argv[i], "-c" ) ) {
140                         int mode;
141                         if ( i+1 >= argc ) ac_error("-c switch requires a parameter\n");
142                         mode = SDL_atoi(argv[i+1]);
143                         i++;
144                         switch ( mode ) {
145                                 case 0:
146                                         Compression_type = CUSTOM_DELTA_RLE;
147                                         break;
148                                 case 1:
149                                         Compression_type = STD_DELTA_RLE;
150                                         break;
151                                 default:
152                                         ac_error("-c only supports compression types 0 and 1\n");
153                                         break;
154                         }       // end switch
155
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]);
159                         i++;
160
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]);
164                         i++;
165
166                 } else if ( !SDL_strcasecmp(argv[i], "-to" ) ) {
167                         Use_custom_xparent_color = 1;
168 #endif
169
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]);
173                         i++;
174
175                 } else if ( !SDL_strcasecmp(argv[i], "-v" ) ) {
176                         printf("AC version: %.2f\n", float(ANIM_VERSION));
177
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]);
181                         exit(0);
182
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]);
186                         exit(0);
187
188                 } else {
189                         start_convert_with(argv[i]);
190                 }
191
192         }
193
194         return 0;
195 }
196
197 void ac_error(const char *msg)
198 {
199         fprintf(stderr, "%s", msg);
200         exit(1);
201 }
202
203
204 void start_convert_with(char* filename)
205 {
206         char *extension;
207         int rc;
208
209         if (strlen(filename) < 4 || filename[strlen(filename) - 4] != '.')
210                 ac_error("Extension must be specified for file to convert");
211
212         extension = filename + strlen(filename) - 3;
213         if (!SDL_strcasecmp(extension, "avi")) {
214                 if ( key_frame_rate > 0 )
215                         key_frame_rate--;
216                 rc = convert_avi_to_anim(filename);
217                 if (rc) {
218                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
219                         ac_error(buffer);
220                 }
221         }
222         else if (!SDL_strcasecmp(extension, "pcx")) {
223                 rc = convert_frames_to_anim(filename);
224                 if (rc) {
225                         sprintf(buffer,"Could not convert %s to ani format\n", filename);
226                         ac_error(buffer);
227                 }
228         }
229         else
230                 ac_error("Type of file to convert is not supported");
231 }