ripacklib
This library unpacks data that a program holds in memory. Most of its
commands deal with IFF ILBM pictures: UnpackIFF unpacks the picture
into a bitmap object, ILBMPalette takes its colours (the CMAP chunk)
into a palette object, ILBMGrab does both, and LoadIFF loads a
picture file and unpacks it in one step. The bitmap must already exist
and be at least as wide and as deep as the picture; the palette object
gets as many colours as the picture has. Besides, PackPBM and
UnPackPBM pack and unpack blocks with ByteRun1, the method of IFF
pictures, and DeIce unpacks files packed with Pack-Ice 2.40 on the
Atari ST.
All commands except ILBMGrab and UnPackPBM can be used as functions
that return -1 on success and 0 on failure, or a length (PackPBM) or
a long (ChunkHeader). LoadIFF reads a file through DOS, so use it
in Amiga mode.
LoadIFF loads the file into a memory bank of the RI Amos Func
library, which must be present as well, and frees the bank again; it
takes the first free bank, so it works with the library’s 50 banks.
UnpackIFF and ILBMPalette find the chunks of the picture by
walking the IFF file from chunk to chunk; for data that do not begin
with a FORM, such as a CMAP chunk given to ILBMPalette by itself,
they search the first few kilobytes for them. UnpackIFF unpacks pictures packed with ByteRun1 and
uncompressed ones, of any width; a mask that the picture was saved
with, as in brushes of DPaint, is skipped. A picture whose width is no
multiple of 16 has its rows padded to whole words in the file; the
bitmap must be as wide as the padded rows, which a bitmap made with
BitMap always is when it is as wide as the picture.
Loading a picture of up to 320 by 256 pixels and 32 colours into bitmap 0 and palette 0:
BitMap 0,320,256,5
If LoadIFF("picture.iff",0,0)
NPrint "loaded"
EndIfThe fixed bugs of the library are listed in Fixes in ripacklib.
Based on the RI Pack Lib guide by Reflective Images.
Library number 73.
Commands
ChunkHeader
The first four characters of a$ as a long, the form in which an IFF chunk name such as "CMAP" appears in memory; the same as Peek.l(&a$).
Function, result .l. Help text: (a$)
Arguments: $
DeIce
Unpacks the Pack-Ice 2.40 data at sourceaddr to destaddr. As a function it returns -1, or 0 if the source is not Pack-Ice data (it does not begin with ICE!).
Statement or function, result .l. Help text: (sourceaddr,destaddr)
Arguments: .l, .l
The data are not checked; the destination must hold the unpacked length. Data packed with the picture option of Pack-Ice, meant for Atari ST pictures, are converted back with the number of 8-byte groups stored in the data, at most as many as the unpacked data hold; Pack-Ice 2.34 writes such data.
ILBMGrab
Unpacks the IFF ILBM picture at sourceaddr into bitmap bitmap# and its colours into palette palette#, the same as UnpackIFF and ILBMPalette together.
Statement. Help text: sourceaddr,bitmap#,palette#
Arguments: .l, .w, .w
It does not tell whether it succeeded; use the two commands by themselves for that.
ILBMPalette
Takes the colours of the CMAP chunk at or behind sourceaddr (an IFF file or a CMAP chunk in memory) into palette palette#. As a function it returns -1, or 0 if no CMAP chunk is found or it holds no whole colour.
Statement or function, result .l. Help text: (sourceaddr,palette#[,#offset)
2 forms:
.l, .l.l, .l, .l
Without offset, the palette object is given exactly as many
colours as the CMAP holds; any colours it had are freed. With
offset, the colours are written from colour number offset on
into the palette as it is. A palette with fewer colours than
offset plus the CMAP’s colours, or with none, grows to that number
and keeps its colours; colours between its old end and offset are
black.
LoadIFF
Loads the IFF ILBM picture file filename$ into bitmap bitmap, and its colours into palette palette if given. As a function it returns -1, or 0 if there is no free bank, the file cannot be loaded or the picture cannot be unpacked into the bitmap.
Statement or function, result .l. Help text: (filename$,bitmap[,palette])
2 forms:
$, .w$, .w, .w
It reads the file through DOS, so use it in Amiga mode. The file is loaded into the first free bank of the RI Amos Func library and unpacked from there, so there must be memory for the whole file; the bank is freed again afterwards.
With palette, it also returns 0 when the picture has no colours (no
CMAP chunk); the picture is still unpacked into the bitmap.
PackPBM
Packs length bytes from sourceaddr to destaddr with ByteRun1 and returns the packed length, or -1 if the packed data would not be smaller than the source.
Function, result .l. Help text: sourceaddr,destaddr,length
Arguments: .l, .l, .l
The destination needs room for length bytes. After -1 it holds the
bytes packed up to that point.
UnpackIFF
Unpacks the IFF ILBM picture at sourceaddr in memory into bitmap bitmap#. As a function it returns -1, or 0 if the picture’s chunks are not found, the picture cannot be unpacked or the bitmap is narrower or less deep than the picture.
Statement or function, result .l. Help text: (sourceaddr,bitmap#[,numlines,xy_offset])
2 forms:
.l, .l.l, .l, .w, .l
sourceaddr is the start of the IFF file in memory, in chip or fast
memory. numlines unpacks only that many lines, and a negative value
all lines; 0 unpacks nothing and returns 0. (The library guide says
that a value of 0 or less aborts; the library takes a negative value
as all lines.) No more lines than the bitmap has are unpacked; a
taller picture is cut off, not refused. xy_offset is a byte offset
from the start of each bitplane, where the picture is put.
The number of lines is not limited to the height of the picture: more lines than the picture has unpack whatever follows its data. Which pictures it unpacks is described in the introduction.
UnPackPBM
Unpacks the ByteRun1 data of length bytes at sourceaddr to destaddr, writing at most destlength bytes.
Statement. Help text: sourceaddr,destaddr,length,destlength
Arguments: .l, .l, .l, .l
It reads nothing behind the length bytes of packed data; a run
that would go past destlength is cut off there.