Graphics on the Letterprinter 100 Using "LA100G" Graphics on the Letterprinter 100 using "LA100G" by Rob Hamilton Multiware, Inc. Davis, California May 1984 1.0 Introduction LA100G is a program that can read a file of formatted generic graphics instructions, translate the instructions into a disk-based "bitmap" file, and then create a hardcopy image on one of Digital's Letterprinter or Letterwriter 100 serial printers. The program features a dot resolution of up to 1024 by 1024, simulated hardware character generation, dotted and dashed line generation, and a flexible means for scaling and rotating an image. The input file format is easily user-generated by "post-processing" device or metafile output from most any popular graphics package. It can be read with standard FORTRAN READ and FORMAT statements. Graphics on the Letterprinter 100 PAGE 2 Using "LA100G" 2.0 How it works LA100G works in two stages. In the first stage, the user's input file is read and processed. Vectors are "rasterized" or converted to "1" dots (bits) in a zeroed background bitmap. Text characters are converted to suitable dot patterns and positioned in the bitmap. In the second stage, the bitmap is accessed in a top-to-bottom direction, and rows of dots are converted to a format that is compatible with the LA100 printers. The serial output is directed to a logical device called "LA:" until all of the bitmap has been transferred. 2.1 The Input File LA100G reads graphics input from a user-specified file. This file should be formatted as rows (ASCII records) of three numeric values each. The spacing or width of the numeric fields within a record is quite flexible because a "free-formatted" READ statement is used to get the values. The first number in each record is an INTEGER operation code. This code defines the nature of the instruction. Examples are "1" for MOVE, "2" for DRAW, "3" for TEXT and "4" for SET_LINE_STYLE. The second and third values in a record are operand arguments, such as X and Y coordinate values or a line style code. A special additional record is used to list text information. Records are read by LA100G one-by-one until an END_OF_PICTURE record or an end-of-file condition is encountered. 2.2 The Raster-Bitmap File In order to store a rectangular bitmap with 1024 points along each side, it is necessary to maintain an array of 1,048,576 bits (1MBit) or 131,072 eight-bit bytes (128K-bytes). This is accomplished by storing the array on a direct-access disk file. Only those parts being updated at a particular moment are read into memory. Furthermore, it is convenient to divide the bitmap into smaller pieces or "cells". Each cell is designed to occupy exactly one disk block, so it can be accessed with relatively little overhead. Cells represent square areas of sixty-four bits on a side. Thus, there are sixteen cells across the top and sixteen cells down the side of the bitmap, for a total of two-hundred and fifty-six cells. Graphics on the Letterprinter 100 PAGE 3 Using "LA100G" It is interesting to note that in many instances, only a portion of the bitmap's cells are actually filled with non-zero information. This is because much of the graphics information we create contains large areas of blank space. LA100G anticipates this condition by storing a mapped file of cells that contain vectors or text. Cells that are not used in an image are not represented in the bitmap file. The first block of the bitmap file is dedicated to holding two-hundred and fifty-six pointers to respective cells. A pointer whose value is zero indicates that the corresponding cell need not be represented. 2.3 Disk-Cache of Cells LA100G maintains a list of bitmap cells that are currently in memory. To maximize the speed at which vectors and text are rasterized, the 16-bit versions keep thirty-two cells resident or "cached." When a new cell is needed and all available cell arrays are full, the cached cell list is examined, and the cell which has been used least recently is swapped to the bitmap file. Thus, cells that are used most frequently are swapped least. Once the input file has been fully processed, the bitmap file is closed and saved for future access. 2.4 Printer Formatting The LA100 printers utilize a six-hammer vertical impact column that moves horizontally. For best scan-to-scan registration, graphics mode limits actual printing to print-head sweeps from left-to-right. A specially defined protocol allows graphics data to be passed to the printer in dense groups of six-bit columns. The LA100G program reads the bitmap file blocks (cells) and then constructs a row of six-bit columns as an array of ASCII bytes. The array is optimized by using the printer's "repeat introducer" sequence. Multiple occurances of adjacent and equivalent characters can be replaced by the repeat introducer, a count value, and the character value. Each six-bit-high row is processed in a different way than the one immediately above or below it. This is because the bitmap file is organized as eight-bit bytes. Four methods of extracting six-bits columns are utilized; 1. Get lowest six bits of cell row 2. Combine highest two bits of cell row with lowest four bits of next cell row 3. Combine highest four bits of cell row with lowest two bits of next cell row 4. Get highest six bits of cell row Graphics on the Letterprinter 100 PAGE 4 Using "LA100G" A rotation of the four methods is used to create adjacent and contiguous six-bit-column rows. The printer places 132 horizontal dots per inch and 72 dot rows per vertical inch. To best approximate a one-to-one aspect ratio, two horizontal dots are drawn for each one specified in the raster bitmap file. Thus, the true aspect ratio of plots drawn is 66x72 or 0.91667. 3.0 System Requirements Under the RT-11 operating system, the LA100G program requires about 21K words of memory. The raster bitmap file (RASFIL.TMP) is created with a maximum initial size of two-hundred and fifty-eight blocks. Space for this file must be available on the default device or directory. The output file in LA100 graphics format is directed to a logical device called "LA:". You should use the ASSIGN command to connect this device with either a disk/directory or an LA100/LS100 printer. 4.0 Special LA100 Setup Requirements The Letterprinter 100 should be set up such that its margins are at the extreme left and right positions. Of course, communications parameters such as BAUD RATE, PARITY, and NUMBER OF BITS must be set in the same manner as for alphanumeric use. The printer should be ON-LINE and WIDE (14-7/8") paper inserted at the TOP-OF-FORM position. Keep in mind that once the program has begun to transmit graphics data to the printer, the printer is in its "graphics" mode. If the program is aborted prematurely, it will probably leave the printer in this mode, causing strange behavior when alphanumeric data is transmitted. For this reason, it is best to let the program finish normally, whereupon the printer mode is reset to alphanumeric. Of course, you can always reset the printer's mode by turning its power off, and then on again. 5.0 Input File Format As discussed in section 2.1, input files consist of FORTRAN-readable formatted records, with three numeric values each. The first value must be an INTEGER operation code between 1 and 12. Each operation code value denotes a unique graphics function. The second and third values are used to hold argument values. Note that some operation codes do not require specific argument values. However, dummy arguments must be supplied to Graphics on the Letterprinter 100 PAGE 5 Using "LA100G" satisfy the FORTRAN sequential free-format READ. The value "0" is usually employed for this purpose. The following table lists graphics operation codes, and their respective operand arguments. Input File Op Codes and Operands Op Code Op Code Argument Argument Function Value 1 2 MOVE 1 X value Y value DRAW 2 X value Y value TEXT 3 No. of Chars. 0 SET_LINE_STYLE 4 Style Code 0 SET_LIMIT 6 X value Y value SET_OFFSET 7 X value Y value SET_LA100_LIMIT 8 X value Y value END_OF_PICTURE 9 0 0 SET_TEXT_PATH 10 degrees 0 SET_TEXT_SIZE 11 X value Y value SET_ROTATE 12 0 or 1 0 5.1 The MOVE command The MOVE command is implemented as operation code 1. Accompanying X and Y argument values direct a new "current position" to be established at the coordinate (X,Y). 5.2 The DRAW command The DRAW command is implemented as operation code 2. A vector is drawn between the previous "current position" and the coordinate specified by the accompanying arguments. This coordinate becomes the new "current position". Graphics on the Letterprinter 100 PAGE 6 Using "LA100G" 5.3 The TEXT command The TEXT command is implemented as operation code 3. The first argument specifies the number of characters to be written. The text string should be placed in the next input record, beginning in column 1. Text records should not contain any other values or arguments. 5.4 The SET_LINE_STYLE command The SET_LINE_STYLE command is implemented as operation code 4. One of eight different styles (dot-dash patterns) of vectors can be selected by using this command. The first argument should hold an INTEGER value between 1 and 8. Line-style 1 (solid) is the default. The others are described here: Line Styles 1 . . . . . . . . . . Solid Line 2 . . . . . . . . . . Dot-Dash 3 . . . . . . . . . . Course Dots 4 . . . . . . . . . . Fine Dots 5 . . . . . . . . . . Spaced Dots 6 . . . . . . . . . . Widely Spaced Dots 7 . . . . . . . . . . Dash-Dash-Gap 8 . . . . . . . . . . Dashed Line 5.5 The SET_TEXT_PATH command The SET_TEXT_PATH command is implemented as operation code 10. Text can be written in one of four directions. The first operand argument is used to select the desired direction in angular degrees: 0 . . . . . . . . . . left-to-right (default) 90 . . . . . . . . . . bottom-to-top 180 . . . . . . . . . . upside-down 270 . . . . . . . . . . top-to-bottom 5.6 The SET_TEXT_SIZE command The SET_TEXT_SIZE command is implemented as operation code 11. This command allows you to select one of seven character sizes. An INTEGER character size code is specified in the first argument position. The default size is 2, which creates characters that Graphics on the Letterprinter 100 PAGE 7 Using "LA100G" are fourteen dots high and ten dots wide. This size is closest in proportion to most popular graphics CRT text sizes. Size 1 makes the smallest text characters at 5x7 dots, and all other sizes are integer multiples of size 1. 5.7 The SET_LIMITS command The SET_LIMITS command is implemented as operation code 6. This command allows you to adjust the range of the input file's coordinate system. The maximum expected X and Y values should be specified as the operand arguments. If this command is not given, a coordinate system that ranges from 0 to 4095 in X, and 0 to 3071 in Y is assumed. 5.8 The SET_LA100_OFFSETS command The SET_LA100_OFFSETS command is implemented as operation code 7. This command allows you to displace an image on the page by the specified number of X and Y LA100 dot units. Positive X and Y values will cause the image to be placed above and to the right of the default (0,0) origin. 5.9 The SET_LA100_LIMITS command The SET_LA100_OFFSETS command is implemented as operation code 8. This command allows you to place an upper limit to the LA100 coordinates to which the input file is scaled. (Note: This feature implements a WINDOW; not a VIEWPORT. Information is scaled and not clipped.) The default LA100 limits are 958 wide by 720 high. 5.10 The SET_ROTATED command The SET_ROTATED command is implemented as operation code 12. Graphics images can be rotated 90 degrees by using this command at the beginning of the input file. When a non-zero first argument is passed, graphics will be rotated. If the argument is zero, graphics images will be displayed normally. Graphics on the Letterprinter 100 PAGE 8 Using "LA100G" 5.11 The END_OF_PICTURE command The END_OF_PICTURE command is implemented as operation code 9. This command defines the end of graphics information in an input file. No other information in the file will be read or interpretted. 5.12 Example Input File Following is a simple input file that draws a rectangle, a diagonal line through the rectangle, the eight line types, and a text string "Testing ONE TWO". 12 1 0 ! rotate graphics 1 10 10 2 2000, 10 2 2000, 1000 2 10, 1000 2 10 10 1 1000, 300 3 15 0 Testing ONE TWO 4 1 0 1 100 900 2 500 900 4 2 0 1 100 850 2 500 850 4 3 0 1 100 800 2 500 800 4 4 0 1 100 750 2 500 750 4 5 0 1 100 700 2 500 700 4 6 0 1 100 650 2 500 650 4 7 0 1 100 600 2 500 600 4 8 0 1 100 350 2 500 350 4 1 0 1 10 10 2 2000, 1000 9 0 0 ! end picture Graphics on the Letterprinter 100 PAGE 9 Using "LA100G" 6.0 Installation of LA100G The program as distributed for RT-11 and RSX-11M systems, consists of six FORTRAN source files: LA100G.FOR . . . . Main module LA100D.FOR . . . . Input file decoder LA100B.FOR . . . . Bitmap Management and Vector Rasterizer LA100C.FOR . . . . Dot-Matrix Character Generation LA100P.FOR . . . . Bitmap to LA100 conversion LA100S.FOR . . . . LA100 format and output processor Also provided is a command file for compiling and linking the program. This command file is called LA100G.COM. 7.0 Sample Run You can run the LA100G program by typing your system's RUN command. The program will ask you for an input file specification. After the file specification has been typed, the bitmap file will be opened on your default device. If this fails, an error diagnostic message will be printed. You should make certain that there is space available for a file of 258 blocks in length before trying again. .RUN LA100G Name of input file: TEST1.ARG Processing input record 128 Beginning LA100 Graphics Printing. Another copy? NO . Note that the program creates but does not delete the raster bitmap file RASFIL.TMP. This file is kept so that more copies of the image can be made, without repeating the rasterization step. If it is no longer needed, you can use your system's DELETE command to reclaim the disk space. To make more copies from an existing raster bitmap file, you can simply press in response to the "Name of input file:" prompt. A message will appear that says Attempt to print from existing bitmap file... Graphics on the Letterprinter 100 PAGE 10 Using "LA100G" 7.1 Error Diagnostic Messages ?LA100P-F-LA100 output file failed to open The logical device "LA:" does not exist. Use your system's ASSIGN statement to connect a device or directory with this name. ?LA100G-F-Named input file not found. The input file you specified does not exist on the directory or device specified. Make certain that you typed its name correctly. ?LA100G-F-Intermediate bitmap file (RASFIL.TMP) not found. No input file specification was given, so LA100G attempted to open an existing bitmap file. This file did not exist or was "locked". Check to see whether the file is present and that it is ready for access. ?LA100G-F-Raster file failed on open The system tried to open the raster bitmap file RASFIL.TMP on your default directory and failed, probably due to lack of space. This file requires an initial allocation of 258 blocks. Once it has been created and closed, it will probably occupy less space.