Transparent black and truecolor handling for .cel (hardware) files

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1557 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2005-02-22 21:11:43 +00:00
parent df02337ba7
commit 4fed8985cb
2 changed files with 36 additions and 14 deletions
+3 -1
View File
@@ -2,7 +2,9 @@ unani: unani.c unani.h
gcc -W -Wall -g -O0 unani.c -o unani -lpng gcc -W -Wall -g -O0 unani.c -o unani -lpng
clean: clean:
rm unani unani.tgz [ ! -f unani.exe ] || rm unani.exe
[ ! -f unani ] || rm unani
rm unani.tgz
tgz: unani.c unani.h Makefile tgz: unani.c unani.h Makefile
tar -cvzf unani.tgz unani.c unani.h Makefile tar -cvzf unani.tgz unani.c unani.h Makefile
+33 -13
View File
@@ -35,6 +35,8 @@ struct options {
int num_palettefiles; int num_palettefiles;
char **palettefiles; char **palettefiles;
char font; char font;
char blacktrns;
char truecolor;
}; };
int max_palettes; int max_palettes;
@@ -43,7 +45,7 @@ png_color palettes[256][256];
index_header *readIndex(const uint8 *buf, int isfont); index_header *readIndex(const uint8 *buf, int isfont);
void printIndex(const index_header *h, const uint8 *buf, FILE *out); void printIndex(const index_header *h, const uint8 *buf, FILE *out);
void generateAni(const index_header *h, const uint8 *buf, const char *prefix, void generateAni(const index_header *h, const uint8 *buf, const char *prefix,
FILE *out); char blacktrns, char truecolor, FILE *out);
int findTransparentColourPacked(const char *name, const frame_desc *f, int findTransparentColourPacked(const char *name, const frame_desc *f,
const uint8 *data); const uint8 *data);
void writeFiles(const index_header *h, const uint8 *data, const char *path, void writeFiles(const index_header *h, const uint8 *data, const char *path,
@@ -118,7 +120,7 @@ main(int argc, char *argv[]) {
prefix = opts.prefix; prefix = opts.prefix;
if (opts.makeani) { if (opts.makeani) {
generateAni(h, buf, prefix, stdout); generateAni(h, buf, prefix, opts.blacktrns, opts.truecolor, stdout);
} }
if (!opts.print && !opts.list && !opts.makeani) { if (!opts.print && !opts.list && !opts.makeani) {
@@ -155,9 +157,15 @@ main(int argc, char *argv[]) {
void void
usage() { usage() {
fprintf(stderr, fprintf(stderr,
"unani -a [-f] <infile>\n" "unani -a [-f] [-b] [-t] <infile>\n"
"unani -p [-f] <infile>\n" "unani -p [-f] <infile>\n"
"unani [-f] [-c <clutfile>] [-o <outdir>] [-n <prefix>] <infile>\n"); "unani [-f] [-b] [-t] [-c <clutfile>] [-o <outdir>] [-n <prefix>] <infile>\n"
"Options:\n"
"\t-c use <clutfile> when converting (can use more than one)\n"
"\t-f <infile> is a font file\n"
"\t-b assume black (RGB 0,0,0) is transparent in .cel files\n"
"\t-t assume .cel files are truecolor, and so do not use cluts\n"
);
} }
void void
@@ -166,7 +174,7 @@ parse_arguments(int argc, char *argv[], struct options *opts) {
memset(opts, '\0', sizeof (struct options)); memset(opts, '\0', sizeof (struct options));
while (1) { while (1) {
ch = getopt(argc, argv, "ac:hln:o:pfv"); ch = getopt(argc, argv, "ac:hln:o:pfbtv");
if (ch == -1) if (ch == -1)
break; break;
switch(ch) { switch(ch) {
@@ -194,6 +202,12 @@ parse_arguments(int argc, char *argv[], struct options *opts) {
case 'f': case 'f':
opts->font = 1; opts->font = 1;
break; break;
case 'b':
opts->blacktrns = 1;
break;
case 't':
opts->truecolor = 1;
break;
case 'v': case 'v':
opts->verbose = 1; opts->verbose = 1;
break; break;
@@ -321,7 +335,7 @@ listFrames(const index_header *h, const uint8 *buf, FILE *out) {
void void
generateAni(const index_header *h, const uint8 *buf, const char *prefix, generateAni(const index_header *h, const uint8 *buf, const char *prefix,
FILE *out) { char blacktrns, char truecolor, FILE *out) {
int i; int i;
int transparentPixel; int transparentPixel;
@@ -331,19 +345,25 @@ generateAni(const index_header *h, const uint8 *buf, const char *prefix,
sprintf(tempbuf, "frame %d", i); sprintf(tempbuf, "frame %d", i);
transparentPixel = findTransparentColourPacked(tempbuf, transparentPixel = findTransparentColourPacked(tempbuf,
&h->frames[i], h->frames[i].start); &h->frames[i], h->frames[i].start);
} else } else if (blacktrns && (h->frames[i].flags & FLAG_DATA_HARDWARE))
transparentPixel = 0;
else
transparentPixel = -1; transparentPixel = -1;
fprintf(out, "%s.%d.%s %d %d %d %d\n", fprintf(out, "%s.%d.%s %d %d %d %d\n",
prefix, h->frames[i].index, prefix, (int)h->frames[i].index,
(h->frames[i].flags & FLAG_DATA_HARDWARE) ? "png" : (h->frames[i].flags & FLAG_DATA_HARDWARE) ? "png" :
(h->frames[i].flags & FLAG_DATA_PACKED) ? "png" : "???", (h->frames[i].flags & FLAG_DATA_PACKED) ? "png" : "???",
transparentPixel, h->frames[i].plut, transparentPixel,
#if 1 (truecolor && (h->frames[i].flags & FLAG_DATA_HARDWARE)) ? -1 :
(int)h->frames[i].plut,
/* from comparing 3DO and DOS content: X_FLIP does not apply to hotspots */
#if 0
(h->frames[i].flags & FLAG_X_FLIP) ? (h->frames[i].flags & FLAG_X_FLIP) ?
h->frames[i].bounds.w - h->frames[i].hotspot.x /* - 1 */: (int)h->frames[i].bounds.w - h->frames[i].hotspot.x /* - 1 */:
#endif #endif
h->frames[i].hotspot.x, (int)h->frames[i].hotspot.x,
h->frames[i].hotspot.y); (int)h->frames[i].hotspot.y);
#if 0 #if 0
fprintf(out, "%s.%d.%s %d %d %d %d %d %d %d %d\n", fprintf(out, "%s.%d.%s %d %d %d %d %d %d %d %d\n",
prefix, h->frames[i].index, prefix, h->frames[i].index,