2 |
- |
1 |
/* Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
6 |
This software is distributed under license and may not be copied,
|
|
|
7 |
modified or distributed except as expressly authorized under the terms
|
|
|
8 |
of the license contained in the file LICENSE in this distribution.
|
|
|
9 |
|
|
|
10 |
For more information about licensing, please refer to
|
|
|
11 |
http://www.ghostscript.com/licensing/. For information on
|
|
|
12 |
commercial licensing, go to http://www.artifex.com/licensing/ or
|
|
|
13 |
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
|
|
|
14 |
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: scfparam.c,v 1.5 2005/07/06 20:54:07 stefan Exp $ */
|
|
|
18 |
/* CCITTFax filter parameter setting and reading */
|
|
|
19 |
#include "std.h"
|
|
|
20 |
#include "gserror.h"
|
|
|
21 |
#include "gserrors.h"
|
|
|
22 |
#include "gstypes.h"
|
|
|
23 |
#include "gsmemory.h"
|
|
|
24 |
#include "gsparam.h"
|
|
|
25 |
#include "scommon.h"
|
|
|
26 |
#include "scf.h" /* for cfe_max_width */
|
|
|
27 |
#include "scfx.h"
|
|
|
28 |
|
|
|
29 |
/* Define the CCITTFax parameters. */
|
|
|
30 |
private const gs_param_item_t s_CF_param_items[] =
|
|
|
31 |
{
|
|
|
32 |
#define cfp(key, type, memb) { key, type, offset_of(stream_CF_state, memb) }
|
|
|
33 |
cfp("Uncompressed", gs_param_type_bool, Uncompressed),
|
|
|
34 |
cfp("K", gs_param_type_int, K),
|
|
|
35 |
cfp("EndOfLine", gs_param_type_bool, EndOfLine),
|
|
|
36 |
cfp("EncodedByteAlign", gs_param_type_bool, EncodedByteAlign),
|
|
|
37 |
cfp("Columns", gs_param_type_int, Columns),
|
|
|
38 |
cfp("Rows", gs_param_type_int, Rows),
|
|
|
39 |
cfp("EndOfBlock", gs_param_type_bool, EndOfBlock),
|
|
|
40 |
cfp("BlackIs1", gs_param_type_bool, BlackIs1),
|
|
|
41 |
cfp("DamagedRowsBeforeError", gs_param_type_int, DamagedRowsBeforeError),
|
|
|
42 |
cfp("FirstBitLowOrder", gs_param_type_bool, FirstBitLowOrder),
|
|
|
43 |
cfp("DecodedByteAlign", gs_param_type_int, DecodedByteAlign),
|
|
|
44 |
#undef cfp
|
|
|
45 |
gs_param_item_end
|
|
|
46 |
};
|
|
|
47 |
|
|
|
48 |
/* Define a limit on the Rows parameter, was too low at 32000 */
|
|
|
49 |
#define cf_max_height 1000000
|
|
|
50 |
|
|
|
51 |
/* Get non-default CCITTFax filter parameters. */
|
|
|
52 |
stream_state_proc_get_params(s_CF_get_params, stream_CF_state); /* check */
|
|
|
53 |
int
|
|
|
54 |
s_CF_get_params(gs_param_list * plist, const stream_CF_state * ss, bool all)
|
|
|
55 |
{
|
|
|
56 |
stream_CF_state cfs_defaults;
|
|
|
57 |
const stream_CF_state *defaults;
|
|
|
58 |
|
|
|
59 |
if (all)
|
|
|
60 |
defaults = 0;
|
|
|
61 |
else {
|
|
|
62 |
s_CF_set_defaults_inline(&cfs_defaults);
|
|
|
63 |
defaults = &cfs_defaults;
|
|
|
64 |
}
|
|
|
65 |
return gs_param_write_items(plist, ss, defaults, s_CF_param_items);
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
/* Put CCITTFax filter parameters. */
|
|
|
69 |
stream_state_proc_put_params(s_CF_put_params, stream_CF_state); /* check */
|
|
|
70 |
int
|
|
|
71 |
s_CF_put_params(gs_param_list * plist, stream_CF_state * ss)
|
|
|
72 |
{
|
|
|
73 |
stream_CF_state state;
|
|
|
74 |
int code;
|
|
|
75 |
|
|
|
76 |
state = *ss;
|
|
|
77 |
code = gs_param_read_items(plist, (void *)&state, s_CF_param_items);
|
|
|
78 |
if (code >= 0 &&
|
|
|
79 |
(state.K < -cf_max_height || state.K > cf_max_height ||
|
|
|
80 |
state.Columns < 0 || state.Columns > cfe_max_width ||
|
|
|
81 |
state.Rows < 0 || state.Rows > cf_max_height ||
|
|
|
82 |
state.DamagedRowsBeforeError < 0 ||
|
|
|
83 |
state.DamagedRowsBeforeError > cf_max_height ||
|
|
|
84 |
state.DecodedByteAlign < 1 || state.DecodedByteAlign > 16 ||
|
|
|
85 |
(state.DecodedByteAlign & (state.DecodedByteAlign - 1)) != 0)
|
|
|
86 |
)
|
|
|
87 |
code = gs_note_error(gs_error_rangecheck);
|
|
|
88 |
if (code >= 0)
|
|
|
89 |
*ss = state;
|
|
|
90 |
return code;
|
|
|
91 |
}
|