home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 August
/
Silicon_Graphics_812-0542-002.iso
/
dist
/
impr_base.idb
/
usr
/
lib
/
print
/
rgb2ps_prolog.z
/
rgb2ps_prolog
Wrap
Text File
|
1996-08-03
|
11KB
|
385 lines
%!
% A prolog file for the future tops. Written originally by Tektronix
% folks and then adopted into rgb2ps. -suresh 8/16/91
%
% Originating with some postscript by Chris Shaver,
% modified by some code from Rod Belshee for color table lookup,
% all merged, and made to work with binary data by Sean Kamath.
%
% width height bits/primary x-size y-size orientation LUTlen
%
% width - width of one image raster in pixels (integer)
% height - number of rasters (integer)
% bits/primary - number of bits per primary (1, 2, 4 or 8)
% zoom - zoom factor 0 to 1.0
% 0 = do not zoom
% 1 = zoom to fit page
% .5= zoom to fit half page
% orientation - 0 = as needed, 1 = portrait, 2 = landscape (integer)
% Binary - 0 = hex, 1 = binary
% image - 0 = bw image, 1 = color
% flip - 0 = no flip, 1 = flip
% angle - angle of rotation
% presolution - printer resolution
% ppi - Pixels Per Inch
% Triplets - 0 = CLUT, 1 = RGB triplets
% [LUTlen] - length of color map (in triplets, only if CLUT).
%
% If orientation = 0, the output will be portrait if height >= width
% or landscape if height < width.
%
% If flip is true, then the image would be flipped. Used for
% Transperancy media.
%
% The image will always be rotated by user specified angle.
%
% The LUT is in RGB triplet form (three bytes per index) and the
% image data folows (without breaks!)
%
% There must be NO blank lines after the line containing this data!!!
% The binary image data must imediately follow this line with only a
% single intervening CR/LF (or just a CR or just LF) line terminator.
/do_image {
% to snarf tokens.
/readnum {
currentfile token pop
} bind def
% Define proc to do the image and print it.
/I_width readnum def % Width (in pixels)
/I_height readnum def % Height (in pixels)
/I_bpp readnum def % Bits per pixel
/Z_factor readnum def % Specified zoom
/Orientation readnum def % Specified Orientation
/Binary readnum def % If it's Binary or Hex
/Image readnum def % If it's bw or color
/Flip readnum def % Flip the image
/Angle readnum def % rotate angle
/Ppi readnum def % PixelsPerInch
/Presolution readnum def % Printer Resolution
/Triplets readnum def % If it's in triplets
% (1 = RGB)
% (0 = CLUT)
% set the default Resolution to be 300, if it is
% not defined.
Presolution 0 eq { /Presolution 300 def } if
% define mygetbyte to read either ascii or direct bytes
Binary 0 eq { /mygetbyte { readhexstring } bind def }
{ /mygetbyte { readstring } bind def }
ifelse
Flip 1 eq { 1 neg 1 scale } if % Flip the image
Angle neg rotate % rotate the image by Angle
16 16 neg scale % Lets work in inches
% added neg to mirror
newpath clippath pathbbox % Get imageable area
/URy exch def
/URx exch def
/LLy exch def
/LLx exch def
/Width URx LLx sub 0.005 sub def % avoid clipping!
/Height URy LLy sub 0.005 sub def
Ppi 0 gt { % ppi is set
/X_size Presolution Ppi div I_width mul 72 div def
/Y_size Presolution Ppi div I_height mul 72 div def
LLx LLy translate % Position of LL corner
} % if Ppi is set
{
/angle Angle abs def
/angle_mod angle cvi 90 mod def
angle_mod 0 eq {
Z_factor 0 eq
{ % Set X,Y for nonzoom option
/X_size I_width 72 div def
/Y_size I_height 72 div def
} if
Z_factor 1 eq % Zoom the image to fit the page
{ /X_size 0 def /Y_size 0 def } if
Z_factor 0 ne Z_factor 1 ne and
{ % Zoom the image by user
% requested zoom factor
I_width I_height lt
{ /Y_size Height Z_factor mul def /X_size 0 def }
{ /X_size Width Z_factor mul def /Y_size 0 def } ifelse
} if
LLx LLy translate % Position of LL corner
% of imageable area
% If zero Rotate Angle is requested then only determine
% the Orientation.
Angle 0 eq {
% If Orientation was *not* specifed, determine best fit
Orientation 0 eq % Determine orientation
{
I_height I_width ge
{ /Orientation 1 def }
{ /Orientation 2 def } ifelse
} if
% Orientation specified as Landscape
Orientation 2 eq % Transform to landscape
{ % if necessary
90 rotate
0 Width neg translate
Width Height /Width exch def /Height exch def
} if
} if % if anlgle = 0
% default to portrait orientation
% neither x or y was requested (i.e., make it as large as
% possible
X_size 0 eq Y_size 0 eq and % Calculate an X or Y size
{ % for largest possible image
Width I_width div
Height I_height div gt
{ /Y_size Height def }
{ /X_size Width def } ifelse
} if
% if Y was given, but no X, determine correct X size
X_size 0 eq % Calculate X sixe for given
{ % Y size
I_width I_height gt
{ /X_size I_height I_width div Y_size mul def }
{ /X_size I_width I_height div Y_size mul def } ifelse
} if
% if X was given, but no Y, determine correct Y size
Y_size 0 eq % Calculate Y sixe for given
{ % X size
I_width I_height gt
{ /Y_size I_height I_width div X_size mul def }
{ /Y_size I_width I_height div X_size mul def } ifelse
} if
} if % if angle 90 or 270 or 180 or 360
% If non-orthogonal rotation is requested then calculate a new
% bounding box for the rotated image and a new scaling factor.
angle 90 ne angle 180 ne and
{ angle 270 ne angle 360 ne and
{ angle 0 ne
{
/I_height I_height 1 sub def
/I_width I_width 1 sub def
/NX1 0 def
/NY1 0 def
/NX2 I_height Angle sin mul def
/NY2 I_height Angle cos mul def
/NX3_A I_width Angle cos mul def
/NX3_B I_height Angle sin mul def
/NX3 NX3_A NX3_B add def
/NY3_A I_width Angle sin mul def
/NY3_B I_height Angle cos mul def
/NY3 NY3_A neg NY3_B add def
/NX4 I_width Angle cos mul def
/NY4 I_width Angle sin mul neg def
NX1 NX2 gt { /MAX_X1 NX1 def } { /MAX_X1 NX2 def } ifelse
NX3 NX4 gt { /MAX_X2 NX3 def } { /MAX_X2 NX4 def } ifelse
MAX_X1 MAX_X2 gt { /MAX_X MAX_X1 def } { /MAX_X MAX_X2 def } ifelse
NY1 NY2 gt { /MAX_Y1 NY1 def } { /MAX_Y1 NY2 def } ifelse
NY3 NY4 gt { /MAX_Y2 NY3 def } { /MAX_Y2 NY4 def } ifelse
MAX_Y1 MAX_Y2 gt { /MAX_Y MAX_Y1 def } { /MAX_Y MAX_Y2 def } ifelse
NX1 NX2 lt { /MIN_X1 NX1 def } { /MIN_X1 NX2 def } ifelse
NX3 NX4 lt { /MIN_X2 NX3 def } { /MIN_X2 NX4 def } ifelse
MIN_X1 MIN_X2 lt { /MIN_X MIN_X1 def } { /MIN_X MIN_X2 def } ifelse
NY1 NY2 lt { /MIN_Y1 NY1 def } { /MIN_Y1 NY2 def } ifelse
NY3 NY4 lt { /MIN_Y2 NY3 def } { /MIN_Y2 NY4 def } ifelse
MIN_Y1 MIN_Y2 lt { /MIN_Y MIN_Y1 def } { /MIN_Y MIN_Y2 def } ifelse
/NI_width MAX_X MIN_X sub abs def
/NI_height MAX_Y MIN_Y sub abs def
/ScaleX I_width NI_width div def
/ScaleY I_height NI_height div def
/I_height I_height 1 add def
/I_width I_width 1 add def
Z_factor 0 eq
{ % Set X,Y for nonzoom option
/X_size NI_width 72 div def
/Y_size NI_height 72 div def
} if
Z_factor 1 eq % Zoom the image to fit the page
{ /X_size 0 def /Y_size 0 def } if
Z_factor 0 ne Z_factor 1 ne and
{ % Zoom the image by user
% requested zoom factor
NI_width NI_height lt
{ /Y_size Height Z_factor mul def /X_size 0 def }
{ /X_size Width Z_factor mul def /Y_size 0 def } ifelse
} if
LLx LLy translate % Position of LL corner
% of imageable area
% If zero Rotate Angle is requested then only determine
% the Orientation.
Angle 0 eq {
% If Orientation was *not* specifed, determine best fit
Orientation 0 eq % Determine orientation
{
NI_height NI_width ge
{ /Orientation 1 def }
{ /Orientation 2 def } ifelse
} if
% Orientation specified as Landscape
Orientation 2 eq % Transform to landscape
{ % if necessary
90 rotate
0 Width neg translate
Width Height /Width exch def /Height exch def
} if
} if % if anlgle = 0
% default to portrait orientation
% neither x or y was requested (i.e., make it as large as
% possible
X_size 0 eq Y_size 0 eq and % Calculate an X or Y size
{ % for largest possible image
Width NI_width div
Height NI_height div gt
{ /Y_size Height def }
{ /X_size Width def } ifelse
} if
% if Y was given, but no X, determine correct X size
X_size 0 eq % Calculate X sixe for given
{ % Y size
NI_width NI_height gt
{ /X_size NI_height NI_width div Y_size mul def }
{ /X_size NI_width NI_height div Y_size mul def } ifelse
} if
% if X was given, but no Y, determine correct Y size
Y_size 0 eq % Calculate Y sixe for given
{ % X size
NI_width NI_height gt
{ /Y_size NI_height NI_width div X_size mul def }
{ /Y_size NI_width NI_height div X_size mul def } ifelse
} if
/X_size X_size ScaleX mul 0.62 mul def
/Y_size Y_size ScaleY mul 0.62 mul def
} if
} if
} if % if angle ne orthogonal
} ifelse % not ppi
% Center the image on the page
Width X_size sub 2 div
Height Y_size sub 2 div
translate
% Setup for and do the image
Image 1 eq
{
Triplets 0 eq
{
% Color Lookup Table ---------------------------------------
/cmap_len readnum def % color index lookup table length
/LUT cmap_len array def % color index lookup table
cmap_len { currentfile 3 string mygetbyte pop } repeat
LUT astore pop
% Define procedure for colorimage to lookup indicies
/I_inbuf I_width string def
/I_outbuf I_width 3 mul string def % Allocate output raster storage
%--------------------------------------------------
} % else, handle it further down during the read
{ /I_str I_width 3 mul string def }
ifelse
} if % If only color image
% Start colorimage operator...
% if ! Triplets
% Insert the image data after the colorimage operator, as
% one binary bytes per index, with no separators.
% else
% Inset RGB data right after colorimage operator.
X_size Y_size scale % Scale properly
I_width I_height 8 % I_bpp % Image size
[ I_width 0 0 I_height neg 0 I_height ] % Image matrix
% this is the image proc. It depends on how the data is sent,
% i.e., if it's RGB triplets (triplets=1) or Color Lookup
% Table.
Image 1 eq
{
Triplets 0 eq
{
% It's a RGB Triplet data stream
{
% /readindex
% reads a scan line of indicies into inbuf, looks up the
% RGB triplets in the LUT, and assembles the triplets for
% the scan line into outbuf, which is left on the stack
currentfile I_inbuf mygetbyte pop
% for 0..width
pop
0 1 I_width 1 sub {
I_outbuf % destination for putinterval
1 index % inbuf index
dup 3 mul % outbuf index
LUT % source string for get
I_inbuf
4 -1 roll
get % get color index from inbuf
get % get RGB triplet from LUT at index
putinterval % put RGB triplet into outbuf at 3*index
pop
}
for
I_outbuf
} bind % Image proc
} % else
{
{ currentfile I_str mygetbyte pop } bind
}
ifelse
false 3 % Image color information
colorimage
}
{ /picstr I_width string def
{ currentfile picstr mygetbyte pop }
image
} ifelse
showpage
} bind def
do_image