]>
iEval git - xfishtank.git/blob - pcfshtofish/pcfshtofish.c
4 #define DEFAULT_NAME "fish"
7 unsigned int red
, green
, blue
;
12 ReadFshColors(ifp
, colrs
)
14 struct rgb_color
*colrs
;
19 for (i
= 0; i
< 132; i
++) {
23 for (i
= 0; i
< 16; i
++) {
43 data
= (unsigned char *) malloc(64 * 64);
44 for (j
= 63; j
>= 0; j
--) {
46 for (i
= 0; i
< 32; i
++) {
48 val2
= (val
>> 4) & 0x0f;
49 data
[indx
] = (unsigned char) val2
;
52 data
[indx
] = (unsigned char) val2
;
68 for (i
= 0; i
< (16 * 32); i
++) {
72 data
= (unsigned char *) malloc(64 * 64);
73 for (j
= 63; j
>= 0; j
--) {
75 for (i
= 0; i
< 32; i
++) {
77 val2
= (val
>> 4) & 0x0f;
78 data
[indx
] = (unsigned char) val2
;
81 data
[indx
] = (unsigned char) val2
;
91 MapColors(data1
, colrs1
, data2
, colrs2
, width
, height
, Cnt
)
93 struct rgb_color
*colrs1
;
95 struct rgb_color
*colrs2
;
101 int Mapping
[MAXCOLORS
];
103 struct rgb_color
*fcolrs
;
105 fcolrs
= (struct rgb_color
*) malloc((MAXCOLORS
+ 1) * sizeof(struct rgb_color
));
109 for (i
= 0; i
< (width
* height
); i
++) {
111 for (j
= 0; j
< fcnt
; j
++) {
112 if ((fcolrs
[j
].red
== colrs1
[indx
].red
) &&
113 (fcolrs
[j
].green
== colrs1
[indx
].green
) &&
114 (fcolrs
[j
].blue
== colrs1
[indx
].blue
)) {
119 fcolrs
[j
].red
= colrs1
[indx
].red
;
120 fcolrs
[j
].green
= colrs1
[indx
].green
;
121 fcolrs
[j
].blue
= colrs1
[indx
].blue
;
124 if (fcnt
> MAXCOLORS
) {
125 fprintf(stderr
, "Error: cannot use more than %d colors in your fish\n",
133 for (i
= 0; i
< (width
* height
); i
++) {
135 *ptr
= (unsigned char) (Mapping
[indx
]);
140 for (i
= 0; i
< (width
* height
); i
++) {
142 for (j
= 0; j
< fcnt
; j
++) {
143 if ((fcolrs
[j
].red
== colrs2
[indx
].red
) &&
144 (fcolrs
[j
].green
== colrs2
[indx
].green
) &&
145 (fcolrs
[j
].blue
== colrs2
[indx
].blue
)) {
150 fcolrs
[j
].red
= colrs2
[indx
].red
;
151 fcolrs
[j
].green
= colrs2
[indx
].green
;
152 fcolrs
[j
].blue
= colrs2
[indx
].blue
;
155 if (fcnt
> MAXCOLORS
) {
156 fprintf(stderr
, "Error: cannot use more than %d colors in your fish\n",
164 for (i
= 0; i
< (width
* height
); i
++) {
166 *ptr
= (unsigned char) (Mapping
[indx
]);
170 for (i
= 0; i
< fcnt
; i
++) {
171 fcolrs
[i
].red
= fcolrs
[i
].red
* 256;
172 fcolrs
[i
].green
= fcolrs
[i
].green
* 256;
173 fcolrs
[i
].blue
= fcolrs
[i
].blue
* 256;
175 for (i
= fcnt
; i
< 16; i
++) {
196 struct rgb_color colrs1
[MAXCOLORS
];
197 struct rgb_color
*fcolrs
;
198 unsigned char *data1
, *data2
;
205 ifp
= fopen(argv
[1], "r");
213 ReadFshColors(ifp
, colrs1
);
214 data1
= ReadFshData1(ifp
);
215 data2
= ReadFshData2(ifp
);
217 fcolrs
= MapColors(data1
, colrs1
, data2
, colrs1
, width
, height
, &fcnt
);
224 while ((argv
[1][cnt
] != '.') && (argv
[1][cnt
] != '\0')) {
229 outname
= (char *) malloc(strlen(DEFAULT_NAME
) + 1);
230 strcpy(outname
, DEFAULT_NAME
);
232 outname
= (char *) malloc(cnt
+ 1);
233 strncpy(outname
, argv
[1], cnt
);
237 sprintf(outfile
, "%s.h", outname
);
239 ofd
= fopen(outfile
, "w");
241 fprintf(stderr
, "Error: cannot open (%s) for writing\n", outfile
);
245 fprintf(ofd
, "#define %s_width\t\t%d\n", outname
, width
);
246 fprintf(ofd
, "#define %s_height\t\t%d\n", outname
, height
);
247 fprintf(ofd
, "#define %s_colors\t\t%d\n", outname
, fcnt
);
248 fprintf(ofd
, "#define %s_back\t\t%d\n", outname
, (int) data1
[0]);
249 fprintf(ofd
, "int\t%s_reds[] = {", outname
);
250 for (i
= 0; i
< fcnt
; i
++) {
251 if (i
== (fcnt
- 1)) {
252 fprintf(ofd
, "%d};\n", fcolrs
[i
].red
);
254 fprintf(ofd
, "%d, ", fcolrs
[i
].red
);
257 fprintf(ofd
, "int\t%s_greens[] = {", outname
);
258 for (i
= 0; i
< fcnt
; i
++) {
259 if (i
== (fcnt
- 1)) {
260 fprintf(ofd
, "%d};\n", fcolrs
[i
].green
);
262 fprintf(ofd
, "%d, ", fcolrs
[i
].green
);
265 fprintf(ofd
, "int\t%s_blues[] = {", outname
);
266 for (i
= 0; i
< fcnt
; i
++) {
267 if (i
== (fcnt
- 1)) {
268 fprintf(ofd
, "%d};\n", fcolrs
[i
].blue
);
270 fprintf(ofd
, "%d, ", fcolrs
[i
].blue
);
273 fprintf(ofd
, "unsigned char\t%s_rasterA[] = {\n", outname
);
274 for (i
= 0; i
< (width
* height
); i
++) {
275 fprintf(ofd
, "0x%02x,", data1
[i
]);
277 fprintf(ofd
, "};\n");
278 fprintf(ofd
, "unsigned char\t%s_rasterB[] = {\n", outname
);
279 for (i
= 0; i
< (width
* height
); i
++) {
280 fprintf(ofd
, "0x%02x,", data2
[i
]);
282 fprintf(ofd
, "};\n");
This page took 0.060875 seconds and 4 git commands to generate.