/* redo_bw.c rb1.bat = cl /AL redo_bw.c Reads a monochrome image and rescales it from 0 - 63 and makes a color table from 64 - 255 with 6 reds, 8 greens and 4 blues redo_bw [infile] [irows] [icols] [outfile] [row1] [col1] [orows] [ocols] where: infile --- input file name with extension irows ---- number of rows in input image icols ---- number of columns in input image outfile -- output file name without extension row1 ----- first row in input image to use in output image col1 ----- first column in input image to use in output image orows ---- number of rows in output image ocols ---- number of columns in output image */ #include #include #define NUMRED 6 #define NUMGRN 6 #define NUMBLU 5 #define MAXPTS 25000 unsigned char Buffer[MAXPTS]; int Red[NUMRED]={0,51,102,153,204,255}; int Grn[NUMGRN]={0,51,102,153,204,255}; int Blu[NUMBLU]={0,64,128,191,255}; main(int argc,char *argv[]) { long i,j,k,l,m,n,r,g,b; long irow,icol,orow,ocol,row1,col1; char infile[100],outname[100],string[100],cr=0xd; FILE *fpin,*fplbl,*fppal,*fpdat; long offset,sample=1; if(argc<9) print_format(); strcpy(infile,argv[1]); fpin=fopen(infile,"rb"); if(!fpin) not_open(infile,"read"); if(sscanf(argv[2],"%ld",&irow)<1) not_read("irow"); if(sscanf(argv[3],"%ld",&icol)<1) not_read("icol"); if(sscanf(argv[5],"%ld",&row1)<1) not_read("row1"); if(sscanf(argv[6],"%ld",&col1)<1) not_read("col1"); if(sscanf(argv[7],"%ld",&orow)<1) not_read("orow"); if(sscanf(argv[8],"%ld",&ocol)<1) not_read("ocol"); if(argc==10) { if(sscanf(argv[9],"%ld",&i)==1) sample=i; } strcpy(outname,argv[4]); sprintf(string,"%s.lbl",outname); fplbl=fopen(string,"wt"); if(!fplbl) not_open(string,"write"); fprintf(fplbl,"FILE_TYPE = IMAGE\n"); fprintf(fplbl,"IMAGE_LINES = %6ld\n",orow/sample); fprintf(fplbl,"LINE_SAMPLES = %6ld\n",ocol/sample); fprintf(fplbl,"IMAGE_POINTER = '%s.dat'\n",outname); fprintf(fplbl,"PAL_POINTER = '%s.pal'\n",outname); fprintf(fplbl,"PALETTE_POINTER = '%s.pal'\n",outname); fprintf(fplbl,"Source image = '%s'\n",infile); fprintf(fplbl," Source_Image_Rows = %6ld\n",irow); fprintf(fplbl," Source_Image_Cols = %6ld\n",icol); fprintf(fplbl," Source_Image_Row1 = %6ld\n",row1); fprintf(fplbl," Source_Image_Col1 = %6ld\n",col1); if(sample!=1) { fprintf(fplbl," Sample_Rate = %6ld\n",sample); fprintf(fplbl," OutPut_Rows = %6ld\n",orow); fprintf(fplbl," OutPut_Cols = %6ld\n",ocol); } fprintf(fplbl,"END\n"); fclose(fplbl); sprintf(string,"%s.pal",outname); fppal=fopen(string,"wt"); if(!fppal) not_open(string,"write"); for(i=0;i<64;i++) fprintf(fppal,"%3ld %3ld %3ld %3ld\n",i,i*4,i*4,i*4); n=64; for(r=0;r\n"); printf("\n"); printf("where:\n"); printf(" infil --- input file name with extension\n"); printf(" irow ---- number of rows in input image\n"); printf(" icol ---- number of columns in input image\n"); printf(" outfil -- output file name without extension\n"); printf(" row1 ---- first row in input image to use in output image\n"); printf(" col1 ---- first column in input image to use in output image\n"); printf(" orow ---- number of rows to output from input image\n"); printf(" ocol ---- number of columns to output from input image\n"); printf(" sample -- OPTIONAL sample rate ( 2 will give orow/2 x ocol/2\n"); printf("\n"); exit(0); }