/********************************************************/
/* How to interface and use Decrunch30.S with SAS C	*/
/*							*/
/* Copyright © 1992-1994 by Stefano Reksten		*/
/********************************************************/

#include <exec/types.h>
#include <exec/memory.h>

#include <intuition/intuition.h>
/* for struct Image */

UWORD chip something_cdata[] = { ... };

struct Image an_image = {	leftedge, topedge, width, height, depth,
				USHORT *ImageData,
				planepick, planeonoff, *nextimage };

/* Please note: ImageData can be
	o	NULL;

	o	a pointer to compressed data;

	o	a pointer to uncompressed data
			(and in this case this file is useless!!!) */

/* First, declare: */
extern BOOL __asm Decrunch30 ( register __a0 UBYTE *, register __a1 UBYTE * );

UBYTE *mem_ptr;
UBYTE *data_ptr;
ULONG data_size;

void decodeStuff()
	{
	/* if we're using an_image and an_image.ImageData */
	/* contains the compressed-data-pointer, we do:   */

	data_ptr = (UBYTE *)an_image.ImageData;

	/* else we do */

	data_ptr = (UBYTE*)someting_cdata;

	/* hoping that something_cdata actually contains */
	/* compressed data from a pic, or something else */

	data_size = *(ULONG *)(data_ptr+4);

	/* ...to know how much mem we need to decrunch... */

	if ( !( mem_ptr = (UBYTE *)AllocMem( data_size, MEMF_CHIP|MEMF_CLEAR ) ) )
		exit( 0 );


	(void)Decrunch30( mem_ptr, data_ptr );
	/* Actually Decrunch30 returns a BOOL value, 0 if failed */
	/* that is, if data was not compressed.			 */


	/* if we use an_image now we can do:

	an_image.ImageData = (UWORD *)mem_ptr;

	DrawImage( a_RastPort, &image, x_coord, y_coord );

	it is recommended to pass the whole structure of the image
	instead of the pointer because we change the pointer to the
	ImageData. If not, just store somewhere an_image.ImageData
	and restore it later. Anyway, this is up to you. */

	/* ... do whatever you want with your decompressed data, then... */

	FreeMem( mem_ptr, data_size );
	}
