Alpha-channel sprites
Previous versions of RISC OS have provided sprites with binary masks. Select 3 brings support for a new type of sprite to the operating system. These 'Alpha-channel' sprites provide 8 bits of mask data, allowing each pixel within the image to have one of 256 levels of translucency.
In RISC OS 3.5, the 'sprite type' was introduced, allowing for a greater range of sprite types. This range has been expanded to include these alpha channel sprites. Sprites under RISC OS 3.6 used a standard 1 bit per mask pixel. This ensured that the mask data was reduced to the smallest it could be for the image. Under RISC OS Select 3, the mask data on these alpha-channel sprites is 8 bits per mask pixel.
The new definition of the sprite mode word is as follows :
Bit(s) Meaning
0 Set (indicator that this is a new format sprite)
1-13 Horizontal dots per inch
14-26 Vertical dots per inch
27-30 Sprite type :
0 = Old format mode word (mode is a standard number)
1 = 1 bpp
2 = 2 bpp
3 = 4 bpp
4 = 8 bpp
5 = 16 bpp
6 = 24 bpp
7 = CMYK
8 = 24 bpp compact format (allocated but not used)
9 = JPEG data (allocated by not used)
10-15 Reserved
31 If set, alpha channel data present, if clear, binary mask
data present. May NOT be set for type 0 sprites.
The 'dots per inch value' only reliably supports values of 11, 23, 45, 90 and 180 under any version of the operating system.
Image data within alpha-channel sprites is identical to that within the non-alpha-channel sprite. Mask data, however, is 8 bits wide per pixel, rather than 1 bit per pixel. Within the mask data, the value 0 indicates a completely transparent pixel, and the value 255 indicates a completely opaque pixel.
Images with the alpha channel bit set but no mask data present will be treated as if the alpha channel bit was not present.
Sprite operations on alpha-channel sprites should perform exactly as expected. Rendering alpha-channel sprites using scaling or transformation is supported. Reading mask values from sprites will return values from 0 to 255 from the alpha-channel. Writing to the mask will write those values to the mask. When output is redirected to an alpha-channel mask, the mask is treated as a greyscale from black (0, completely translucent) through to white (255, completely opaque).
Rendering alpha-channel images through a colour-map, or with translucency is supported, as is rendering scaled with dithering (although in this last case the quality reduces with the increase in translucency). For example a 50% translucent alpha-channel image would appear more translucent than a normal alpha-channel image.
Applications which directly manipulate mask data or who provide their own rendering of sprites may not function correctly with these new alpha-channel sprites.
When rendered to paletted frame buffers alpha-channel sprites cannot perform as well as when rendered to 16bpp or 24bpp buffers. For reference, the following operations are performed :
- When rendered to 8bpp a similar scheme to that used by FontManager is used - using the InverseTable module to provide a conversion between destination index and RGB value. These tables have a resolution of 5 bits per component, therefore a quantisation effect will be observed. This may be most visible in a linear scaled output (such as greyscale).
- When rendering to 4bpp or lower BlendTable is used to generate matching tables at 6 levels, providing 8 levels of translucency over the entire image (6 blend tables, plus 2 'pass through' conditions for totally opaque and totally transparent pixels).
- When rendering to 16 bpp the alpha-channel is quantised to 5 bits before being used to calculate the output value. This may have a noticeable effect on linear fades of the alpha-channel.
- When rendering in 24 bpp the alpha-channel is calculated correctly using the full 8 bits.
Within the change documentation, the phrase 'opaque sprites' is used for the new alpha-channel sprite format. A little more information can be found in the summaries for SpriteExtend, ColourTrans, Kernel and ConvertPNG.
|