/*
* 2ooM: The Master of Orion II Reverse Engineering Project
* Simple command-line tool to convert an LBX image to a set of PNGs.
- * Copyright (C) 2006-2010 Nick Bowler
+ * Copyright © 2006-2011, 2013 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
puts("For now, see the man page for detailed help.");
}
-static const char *progname;
-#define errmsg(fmt, ...) (\
- fprintf(stderr, "%s: " fmt, progname, __VA_ARGS__)\
-)
-
enum {
MODE_NONE,
MODE_DECODE,
MODE_IDENT,
};
-int parserange(struct lbx_imginfo *info, char *str, unsigned char *bits)
+int parserange(unsigned frames, char *str, unsigned char *bits)
{
unsigned long start, end;
unsigned int i;
char *endptr;
start = strtoul(str, &endptr, 0);
- if (start >= info->nframes) {
+ if (start >= frames) {
errmsg("frame %lu out of range.\n", start);
return -1;
}
break;
case '-':
end = strtoul(endptr+1, &endptr, 0);
- if (end >= info->nframes) {
+ if (end >= frames) {
errmsg("frame %lu out of range.\n", end);
return -1;
}
if (endptr == str)
- end = info->nframes - 1;
+ end = frames - 1;
break;
default:
errmsg("invalid frame range: %s.\n", str);
lbx_img_getinfo(img, &info);
- framebits = calloc(1, info.nframes / CHAR_BIT + 1);
+ framebits = calloc(1, img->frames / CHAR_BIT + 1);
if (!framebits) {
return EXIT_FAILURE;
}
/* Figure out what images we're extracting. */
if (!argv[0]) {
/* extract all images by default. */
- memset(framebits, -1, info.nframes / CHAR_BIT + 1);
+ memset(framebits, -1, img->frames / CHAR_BIT + 1);
} else {
for (i = 0; argv[i]; i++) {
- parserange(&info, argv[i], framebits);
+ parserange(img->frames, argv[i], framebits);
}
}
}
/* Extract the images, in order. */
- for (i = 0; i < info.nframes; i++) {
+ for (i = 0; i < img->frames; i++) {
unsigned char **data;
unsigned char **mask;
mask = lbx_img_getmask(img);
- if (!outpng(i, data, mask, info.width, info.height, palette)) {
+ if (!outpng(i, data, mask, img->width, img->height, palette)) {
extracted = 1;
}
}
{ 0 }
};
- progname = "lbximg"; /* argv[0]; */
+ tool_init("lbximg", argc, argv);
while ((opt = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) {
switch(opt) {
case 'i':
}
break;
case 'V':
- puts(VERSION_BOILERPLATE("lbximg"));
+ tool_version();
return EXIT_SUCCESS;
case 'U':
printusage();
lbx_img_getinfo(img, &info);
printf("%s is %ux%u LBX image, %u frame(s)%s%s\n",
- file, info.width, info.height, info.nframes,
+ file, img->width, img->height, img->frames,
info.palettesz ? ", embedded palette" : "",
- info.chunk ? ", chunked" : "",
+ img->chunk ? ", chunked" : "",
info.looping ? ", loops" : "");
}