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

CMYK sprites (aka 'type 7 sprites') may now be rendered by SpriteExtend.
Calls to PlotSpriteScaled, and PlotSpriteTransformed for these sprites
will now render the sprite in the same manner as 32 bpp sprites ('type 6').
As such, CMYK sprites will be subject to colour mapping as 16 bpp or 32 bpp
sprites.

Data within CMYK sprites is stored in the format &KKYYMMCC, as compared to
32 bpp RGB sprites which is stored in the format &00BBGGRR. As with other
new format sprites, masks are held in 1 bpp format.


Caveats
-------
A side effect of CMYK-style sprites is that because the colour number
(ColourTrans_ReturnColourNumber et al) now spans the whole 32 bits. Thus, it
is possible to generate colour numbers which, if treated as signed values,
are negative. If any private data has previously been stored in the top 8
bits of the colour number by applications or extensions this may now be
invalid. The assumption that a colour number would be 24bits wide was
incorrect.

An example of code that might fail would be code that used +ve colour
numbers to mean literal colours, and -ve values to mean special effects,
such as ECF plotting. Where such assumptions are made, this may result
in undefined behaviour of the application concerned. If applications
restrict their processing to the standard RGB colours, this should not be
an issue.


Masks
-----
Masks should function as for other new format sprites; masks are 1bpp.
Operations to create and remove masks function correctly, as does
redirection to masks.


Redirection
-----------
Standard graphical operations will function normally if ColourTrans is used.
For sprite plotting, pixel translation tables must be 'wide' (bit 4 set) to
allow colour matching to be performed correctly, as is the case with 16 and
32bpp RGB sprites. Operations which use ColourTrans should function
normally.

If it is necessary to determine whether output is directed to a CMYK sprite,
OS_ReadModeVariable/OS_ReadVduVariables 0 should be used to read the mode
flags. Additional bits have been defined to describe the format of the
data :

  bits   meaning
  12-15  data format :
            0 RGB data (sprite types 0 to 6 will return this)
            1 CMYK data (sprite type 7 will return this)


Mode variables for CMYK sprites
-------------------------------
Variables returned for CMYK sprites through OS_ReadModeVariable or
OS_ReadVduVariables have been updated to supply the following values :
  
  Variable  Value
  0         (see above for new data format flags)
  3         &FFFFFFFF
  4         from sprite type word
  5         from sprite type word
  9         5
  10        5

Other values are undefined.


Reading colours
---------------
Reading a pixel colour will return the colour number at the position
declared in the native format (as with the other sprite formats). To convert
this to RGB you may need to use ColourTrans_ConvertCMYKToRGB.


Advanced notes
--------------
Converting to and from RGB may need to be performed quickly by more advanced
applications. Where no calibration is necessary, this can be done with the
following code snippets :

RGB to CMYK conversion (&00BBGGRR to &KKYYMMCC) :

        ; First, invert the lot
        MVN     r_pixel,r_pixel                 ; invert
        ; Now work out what 'black' value to use
        AND     r_temp1,r_pixel,#&00FF00        ; green component
        AND     r_temp2,r_pixel,#&0000FF        ; red component
        CMP     r_temp1,r_temp2,LSL #8          ; compare them
        MOVHI   r_temp1,r_temp2,LSL #8          ; red was lower
        AND     r_temp2,r_pixel,#&FF0000        ; blue component
        CMP     r_temp1,r_temp2,LSR #8          ; compare them
        MOVHI   r_temp1,r_temp2,LSR #8          ; blue was lower
        ; r_temp1 now = &0000KK00
        ORR     r_temp2,r_temp1,r_temp1,LSL #8  ; &00KKKK00
        ORR     r_temp2,r_temp2,r_temp2,LSL #8  ; &KKKKKK00
        RSB     r_pixel,r_temp2,r_pixel,LSL #8  ; &YYMMCC00
        MOV     r_pixel,r_pixel,LSR #8          ; &00YYMMCC
        ORR     r_pixel,r_pixel,r_temp1,LSL #16 ; &KKYYMMCC

CMYK to RGB conversion (&KKYYMMCC to &00BBGGRR) :

        ; r_pixel = &KKYYMMCC
        AND     r_temp1, r_pixel, #&ff000000       ; K
    
        AND     r_temp2, r_pixel, #&00ff0000       ; Y
        ADDS    r_temp2, r_temp1, r_temp2, LSL #8  ; Y + K
        MOVCS   r_temp2, #&ff000000                ; clamp
        MOV     r_pixel, r_pixel, LSL #16
        ; r_pixel = &MMCC0000
        ORR     r_pixel, r_pixel, r_temp2, LSR #16 ; B
        ; r_pixel = &MMCCBB00
    
        ADDS    r_temp2, r_temp1, r_pixel          ; M + K
        MOVCS   r_temp2, #&ff000000
        ORR     r_pixel, r_pixel, r_temp2, LSR #24 ; G
        ; r_pixel = &MMCCBBGG
    
        ADDS    r_temp2, r_temp1, r_pixel, LSL #8  ; C + K
        MOVCS   r_temp2, #&ff000000
        MOV     r_pixel, r_pixel, LSL #16          ; clear top half
        ; r_pixel = &BBGG0000
        ORR     r_pixel, r_pixel, r_temp2, LSR #16 ; R
        ; r_pixel = &BBGGRRxx
    
        ; inverted to be true colours
        MVN     r_pixel, r_pixel ; Invert
        MOV     r_pixel, r_pixel, LSR #8 ; Shift to bottom
        ; true 00BBGGRR


Requirements
------------
For certain operations an updated version of ColourTrans will be necessary.
