1 /* Copyright (C) 2001-2012 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134, San Rafael,
13    CA  94903, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* CCITTFax filter state definition */
18 /* Requires strimpl.h */
19 
20 #ifndef scfx_INCLUDED
21 #  define scfx_INCLUDED
22 
23 #include "shc.h"
24 
25 /* Common state */
26 #define stream_CF_state_common\
27         stream_hc_state_common;\
28                 /* The client sets the following before initialization. */\
29         bool Uncompressed;\
30         int K;\
31         bool EndOfLine;\
32         bool EncodedByteAlign;\
33         int Columns;\
34         int Rows;\
35         bool EndOfBlock;\
36         bool BlackIs1;\
37         int DamagedRowsBeforeError;	/* (Decode only) */\
38         /*bool FirstBitLowOrder;*/	/* in stream_hc_state_common */\
39         int DecodedByteAlign;\
40                 /* The init procedure sets the following. */\
41         uint raster;\
42         byte *lbuf;		/* current scan line buffer */\
43                                 /* (only if decoding or 2-D encoding) */\
44         byte *lprev;		/* previous scan line buffer (only if 2-D) */\
45                 /* The following are updated dynamically. */\
46         int k_left		/* number of next rows to encode in 2-D */\
47                                 /* (only if K > 0) */
48 typedef struct stream_CF_state_s {
49     stream_CF_state_common;
50 } stream_CF_state;
51 
52 /* Define common default parameter setting. */
53 #define s_CF_set_defaults_inline(ss)\
54   ((ss)->Uncompressed = false,\
55    (ss)->K = 0,\
56    (ss)->EndOfLine = false,\
57    (ss)->EncodedByteAlign = false,\
58    (ss)->Columns = 1728,\
59    (ss)->Rows = 0,\
60    (ss)->EndOfBlock = true,\
61    (ss)->BlackIs1 = false,\
62                 /* Added by Adobe since the Red Book */\
63    (ss)->DamagedRowsBeforeError = 0, /* always set, for s_CF_get_params */\
64    (ss)->FirstBitLowOrder = false,\
65                 /* Added by us */\
66    (ss)->DecodedByteAlign = 1,\
67         /* Clear pointers */\
68    (ss)->lbuf = 0, (ss)->lprev = 0,\
69         /* Clear errors */\
70    (ss)->error_string[0] = 0)
71 
72 /* CCITTFaxEncode */
73 typedef struct stream_CFE_state_s {
74     stream_CF_state_common;
75     /* The init procedure sets the following. */
76     int max_code_bytes;		/* max # of bytes for an encoded line */
77     byte *lcode;		/* buffer for encoded output line */
78     /* The following change dynamically. */
79     int read_count;		/* # of bytes to copy into lbuf */
80     int write_count;		/* # of bytes to copy out of lcode */
81     int code_bytes;		/* # of occupied bytes in lcode */
82 } stream_CFE_state;
83 
84 #define private_st_CFE_state()	/* in scfe.c */\
85   gs_private_st_ptrs3(st_CFE_state, stream_CFE_state, "CCITTFaxEncode state",\
86     cfe_enum_ptrs, cfe_reloc_ptrs, lbuf, lprev, lcode)
87 #define s_CFE_set_defaults_inline(ss)\
88   (s_CF_set_defaults_inline(ss), (ss)->lcode = 0)
89 extern const stream_template s_CFE_template;
90 
91 /* CCITTFaxDecode */
92 typedef struct stream_CFD_state_s {
93     stream_CF_state_common;
94     int cbit;			/* bits left to fill in current decoded
95                                    byte at lbuf[wpos] (0..7) */
96     int rows_left;		/* number of rows left */
97     int row;			/* current row, first is 0 */
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' for 2-D decoding */
103     int run_color;		/* -1 if processing white run,
104                                    0 if between runs but white is next,
105                                    1 if between runs and black is next,
106                                    2 if processing black run */
107     int damaged_rows;		/* # of consecutive damaged rows preceding
108                                    the current row */
109     bool skipping_damage;	/* true if skipping a damaged row looking
110                                    for EOL */
111     /* The following are not used yet. */
112     int uncomp_run;		/* non-0 iff we are in an uncompressed
113                                    run straddling a scan line (-1 if white,
114                                    1 if black) */
115     int uncomp_left;		/* # of bits left in the run */
116     int uncomp_exit;		/* non-0 iff this is an exit run
117                                    (-1 if next run white, 1 if black) */
118 } stream_CFD_state;
119 
120 #define private_st_CFD_state()	/* in scfd.c */\
121   gs_private_st_ptrs2(st_CFD_state, stream_CFD_state, "CCITTFaxDecode state",\
122     cfd_enum_ptrs, cfd_reloc_ptrs, lbuf, lprev)
123 #define s_CFD_set_defaults_inline(ss)\
124   s_CF_set_defaults_inline(ss)
125 extern const stream_template s_CFD_template;
126 
127 #endif /* scfx_INCLUDED */
128