/****************************************************************************
* $Id: zerotree.h,v 1.1 2006-01-17 14:27:51+01 rolf Exp rolf $
*****************************************************************************/

#ifndef _ZEROTREE_H_

#define _ZEROTREE_H_

#include "defines.h"
#undef ZT_DEBUG

#define ztLIP	    1	/* Mode:    List of Insignificant Pixels */
#define ztLSPR	    2	/* Mode:    Pixel has been added to LIP recently */
#define ztLSP	    4	/* Mode:    List of Significant Pixels */
#define ztLIS_A	    1	/* TreeMode:List of Insignificant Sets (Trees), Type A: incl. direct descendants */
#define ztLIS_B	    2	/* TreeMode:List of Insignificant Sets (Trees), Type B: excl. direct descendants */
#define ztLSS	    4	/* TreeMode:List of Significant Sets (Trees) */

typedef void ztree_func( size_t x, size_t y );

typedef struct ztreeNodeStruct  *ztreeNodePtr;

typedef struct ztreeNodeStruct {
    uWord			Sign;		/* ZeroTree2: the sign of Value */
    uWord	 		Value;		/* pixel or wavelet coefficient UNSIGNED !!! */
    sWord			TreeBits;	/* maximum no. of bits needed for tree (excl. value) */
    sWord			Shift;		/* shift for this value */
    uByte			Mode;		/* coding/decoding mode */
    uByte			TreeMode;	/* coding/decoding mode */
    ztreeNodePtr   Child;		/* pointer to 4 children nodes  */
} ztreeNode;

ztreeNodePtr ztree_build( sWord *src, size_t blockSize, size_t lineSize );
void ztree_free( ztreeNodePtr tree );
void ztree_undo( ztreeNodePtr node, sWord *dest, size_t blockSize, size_t lineSize );
int  ztree_code( ztreeNodePtr tree, unsigned maxStep );
int  ztree_decode( ztreeNodePtr tree, unsigned maxStep );

#endif /* _ZEROTREE_H_ */
