ColourMapping of deep sprites

Introduction and Overview

Deep sprites - those of 16bpp or 24bpp depths - cannot be operated on using standard pixel translation tables. The tables necessary to operate on such sprites would be 2<<16 bytes (128k), or 4<<24 bytes (64M). Since such tables would be impractical at best, and the range of operations that are possible on such images is large, a manner in which these images can be manipulated has been implemented.

For non-deep sprites pixel translation tables are generated using ColourTrans (q.v. SWI ColourTrans_SelectTable, SWI ColourTrans_GenerateTable) or manually. This initial scheme was suitable for paletted images. It was later extended to encompass more accurate plotting of paletted images in deep modes, and to allow the translation tables to be transformed through a transfer function. The transfer function allows arbitrary translation of an RGB value to another RGB value before that value is used in calculations.

For deep sprites a similar method has been adopted. As before, a transfer function provides a conversion between one source RGB value and a destination RGB value. This allows any deep sprite to be colour transformed. Since this transformation must be performed on every pixel plotted the additional processing required for the colour transformation (henceforth called 'colour mapping', or more simply 'mapping' to distinguish it from a spatial transformations) may be much greater than a plain plot of the same graphic.

Technical Details

API changes

The interface for rendering colour mapped sprites is an extension of that used for plain plotting. Sprite operations PutSpriteScaled and PutSpriteTransformed, and JPEG operations JPEG_PlotScaled, JPEG_PlotFileScaled, JPEG_PlotTransformed and JPEG_PlotFileTransformed have updated APIs to handle the new form of colour mapping.

Colour mapping functions only apply to deep sprites. Using the functions on non-deep sprites will generate an error. Such sprites should use pixel translation tables if they wish to be colour mapped.

Colour mapping descriptor and transfer function

The colour mapping descriptor is a small structure containing the workspace and transfer function pointer. The structure has the following layout :

OffsetContents
0Workspace to pass in R12 to transfer function
4Pointer to transfer function

The transfer function used by these operations is exactly the same as that used by the SWI ColourTrans_SelectTable calls (PRM 3-346). The function will be called in SVC mode with the usual supervisor stack limits. It is described under ColourMapTransfer.

SWI Calls

OS_SpriteOp 34OS_SpriteOp_PutSpriteScaledSWI &2E
Plot a deep sprite scaled, with colour mapping (PutSpriteScaled)
R0=52 + operation type (refer to the OS_SpriteOp documentation)
R1=Pointer to sprite area
R2=Pointer to sprite name, or sprite pointer
R3=X coordinate
R4=Y coordinate
R5=Plot action; valid bits:
Bit(s)Meaning
3Use mask
6Dithering on
7Use colour mapping (new flag for this call)
All other values will be ignored, and may be explicitly faulted.
R6=Pointer to scale factors (refer to the OS_SpriteOp documentation)
R7=Pointer to colour mapping descriptor
R0 - R7=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation will plot a deep sprite using the colour mapping supplied.

OS_SpriteOp 38OS_SpriteOp_PutSpriteTransformedSWI &2E
Plot a deep sprite transformed, with colour mapping (PutSpriteTransformed)
R0=56 + operation type (refer to the OS_SpriteOp documentation)
R1=Pointer to sprite area
R2=Pointer to sprite name, or sprite pointer
R3=Flags (refer to the OS_SpriteOp documentation)
R4=Pointer to source rectangle within sprite
R5=Plot action; valid bits:
Bit(s)Meaning
3Use mask
7Use colour mapping (new flag for this call)
All other values will be ignored, and may be explicitly faulted.
R6=Pointer to transformation matrix, or destination co-ordinates (refer to the OS_SpriteOp documentation)
R7=Pointer to colour mapping descriptor
R0 - R7=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation will plot a deep sprite using the colour mapping supplied.

JPEG_PlotScaledSWI &49982
Plot a JPEG scaled, using colour mapping
R0=Pointer to JPEG
R1=X coordinate
R2=Y coordinate
R3=Pointer to scale factors (refer to the JPEG_PlotScaled documentation)
R4=Length of image
R5=Plot flag bits:
Bit(s)Meaning
0Dither output when plotting 24bit JPEG at 16bpp or below
1Invalid
3Use colourmap (new flag for this call)
R6=Pointer to colour mapping descriptor
R0 - R6=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation plots a JPEG using the colour mapping supplied.

JPEG_PlotFileScaledSWI &49983
Plot a JPEG file scaled, using colour mapping
R0=Pointer to filename of JPEG file
R1=X coordinate
R2=Y coordinate
R3=Pointer to scale factors (refer to the JPEG_PlotFileScaled documentation)
R4=Plot flag bits:
Bit(s)Meaning
0Dither output when plotting 24bit JPEG at 16bpp or below
1Invalid
3Use colourmap (new flag for this call)
R5=Pointer to colour mapping descriptor
R0 - R5=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation plots a JPEG using the colour mapping supplied.

JPEG_PlotTransformedSWI &49984
Plot a JPEG transformed, using colour mapping
R0=Pointer to JPEG
R1=Transformation flag bits:
Bit(s)Meaning
0R2 is a pointer to a destination coordinate block, rather than a matrix
1Dither output when plotting 24bit JPEG at 16bpp or below
2Invalid
4Use colourmap (new flag for this call)
R2=Pointer to transformation matrix, or destination co-ordinates (refer to the JPEG_PlotTransformed documentation)
R3=Length of image
R4=Pointer to colour mapping descriptor
R0 - R4=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation plots a JPEG using the colour mapping supplied.

JPEG_PlotFileTransformedSWI &49985
Plot a JPEG file transformed, using colour mapping
R0=Pointer to filename of JPEG file
R1=Transformation flag bits:
Bit(s)Meaning
0R2 is a pointer to a destination coordinate block, rather than a matrix
1Dither output when plotting 24bit JPEG at 16bpp or below
2Invalid
4Use colourmap (new flag for this call)
R2=Pointer to transformation matrix, or destination co-ordinates (refer to the JPEG_PlotFileTransformed documentation)
R3=Pointer to colour mapping descriptor
R0 - R3=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This operation plots a JPEG using the colour mapping supplied.

Entry Points

ColourMapTransfer
Colour mapping transfer function
R0=Palette entry (&BBGGRR00)
R12=Workspace value passed when call made
R13=Supervisor stack
R14=Return address
R0=Palette entry (&BBGGRR00)
R12=May be corrupt
R14=May be corrupt
Interrupts are undefined
Fast interrupts are undefined
Processor is in SVC mode
Not defined

The transfer function should perform whatever processing is required on the palette entry passed to it. The routine may not change mode, perform any operation which might cause SpriteExtend to be threaded out of (eg VDU output) or cause the machine to block. You should return with MOV pc,lr. The transfer function will not be called for masked pixels.