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: zcsindex.c 9043 2008-08-28 22:48:19Z giles $ */
15 /* Indexed color space support */
16 #include "memory_.h"
17 #include "ghost.h"
18 #include "oper.h"
19 #include "gsstruct.h"
20 #include "gscolor.h"
21 #include "gsmatrix.h" /* for gxcolor2.h */
22 #include "gxcspace.h"
23 #include "gxfixed.h" /* ditto */
24 #include "gxcolor2.h"
25 #include "estack.h"
26 #include "ialloc.h"
27 #include "icsmap.h"
28 #include "igstate.h"
29 #include "ivmspace.h"
30 #include "store.h"
31
32
33 /* ------ Internal routines ------ */
34
35 /* Allocate, and prepare to load, the index or tint map. */
36 int
zcs_begin_map(i_ctx_t * i_ctx_p,gs_indexed_map ** pmap,const ref * pproc,int num_entries,const gs_color_space * base_space,op_proc_t map1)37 zcs_begin_map(i_ctx_t *i_ctx_p, gs_indexed_map ** pmap, const ref * pproc,
38 int num_entries, const gs_color_space * base_space,
39 op_proc_t map1)
40 {
41 gs_memory_t *mem = gs_state_memory(igs);
42 int space = imemory_space((gs_ref_memory_t *)mem);
43 int num_components = cs_num_components(base_space);
44 int num_values = num_entries * num_components;
45 gs_indexed_map *map;
46 int code = alloc_indexed_map(&map, num_values, mem,
47 "setcolorspace(mapped)");
48 es_ptr ep;
49
50 if (code < 0)
51 return code;
52 *pmap = map;
53 /* Map the entire set of color indices. Since the */
54 /* o-stack may not be able to hold N*4096 values, we have */
55 /* to load them into the cache as they are generated. */
56 check_estack(num_csme + 1); /* 1 extra for map1 proc */
57 ep = esp += num_csme;
58 make_int(ep + csme_num_components, num_components);
59 make_struct(ep + csme_map, space, map);
60 ep[csme_proc] = *pproc;
61 make_int(ep + csme_hival, num_entries - 1);
62 make_int(ep + csme_index, -1);
63 push_op_estack(map1);
64 return o_push_estack;
65 }
66