Alpha mask promotion and demotion

Since Select 3 additional mask operations are available for alpha-channel sprites. These allow the alpha channel to be added or removed using a new SpriteOp call.

OS_SpriteOp 38 (SWI &2E)

Add or remove alpha-channel mask on a sprite

On entry
   R0 = reason code (38 + area type)
   R1 = pointer to sprite area
   R2 = pointer to sprite, or pointer to sprite name
   R3 = flags :
         bits 0-7 = Cut off point for mask reduction, or 0 to only reduce the
                    mask if it is binary
         bit 8 = Remove mask if completely unnecessary
         bit 31 = Set to add an alpha-channel, clear to remove an alpha channel
On exit
   R3 = 0 if no area size change was necessary.
         Additional space required if call failed (V set)

This call is used to add or remove an alpha-channel mask on a sprite. This call will only function on 'new format' sprites - those using the sprite type. Operations on 'old format' sprites - those defined using mode numbers - will be faulted. The sprite type will have been modified by this call - there is no need for users of this call to modify the sprite data itself.

Alpha-channel removal

When removing the mask the 'cut off point' given in bits 0-7 will be used to decide which pixels will be masked and which will be solid. Any alpha-channel values which match or exceed the cut off point will be made solid. Any values which are below the cut off point will be made masked. The special value 0 is used to indicate that the operation should only reduce the mask if it is already binary - that is, if it consists of totally solid and totally masked pixels.

If bit 8 is set, the special case of a totally solid image will be reduced to no mask at all.

Examples on different sprite types :

Sprite with solid mask (all &FF) :
        will be reduced to 1bpp if b8 clear
        will be removed if b8 set Sprite with binary mask (all &FF or &00) :
        will be reduced to 1bpp if b0-7 clear
        will be reduced to 1bpp with cutoff if any b0-7 set Sprite with variable mask (any values) :
        will be ignored if b0-7 clear
        will be reduced to 1bpp with cutoff if any b0-7 set

The most usual use of this call would be to set bit 8 to remove the mask if it serves no purpose and to set the cut-off point at 128, making this a binary mask at the half-way point.

Alpha-channel promotion

Sprites may be promoted to alpha channel by setting bit 31. Bits 0-8 have no meaning when adding an alpha channel. If a mask already exists it will be promoted to alpha-channel. If no mask is present, the sprite will be promoted to be alpha-channel and a completely solid mask added.

Typical operations

Some typical operations that you might wish to perform are listed below, together with the method of achieving them :

  • Add an alpha-channel mask to an existing 1bpp sprite.
    SpriteOp 38 (&26), flags = b31
  • Convert an alpha-channel sprite to a form that can be used on pre-Select 3 systems.
    SpriteOp 38 (&26), flags = b8 + 128
  • Reduce an alpha-channel sprite to its most compact form.
    SpriteOp 38 (&26), flags = b8 + 128
  • Remove an alpha-channel mask.
    SpriteOp 30 (&1E)

Note that this leaves the sprite as an alpha-channel sprite.

You will have to modify the sprite type to remove the alpha-channel bit (bit 31 of the sprite mode) if you wish to use a 1 bpp mask.

This documentation is copyright 3QD Developments Ltd 2013 and may not be reproduced or published in any form without the copyright holders permission. RISC OS is subject to continuous development and improvement as such all information is reproduced by 3QD Developments Ltd in good faith and is believed to be correct at the time of publication E&OE. 3QD Developments Ltd cannot accept any liability for any loss or damage arising from the use of any information provided as part of the RISC OS Documentation.

HTML document version 1.03 3rd November 2015