The graphics system
===================

Overview
--------
The graphics system in RISC OS is made up of many different components. Each
of these components provides some facilities to the whole. For the most part,
graphics operations are abstracted through a system of vectored system calls
(SWIs). These are dispatched to claimants, allowing extension of the standard
graphical operations.

The major components in the graphics system are :

   Kernel
     The Kernel provides core graphics capabilities for output to a raster
     buffer used by the VIDC chip to display video.
     In addition to this, it provides rudimentary support for simple sprite
     (bitmap) operations, simple line and block based graphic operations,
     and simple bitmap font rendering.
   
   ScreenModes
     The ScreenModes module provides a centralised point for defining
     modes (resolution, DPI and colour depth groups). The module provides
     enumeration of screen modes, and mode information through a number
     of system calls.

   ColourTrans
     Colour translations for different modes are provided by the ColourTrans
     module. All colour selection passes (via DrawV) to ColourTrans.
   
   SpriteExtend
     The Sprite Extension module provides more complex sprite operations
     which are not present in the kernel. Rendering of scaled and
     transformed sprites is the primary function of the SpriteExtend
     module.
     In addition, SpriteExtend provides facilities for rendering most common
     baseline JPEGs held within JFIF or Exif format files.
   
   Draw
     The Draw module provides vector graphic rendering facilities. The Draw
     module is based on the primitives provided by the PostScript language
     for path rendering.
   
   FontManager
     The FontManager provides scaleable, vector based anti-aliased font
     rendering operations.
   
   InverseTable
     The InverseTable module provides supporting tables for BlendTable
     and FontManager to make rendering blended objects to 256 colour modes
     possible. InverseTable generates tables to convert 5 bit colour
     components to colour indices and vice-versa.
   
   BlendTable
     The BlendTable module provides supporting tables for SpriteExtend to
     allow it to render translucent objects in shallow colour (<=8 bit per
     pixel) modes.
   
   DrawFile
     The DrawFile module provides rendering facilities for the filetype
     used by the Draw application. Extensions to the DrawFile module can
     be provided through the use of service calls.
   
   CompressJPEG (aka JCompMod)
     The CompressJPEG module provides transcoding and creation facilities
     for JPEGs. Given RGB input data, CompressJPEG can create a JPEG at a
     given quality. The CompressJPEG module can also be used to transcode
     (convert to another variant of JPEG) a JPEG. This facility is used by
     SpriteExtend to allow it to render progressive (multi-pass) JPEGs.

   PNG
     The PNG module provides an interface for converting (but not rendering)
     PNG graphics to or from raster images. The PNG module can be used to
     generate sprites from PNGs and vice-versa, and to extract information
     about the image.
   
   SpriteUtil
     The SpriteUtil module provides facilities from earlier versions of the
     Operating System based around the 'System Sprite Area' - a shared pool
     of sprites. Since RISC OS 2, use of the system sprite area has been
     deprecated.


Entry points used by the graphics components :

   SpriteV
     The Sprite Vector is the entry point through which all sprite
     operations are passed in order to satisfy them. Sprite operations are
     split between Kernel and SpriteExtend but can be extended by other
     components through the Sprite vector. When printing, the Sprite vector
     is usually claimed to ensure that all sprite operations are sent to
     the output device.
   
   ColourV
     The Colour Vector is the entry point through which all colour selection
     operations are performed. ColourV is claimed by ColourTrans to provide
     colour matching.
   
   PaletteV
     The Palette Vector provides a mechanism to read and write the current
     palette in an abstract manner. It is provided by the Kernel. Certain
     operations are monitored by other modules to ensure that changes to the
     palette are reflected in their internal state.
     
   DrawV
     The Draw Vector is the entry point for all Draw operations. All vector
     operations are passed through this vector by the Draw module. During
     printing operations, the DrawV is usually redirected to the printer
     driver for rendering.

   Service_DrawFileRender
     The DrawFileRender service is issued when the DrawFile module
     encounters an object which it does not understand. It is expected that
     extension components provide the rendering facilities for the object.
     

Changes to the graphics system
------------------------------

The graphics system as a whole has had a number of changes applied to it
which may affect certain applications. Many of the components has been
extended to provide greater facilities to others. In order to explain
where changes have taken place, the change will be documented, followed
by the components that are affected.


CMYK sprites
------------

Since RISC OS 3.6, this format has been allocated but unsupported by the
operating system. These are now supported within the OS. CMYK sprites are
held in 32bits containing the Cyan, Magenta, Yellow and Black components,
rather than Red, Green and Blue components.


Kernel:
  The Kernel will now provide information on these sprites through the
  standard OS_ReadModeVariable (and OS_ReadVduVariables) calls. Refer to
  a separate document for more details about CMYK sprites.

ColourTrans:
  ColourTrans has been updated to generate tables of CMYK-formatted pixel
  translation tables and to return suitable information for rendering to
  CMYK format sprites.

SpriteExtend:
  SpriteExtend can render CMYK sprites through its scaled and transformed
  entry points. SpriteExtend can render to a CMYK output using both RGB
  and CMYK input sprites.


JPEG rendering
--------------

JPEG rendering has been improved in a number of ways to allow a greater
range of JPEGs to be rendered.


SpriteExtend:
  The SpriteExtend module provides the core code to render JPEGs and so
  has undergone extensive changes.
  A greater number of sampling ratios are now understood by the renderer,
  and some latent faults in rendering of obscure ratios have been corrected.
  The renderer is capable of processing JPEGs with Y sampling ratios of
    1x1, 1x2, 2x1, 2x2 (earlier versions)
    4x1 and 4x2 (new)
  The renderer cannot handle U or V sampling ratios other than 1x1.
  Under previous versions, rendering a small (<17% scaling) JPEG to a
  greyscale output would result in corrupt output. This has been addressed.
  Where JPEGs are scaled up in 256 colour modes using the 'dithered' mode,
  the output is now dithered in a similar manner as that of sprites with
  the 'dithered' bit set.
  Where the JPEG cannot be processed by SpriteExtend, a number of more
  descriptive error messages are now returned.

CompressJPEG:
  The CompressJPEG module has been extended to support transcoding to
  convert progressive JPEGs to baseline JPEGs.


Colour mapping
--------------

Colour mapping allows the colour system to be manipulated for certain
operations. ColourTrans has, since RISC OS 3, provided a mechanism for
generating pixel translation tables for shallow sprites (<= 8 bit per
pixel). However, this mechanism does not scale well to true colour.
Colour mapping routines follow the same mechanism as that used by
ColourTrans pixel translation table transfer functions to translate a
RGB palette entry to a destination entry.

Typically, colour mapping would be used to affect the brightness, contrast,
or to fade or highlight an image.

SpriteExtend:
  Sprite and JPEG rendering can use colour mapping to translate the
  colours in the deep colour sprites.

DrawFile:
  DrawFile rendering can use colour mapping to translate the colours
  before rendering. Vectors, text areas, text, sprites and JPEGs are
  rendered through the colour mapping functions.


Translucent rendering
---------------------

The standard 8 plot operations (overwrite, OR, AND, EOR, invert, NOP, AND
NOT, and OR NOT) are used for rendering sprites. Sprites themselves may
contain masks to make parts of the sprite opaque or transparent. Whilst
these masks are binary (they are either on or off), it is now possible to
make the entire sprite translucent when rendered. 256 degrees of
translucency are available (subject to colour depth restrictions).

SpriteExtend:
  Sprite and JPEG rendering can use translucent rendering to allow them to
  be rendered 'over' the background image.

BlendTable:
  The BlendTable module is a new module created to generate translation
  tables for shallow depth modes where the size of the palette is not
  prohibitive. For deep modes, the blend must be calculated by clients
  (SpriteExtend generates code for these cases).

InverseTable:
  The InverseTable module has been extended to provide generation of tables
  for other modes than the present one.
