Graphics Library Available
Dave Lewis
lewis at m2-net.UUCP
Sun Jun 26 15:58:57 AEST 1988
A library of graphics primitives for System V/AT (and probably any
other Intel unix, with a bit of hacking) is now available, supporting
common video cards and printers. Demonstration programs are included
with the code.
Please contact me by e-mail if you would like a copy. If there is
sufficient interest, I will post source (about 130K bytes).
Dave Lewis
Ann Arbor, MI
...![ itivax umix ]!m-net!dtlewis!lewis
or lewis at m-net.UUCP
Summary of functionality follows:
------------------------------------------------------------------------
Graphics library for System V/AT
--------------------------------
This collection of routines is designed to provide graphic output to
a number of video adapters and printers for PC/AT class computers running
under Microport System V/AT (r). Various output devices are supported.
For each type of device, one or more graphics "modes" is defined in
graphics.h, and the corresponding bitmaps are defined in bitmaps.h.
These modes roughly correspond to the BIOS video modes defined for MS-DOS,
with additional modes defined for Hercules (r) and for printer output.
The routines are:
init() Initialize device, buffers, variables. Attach
to shared memory segment or malloc'ed buffers.
finish() Release resources, detach segments.
clear() Clear screen.
write_pix() Turn one pixel on.
movpen() Move logical cursor in 32768 x 32768 address space.
draw() Draw vector.
linedraw() Draw line.
box() Draw box.
grafchar() Display a vectorized text character (stroke font).
grafstr() Display a character string, stroke font.
cellchar() Display a bit mapped character.
cellstr() Display a string, bit mapped characters.
cursor() Move to character column and row for cellstr().
pix_mode() Establish OR mode or XOR mode pixel setting, returns
previous mode value.
pix_color() Set pixel color, returns previous color value.
Currently supported devices are Hercules mono, CGA, EGA (currently mono only),
and dot matrix printers (IBM, IBM Proprinter, Epson FX85, Star10X, Tandy
DMP130, and probably others). Additional device support is straightforward,
as all routines call write_pix() to do output.
How it works:
-------------
Init() attaches the shared memory segment for your video board to your
process address space. The pointer to this memory segment is used for
direct read and write access to bit mapped graphics. In the case of
a printer, init() simply allocates some memory buffers which it
treats like the bit map for the printer, then adds some escape codes
and spools the whole mess off to the lp program.
The screen (or printer page) is represented by a normalized address
space of 32768 by 32768. This gives a reasonable amount of resolution,
and allows valid addresses to be represented by non-negative short integers,
giving efficient calculations and easy checking for addresses that would
be "off the edge of the screen." All of the output routines, except
write_pix(), use this normalized address space, regardless of the pixel
aspect ratio or the aspect ratio of the physical screen.
The write_pix() routine uses physical pixel coordinates (row,col)
to access one pixel on the graphics device. All output, whether lines,
dots or text, use the write_pix() routine at the lowest level. In
this way, all knowledge of the display bit map, interleaving and
segmentation are localized to the write_pix() routine.
Positioning on the screen is done with a "graphics cursor," which
is used to position all graphics and text output. The cursor is
positioned in normalized coordinates using the movepen() routine.
Routines such as draw() cause the cursor to be moved to new positions.
The box() and linedraw() routines, as well as the stroke font text,
call movepen() and linedraw() to position the cursor and draw a vector,
respectively. This is the basis of all the graphical output, with
the low level output handled by write_pix().
Two types of text output are supported. A stroke font is invoked by
grafstr(), and a bit cell font is invoked by cellstr(). Grafchar()
and cellchar() are single character versions which should normally
not be directly called (just use the grafstr() and cellstr() versions).
Cursor() is used to position the graphics cursor in terms of character
rows and columns, as if it were a text cursor.
The finish() routine detaches shared memory, frees resources, and
sends any output to the print queue.
All routines are written in C (no assembler at all) and use short integer
arithmetic wherever possible. Long integers are used when more accuracy
is required, and floats and doubles are avoided wherever possible. The
overall performance is quite acceptable, even for text output, and is
in fact considerably faster than similar code under MS-DOS using BIOS
rather than write_pix(). The development machine for this code is a
6 MHz Zenith 241 with no 80287 coprocessor, hence the avoidance of floating
point math.
Credits:
--------
Thanks to John Antypas, Denis Fortin and Bill Rankin for assistance in
testing and developing the code. Data for stroke fonts is taken from
_Graphics_in_C_, Nelson Johnson, McGraw-Hill, 1987, and may be used but
not "reproduced for publication." Data for cell fonts is attributed
to Richard Wilton, and is presumed public domain.
--
Dave Lewis
Ann Arbor, MI
...![ itivax umix ]!m-net!dtlewis!lewis
More information about the Comp.unix.microport
mailing list