Mercurial > fife-parpg
comparison utils/frmconv/frmconv.c @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 //frmconv - A tool to convert the frm file format to png/mng | |
2 //Copyright (C) 2005 IanOut Team (RogerWilco) | |
3 // | |
4 //This program is free software; you can redistribute it and/or | |
5 //modify it under the terms of the GNU General Public License | |
6 //version 2 as published by the Free Software Foundation; | |
7 // | |
8 //This program is distributed in the hope that it will be useful, | |
9 //but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 //GNU General Public License for more details. | |
12 // | |
13 //You should have received a copy of the GNU General Public License | |
14 //along with this program; if not, write to the Free Software | |
15 //Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA | |
16 | |
17 | |
18 // frmconv is inspired by frm2bmp by Borg Locutus (dystopia@iname.com) and | |
19 // the documentation of the frm file format (written by Noid and Anchorite) | |
20 // was used extensively | |
21 | |
22 | |
23 | |
24 // ToDo: *Add mng support for true animations | |
25 | |
26 #ifdef _WIN32 | |
27 #define ssize_t int | |
28 #include <io.h> | |
29 #include <sys/types.h> | |
30 #include <Winsock2.h> | |
31 #else | |
32 #include <netinet/in.h> | |
33 #include <getopt.h> | |
34 #endif | |
35 | |
36 #include <stdlib.h> | |
37 #include <stdio.h> | |
38 #include <string.h> | |
39 #include <unistd.h> | |
40 | |
41 #include "frm.h" | |
42 #include "out_png.h" | |
43 | |
44 const char helpstr[] = "frmconv v1.0 - (c) 2005 by IanOut Team (RogerWilco)\nUsage: %s [-m] -f <frm-file> [-o <basename>]\n"; | |
45 const char verstr[] = "frmconv v1.0 - (c) 2005 by IanOut Team (RogerWilco)\n"; | |
46 | |
47 int main(int argc, char *argv[]) { | |
48 char *buf=NULL, *inputname=NULL, *outputname=NULL; | |
49 frm_frame *frame; | |
50 frm_anim *anim; | |
51 FILE *outfile=NULL, *inputfile; | |
52 short int mng=0; | |
53 int c, i; | |
54 | |
55 if (argc > 6) { | |
56 printf(helpstr,argv[0]); | |
57 return 0; | |
58 } | |
59 | |
60 while ( (c = getopt(argc, argv, "mf:o:")) ) { | |
61 if (c == -1) | |
62 break; | |
63 | |
64 switch (c) { | |
65 case 'm': | |
66 mng = 1; | |
67 printf("Sorry, mng support is not working.\n"); | |
68 return 2; | |
69 break; | |
70 case 'f': | |
71 inputname = optarg; | |
72 break; | |
73 case 'o': | |
74 outputname = optarg; | |
75 break; | |
76 } | |
77 } | |
78 | |
79 if (!inputname) { | |
80 printf("frmconv v1.0 - (c) 2005 by IanOut Team (RogerWilco)\nUsage: %s [-m] -f <frm-file> [-o <basename>]\n", argv[0]); | |
81 return 1; | |
82 } | |
83 | |
84 if (0 != (inputfile = fopen(inputname, "rb"))) { | |
85 anim = loadFRMAnim(inputfile); | |
86 } else { | |
87 printf("Couldn't open %s.\n", inputname); | |
88 return 2; | |
89 } | |
90 | |
91 | |
92 if (anim) { | |
93 if (outputname) { | |
94 buf = malloc(strlen(outputname)+8); | |
95 if (!buf) { | |
96 freefrmanim(anim); | |
97 return 1; | |
98 } | |
99 strcpy(buf, outputname); | |
100 } | |
101 | |
102 frame = anim->frames; | |
103 | |
104 for (i=0; frame && i<anim->nrofframes && i<999; ++i) { | |
105 if (outputname) { | |
106 sprintf(buf, "%s%03d.png", outputname, i); | |
107 outfile = fopen(buf, "wb"); | |
108 } | |
109 | |
110 if (mng) { | |
111 } else { | |
112 writePNGFile(frame, anim->palette, outputname?outfile:stdout); | |
113 } | |
114 | |
115 if (outfile) | |
116 fclose(outfile); | |
117 | |
118 frame = frame->next_frame; | |
119 } | |
120 } | |
121 | |
122 fclose(inputfile); | |
123 freefrmanim(anim); | |
124 return 0; | |
125 } |