ftp.nice.ch/pub/next/tools/cdrom/pCD.0.34.N.bs.tar.gz#/pCD0.3.4/hpcdtoppm.0.4/postscr.c

This is postscr.c in view mode; [Download] [Up]

/* hpcdtoppm (Hadmut's pcdtoppm) v0.4
*  Copyright (c) 1992, 1993 by Hadmut Danisch (danisch@ira.uka.de).
*  Permission to use and distribute this software and its
*  documentation for noncommercial use and without fee is hereby granted,
*  provided that the above copyright notice appear in all copies and that
*  both that copyright notice and this permission notice appear in
*  supporting documentation. It is not allowed to sell this software in 
*  any way. This software is not public domain.
*/

#include "hpcdtoppm.h"


float PAPER_LEFT   =DEF_PAPER_LEFT;
float PAPER_BOTTOM =DEF_PAPER_BOTTOM;
float PAPER_WIDTH  =DEF_PAPER_WIDTH;
float PAPER_HEIGHT =DEF_PAPER_HEIGHT;



static char pshdr[]=
"%%Creator: hpcdtoppm by Hadmut Danisch (danisch@ira.uka.de), hpcd_ps by Adolf Mathias (mathias@ira.uka.de)\n";


/* find an appropriate scaling coefficient and generate a ps header
 * including a BoundingBox comment and a translate/scale sequence to 
 * fit the pixw*pixh image into a square on paper with PS user coordinates 
 * x,y,w,h 
 */
static void size_dependant(pixw,pixh, x,y,w,h)
  int pixw,pixh;
  float x,y,w,h;
{ float scale=(float)w/pixw,scaley=(float)h/pixh;

  if(scale>scaley) scale=scaley;
  x+=w/2.0;y+=h/2.0;
  fprintf(fout,"%s",pshdr);
  fprintf(fout,"%%%%BoundingBox %.8g %.8g %.8g %.8g\n",
	 x-scale*pixw/2.0,y-scale*pixh/2.0,
	 x+scale*pixw/2.0,y+scale*pixh/2.0);

  if(pcdname) fprintf(fout,"%%%%Title: %s\n",pcdname);
  fputs("%%EndComments\n\n",fout);

  fprintf(fout,"%f %f translate\n",x-scale*pixw/2.0,y-scale*pixh/2.0);
  fprintf(fout,"%f %f scale\n",scale*pixw,scale*pixh);
}






static void sub_psgrey(w,h, ptr,zeil,pix)
  sdim w,h, zeil,pix;
  uBYTE *ptr;

{ sdim x,y;
  register uBYTE *p;
  int c;

  size_dependant(w,h,PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT);
  fprintf(fout,"%ld string\n",w);
  fprintf(fout,"%ld %ld 8\n",w,h);	/* always 8 bit per channel */
  fprintf(fout,"[%ld 0 0 %ld 0 %ld]\n",w,-h,h);
  fputs("{currentfile 1 index readhexstring pop} image\n",fout);
  
  c=0;
  for(y=0;y<h;y++,ptr+=zeil)
    for(p=ptr,x=0;x<w;x++,p+=pix)
      {fprintf(fout,"%.2X",*p);
       if(!(++c % 36)) fputs("\n",fout);
      }

  fputs("pop\n",fout);
}


void write_epsgrey(w,h, ptr,zeil,pix)
  sdim w,h, zeil,pix;
  uBYTE *ptr;
{ 
  fputs("%!PS-Adobe-2.0 EPSF-2.0\n",fout);
  sub_psgrey(w,h, ptr,zeil,pix);
}

void write_psgrey(w,h, ptr,zeil,pix)
  sdim w,h, zeil,pix;
  uBYTE *ptr;
{ 
  fputs("%!PS-Adobe-2.0\n",fout);
  sub_psgrey(w,h, ptr,zeil,pix);
  fputs("showpage\n",fout);
}











static void sub_psrgb(w,h, rptr,rzeil,rpix,  
			   gptr,gzeil,gpix,  
			   bptr,bzeil,bpix) 
  sdim w,h, rzeil,gzeil,bzeil, rpix,gpix,bpix;
  uBYTE *rptr,*gptr,*bptr;

{ sdim x,y;
  register uBYTE *pr,*pg,*pb;
  int c;

  size_dependant(w,h,PAPER_LEFT,PAPER_BOTTOM,PAPER_WIDTH,PAPER_HEIGHT);
  fprintf(fout,"%ld string\n",w*3);
  fprintf(fout,"%ld %ld 8\n",w,h);	/* always 8 bit per channel */
  fprintf(fout,"[%ld 0 0 %ld 0 %ld]\n",w,-h,h);
  fputs("{currentfile 1 index readhexstring pop} false 3 colorimage\n",fout);
  
  c=0; 
  for(y=0;y<h;y++,rptr+=rzeil,gptr+=gzeil,bptr+=bzeil)
    for(pr=rptr,pg=gptr,pb=bptr,x=0;x<w;x++,pr+=rpix,pg+=gpix,pb+=bpix)
      {fprintf(fout,"%.2X%.2X%.2X",*pr,*pg,*pb);
       if(!(++c % 12)) fputs("\n",fout);
      }

  fputs("\npop\n",fout);
}


void write_epsrgb(w,h, rptr,rzeil,rpix,  
			     gptr,gzeil,gpix,  
			     bptr,bzeil,bpix) 
  sdim w,h, rzeil,gzeil,bzeil, rpix,gpix,bpix;
  uBYTE *rptr,*gptr,*bptr;
{ 
  fputs("%!PS-Adobe-2.0 EPSF-2.0\n",fout);
  sub_psrgb(w,h, rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix);
}



void write_psrgb(w,h, rptr,rzeil,rpix,  
			     gptr,gzeil,gpix,  
			     bptr,bzeil,bpix) 
  sdim w,h, rzeil,gzeil,bzeil, rpix,gpix,bpix;
  uBYTE *rptr,*gptr,*bptr;
{ 
  fputs("%!PS-Adobe-2.0\n",fout);
  sub_psrgb(w,h, rptr,rzeil,rpix,gptr,gzeil,gpix,bptr,bzeil,bpix);
  fputs("showpage\n",fout);
}



These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.