/*----------------------------------------------------------------------*/ /* clrmap.c, replaces any colormap in a SunRasterfile with a 3 X 256 */ /* equal RGB colormap. This is done because *occaisionally* when djpeg */ /* decompresses a JPEG compressed SunRasterfile, it uses a slightly */ /* smaller colormap than usual to save space. The tools provided in */ /* the raster toolkit do not accept a colormap smaller than 3 * 256. */ /* */ /* NOTE: This program should only be used on SunRasterfiles with a bad */ /* colormap. The presence of a bad colormap is indicated by the */ /* size of the 640 X 4880 image file being less than 308000 bytes.*/ /*----------------------------------------------------------------------*/ #include "rvmlibv2.h" /*----------------------------*/ /* provides usage information */ /*----------------------------*/ void usage() { fprintf(stdout, "\nusage: clrmap [-h] filename...\n\ -h show help page\n\ filename: SunRaster image file\n\ Image file names are unchanged\n\ WARNING: Output files will over-write files with same name\n\n"); exit(0); } /*---------------------------*/ /* provides help information */ /*---------------------------*/ void help() { fprintf(stdout, "\n\ NAME\n\ CLRMAP\n\ SYNOPSIS\n\ clrmap [-h] filename...\n\ DESCRIPTION\n\ clrmap simply checks the colormap size of a SunRasterfile and replaces\n\ the colormap if it is not a 3X256/Equal RGB/Black&White valid colormap.\n\ clrmap can be useful in cases where JPEG decompression reduces the size\n\ of the colormap and to ensure that all possible values (0 thru 256) can\n\ be used by various analysis programs.\n\ OPTIONS\n\ -h show help page\n\ OUTPUT\n\ clrmap input filenames are unchanged.\n\n"); exit(); } /*----------------------*/ /* clrmap main function */ /*----------------------*/ void main(int argc, char *argv[]) { FILE *fp; struct RAS_IMAGE *imgdat; int file; if(argc < 2) usage(); /*------------------*/ /* initialize stuff */ /*------------------*/ file = 1; /*------------------------------*/ /* parse command line arguments */ /*------------------------------*/ while(*argv[file] == '-') { switch(*(argv[file] + 1)) { case 'h': help(); default: usage(); } } /*------------------*/ /* for each file... */ /*------------------*/ while(file < argc) { /*----------------------------*/ /* print the name of the file */ /*----------------------------*/ fprintf(stdout, "%s\n", argv[file]); /*----------------------------*/ /* open input file, read data */ /*----------------------------*/ fp = (FILE *) open_file(argv[file], "rb"); imgdat = (struct RAS_IMAGE *) read_sunraster(fp); fclose(fp); /*------------------*/ /* fix the colormap */ /*------------------*/ fix_clrmap(imgdat); /*------------------------------*/ /* open output file, write data */ /*------------------------------*/ fp = (FILE *) open_file(argv[file], "wb"); write_sunraster(fp, imgdat); /*-----------------------*/ /* close the output file */ /*-----------------------*/ fclose(fp); /*----------------------------*/ /* increment the file counter */ /*----------------------------*/ file++; } free(imgdat); exit(); }