Convert a raster object into an hardwareSprite object
Source:R/hardwareSprites.r
rasterToHWSprite.Rd
Convert a grDevices raster object into an Amiga hardwareSprite class object.
Arguments
- x
A
grDevices()
raster object (grDevices::as.raster()
) that needs to be converted into ahardwareSprite()
class object. Note that ahardwareSprite()
has a maximum width of 16 pixels. Whenx
is wider, it will be cropped.- indexing
A function that accepts two arguments:
x
(a grDevicesraster
object);length.out
, a numeric value indicating the desired size of the palette (i.e., the number of colours). It should return a matrix with numeric palette indices (ranging from 1 up to the number of colours in the palette). The result should have an attribute namedpalette' that contains the colours that correspond with the index numbers. The result should also carry an attribute with the name
transparent', with a single numeric value representing which colour in the palette should be treated as transparent (orNA
when no transparency is required). By default the functionindex.colours()
is used.
Value
Returns a hardwareSprite()
class object based on x
Details
A grDevices()
raster image can be converted into a
hardwareSprite()
class object with this function. For this purpose
the any true-colour image will be converted to an indexed palette with 4 colours.
The Amiga hardware sprite will reserve one of the colours as transparent. Thos function
will use fully transparent colours in the original image (i.e., the alpha level equals 0)
for this purpose. Or when the image has no fully transparent colours, it will use the
most frequently occuring colour (at least when the default indexing
function
is used).
See also
Other raster.operations:
AmigaBitmapFont
,
as.raster.AmigaBasicShape()
,
bitmapToRaster()
,
dither()
,
index.colours()
,
rasterToAmigaBasicShape()
,
rasterToAmigaBitmapFont()
,
rasterToBitmap()
,
rasterToIFF()
Other HWSprite.operations:
rawToHWSprite()
Examples
if (FALSE) {
## first create a raster object that can be used as input
## (making sure that the background is transparent):
rst <- as.raster(simpleSysConfig()$PointerMatrix, "#AAAAAA00")
## now turn it into a hardware sprite:
spr <- rasterToHWSprite(rst)
## and plot it as a check:
plot(spr)
}