rasterToHWSprite: Convert a raster object into an hardwareSprite object

View source: R/hardwareSprites.r

rasterToHWSpriteR Documentation

Convert a raster object into an hardwareSprite object

Description

Convert a grDevices raster object into an Amiga hardwareSprite class object.

Usage

rasterToHWSprite(x, indexing = index.colours)

Arguments

x

A grDevices() raster object (grDevices::as.raster()) that needs to be converted into a hardwareSprite() class object. Note that a hardwareSprite() has a maximum width of 16 pixels. When x is wider, it will be cropped.

indexing

A function that accepts two arguments: x (a grDevices raster 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 named ⁠palette' 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 (or NA when no transparency is required). By default the function index.colours() is used.

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).

Value

Returns a hardwareSprite() class object based on x

Author(s)

Pepijn de Vries

See Also

Other raster.operations: AmigaBitmapFont, as.raster.AmigaBasicShape(), bitmapToRaster(), dither(), index.colours(), rasterToAmigaBasicShape(), rasterToAmigaBitmapFont(), rasterToBitmap(), rasterToIFF()

Other HWSprite.operations: rawToHWSprite()

Examples

## Not run: 
## 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)

## End(Not run)

AmigaFFH documentation built on June 22, 2024, 11:03 a.m.