Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-10 - decus/20-189/macps.commented
There are no other files named macps.commented in the archive.
%!
% Postscript pre-amble to parse scribepic output.  This is a fairly
% straightforward translation of Peter Rowley's (U Toronto) C code to
% do the same thing. 
%
%   Originally converted to PostScript by J.W. Peterson
%   Arbitrary bitmap sizing added by J. Schimpf
%   Margin & format control added by J. Schimpf
%
%   SEE SCRIBEPIC info sheet for the use of this file
%   YOU SHOULDN'T TRY TO EDIT THIS FILE - IT IS COPIED
%   FOR YOU.
%
%---------------------------------------------------------------------
%
%      HEX FILE FORMAT
%
%      <Invert> <XBYTES> <YSIZE> <Margin> <Height> <Move UP>
%      <Hex Data.......>
%             
%      Where Invert -> 1 For straight through data
%                      0 To invert data
%      Where YSIZE  ->  # Of Scan lines
%            XBYTES  -> # Bytes/scan line
%            Margin  -> Width of the scribe column (in inches)
%            Height  -> Height of picture (in inches)
%            Move UP -> Distance picture is moved up (in inches)
%
%      Hex data is of the form:
%
%      <Count><Data>   -> If <Count> < 0x80 then this is count
%                         of # bytes to read here
%                      -> If <Count> >= 0x80 This is count of # times
%                         next byte is to be repeated
%
%--------------------------------------------------------------------------
%  Open file routine
/infile (%stdin) (r) file def		% This gets around broke "currentfile"?

%--------------------------------------------------------------------------
%  Get a byte from file routine
/getbyte 
  { infile (x) readhexstring 
    pop 0 get } def  			% Reads 1 byte of data

%-------------------------------------------------------------------------
%  Useful routines & definitions
/inch { 72 mul } def			% Conversion inches => points
/inc { 1 add } def			% increment TOS
                                       
%--------------------------------------------------------------------------
%  Read file and form 1 scan line
/parseline
{
  /in_pos 0 def				% output array pos
  {
     in_pos xbytes lt			% while in_pos < xbytes DO...
     {
     	/cnt getbyte def		% get run length
  
	cnt 127 gt
	  { /cnt cnt 256 sub def } 	% if cnt > 128, cnt -= 256;
	if

	cnt 0 ge			% if cnt >= 0...
	{  
     	  cnt inc 			% for count+1 times...
	  { scanline in_pos getbyte put % scanline[in_pos] = getbyte...
	    /in_pos in_pos inc def	% in_pos++
	  } repeat			
	}
	 				% ELSE
	{
	  /data_byte getbyte def	% fetch the run data
	  cnt neg 1 add			% -cnt + 1
	  { scanline in_pos data_byte put   % scanline[in_pos] = getbyte...
	    /in_pos in_pos inc def	% in_pos++
	  } repeat
	}
	ifelse
     }
     { exit }				% Exit loop if !(in_pos < xbytes)
     ifelse

  }
  loop
  scanline				% leave the data on the stack
} def

 
%----------------------------------------------------------------------
%  MAIN ROUTINE
%
% Group all the operations to draw the picture into one procedure, to
% minimize confusion between PostScript commands and hex data...
%
/drawpaint 
{
  gsave                        % Push graphics enviroment
   
%  Read if this is to be inverted or not put onto the stack, then decide
%  If we should invert the data

    infile token pop
    1 eq
    {
       /invstat true def               % Don't Invert the data
    }
    {
       /invstat false def              % Invert the data
    }
   ifelse

%  Get the X & Y size from the file

    /xbytes infile token pop def     % Bytes/scanline
    /ysize infile token pop def      % # Scan lines

%  Get the margin, height & upward movement

    /margin infile token pop def     % Default usually 6.5 in
    /height infile token pop def     % Default usually 2   in
    /up     infile token pop def     % Default usually 0

%  Generate some constants we will need

    /scanline xbytes string def      % Create output scan buffer
    /nysize ysize neg def            %  Used in matrix to define size
    /xbits xbytes 8 mul def          % Calculate # pixels/scanline
    /width height xbits ysize div mul def  % Width = height * (x / y)

% Generate the transformation to place the "unit square" imagemask uses.

  margin width sub 2 div inch	% center on page (with scribe margins)
  				% with x xlate = (margin - width) / 2
  up inch			% Y translate by UP translate
  translate 			% Center image on the page.

  width inch			% Adjust X size to keep aspect ratio right
  height inch 			% convert Y height to inches
  scale 

%------------------------------------------------------------------
% 
%  Generate image in unit box

       %  The next 5 things are placed on the stack for
       %  the imagemask function

       xbits                   % # Pixels/Scanline
       ysize                   % # Scan lines

       invstat		  	 % Use invstat to choose pixel black/white
    [ xbits 0 0 nysize 0 ysize ] % Bit map description matrix
    { parseline }                % Routine to read scan lines
  imagemask			 % Move bitmap to page
  grestore                       % Restore graphics enviroment
} def

% Put the hex data directly after the "drawpaint" command...
drawpaint