Drawfile format


The Drawfile format provides an object-oriented description of a graphic image. It represents an object in its editable form, unlike a page-description language such as PostScript which simply describes an image.

This document describes the file format, and the rules that should be used in order to render the object on a display device.

Programmers wishing to define their own object types should use the same approach as for the allocation of SWI numbers.

Coordinates

All coordinates within an Draw file are signed 32-bit integers that give absolute positions on a large image plane. The units are 1/(180*256) inches, or 1/640 of a printer's point. When plotting on an Archimedes screen, an assumption is made that one OS-unit on the screen is 1/180 of an inch. This gives an image reaching over half a mile in each direction from the origin. The actual image size (eg. the page format) is not defined by the file, though the maximum extent of the objects defined is quite easy to calculate. Positive-x is to the right, positive-y is up. The printed page conventionally has the origin at its bottom left hand corner. When rendering the image on a raster device, the origin is at the bottom left hand corner of a device pixel.

Colours

Colours are specified in Draw files as absolute RGB values in a 32-bit word. The format is:
Byte        Description
----------- ----------------------------------------------------
0           reserved (must be zero)
1           unsigned red value
2           unsigned green value
3           unsigned blue value

For colour values, 0 means none of that colour and 255 means fully saturated in that colour.

(Aside: the phrase "reserved and must be zero" means:

  • when creating such an object, set to zero
  • when reading such an object, do NOT assume that these fields are zero
  • This allows the fields to be used for future expansion. End aside.)

    The bytes in a word of an Draw file are in little-endian order, eg. the lest significant byte appears first in the file.

    The special value &FFFFFFFF is used in the filling of areas and outlines to mean 'transparent'.

    The File Header

    The file consists of a header, followed by a sequence of objects.

    The file header is of the following form.

    Size        Description
    ----------- ----------------------------------------------------
    4           'Draw'           
    4           major format version stamp - currently 201 (decimal)
    4           minor format version stamp - currently 0
    12          identity of the program that produced this file
                - typically 8 ASCII chars, padded with spaces.
    16          Bounding box: low x, low y, high x, high y
    
    
    When rendering an Draw file, check the major version number. If this is greater than the latest version you recognise then refuse to render the file (eg. generate an error message for the user), as an incompatible change in the format has occured.

    The entire file is rendred by rendering the objects one by one, as they appear in the file.

    The bounding box indicates the intended image size for this drawing.

    The Object Header

    Each object consists of an object header, followed by a variable amount of data depending on the object type. the object header is of the following form:
    Size        Description
    ----------- ----------------------------------------------------
    4           object type field
    4           object size: number of bytes in the object, always a
                   multiple of 4
    16          object bounding box: low x, low y, high x, high y
    
    
    The bounding box describes the maximum extent of the rendition of the object: the object cannot affect the appearance of the display outside this rectangle. The upper coordinates are an outer bound, in that the device pixel at (x-low, y-low) may be affected by the object, but the one at (x-high, y-high) may not be. The rendition procedure may use clipping on these rectangles to abandon obviously invisible objects.

    Objects with no direct effect on the rendition of the file have no bounding box: these will be identified explicitly in the object descriptions that follow.

    If an unidientified object type field is encountered when rendering a file, ignore the object and contine.

    The object size field includes the object header.

    The rest of the data for and object depends on the object type field.

    Objects


    Draw type transformation matrices

    Typical 2D transformation matrices are expressed in the form:
     _         _
    |  a  b  0  |
    |  c  d  0  |
    |_ e  f  1 _|
    
    
    This matrix transforms a coordinate (x,y) into another coordinate (x',y') as follows:

    x' = ax + cy + e
    y' = bx + dy + f

    When a transformation matrix appears in a Drawfile, it is stored as follows:

    Size        Description
    ----------- ----------------------------------------------------
    4           a
    4           b
    4           c
    4           d
    4           e
    4           f
    
    Values a - d are stored in '16.16' fixed point format (ie. 16 bits for the integer part and 16 bits for the fractional part). Values e and f are integers and are in Draw units.

    -----Hot links to other pages-----
    Acorn Computer Group Acorn Education


    © 1995 Acorn Computer Group plc.
    Design: © 1995 Cave Rock Software Ltd.
    Contact: webmaster@acorn.co.uk