0-prepended frame index in filenames option
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1554 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
+34
-17
@@ -141,6 +141,7 @@ struct options
|
|||||||
int crop;
|
int crop;
|
||||||
int verbose;
|
int verbose;
|
||||||
int plut;
|
int plut;
|
||||||
|
int zeropos;
|
||||||
int num_palettefiles;
|
int num_palettefiles;
|
||||||
char **palettefiles;
|
char **palettefiles;
|
||||||
};
|
};
|
||||||
@@ -153,9 +154,9 @@ void verbose(int level, const char* fmt, ...);
|
|||||||
index_header_t* readIndex(uint8_t *buf);
|
index_header_t* readIndex(uint8_t *buf);
|
||||||
void freeIndex(index_header_t *);
|
void freeIndex(index_header_t *);
|
||||||
void printIndex(const index_header_t* h, const uint8_t *buf, FILE *out);
|
void printIndex(const index_header_t* h, const uint8_t *buf, FILE *out);
|
||||||
void generateAni(const index_header_t* h, const char *prefix, int plut, FILE *out);
|
void generateAni(const index_header_t* h, const char *prefix, int zeropos, int plut, FILE *out);
|
||||||
int findTransparentColour(const char *name, const frame_info_t* f);
|
int findTransparentColour(const char *name, const frame_info_t* f);
|
||||||
void writeFiles(const index_header_t* h, const char *path, const char *prefix);
|
void writeFiles(const index_header_t* h, const char *path, const char *prefix, int zeropos);
|
||||||
void parse_arguments(int argc, char *argv[], struct options *opts);
|
void parse_arguments(int argc, char *argv[], struct options *opts);
|
||||||
void listFrames(const index_header_t* h, FILE *out);
|
void listFrames(const index_header_t* h, FILE *out);
|
||||||
int loadPalette(const char *filename);
|
int loadPalette(const char *filename);
|
||||||
@@ -251,17 +252,17 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opts.makeani)
|
if (opts.makeani)
|
||||||
generateAni(h, prefix, opts.plut, stdout);
|
generateAni(h, prefix, opts.zeropos, opts.plut, stdout);
|
||||||
|
|
||||||
if (!opts.print && !opts.list && !opts.makeani)
|
if (!opts.print && !opts.list && !opts.makeani)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = strlen(opts.outdir);
|
len = strlen(opts.outdir);
|
||||||
if (opts.outdir[len - 1] == '/')
|
if (opts.outdir[len - 1] == '/')
|
||||||
opts.outdir[len - 1] = '\0';
|
opts.outdir[len - 1] = '\0';
|
||||||
|
|
||||||
writeFiles(h, opts.outdir, prefix);
|
writeFiles(h, opts.outdir, prefix, opts.zeropos);
|
||||||
}
|
}
|
||||||
|
|
||||||
freeIndex(h);
|
freeIndex(h);
|
||||||
@@ -285,9 +286,9 @@ void verbose(int level, const char* fmt, ...)
|
|||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"undani -a [-m <plutind>] [-r] <infile>\n"
|
"undani -a [-m <plutind>] [-r] [-0] <infile>\n"
|
||||||
"undani -p <infile>\n"
|
"undani -p <infile>\n"
|
||||||
"undani [-c <palfile>] [-r] [-o <outdir>] [-n <prefix>] <infile>\n"
|
"undani [-c <palfile>] [-r] [-0] [-o <outdir>] [-n <prefix>] <infile>\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-a output .ani file\n"
|
"\t-a output .ani file\n"
|
||||||
"\t-p print header and frame info\n"
|
"\t-p print header and frame info\n"
|
||||||
@@ -296,6 +297,7 @@ void usage()
|
|||||||
"\t-n name pngs <prefix>.<N>.png\n"
|
"\t-n name pngs <prefix>.<N>.png\n"
|
||||||
"\t-r crop the images removing edge rows and columns consisting\n"
|
"\t-r crop the images removing edge rows and columns consisting\n"
|
||||||
"\t entirely of transparent color (affects hotspots with -a)\n"
|
"\t entirely of transparent color (affects hotspots with -a)\n"
|
||||||
|
"\t-0 make <N> 0-prepended; use several to specify width\n"
|
||||||
"\t-v increase verbosity level (use more than once)\n"
|
"\t-v increase verbosity level (use more than once)\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -307,7 +309,7 @@ void parse_arguments(int argc, char *argv[], struct options *opts)
|
|||||||
memset(opts, 0, sizeof (struct options));
|
memset(opts, 0, sizeof (struct options));
|
||||||
opts->plut = -1;
|
opts->plut = -1;
|
||||||
|
|
||||||
while (-1 != (ch = getopt(argc, argv, "ac:h?ln:o:m:prv")))
|
while (-1 != (ch = getopt(argc, argv, "ac:h?ln:o:m:pr0v")))
|
||||||
{
|
{
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
@@ -338,6 +340,9 @@ void parse_arguments(int argc, char *argv[], struct options *opts)
|
|||||||
case 'r':
|
case 'r':
|
||||||
opts->crop = 1;
|
opts->crop = 1;
|
||||||
break;
|
break;
|
||||||
|
case '0':
|
||||||
|
opts->zeropos++;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
opts->verbose++;
|
opts->verbose++;
|
||||||
break;
|
break;
|
||||||
@@ -560,10 +565,17 @@ void listFrames(const index_header_t* h, FILE *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void generateAni(const index_header_t *h, const char *prefix, int plut, FILE *out)
|
void generateAni(const index_header_t *h, const char *prefix, int zeropos, int plut, FILE *out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int transparentPixel = -1;
|
int transparentPixel = -1;
|
||||||
|
char fmt[40] = "%s.%";
|
||||||
|
|
||||||
|
if (zeropos > 0)
|
||||||
|
sprintf(fmt + strlen(fmt), "0%dd", zeropos);
|
||||||
|
else
|
||||||
|
strcat(fmt, "d");
|
||||||
|
strcat(fmt, ".%s %d %d %d %d\n");
|
||||||
|
|
||||||
for (i = 0; i < h->num_frames; i++)
|
for (i = 0; i < h->num_frames; i++)
|
||||||
{
|
{
|
||||||
@@ -583,9 +595,9 @@ void generateAni(const index_header_t *h, const char *prefix, int plut, FILE *ou
|
|||||||
actplut = -1; // no colormap for masks
|
actplut = -1; // no colormap for masks
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(out, "%s.%d.%s %d %d %d %d\n",
|
fprintf(out, fmt,
|
||||||
prefix, (int)INDEX_GET(desc->index),
|
prefix, (int)INDEX_GET(desc->index), "png",
|
||||||
"png", transparentPixel, actplut,
|
transparentPixel, actplut,
|
||||||
(int)desc->hotspot.x - info->sx0,
|
(int)desc->hotspot.x - info->sx0,
|
||||||
(int)desc->hotspot.y - info->sy0);
|
(int)desc->hotspot.y - info->sy0);
|
||||||
}
|
}
|
||||||
@@ -979,29 +991,34 @@ void writeBitmapMask(const char *filename, const frame_info_t* f)
|
|||||||
}
|
}
|
||||||
#endif // 0 or 1
|
#endif // 0 or 1
|
||||||
|
|
||||||
void writeFiles(const index_header_t *h, const char *path, const char *prefix)
|
void writeFiles(const index_header_t *h, const char *path, const char *prefix, int zeropos)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char filename[512];
|
char filename[512];
|
||||||
|
char fmt[32] = "%s/%s.%";
|
||||||
|
|
||||||
|
if (zeropos > 0)
|
||||||
|
sprintf(fmt + strlen(fmt), "0%dd", zeropos);
|
||||||
|
else
|
||||||
|
strcat(fmt, "d");
|
||||||
|
strcat(fmt, ".%s");
|
||||||
|
|
||||||
for (i = 0; i < h->num_frames; i++)
|
for (i = 0; i < h->num_frames; i++)
|
||||||
{
|
{
|
||||||
frame_desc_t* desc = h->frames[i].desc;
|
frame_desc_t* desc = h->frames[i].desc;
|
||||||
|
|
||||||
sprintf(filename, "%s/%s.%d.",
|
sprintf(filename, fmt, path, prefix, (int)INDEX_GET(desc->index), "png");
|
||||||
path, prefix, (int)INDEX_GET(desc->index));
|
|
||||||
if (desc->flags & GFX_DATA_FLAG2)
|
if (desc->flags & GFX_DATA_FLAG2)
|
||||||
{
|
{
|
||||||
verbose(2, "Do not know the meaning of DATA_FLAG2, image index %d\n", i);
|
verbose(2, "Do not know the meaning of DATA_FLAG2, image index %d\n", i);
|
||||||
}
|
}
|
||||||
else if (h->flags & GFX_HAS_IMAGES)
|
else if (h->flags & GFX_HAS_IMAGES)
|
||||||
{
|
{
|
||||||
strcat(filename, "png");
|
|
||||||
writePaletted(filename, h->frames + i);
|
writePaletted(filename, h->frames + i);
|
||||||
}
|
}
|
||||||
else if (h->flags & GFX_HAS_MASKS)
|
else if (h->flags & GFX_HAS_MASKS)
|
||||||
{
|
{
|
||||||
strcat(filename, "png");
|
|
||||||
writeBitmapMask(filename, h->frames + i);
|
writeBitmapMask(filename, h->frames + i);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user