From: izen@amelia.nas.nasa.gov (Prof. Steven H. Izen) Newsgroups: comp.sys.sgi Subject: New version of RGB to Color PS program Keywords: color postscript, rgb image Date: 27 Apr 90 19:13:23 GMT Reply-To: izen@cwru.cwru.edu (Prof. Steven H. Izen) Organization: Case Western Reserve University Lines: 366 Here is my updated vesrion of tocolps.c in its entirety. I have updated the spot function to the one currently the default in postscript printers. I have also added the capability of modifying the screen frequencies and angles for each of the colors separately. Finally, I have added landscape support which is selectable either by switch of by running the program as tocolpsl instead of tocolps. As always, positive feedback is greatly appreciated. Steve I. ================snip snip snip--- tear----tear---tear========================= /* tocolps - * Convert a color image to color PostScript. * This knows how to print images with either 1, 2, 4, or 8 bits per * pixel, and how to generate different screen densities and screen * angles. Postscript data is written to standard out, so use a * command like: * * tocolps blat.rgb | lp * * to actually print a picture (portrait). * * tocolpsl blat.rgb | lp * * to actually print a picture (landscape). * * compile with: * cc -o tocolps -O tocolps.c -lc_s -limage -lm * ln tocolps tocolpsl * to create portrait and landscape versions. Note that the landscape * version can be accessed from tocolps by the -l switch. This also swaps * the values of maxxsize and maxysize. * * This version also now uses different screen angles for each color, * uses a default screen density of 50, and has an improved spot function. * Also, screen angles and frequencies can be changed by tches. * * Improvements and bug fixes will be gratefully accepted. Send to the * addresses below. Complaints will be forwarded to /dev/null. * * * Steven H. Izen, 4/26/90 * * tops.c by Paul Haeberli - 1988 * * Adapted from P. H.'s tops.c to work with color * January, April, 1990. * by Steven H. Izen, Dept. of Math. & Stat., * Case Western Reserve University, Cleveland, OH 44106 * izen@cwru.cwru.edu or steve@pitacat.math.cwru.edu or * steve@izen386.math.cwru.edu */ #include #include #include #include int hi[256], low[256]; int reverse_flag = 0; int landscape_flag = 0; short buf[4096]; main(argc,argv) int argc; char **argv; { float pixperinch, maxxsize, maxysize, temp; float cyanscreendensity, cyanscreenangle; float magentascreendensity, magentascreenangle; float yellowscreendensity, yellowscreenangle; float blackscreendensity, blackscreenangle; int bitsper, i; IMAGE *image; if(argc<2) { fprintf(stderr,"usage: %s inimage [-b bitsperpixel]\n",argv[0]); fprintf(stderr," [-l ] # landscape mode\n"); fprintf(stderr," [-k blackscreendensity]\n"); fprintf(stderr," [-K blackscreenangle]\n"); fprintf(stderr," [-c cyanscreendensity]\n"); fprintf(stderr," [-C cyanscreenangle]\n"); fprintf(stderr," [-g magentascreendensity]\n"); fprintf(stderr," [-G magentascreenangle]\n"); fprintf(stderr," [-y yellowscreendensity]\n"); fprintf(stderr," [-Y yellowscreenangle]\n"); fprintf(stderr," [-p pixelsperinch]\n"); fprintf(stderr," [-m maxxinches maxyinches]\n"); exit(1); } if (strcmp(argv[0],"tocolpsl")==0) landscape_flag = 1; image = iopen(argv[1],"r"); if(!image) { fprintf(stderr,"%s: can't open input image file\n",argv[0]); exit(1); } cyanscreendensity = 50.0; cyanscreenangle = 15.0; magentascreendensity = 50.0; magentascreenangle = 75.0; yellowscreendensity = 50.0; yellowscreenangle = 0.0; blackscreendensity = 50.0; blackscreenangle = 45.0; pixperinch = -1.0; maxxsize = 528.0; maxysize = 700.0; bitsper = 8; for(i=2; ixsize; ysize = image->ysize; maketables(); picstrlen = xsize*bitsper; picstrlen = (picstrlen+7)/8; if(ysize/(float)xsize < maxysize/maxxsize) doscale = maxxsize/xsize; else doscale = maxysize/ysize; if(pixperinch > 0.0) { ppiscale = 72.0/pixperinch; if(ppiscale> 7; x++; } psputchar("0123456789abcdef"[val]); } break; case 2: x=0; for(n=2*picstrlen; n--; ) { val = 0; for(i=0; i<2; i++) { val <<= 2; val |= (buf[x]&0xc0) >> 6; x++; } psputchar("0123456789abcdef"[val]); } break; case 4: x=0; for(n=2*picstrlen; n--; ) { val = (buf[x]&0xf0) >> 4; x++; psputchar("0123456789abcdef"[val]); } break; case 8: x=0; for(n=2*picstrlen; n--; ) { val = buf[x]; if(val > 255) fprintf(stderr,"bad poop\n"); x++; n--; psputchar(hi[val]); psputchar(low[val]); } break; default: fprintf(stderr,"bits per pixel must be a power of 2!!\n"); exit(1); } } } printf("\nshowpage\n"); } maketables() { register int i; for(i=0; i<256; i++) { hi[i] = "0123456789abcdef"[i>>4]; low[i] = "0123456789abcdef"[i&0xf]; } } static int pos = 0; psputchar(c) int c; { putchar(c); if(++pos == 50) { putchar('\n'); pos = 0; } }