PostScript output routines

Brent L. Bates AAD/TAB MS361 x42854 blbates at AERO4.LARC.NASA.GOV
Wed Jul 25 07:14:00 AEST 1990


--------------------------------- cut here -----------------------------
#include <gl.h>
#include <device.h>
#include <stdio.h>

blackwhite(paper)
Boolean paper;
{
/*
        Brent L. Bates
        NASA-Langley Research Center
        M.S. 294
        Hampton, Virginia  23665-5225
        (804) 864-2854
        E-mail: blbates at aero4.larc.nasa.gov or blbates at aero2.larc.nasa.gov
*/
   static Boolean fileopen=FALSE;
   register short y;
   register unsigned short i,temp,x;
   unsigned char value;
   char fileout[81];
   static FILE *ounit;
   extern char outfile[81];
   extern RGBvalue image[YMAXSCREEN+1][3][XMAXSCREEN+1];
   extern Scoord xlen,ylen;
   ringbell();
   if(!fileopen) {
      strcpy(fileout,outfile);
      strcat(fileout,"bw.ps");
      ounit=fopen(fileout,"w");
      fseek(ounit,0L,0);
      fileopen=TRUE;
      if(!paper) fprintf(ounit,"%c!\nshowpage\n",'%');
   }
   fprintf(ounit,"/picstr %d string def\n",ylen);
   if(paper) {
      fprintf(ounit,"15.0 20.0 translate\n");
      fprintf(ounit,"0.0 rotate\n");
      fprintf(ounit,"%f %f scale\n",0.407*1024/xlen,
                                    0.407*1024/xlen);
   }
   else {
      fprintf(ounit,"15.0 20.0 translate\n");
      fprintf(ounit,"90.0 rotate\n");
      fprintf(ounit,"%f %f scale\n",0.74*1024/xlen,
                                    0.74*1024/xlen);
   }
   fprintf(ounit,"%d %d 1 [1 0 0 -1 0 1]",4*(xlen/4),ylen);
   fprintf(ounit,"{currentfile picstr readhexstring pop}\n");
   fprintf(ounit,"image\n");
   for(y=ylen-1;y>=0;y--) {
      for(x=0;x<xlen;x+=4) {
         value=0;
         for(i=1;i<=4;i++) {
            temp=x+i;
            value=value<<1;
            if(image[y][0][temp]==0 && image[y][1][temp]==0 &&
               image[y][2][temp]==0) value=value|1;
         }
         if(value<10) {
            value+=48;
         }
         else {
            value+=87;
         }
         fwrite(&value,sizeof value,1,ounit);
      }
      fprintf(ounit,"\n");
   }
   if(!paper) fprintf(ounit,"showpage\n");
}
--------------------------------- cut here -----------------------------
#include <gl.h>
#include <device.h>
#include <stdio.h>

grayscale(inverse,paper)
Boolean inverse,paper;
{
/*
         Brent L. Bates
         NASA-Langley Research Center
         M.S. 294
         Hampton, Virginia  23665-5225
         (804) 864-2854
         E-mail: blbates at aero4.larc.nasa.gov or blbates at aero2.larc.nasa.gov
*/
   static Boolean fileopen=FALSE;
   static unsigned char mask=0x0f;
   register short y;
   register unsigned short x;
   register unsigned char value;
   unsigned char vtemp;
   char fileout[81];
   static FILE *ounit;
   register float b,g,r;
   extern char outfile[81];
   extern RGBvalue image[YMAXSCREEN+1][3][XMAXSCREEN+1];
   extern Scoord xlen,ylen;
   ringbell();
   if(!fileopen) {
      strcpy(fileout,outfile);
      strcat(fileout,"gr.ps");
      ounit=fopen(fileout,"w");
      fseek(ounit,0L,0);
      fileopen=TRUE;
      if(!paper) fprintf(ounit,"%c!\nshowpage\n",'%');
/*      fprintf(ounit,"/spotproc {abs 1 sub dup mul exch abs 1 sub dup");
      fprintf(ounit," mul add 1 exch sub dup mul 2 mul 1 exch sub} def\n");
      fprintf(ounit,"20.0 45.0 /spotproc load setscreen\n");  */
   }
   fprintf(ounit,"/picstr %d string def\n",ylen);
   if(paper) {
      fprintf(ounit,"15.0 20.0 translate\n");
      fprintf(ounit,"0.0 rotate\n");
      fprintf(ounit,"%f %f scale\n",0.407*1024/xlen,
                                    0.407*1024/xlen);
   }
   else {
      fprintf(ounit,"15.0 20.0 translate\n");
      fprintf(ounit,"90.0 rotate\n");
      fprintf(ounit,"%f %f scale\n",0.74*1024/xlen,
                                    0.74*1024/xlen);
   }
   fprintf(ounit,"%d %d 8 [1 0 0 -1 0 1]",xlen,ylen);
   fprintf(ounit,"{currentfile picstr readhexstring pop}\n");
   fprintf(ounit,"image\n");
   for(y=ylen-1;y>=0;y--) {
      value=0;
      for(x=0;x<xlen;x++) {
         r=(float)image[y][0][x]*0.30;
         g=(float)image[y][1][x]*0.59;
         b=(float)image[y][2][x]*0.11;
         if(inverse) {
            value=(int)(255.5-(r+g+b));
         }
	 else {
            value=(int)(r+g+b+0.5);
         }
         vtemp=(value>>4)&mask;
         if(vtemp<10) {
            vtemp+=48;
         }
         else {
            vtemp+=87;
         }
         fwrite(&vtemp,sizeof vtemp,1,ounit);
         vtemp=value&mask;
         if(vtemp<10) {
            vtemp+=48;
         }
         else {
            vtemp+=87;
         }
         fwrite(&vtemp,sizeof vtemp,1,ounit);
      }
      fprintf(ounit,"\n");
   }
   if(!paper) fprintf(ounit,"showpage\n");
}
--------------------------------- cut here -----------------------------
--

					Brent



More information about the Comp.sys.sgi mailing list