Convert raw data into a bitmap or vice versa (i.e., binary data) conform Amiga specifications.
Usage
rawToBitmap(x, invert.bytes = F, invert.longs = T)
bitmapToRaw(x, invert.bytes = T, invert.longs = T)
Arguments
- x
A
vector
ofraw
data, in caserawToBitmap
is used. Avector
ofraw
,interger
orlogical
values should be used in case ofbitmapToRaw
. In the latter case each value in thevector
is interpreted as a bit and should be a multiple of 8 long.- invert.bytes
A
logical
value. When set toTRUE
, the bit order of bytes are reversed.- invert.longs
A
logical
value. When set toTRUE
, the bit order of long values (32 bits) are reversed. Whenx
does not have a multiple length of 32 bits or 4 bytes,x
will be padded with zeros to the right, but the result will be trimmed to correspond with the length ofx
. Note that data might get lost this way.
Value
Returns a vector
of raw
data in case of
bitmapToRaw
, and a vector
of binary raw
values
in case of rawToBitmap
.
Details
A bitmap is simply put a map of bits (binary data, which can be interpeted as 0 or 1; or FALSE and TRUE). Bitmaps can have several purposes, also on the Commodore Amiga. The Amiga file system uses a bitmap to indicates which blocks are occupied with data and which are free. Bitmaps can also be used in bitmap images where each bit indicates which color should be used for a specific pixel in an image. These function can be used to convert raw data into usable bitmaps or vice versa.
As the Commodore Amiga is a big-endian system (most significant
bit first) using a 32 bit CPU, it may sometimes necessary to invert
the bits of a byte or longs (4 bytes, 32 bits), which can be done
with the arguments 'invert.bytes
' and 'invert.longs
'
respectively.
See also
Other raw.operations:
amigaDateToRaw()
,
amigaIntToRaw()
,
displayRawData()
,
rawToAmigaDate()
,
rawToAmigaInt()
Examples
## The bitmap block of the example disk is located at block
## number 882 (note that this is not true for all disks,
## the actual location is stored in the root block)
data(adf.example)
bitmap.block <- amigaBlock(adf.example, 881)
## bitmap data are stored in bytes 5 up to 224 in this block:
bitmap.raw <- bitmap.block@data[5:224]
## let's get the bitmap from the raw data:
bitmap <- rawToBitmap(bitmap.raw)
## Whe can now get the occupied blocks (minus one is used for
## the discrepancy in indexing):
which(bitmap != as.raw(0x01)) - 1
#> [1] 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
#> [20] 897 898 899 900 901 902 903 904 905 906 907 908 909 913 914 915
## we can also do the reverse:
bitmap.raw.new <- bitmapToRaw(bitmap)
## it should be the same as the original raw data:
all(bitmap.raw.new == bitmap.raw)
#> [1] TRUE
## WARNING: don't use these methods to directly
## modify an amigaDisk objects bitmap block. The
## file system on that object may get corrupted.
## All methods in this package should update the
## bitmap block automatically and cleanly...