Convert colours to Amiga compatible raw data or vice versa
Source:R/generic_support.r
colourToAmigaRaw.Rd
Convert colours to Amiga compatible raw data or vice versa, such that it can be used in graphical objects from the Commodore Amiga.
Arguments
- x
In the case
amigaRawToColour
is called,x
should be avector
ofraw
data. The length of this vector should be a multiple of 2 (whenn.bytes = "2"
) or 3 (whenn.bytes = "3"
). WhencolourToAmigaRaw
is called,x
should be acharacter
strings representing a colour.- colour.depth
A
character
string:"12 bit"
(default) or"24 bit"
. The first should be used in most cases, as old Amigas have a 12 bit colour depth.- n.bytes
A
character
string:"2"
or"3"
. The number of bytes that is used or should be used to store each colour.
Value
In the case amigaRawToColour
is called, a (vector of)
colour character
string(s) is returned. When colourToAmigaRaw
is called, raw
representing the colour(s) specified in x
is
returned.
Details
On the original Commodore Amiga chipset, graphics used indexed palettes of 12 bit colours. Colours are specified by their RGB (Red, Green and Blue) values, each component requiring 4 bits (with corresponding values ranging from 0 up to 15). Data structures on the Amiga were WORD (2 bytes) aligned. Colours are therefore typically stored in either 2 bytes (skipping the first four bits) or 3 bytes (one byte for each value).
These functions can be used to convert R colours into the closest matching
Amiga colour in a raw
format, or vice versa. Note that later Amiga
models with the advanced (graphics) architecture (known as AA or AGA) allowed
for 24 bit colours.
See also
Other raw.operations:
as.AmigaBasic()
,
as.raw.AmigaBasic()
,
packBitmap()
,
rawToAmigaBasicBMAP()
,
rawToAmigaBasicShape()
,
rawToAmigaBasic()
,
rawToAmigaBitmapFontSet()
,
rawToAmigaBitmapFont()
,
rawToAmigaIcon()
,
rawToHWSprite()
,
rawToIFFChunk()
,
rawToSysConfig()
,
simpleAmigaIcon()
Examples
## Let's create some Amiga palettes:
colourToAmigaRaw(c("red", "navy blue", "brown", "#34AC5A"))
#> [1] 0f 00 00 08 0a 22 03 a5
## let's do the reverse.
## this is white:
amigaRawToColour(as.raw(c(0x0f, 0xff)))
#> [1] "#FFFFFF"
## this is white specified in 3 bytes:
amigaRawToColour(as.raw(c(0xf0, 0xf0, 0xf0)), n.bytes = "3")
#> [1] "#FFFFFF"
## lower nybbles are ignored, you will get a warning when it is not zero:
amigaRawToColour(as.raw(c(0xf0, 0xf0, 0x0f)), n.bytes = "3")
#> Warning: The low nybble is not zero for all colours.
#> [1] "#FFFF00"