1 /* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: scfx.h,v 1.2.6.1.2.1 2003/01/17 00:49:05 giles Exp $ */
20 /* CCITTFax filter state definition */
21 /* Requires strimpl.h */
22 
23 #ifndef scfx_DEFINED
24 #  define scfx_DEFINED
25 
26 #include "shc.h"
27 
28 /* Common state */
29 #define stream_CF_state_common\
30 	stream_hc_state_common;\
31 		/* The client sets the following before initialization. */\
32 	bool Uncompressed;\
33 	int K;\
34 	bool EndOfLine;\
35 	bool EncodedByteAlign;\
36 	int Columns;\
37 	int Rows;\
38 	bool EndOfBlock;\
39 	bool BlackIs1;\
40 	int DamagedRowsBeforeError;	/* (Decode only) */\
41 	/*bool FirstBitLowOrder;*/	/* in stream_hc_state_common */\
42 	int DecodedByteAlign;\
43 		/* The init procedure sets the following. */\
44 	uint raster;\
45 	byte *lbuf;		/* current scan line buffer */\
46 				/* (only if decoding or 2-D encoding) */\
47 	byte *lprev;		/* previous scan line buffer (only if 2-D) */\
48 		/* The following are updated dynamically. */\
49 	int k_left		/* number of next rows to encode in 2-D */\
50 				/* (only if K > 0) */
51 typedef struct stream_CF_state_s {
52     stream_CF_state_common;
53 } stream_CF_state;
54 
55 /* Define common default parameter setting. */
56 #define s_CF_set_defaults_inline(ss)\
57   ((ss)->Uncompressed = false,\
58    (ss)->K = 0,\
59    (ss)->EndOfLine = false,\
60    (ss)->EncodedByteAlign = false,\
61    (ss)->Columns = 1728,\
62    (ss)->Rows = 0,\
63    (ss)->EndOfBlock = true,\
64    (ss)->BlackIs1 = false,\
65 		/* Added by Adobe since the Red Book */\
66    (ss)->DamagedRowsBeforeError = 0, /* always set, for s_CF_get_params */\
67    (ss)->FirstBitLowOrder = false,\
68 		/* Added by us */\
69    (ss)->DecodedByteAlign = 1,\
70 	/* Clear pointers */\
71    (ss)->lbuf = 0, (ss)->lprev = 0)
72 
73 /* CCITTFaxEncode */
74 typedef struct stream_CFE_state_s {
75     stream_CF_state_common;
76     /* The init procedure sets the following. */
77     int max_code_bytes;		/* max # of bytes for an encoded line */
78     byte *lcode;		/* buffer for encoded output line */
79     /* The following change dynamically. */
80     int read_count;		/* # of bytes to copy into lbuf */
81     int write_count;		/* # of bytes to copy out of lcode */
82     int code_bytes;		/* # of occupied bytes in lcode */
83 } stream_CFE_state;
84 
85 #define private_st_CFE_state()	/* in scfe.c */\
86   gs_private_st_ptrs3(st_CFE_state, stream_CFE_state, "CCITTFaxEncode state",\
87     cfe_enum_ptrs, cfe_reloc_ptrs, lbuf, lprev, lcode)
88 #define s_CFE_set_defaults_inline(ss)\
89   (s_CF_set_defaults_inline(ss), (ss)->lcode = 0)
90 extern const stream_template s_CFE_template;
91 
92 /* CCITTFaxDecode */
93 typedef struct stream_CFD_state_s {
94     stream_CF_state_common;
95     int cbit;			/* bits left to fill in current decoded */
96     /* byte at lbuf[wpos] (0..7) */
97     int rows_left;		/* number of rows left */
98     int rpos;			/* rptr for copying lbuf to client */
99     int wpos;			/* rlimit/wptr for filling lbuf or */
100     /* copying to client */
101     int eol_count;		/* number of EOLs seen so far */
102     byte invert;		/* current value of 'white' */
103     /* for 2-D decoding */
104     int run_color;		/* -1 if processing white run, */
105     /* 0 if between runs but white is next, */
106     /* 1 if between runs and black is next, */
107     /* 2 if processing black run */
108     int damaged_rows;		/* # of consecutive damaged rows preceding */
109     /* the current row */
110     bool skipping_damage;	/* true if skipping a damaged row looking */
111     /* for EOL */
112     /* The following are not used yet. */
113     int uncomp_run;		/* non-0 iff we are in an uncompressed */
114     /* run straddling a scan line (-1 if white, */
115     /* 1 if black) */
116     int uncomp_left;		/* # of bits left in the run */
117     int uncomp_exit;		/* non-0 iff this is an exit run */
118     /* (-1 if next run white, 1 if black) */
119 } stream_CFD_state;
120 
121 #define private_st_CFD_state()	/* in scfd.c */\
122   gs_private_st_ptrs2(st_CFD_state, stream_CFD_state, "CCITTFaxDecode state",\
123     cfd_enum_ptrs, cfd_reloc_ptrs, lbuf, lprev)
124 #define s_CFD_set_defaults_inline(ss)\
125   s_CF_set_defaults_inline(ss)
126 extern const stream_template s_CFD_template;
127 
128 #endif /* scfx_INCLUDED */
129