User guide

94 CHAPTER 3. THE LIBRARY
3.8 The Gr a phi cs Libra r y
The graphics library provides facilities for drawing pictures and outputi ng them to file.
This library is designed to gen er at e .bmp files representing potentially large images
using 8-bit pixels. It should not be confused with the SDL and GL libraries (described
later) used to generate images on the display screen.
This library uses a rectangular canvas of 8-bit pixels with a predefined mapping from
8-bit values to RGB colour s . The user can specify the canvas size (which can be quite
large) but the colour map is preset. There is a graphics header file (g/graphics.h)
declaring various constants and globals. The libr ary itself can be inserted into a pro-
gram by the following statements.
GET "libhdr"
//MANIFEST { g_grfbase=nnn } // Needed if default of 400 not suitable.
GET "graphics.h"
GET "graphics.b"
The constant g
grfbase specifies the position of the first global variable to be used by
this graphics library. Its default value is given in libhdr. An example of how to use
the graphics library is the program bcplprog/tests/tstgraphics.b.
3.8.1 The Graphics Constants
The constants col
white, col rb, col b, col gb, col g, col rg, col r, and col black
are the 8-bit values representing a selection of basic colours from white to black. The
letter r, g, and b represent the presence of red, green and blue.
3.8.2 The Graphics Global Variables
The following variables are pr i vate to the graphics libr ar y and should not normally be
directly accessed by the user .
canvas Rectangular array of pixel bytes
canvassize Number of bytes in canvas
canvasupb UPB of canvas in wor ds
xsize The number of pixels in the x direction
ysize The number of pixels in the y direction
colourtab Vector to map pixe l bytes to RGB values
rowlen xsize rounded up to a multiple of 4 bytes
plotx Current x posi ti on
ploty Cyrrent y pos i ti on
plotcolour Current colour