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: zfimscale.c 6651 2006-03-13 16:18:19Z raph $ */
15 
16 /* This is the ps interpreter interface to the image mask interpolating
17    filter. */
18 
19 #include "memory_.h"
20 #include "ghost.h"
21 #include "oper.h"
22 #include "gsstruct.h"
23 #include "ialloc.h"
24 #include "idict.h"
25 #include "stream.h"
26 #include "strimpl.h"
27 #include "ifilter.h"
28 #include "idparam.h"
29 #include "sisparam.h"
30 #include "simscale.h"
31 
32 /* <source> <dict> imscale/filter <file> */
33 
34 static int
z_imscale_d(i_ctx_t * i_ctx_p)35 z_imscale_d(i_ctx_t * i_ctx_p)
36 {
37     os_ptr op = osp;		/* i_ctx_p->op_stack.stack.p defined in osstack.h */
38     int width, height;
39     stream_imscale_state state;
40 
41     /* extract the key from the parameter dictionary */
42     check_type(*op, t_dictionary);
43     check_dict_read(*op);
44     if (dict_int_param(op, "Width", 0, 1<<24, -1, &width) < 0)
45 	return_error(e_rangecheck);
46     if (dict_int_param(op, "Height", 0, 1<<24, -1, &height) < 0)
47 	return_error(e_rangecheck);
48 
49     state.params.Colors = 1;
50     state.params.BitsPerComponentIn = 1;
51     state.params.MaxValueIn = 1;
52     state.params.WidthIn = width;
53     state.params.HeightIn = height;
54     state.params.BitsPerComponentOut = 1;
55     state.params.MaxValueOut = 1;
56     state.params.WidthOut = width << 2;
57     state.params.HeightOut = height << 2;
58 
59     /* we pass npop=0, since we've no arguments left to consume */
60     /* we pass 0 instead of the usual rspace(sop) will allocate storage for
61        filter state from the same memory pool as the stream it's coding. this
62        causes no trouble because we maintain no pointers */
63     return filter_read(i_ctx_p, 0, &s_imscale_template,
64 		       (stream_state *) & state, 0);
65 }
66 
67 /* Match the above routines to their postscript filter names.
68    This is how our static routines get called externally. */
69 const op_def zfimscale_op_defs[] = {
70     op_def_begin_filter(),
71     {"2ImscaleDecode", z_imscale_d},
72     op_def_end(0)
73 };
74