#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <assert.h>
#include "image.h"
void print_usage(const char *argv0);
{
int i, mode = 0;
int text = 0;
+ int renibble = 0;
char *fname = 0, *outfname = 0;
struct image img;
FILE *out = stdout;
text = 1;
break;
+ case 'n':
+ renibble = 1;
+ break;
+
case 'o':
if(!argv[++i]) {
fprintf(stderr, "%s must be followed by a filename\n", argv[i - 1]);
return 1;
}
+ if(img.bpp == 4 && renibble) {
+ unsigned char *ptr = img.pixels;
+ for(i=0; i<img.width * img.height; i++) {
+ unsigned char p = *ptr;
+ *ptr++ = (p << 4) | (p >> 4);
+ }
+ }
+
if(outfname) {
if(!(out = fopen(outfname, "wb"))) {
fprintf(stderr, "failed to open output file: %s: %s\n", outfname, strerror(errno));
switch(mode) {
case 0:
- if(img.bpp > 8 || img.cmap_ncolors == 0 || img.cmap_ncolors > 16) {
- fwrite(img.pixels, 1, img.scansz * img.height, out);
- } else {
- /* pack into nibbles */
- unsigned char *ptr = img.pixels;
- for(i=0; i<img.width * img.height / 2; i++) {
- unsigned char pair = (ptr[0] << 4) | ptr[1];
- fputc(pair, out);
- ptr += 2;
- }
- }
+ fwrite(img.pixels, 1, img.scansz * img.height, out);
break;
case 1:
{
printf("Usage: %s [options] <input file>\n", argv0);
printf("Options:\n");
+ printf(" -o <output file>: specify output file (default: stdout)\n");
printf(" -p: dump pixels (default)\n");
printf(" -c: dump colormap (palette) entries\n");
printf(" -i: print image information\n");
printf(" -t: dump as text\n");
+ printf(" -n: swap the order of nibbles (for 4bpp)\n");
printf(" -h: print usage and exit\n");
}