/*->h.g3g4 */


#define WHITE 0
#define BLACK 1

#define NULL_MODE 0
#define PASS_MODE 1
#define HORIZONTAL_MODE 2
#define VERTICAL_V0_MODE 3
#define VERTICAL_VR1_MODE 4
#define VERTICAL_VR2_MODE 5
#define VERTICAL_VR3_MODE 6
#define VERTICAL_VL1_MODE 7
#define VERTICAL_VL2_MODE 8
#define VERTICAL_VL3_MODE 9
#define EXT_MODE_UNCOMPRESSED 10
#define ERROR_MODE 11
#define ERROR_MODE_1 12

#define PASS_CODEWORD           0x1000
#define HORIZONTAL_CODEWORD     0x2000
#define VERTICAL_V0_CODEWORD    0x8000
#define VERTICAL_VR1_CODEWORD   0x6000
#define VERTICAL_VR2_CODEWORD   0x0C00
#define VERTICAL_VR3_CODEWORD   0x0600
#define VERTICAL_VL1_CODEWORD   0x4000
#define VERTICAL_VL2_CODEWORD   0x0800
#define VERTICAL_VL3_CODEWORD   0x0400

#define PASS_CODELEN            4
#define HORIZONTAL_CODELEN      3
#define VERTICAL_V0_CODELEN     1
#define VERTICAL_VR1_CODELEN    3
#define VERTICAL_VR2_CODELEN    6
#define VERTICAL_VR3_CODELEN    7
#define VERTICAL_VL1_CODELEN    3
#define VERTICAL_VL2_CODELEN    6
#define VERTICAL_VL3_CODELEN    7

#define RETURN_OK 0
#define ERROR_NEXT_BYTE 1 /* the routine next_byte () unexpectedly returned
  an error or end-of-file before the end of the image (EOFB) was reached */
#define ERROR_UNSUPPORTED_EXTENSION 2
#define ERROR_INVALID_CODEWORD 3
#define ERROR_PROGRAM_LOGIC 4


#define MSB_FIRST 1
#define LSB_FIRST 2

#define PAD_NONE 1
#define PAD_BYTE 2
#define PAD_NIBBLE 3
#define PAD_ODD_NIBBLE 4

char  (*p_decode_black) (short);
char  (*p_decode_new_row) (void);
short (*p_decode_next_byte) (void);
char  (*p_decode_white) (short);

char g3i_decode_T (void);
char g3i_decode (void);
char g3i_initialize (short, short);
char g4i_decode (void);
char g4i_initialize (short, short);

char (*p_encode_next_byte) (unsigned char);

char g3j_encode_black (short);
char g3j_encode_white (short);
char g3j_encode_new_row (void);
char g3j_encode_pad (char);
char g3j_initialize (short, short);
char g4j_encode_black (short);
char g4j_encode_white (short);
char g4j_encode_EOFB (void);
char g4j_encode_new_row (void);
char g4j_initialize (short, short);

/* internal stuff */

void encode_word (unsigned short, short);
void initialize_encode (void);
short encode_position;

char output_fill_order, input_fill_order;
unsigned char encode_buffer;
unsigned char *decode_mask, *encode_mask, *encode_head_mask, *encode_tail_mask;
short pending_black, pending_white;

char trace_flag;                        /* for debug */

