View source: R/generic_support.r
rasterToBitmap | R Documentation |
raster
object into binary bitmap dataConverts an image represented by a grDevices raster
object into binary
(Amiga) bitmap data.
rasterToBitmap(x, depth = 3, interleaved = T, indexing = index.colours)
x |
A raster object created with |
depth |
The colour depth of the bitmap image. The image will be composed
of
|
interleaved |
A |
indexing |
A function that accepts two arguments: |
Images represented by grDevices raster
objects are virtually true colour (24 bit
colour depth) and an alpha layer (transparency). On the early Amiga's the chipset
(in combination with memory restrictions) only allowed images with indexed
palettes. The colour depth was 12 bit with the original chipset and the number
of colours allowed in a palette also depended on the chipset. This function
will allow you to convert a raster
object into binary bitmap data with
an indexed palette. This means that the image is converted in a lossy way
(information will be lost). So don't expect the result to have the same quality as
the original image.
With the depth
argument, the raster can also be converted
to special mode bitmap images. One of these modes is the
‘hold and modify’ (HAM). In this mode two of the bitplanes
are reserved as modifier switches. If the this switch equals
zero, the remainder of the bitplanes are used as an index for
colours in a fixed palette. If the switch equals 1, 2 or 3, the
red, green or blue component of the previous is modified, using the
number in the remainder of the bitplanes. So it holds the previous
colour but modifies one of the colour components (hence the term
‘hold and modify’.) Here only the HAM6 and
the HAM8 mode are implemented. HAM6 uses 6 bitplanes and a 12 bit
colour depth, HAM8 uses 8 bitplanes and a 24 bit colour depth.
The HAM mode was a special video modes supported by Amiga hardware. Normal mode bitmap images with a 6 bit depth would allow for a palette of 64 (2^6) colours, HAM6 can display 4096 colours with the same bit depth.
In addition to HAM6 and HAM8, sliced HAM (or SHAM) was another HAM variant. Using the coprocessor on the Amiga, it was possible to change the palette at specific scanlines, increasing the number of available colours even further. The SHAM mode is currently not supported by this package.
The bitmap is returned as a vector
of logical
values.
The logical
values reflect the bits for each bitplane. The palette used
for the bitmap is returned as attribute to the vector
. There will also be
an attribute called transparent'. This will hold a numeric index corresponding with the colour in the palette that will be treated as transparent. It will be
NA' when transparency is not used.
Pepijn de Vries
Other raster.operations:
AmigaBitmapFont
,
as.raster.AmigaBasicShape()
,
bitmapToRaster()
,
dither()
,
index.colours()
,
rasterToAmigaBasicShape()
,
rasterToAmigaBitmapFont()
,
rasterToHWSprite()
,
rasterToIFF()
## Not run:
## first: Let's make a raster out of the 'volcano' data, which we can use in the example:
volcano.raster <- as.raster(t(matrix(terrain.colors(1 + diff(range(volcano)))[volcano -
min(volcano) + 1], nrow(volcano))))
## convert the raster into binary (logical) bitmap data:
volcano.bm <- rasterToBitmap(volcano.raster)
## The palette for the indexed colours of the generated bitmap is returned as
## attribute. There is no transparency is the image:
attributes(volcano.bm)
## We can also include a custom function for colour quantisation. Let's include
## some dithering:
volcano.dither <- rasterToBitmap(volcano.raster,
indexing = function(x, length.out) {
index.colours(x, length.out,
dither = "floyd-steinberg")
})
## You can also use a custom indexing function to force a specified palette,
## in this case black and white:
volcano.bw <- rasterToBitmap(volcano.raster,
indexing = function(x, length.out) {
index.colours(x, length.out,
palette = c("black", "white"),
dither = "floyd-steinberg")
})
## Make a bitmap using a special display mode (HAM6):
volcano.HAM <- rasterToBitmap(volcano.raster, "HAM6")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.