BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
ripacklib.c File Reference
#include "blitzlib.h"
#include "blitzobj.h"
#include <graphics/gfx.h>
#include <datatypes/pictureclass.h>

Data Structures

struct  ice

Macros

#define TOK_bload   ((LIB_riamosfunclib << 7) + 15) /* form 1: d0 name, d1 bank */
#define TOK_start   ((LIB_riamosfunclib << 7) + 17) /* d0 bank -> d0 address */
#define TOK_erase   ((LIB_riamosfunclib << 7) + 19) /* d0 bank */
#define TOK_nextbank   ((LIB_riamosfunclib << 7) + 22) /* d0 first -> d0 bank or -1 */
#define W(p)
#define LG(p)
#define ID(a, b, c, d)
#define PDATA(p)
#define PUT(v)

Functions

void packpbm (void)
void deice (void)
void iff1 (void)
void unpackiff (void)
void ilbmpalette (void)
void ilbmpalette2 (void)
void ilbmgrab (void)
void ilbmloadnopal (void)
void ilbmload (void)
void chunkheader (void)
void unpackpbm (void)
static void libinit (void)
 init: does nothing (RTS).
static void libfinit (void)
 finit: does nothing (RTS).
static ULONG chunkheader_c (const UBYTE *s)
 ChunkHeader(a$): the first long of a string, as an IFF id.
static void unpackpbm_c (const UBYTE *src, UBYTE *dst, ULONG len, ULONG dlen)
 UnPackPBM sourceaddr,destaddr,length,destlength: unpacks ByteRun1 data.
static ULONG packpbm_c (const UBYTE *src, UBYTE *dst, ULONG size)
 PackPBM(sourceaddr,destaddr,length): packs data with ByteRun1.
static int ice_bit (struct ice *s)
static UWORD ice_bits (struct ice *s, UWORD n)
static void ice_normal (struct ice *s)
static ULONG getinfo (const UBYTE *p)
static BB_BOOL deice_c (const UBYTE *src, UBYTE *dst)
 DeIce(sourceaddr,destaddr): unpacks Pack-Ice 2.40 data.
static const UBYTE * walkform (const UBYTE *form, ULONG id)
 The chunk id of a FORM, found by walking its chunks (fixed #766).
static const UBYTE * skiprow (const UBYTE *body, UBYTE packed)
 Skips the mask row of a line (fixed #1112), as UnpackIFF reads a plane row: uncompressed its bytes, ByteRun1 its runs (a run past the end of the row skipped whole).
static BB_BOOL unpackiff_c (const UBYTE *src, struct BitMap *bm, ULONG lines, ULONG xy)
 UnpackIFF(sourceaddr,bitmap#,numlines,xy_offset): the BODY of an ILBM in memory into a bitmap.
static BB_BOOL iff1_c (const UBYTE *src, struct BitMap *bm, ULONG lines)
 UnpackIFF(sourceaddr,bitmap#): all lines, no offset (MOVE.w #-1,d2:MOVEQ #0,d3).
static BB_BOOL ilbmpalette2_c (const UBYTE *src, struct bb_palette *obj, LONG offset)
 ILBMPalette(sourceaddr,palette#,offset): the CMAP of an ILBM into a palette object.
static BB_BOOL ilbmpalette_c (const UBYTE *src, struct bb_palette *obj)
 ILBMPalette(sourceaddr,palette#): as with offset -1 (a new colour block).
static void ilbmgrab_c (const UBYTE *src, struct BitMap *bm, struct bb_palette *pal, ULONG lines)
 ILBMGrab sourceaddr,bitmap#,palette#: UnpackIFF(source,bitmap#) and ILBMPalette(source,palette#); the results are dropped.
static BB_BOOL ilbmload_c (ULONG name, struct BitMap *bm, struct bb_palette *pal)
 LoadIFF(filename$,bitmap,palette): loads an ILBM file into a bitmap and a palette.
static BB_BOOL ilbmloadnopal_c (ULONG name, struct BitMap *bm)
 LoadIFF(filename$,bitmap): as above without a palette.

Variables

static const ULONG direkt_tab [10]
static const BYTE length_tab [10] = { 9, 1, 0, -1, -1, 8, 4, 2, 1, 0 }
static const BYTE more_offset [4] = { 11, 4, 7, 0 }
static const WORD more_add [3] = { 0x11f, -1, 0x1f }
struct { 
   ULONG   iffsource 
   ULONG   iffdest 
   UBYTE *   bitplanes [8] 
   UWORD   iffheight 
   UWORD   bytewidth 
   UWORD   bitmapwidth 
   UBYTE   iffdepth 
} v

Macro Definition Documentation

◆ ID

#define ID ( a,
b,
c,
d )
Value:
((ULONG)(a) << 24 | (ULONG)(b) << 16 | (c) << 8 | (d))
ULONG WORD UWORD c
Definition 2dlib.c:2491
static struct @065163037313156332013005143365272036211065172003 d

◆ LG

#define LG ( p)
Value:
(*(ULONG *)(p))

◆ PDATA

#define PDATA ( p)
Value:
(*(ULONG *)&(p)->pdata)
Definition ridatatypeslib.c:763

◆ PUT

#define PUT ( v)
Value:
do { *out++ = (v); if (out == limit) goto failure; } while (0)
static struct @342026374002303043102303243063125232020331002053 v
Definition ab3args.c:62

◆ TOK_bload

#define TOK_bload   ((LIB_riamosfunclib << 7) + 15) /* form 1: d0 name, d1 bank */

◆ TOK_erase

#define TOK_erase   ((LIB_riamosfunclib << 7) + 19) /* d0 bank */

◆ TOK_nextbank

#define TOK_nextbank   ((LIB_riamosfunclib << 7) + 22) /* d0 first -> d0 bank or -1 */

◆ TOK_start

#define TOK_start   ((LIB_riamosfunclib << 7) + 17) /* d0 bank -> d0 address */

◆ W

#define W ( p)
Value:
(*(UWORD *)(p))

Function Documentation

◆ chunkheader()

void chunkheader ( void )

◆ chunkheader_c()

ULONG chunkheader_c ( const UBYTE * s)
static

ChunkHeader(a$): the first long of a string, as an IFF id.

Parameters
sd0: the string (its first four bytes are read, whatever its length)
Returns
d0: the long

◆ deice()

void deice ( void )

◆ deice_c()

BB_BOOL deice_c ( const UBYTE * src,
UBYTE * dst )
static

DeIce(sourceaddr,destaddr): unpacks Pack-Ice 2.40 data.

The data must start with "ICE!" (then the packed and the unpacked length); the picture flag of Pack-Ice converts Atari ST low-res bitplanes into interleaved words, by default 4000 groups of 8 bytes (a 32000-byte picture), else the count stored behind the flag. Fixed (#767): the flag and the count come from the data (Pack-Ice 2.34's decruncher), and at most the unpacked length / 8 groups are converted; the original's (2.40's) default count overwrote the bit buffer: the default was never used, the count was at least $3C00.

Parameters
srcd0: the packed data
dstd1: the destination
Returns
d0: BB_TRUE after unpacking, BB_FALSE without "ICE!"

◆ getinfo()

ULONG getinfo ( const UBYTE * p)
static

◆ ice_bit()

int ice_bit ( struct ice * s)
static

◆ ice_bits()

UWORD ice_bits ( struct ice * s,
UWORD n )
static

◆ ice_normal()

void ice_normal ( struct ice * s)
static

◆ iff1()

void iff1 ( void )

◆ iff1_c()

BB_BOOL iff1_c ( const UBYTE * src,
struct BitMap * bm,
ULONG lines )
static

UnpackIFF(sourceaddr,bitmap#): all lines, no offset (MOVE.w #-1,d2:MOVEQ #0,d3).

Parameters
srcd0: the ILBM data
bma1: the bitmap object
linesd2: its low word is set to -1 (all lines)
Returns
d0: as UnpackIFF's long form

◆ ilbmgrab()

void ilbmgrab ( void )

◆ ilbmgrab_c()

void ilbmgrab_c ( const UBYTE * src,
struct BitMap * bm,
struct bb_palette * pal,
ULONG lines )
static

ILBMGrab sourceaddr,bitmap#,palette#: UnpackIFF(source,bitmap#) and ILBMPalette(source,palette#); the results are dropped.

Parameters
srcd0: the ILBM data
bma0: the bitmap object (parameter 1)
pala1: the palette object (parameter 2)
linesd2: (the palette number) - UnpackIFF sets its low word to -1

◆ ilbmload()

void ilbmload ( void )

◆ ilbmload_c()

BB_BOOL ilbmload_c ( ULONG name,
struct BitMap * bm,
struct bb_palette * pal )
static

LoadIFF(filename$,bitmap,palette): loads an ILBM file into a bitmap and a palette.

The file goes into a free bank of RIAmosFuncLib (NextBank from 0 on, fixed #770: the original's from 51 on needed BankLimit above 51; BLoad), UnpackIFF and (with a palette) ILBMPalette from there, then the bank is erased. Fixed (#771): the result is UnpackIFF's, BB_FALSE also when ILBMPalette fails; the original returned BB_TRUE whenever the file loaded.

Parameters
named0: the file name
bma0: the bitmap object (parameter 1)
pala1: the palette object (parameter 2), NULL: none
Returns
d0: BB_TRUE, BB_FALSE if there is no bank, the file does not load, or UnpackIFF or ILBMPalette fails

◆ ilbmloadnopal()

void ilbmloadnopal ( void )

◆ ilbmloadnopal_c()

BB_BOOL ilbmloadnopal_c ( ULONG name,
struct BitMap * bm )
static

LoadIFF(filename$,bitmap): as above without a palette.

Parameters
named0: the file name
bma0: the bitmap object
Returns
d0: as LoadIFF with a palette

◆ ilbmpalette()

void ilbmpalette ( void )

◆ ilbmpalette2()

void ilbmpalette2 ( void )

◆ ilbmpalette2_c()

BB_BOOL ilbmpalette2_c ( const UBYTE * src,
struct bb_palette * obj,
LONG offset )
static

ILBMPalette(sourceaddr,palette#,offset): the CMAP of an ILBM into a palette object.

Finds the CMAP by walking the FORM at source (fixed #766), else by the raw search of the original (5122 bytes from source, by 2 bytes: also a CMAP chunk at source itself), and writes its colours from colour offset on; offset < 0 gives the object a new colour block of the CMAP's size (the old one freed: "this information is deleted"). Fixed (#769, #991): with an offset, a palette with fewer than offset + CMAP colours (or none) grows: a new block for offset + CMAP colours, the old colours copied into it, the ones between cleared, the cycles kept (as palettelib's DecodePalette since #226); the original replaced it with a block of the CMAP's size and ignored the offset (#769), or for a palette without a block wrote the colours offset * 12 bytes into a block of the CMAP's size (#991). Fixed (#1105): a CMAP of fewer than 3 bytes is refused, the block is sized from the whole colour count; the original wrote 65536 colours for a CMAP below 3 bytes and sized the block from the low word of the CMAP length. The new block is allocated before the old one is freed.

Parameters
srcd0: the ILBM data
obja1: the palette object (parameter 1)
offsetd2: the first colour, < 0: a new block
Returns
d0: BB_TRUE, BB_FALSE without CMAP, with a CMAP of no colour or of more than the 65535 colours of a palette, or without memory (the palette unchanged)

◆ ilbmpalette_c()

BB_BOOL ilbmpalette_c ( const UBYTE * src,
struct bb_palette * obj )
static

ILBMPalette(sourceaddr,palette#): as with offset -1 (a new colour block).

Parameters
srcd0: the ILBM data
obja1: the palette object
Returns
d0: BB_TRUE, BB_FALSE without CMAP or memory

◆ libfinit()

void libfinit ( void )
static

finit: does nothing (RTS).

◆ libinit()

void libinit ( void )
static

init: does nothing (RTS).

◆ packpbm()

void packpbm ( void )

◆ packpbm_c()

ULONG packpbm_c ( const UBYTE * src,
UBYTE * dst,
ULONG size )
static

PackPBM(sourceaddr,destaddr,length): packs data with ByteRun1.

Runs of at most 128 (127 in the counter). Fixed (#772): the failure returns -1; dest holds the packed bytes written up to it. The original fell into UnPackPBM with d0 = -1, which unpacked from address -1 into dest, limited by the caller's d3.

Parameters
srcd0: the source
dstd1: the destination
sized2: the length of the source
Returns
d0: the length of the packed data, or -1 if it would reach length bytes

◆ skiprow()

const UBYTE * skiprow ( const UBYTE * body,
UBYTE packed )
inlinestatic

Skips the mask row of a line (fixed #1112), as UnpackIFF reads a plane row: uncompressed its bytes, ByteRun1 its runs (a run past the end of the row skipped whole).

Always inline: as a call in the line loop it took registers from the loops of the plane rows (their code got slower by 12 % for an unmasked picture); inline the unmasked picture pays one test per line.

Parameters
bodythe BODY data of the mask row
packedthe BMHD's compression (0 or 1)
Returns
the BODY data behind the mask row

◆ unpackiff()

void unpackiff ( void )

◆ unpackiff_c()

BB_BOOL unpackiff_c ( const UBYTE * src,
struct BitMap * bm,
ULONG lines,
ULONG xy )
static

UnpackIFF(sourceaddr,bitmap#,numlines,xy_offset): the BODY of an ILBM in memory into a bitmap.

Finds the BMHD and the BODY by walking the FORM ILBM at source (fixed #766; another FORM fails), else by the raw search of the original (BMHD 5120 bytes from source, BODY from the BMHD on, by 2 bytes), then unpacks numlines lines into the planes, each plane pointer + xy_offset. Fails without BMHD or BODY, if the bitmap has fewer planes or bytes per row than the picture, or no planes, or if the BMHD has no planes (fixed #777: the original stored 256 plane pointers into its table of 8). A row has the word-aligned width of ILBM (fixed #775: the original's width/8), its bytes counted in a word (fixed #774: the original's signed byte skipped rows of 129 bytes and more); a run is cut at the end of the row (fixed #776: the original wrote it into the next row). The BMHD's compression decides: 0 rows as they are, 1 ByteRun1, anything else fails (fixed #773: the original took every BODY as ByteRun1). With the BMHD's masking 1 the mask row behind the planes of every line is skipped (fixed #1112: the original decoded it as the next line's first plane).

Parameters
srcd0: the ILBM data (FORM)
bma1: the bitmap object (parameter 1)
linesd2: the number of lines (word; < 0: the BMHD's height; at most the bitmap's)
xyd3: the byte offset added to every plane
Returns
d0: BB_TRUE, BB_FALSE on failure

◆ unpackpbm()

void unpackpbm ( void )

◆ unpackpbm_c()

void unpackpbm_c ( const UBYTE * src,
UBYTE * dst,
ULONG len,
ULONG dlen )
static

UnPackPBM sourceaddr,destaddr,length,destlength: unpacks ByteRun1 data.

n >= 0 copies n+1 bytes, n < 0 (not -128) repeats the next byte 1-n times, -128 is skipped; stops at the end of the source or of the destination. Fixed (#778): both limits are tested before each access, unsigned, also inside a literal run: nothing at or behind source+length is read, nothing at or behind dest+destlength written. The original tested after the access and signed.

Parameters
srcd0: the packed data
dstd1: the destination
lend2: the length of the packed data
dlend3: the size of the destination

◆ walkform()

const UBYTE * walkform ( const UBYTE * form,
ULONG id )
static

The chunk id of a FORM, found by walking its chunks (fixed #766).

From the first chunk behind the FORM type up to the end of the FORM (its length); a chunk of odd length is followed by its pad byte when that byte is 0, otherwise the next chunk starts right behind the data (a file written without pad, as #189) - an odd address, where the walk stops (the long reads of the callers need even addresses; the raw search, the fallback, does not look there either).

Parameters
formthe FORM (its id was checked)
idthe chunk id
Returns
the chunk (its id), NULL if the FORM has none, a length runs past the FORM's end, or the walk reaches an odd address

Variable Documentation

◆ bitmapwidth

UWORD bitmapwidth

◆ bitplanes

UBYTE* bitplanes[8]

◆ bytewidth

UWORD bytewidth

◆ direkt_tab

const ULONG direkt_tab[10]
static
Initial value:
= {
0x7fff000e, 0x00ff0007, 0x00070002, 0x00030001, 0x00030001,
270 - 1, 15 - 1, 8 - 1, 5 - 1, 2 - 1
}

◆ iffdepth

UBYTE iffdepth

◆ iffdest

ULONG iffdest

◆ iffheight

UWORD iffheight

◆ iffsource

ULONG iffsource

◆ length_tab

const BYTE length_tab[10] = { 9, 1, 0, -1, -1, 8, 4, 2, 1, 0 }
static

◆ more_add

const WORD more_add[3] = { 0x11f, -1, 0x1f }
static

◆ more_offset

const BYTE more_offset[4] = { 11, 4, 7, 0 }
static

◆ [struct]

struct { ... } v