Ticket #1481: palconvert.c

File palconvert.c, 987 bytes (added by eriktorbjorn, 21 years ago)

Quick-and-dirty .pal file converter

Line 
1/* Copied right in 2004 - All rights reversed */
2
3#include <stdio.h>
4
5int main(int argc, char *argv[]) {
6 FILE *in, *out;
7
8 if (argc != 3) {
9 printf("Usage: %s infile outfile\n", argv[0]);
10 return 1;
11 }
12
13 in = fopen(argv[1], "r");
14 if (!in) {
15 printf("Can't open `%s' for reading\n", argv[1]);
16 return 1;
17 }
18
19 out = fopen(argv[2], "wb");
20 if (!out) {
21 printf("Can't open `%s' for writing\n", argv[2]);
22 fclose(in);
23 return 1;
24 }
25
26 while (1) {
27 int i, end, cnt;
28
29 if (fscanf(in, "%i %i", &end, &cnt) != 2)
30 break;
31
32 /* Little-endian, though it doesn't really matter as long as
33 * the cutscene code uses the same encoding.
34 */
35 fputc(end & 0xFF, out);
36 fputc(end >> 8, out);
37
38 fputc(cnt & 0xFF, out);
39 fputc(cnt >> 8, out);
40
41 for (i = 0; i < cnt; i++) {
42 int r, g, b;
43
44 fscanf(in, "%i %i %i", &r, &g, &b);
45 fputc(r, out);
46 fputc(g, out);
47 fputc(b, out);
48 }
49 }
50
51 fclose(in);
52 fclose(out);
53 return 0;
54}
55