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. DrawFile provides an
     ImageFileConvert interface for the generation of SVG files.
   
   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.
   
   ImageFileRender
     The ImageFileRender module provides an abstracted means of rendering
     different forms of files. ImageFileRender itself supports rendering
     of Sprite, DrawFile and JPEG format files. Other components provide
     additional facilities for non-native filetypes.
   
   ImageFileConvert
     The ImageFileConvert module provides an abstracted means of converting
     between different forms of files.
   

In addition to these major components, a collection of smaller components
provide facilities for the ImageFileRender and ImageFileConvert modules :

   ConvertPNG
     The ConvertPNG module provides SWIs, and an ImageFileConvert interface
     for converting between Sprite and PNG files. Through ImageFileConvert,
     this allows rendering of PNG files with ImageFileRender.
   
   ConvertSprite
     The ConvertPNG module provides SWIs, and an ImageFileConvert interface
     for creating Sprite files from arbitrary rendering routines.
     ConvertSprite will provide ImageFileConvert facilities for any type
     registered with ImageFileRender, allowing vector formats to be
     converted to bitmaps.
   
   ConvertGIF
     The ConvertGIF is presently a 'dummy' module which provides an
     ImageFileConvert interface for converting GIFs to sprites. This
     dummy implementation is used whilst LZW licensing is investigated.
   
   ConvertXBM
     The ConvertXBM module provides an ImageFileConvert interface
     converting XBM files to sprites.
   
   ConvertSun
     The ConvertSun module provides an ImageFileConvert interface
     converting Sun Raster files to sprites.
   
   ConvertBMP
     The ConvertBMP module provides an ImageFileConvert interface
     converting Windows bitmap (.bmp) files to sprites.
   
   ConvertPNM
     The ConvertPNN module provides an ImageFileConvert interface
     converting Portable Net Map (.pnm, .pgm, .pbm) files to sprites.
   
   ConvertICO
     The ConvertICO module provides an ImageFileConvert interface
     converting .ico (Windows icon) files to sprites.

   ImageFileRender_Artworks
     The ImageFileRender_Artworks module provides SWIs and an
     ImageFileRender interface for rendering Artworks files.
   
   ColourMap
     The ColourMap module provides a means by which 'standard' colour
     map descriptors may be constructed using simple SWI calls rather
     than embedding assembler in each component.


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.
     
   ImageFileRender registered functions
     Components registered with ImageFileRender will be called through
     interfaces they have provided when operations on their filetype is
     required.
     
   ImageFileConvert registered functions
     Components registered with ImageFileConvert will be called through
     interfaces they have provided when operations on their filetype is
     required.
     

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.

ImageFileRender:
  ImageFileRender is able to provide colourmapping where the underlying
  modules are capable of colour mapping. Any type converted through
  sprite before rendering will be capable of using colour map descriptors,
  as will any type converted through Drawfile. The Artworks renderer
  also supports colourmapping through ImageFileRender.

ColourMap:
  The ColourMap module provides a means by which colour map descriptors
  for any of the above components may be created.



Alpha-channel
-------------

A new sprite type has been introduced which allows 8 bits per mask pixel of
translucency. This means that for any sprite using this new type, the pixels
can blend to the background.

SpriteExtend:
  Can be used to render alpha-channel sprites both scaled and transformed,
  using colourmapping and translucency if required.

ColourTrans:
  Generates a greyscale palette when output is directed to the mask of an
  alpha-channel sprite. This allows it to be used like a normal image for
  rendering to.

Kernel:
  The Kernel understands and returns correct values when output is directed
  to alpha channel sprites. Graphics operations on redirected alpha-channel
  sprites work - on the whole - just like binary masked sprites.



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. Whether the
sprite contains binary or alpha-channel data, 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.
