Title                  :HTPSG
Keywords               :IMAGE PROCESSING, HALFTONE, POSTSCRIPT
Computer               :VAX
Operating System       :VMS
Programming Language   :DEC FORTRAN 77 V4.8
Hardware Requirements  :PostScript compatible printer
Author(s)              :Mark M. Disko
Correspondence Address :140 Fairview Avenue
                       :High Bridge, New Jersey  08829

	"HTPSG.DOC"  -   HalfTone PostScript Generic
	                 |   |    |   |      |
	                 H   T    P   S      G

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Mark M. Disko, 1989
140 Fairview Ave.
High Bridge, New Jersey  08829

(201) 638-2503 

Permission is granted to distribute this software
freely, but it is not to be sold.
	
The user accepts all responsibility for any hardware,
software or data losses related to operation of this
program.  This software is supplied "as is" with no guarantee
of suitability for a particular application.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


Function:
---------

Input an image matrix from disk that has pixel data stored as 
formatted octal, hexadecimal or decimal integer values in a text file.  
The source code can easily be modified so that you can
read in your own 8 bit data (256 gray levels) for display on any
PostScript compatible printer or other output device.



Features:
---------

(1) Flexible data format

(2) Selection of halftone screen parameters - lines/dots, lines per inch,
	image size

(3) Image captions, file name label, and calibration markers 

(4) Portrait or Landscape orientations on page, 4:3 or 1:1 image
	aspect ratios, variable image size on page

(5) Pixel averaging - useful for rapid printing

(6) Compact (for rapid output) hexadecimal image data output in PostScript

(7) FORTRAN demonstration routines for image output and text display in
	PostScript provide functions that can be added to other applications



Restrictions:
-------------

The current version (1.0) does not allow binary file input or the saving
of halftone screen and page layout settings in parameter files.

Simple scale markers in current version, should eventually automatically
scale with the size of the image on teh page.

Optional Encapsulated PostScript mode not yet functional.

Text display has not been debugged for each of the LANDSCAPE page layouts.



Implementation:
---------------

HTPSG was written with VAX VMS FORTRAN V4.8 on a MicroVax II computer.  Test
images have been printeD with a Texas Instrument OmniLaser 2115 printer,
an Apple LaserWriter, and a Compugraphics 9600 phototypesetter.
The actual program has so far been executed only on the MicroVax, but
the FORTRAN used is vanilla FORTRAN 77 without calls to any VAX system
service routines or special functions.  Extended subroutine and 
variable names will probably have to be shortenned for applications 
with some FORTRAN compilers.



Building the Executable Program:
--------------------------------

Create file HTPSG.CMN from the beginning of HTPSG.SRC as described in that
file.  Copy the files HTPSG.SRC and HTPSG.CMN to the same directory.  

On a VAX running VMS the commands to build the executable HTPSG.EXE are:

	$ FORT HTPSG.SRC

	$ LINK HTPSG



Demonstration:
--------------


The file ICOS128.SRC contains a digitized image of a diffraction pattern from
a sample of the Al-Mn icosahedral phase.  This pattern was obtained by Mark
Disko from an electropolished sample and was digitized with an Eikonix
scanning photodiode array system.  The original 512 x 512 x 8 bit image was
pixel averaged to 128 x 128.  The file should be renamed to ICOS128.IMG to
conform to the file extension default of HTPSG.


The format of the data file is described in HTPSG.SRC.  Data files can
be entered wih any editor or created by other programs.  ICOS128.IMG is a
128 by 128 pixel image.  The first line of the data file must be


		HTPSG Version 1.0


followed by the number of pixels/line and the number of lines.  


		128, XPIX
		128, YPIX


Note that descriptive text follows commas on the lines with XPIX and YPIX 
values.  If you omit the commas, than you must also omit the comments - 
they are there so that you can just edit the numbers and leave
the comments as reminders for next time.


The following line contains the image caption


		A popular diffracton pattern...


Next comes the number of pixels on each line in the data file


		32, pixels / line
		HEX     ,pixel format type
		2, two characters per value


These three lines tell the program how to interpret the data file.
It is important to leave at least 5 spaces before the comma and after HEX for 
correct input.  HEX stands for hexadecimal which is a compact way to
place 8 bit values in a text file.  Binary files would take up less
space and provide for faster input, but text files are much easier to
transfer for demonstration purposes.


Thus these three lines tell us that there will be 32 pixels in hexadecimal
format in each line with 2 digits for each value.  Hexadecimal with two
digits covers the range 00 to FF which is 0. to 255. decimal.  Each line
in the image (128 pixels) will thus occupy 4 lines in ICOS128.IMG.


The remaining 4 * 128 = 512 lines of the file contains the pixel values.


To use the program, build the executable as described above and run the
program HTPSG.  Again on the VAX

		$ R HTPSG

A dialog will follow in which you will be asked for the name of the input
file.  Reply with 

		ICOS128

if ICOS128.IMG is in the same directory as HTPSG.EXE.
The .IMG extension is the default and need not be supplied.


Next the program will ask for an output device or file.  The default here is
"LPA0:" - which is the Texas Instruments OmniLaser 2115 printer on our
MicroVax.  In order to use this program your printer must expect to have a
PostScript program file as input.

****************************************************************************
IF YOU ARE NOT SURE WHETHER OR NOT YOUR PRINTER SUPPORTS POSTSCRIPT, 
OR HOW TO PUT YOUR PRINTER IN A POSTSCRIPT EMULATION MODE - SEEK HELP.
****************************************************************************

> If you send the output of a 512 by 512 pixel image to a non-PostScript <
> printer, you will create roughly 150 pages filled with numbers!	 <
> Chances are that your system operator would prefer that you 		 <
> did not do this very often.						 <


Once again, do not enter a printer name when the program solicits one for 
output unless you are sure that device is ready to accept PostScript files.


You can specify a file name for your system instead of a printer name, and 
then send the file to a printer later.  This procedure should work on a
Macintosh using the SendPS public domain utility or on IBM PC's using
PRINT to the PostScript printer device.


After supplying a device name the program will display a menu that will 
let you modify the page appearance.  Go ahead and play.  An important 
parameter to change for ICOS128.IMG is the Page layout type.  The image
was scanned in with a 1:1 aspect ratio, so you should also print it that
way.  The default is 4:3 so you will have to change it using menu option "P".


The remaining parameters are self explainatory.  Remember, the lines per
inch in the halftone screen will affect both the resolution and the number
of gray levels in the output image.  With a 60 line screen on a 300 dpi
printer, your halftone dot will contain 25 marks of ink on the page, for
a total of 25 gray levels.  The number of halftone dots for a given size
image will depend on the size of the area on the page within which you are 
displaying the image.  The default halftone screen for most 300 dpi
PostScript printers is a 50 lpi symmetric dot at an angle of about 40
degrees (guessing on the angle).

A scale marker can be supplied in the "B" menu entry.  You can specify
the position of the marker on the page, line length, and text for
display below the marker.

To modify the default caption, file name, or scale marker positions you
will have to modify the appropriate data statements in subroutine
HTPSG_GET_PAR.  The same goes for the default image box dimensions.



Comments:
---------

I hope to add the missing functions mentioned above in Restrictions.  
Please contact me with your suggestions or questions.
I'm sure there are a few bugs here, but it is a very good starting
point for efficient PostScript image output.  Be sure to read the
excellent books published by Adobe on the PostScript language
if you try to decipher the code that is sent to the printer.

Stock up on toner!


			Mark Disko