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