1 /* Copyright (C) 1998 Aladdin Enterprises. All rights reserved.
3 This file is part of GNU Ghostscript.
5 GNU Ghostscript is distributed in the hope that it will be useful, but
6 WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
7 to anyone for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing. Refer
9 to the GNU General Public License for full details.
11 Everyone is granted permission to copy, modify and redistribute GNU
12 Ghostscript, but only under the conditions described in the GNU General
13 Public License. A copy of this license is supposed to have been given
14 to you along with GNU Ghostscript so you can know your rights and
15 responsibilities. It should be in a file named COPYING. Among other
16 things, the copyright notice and this notice must be preserved on all
19 Aladdin Enterprises supports the work of the GNU Project, but is not
20 affiliated with the Free Software Foundation or the GNU Project. GNU
21 Ghostscript, as distributed by Aladdin Enterprises, does not require any
22 GNU software to build or run it.
26 /* CIE color space management */
31 #include "gsmatrix.h" /* for gscolor2.h */
33 #include "gscolor2.h" /* for gs_set/currentcolorrendering */
36 #include "gxdevice.h" /* for gxcmap.h */
40 /* ---------------- Color space definition ---------------- */
43 private_st_cie_common();
44 private_st_cie_common_elements();
48 private_st_cie_defg();
50 /* Define the CIE color space types. */
51 /* We use CIExxx rather than CIEBasedxxx in some places because */
52 /* gcc under VMS only retains 23 characters of procedure names, */
53 /* and DEC C truncates all identifiers at 31 characters. */
54 extern cs_proc_init_color(gx_init_CIE
);
55 private cs_proc_concrete_space(gx_concrete_space_CIE
);
56 private cs_proc_install_cspace(gx_install_CIE
);
59 gs_private_st_ptrs1(st_color_space_CIEDEFG
, gs_base_color_space
,
60 "gs_color_space(CIEDEFG)", cs_CIEDEFG_enum_ptrs
, cs_CIEDEFG_reloc_ptrs
,
62 extern cs_proc_restrict_color(gx_restrict_CIEDEFG
);
63 extern cs_proc_concretize_color(gx_concretize_CIEDEFG
);
64 extern cs_proc_install_cspace(gx_install_CIEDEFG
);
65 private cs_proc_adjust_cspace_count(gx_adjust_cspace_CIEDEFG
);
66 const gs_color_space_type gs_color_space_type_CIEDEFG
= {
67 gs_color_space_index_CIEDEFG
, true, true,
68 &st_color_space_CIEDEFG
, gx_num_components_4
,
70 gx_init_CIE
, gx_restrict_CIEDEFG
,
71 gx_concrete_space_CIE
,
72 gx_concretize_CIEDEFG
, NULL
,
73 gx_default_remap_color
, gx_install_CIE
,
74 gx_adjust_cspace_CIEDEFG
, gx_no_adjust_color_count
78 gs_private_st_ptrs1(st_color_space_CIEDEF
, gs_base_color_space
,
79 "gs_color_space(CIEDEF)", cs_CIEDEF_enum_ptrs
, cs_CIEDEF_reloc_ptrs
,
81 extern cs_proc_restrict_color(gx_restrict_CIEDEF
);
82 extern cs_proc_concretize_color(gx_concretize_CIEDEF
);
83 extern cs_proc_install_cspace(gx_install_CIEDEF
);
84 private cs_proc_adjust_cspace_count(gx_adjust_cspace_CIEDEF
);
85 const gs_color_space_type gs_color_space_type_CIEDEF
= {
86 gs_color_space_index_CIEDEF
, true, true,
87 &st_color_space_CIEDEF
, gx_num_components_3
,
89 gx_init_CIE
, gx_restrict_CIEDEF
,
90 gx_concrete_space_CIE
,
91 gx_concretize_CIEDEF
, NULL
,
92 gx_default_remap_color
, gx_install_CIE
,
93 gx_adjust_cspace_CIEDEF
, gx_no_adjust_color_count
97 gs_private_st_ptrs1(st_color_space_CIEABC
, gs_base_color_space
,
98 "gs_color_space(CIEABC)", cs_CIEABC_enum_ptrs
, cs_CIEABC_reloc_ptrs
,
100 cs_proc_restrict_color(gx_restrict_CIEABC
);
101 cs_proc_concretize_color(gx_concretize_CIEABC
);
102 cs_proc_install_cspace(gx_install_CIEABC
);
103 private cs_proc_adjust_cspace_count(gx_adjust_cspace_CIEABC
);
104 extern cs_proc_remap_color(gx_remap_CIEABC
);
105 const gs_color_space_type gs_color_space_type_CIEABC
= {
106 gs_color_space_index_CIEABC
, true, true,
107 &st_color_space_CIEABC
, gx_num_components_3
,
109 gx_init_CIE
, gx_restrict_CIEABC
,
110 gx_concrete_space_CIE
,
111 gx_concretize_CIEABC
, NULL
,
112 gx_remap_CIEABC
, gx_install_CIE
,
113 gx_adjust_cspace_CIEABC
, gx_no_adjust_color_count
117 gs_private_st_ptrs1(st_color_space_CIEA
, gs_base_color_space
,
118 "gs_color_space(CIEA)", cs_CIEA_enum_ptrs
, cs_CIEA_reloc_ptrs
,
120 cs_proc_restrict_color(gx_restrict_CIEA
);
121 cs_proc_concretize_color(gx_concretize_CIEA
);
122 cs_proc_install_cspace(gx_install_CIEA
);
123 private cs_proc_adjust_cspace_count(gx_adjust_cspace_CIEA
);
124 const gs_color_space_type gs_color_space_type_CIEA
= {
125 gs_color_space_index_CIEA
, true, true,
126 &st_color_space_CIEA
, gx_num_components_1
,
128 gx_init_CIE
, gx_restrict_CIEA
,
129 gx_concrete_space_CIE
,
130 gx_concretize_CIEA
, NULL
,
131 gx_default_remap_color
, gx_install_CIE
,
132 gx_adjust_cspace_CIEA
, gx_no_adjust_color_count
135 /* Determine the concrete space underlying a CIEBased space. */
136 private const gs_color_space
*
137 gx_concrete_space_CIE(const gs_color_space
* pcs
, const gs_imager_state
* pis
)
139 const gs_cie_render
*pcie
= pis
->cie_render
;
141 if (pcie
== 0 || pcie
->RenderTable
.lookup
.table
== 0 ||
142 pcie
->RenderTable
.lookup
.m
== 3
144 return gs_cspace_DeviceRGB(pis
);
145 else /* pcie->RenderTable.lookup.m == 4 */
146 return gs_cspace_DeviceCMYK(pis
);
149 /* Install a CIE space in the graphics state. */
150 /* We go through an extra level of procedure so that */
151 /* interpreters can substitute their own installer. */
153 gx_install_CIE(gs_color_space
* pcs
, gs_state
* pgs
)
155 return (*pcs
->params
.a
->common
.install_cspace
) (pcs
, pgs
);
158 /* Adjust reference counts for a CIE color space */
160 gx_adjust_cspace_CIEDEFG(const gs_color_space
* pcs
, int delta
)
162 rc_adjust_const(pcs
->params
.defg
, delta
, "gx_adjust_cspace_CIEDEFG");
166 gx_adjust_cspace_CIEDEF(const gs_color_space
* pcs
, int delta
)
168 rc_adjust_const(pcs
->params
.def
, delta
, "gx_adjust_cspace_CIEDEF");
172 gx_adjust_cspace_CIEABC(const gs_color_space
* pcs
, int delta
)
174 rc_adjust_const(pcs
->params
.abc
, delta
, "gx_adjust_cspace_CIEABC");
178 gx_adjust_cspace_CIEA(const gs_color_space
* pcs
, int delta
)
180 rc_adjust_const(pcs
->params
.a
, delta
, "gx_adjust_cspace_CIEA");
183 /* ---------------- Procedures ---------------- */
185 /* ------ Internal initializers ------ */
188 * Set up the default values for the CIE parameters that are common to
189 * all CIE color spaces.
191 * There is no default for the white point, so it is set equal to the
192 * black point. If anyone actually uses the color space in that form,
193 * the results are likely to be unsatisfactory.
196 set_common_cie_defaults(gs_cie_common
* pcommon
, void *client_data
)
198 pcommon
->RangeLMN
= Range3_default
;
199 pcommon
->DecodeLMN
= DecodeLMN_default
;
200 pcommon
->MatrixLMN
= Matrix3_default
;
201 pcommon
->points
.WhitePoint
= BlackPoint_default
;
202 pcommon
->points
.BlackPoint
= BlackPoint_default
;
203 pcommon
->client_data
= client_data
;
207 * Set defaults for a CIEBasedABC color space. This is also used for
208 * CIEBasedDEF and CIEBasedDEFG color spaces.
211 set_cie_abc_defaults(gs_cie_abc
* pabc
, void *client_data
)
213 set_common_cie_defaults(&pabc
->common
, client_data
);
214 pabc
->RangeABC
= Range3_default
;
215 pabc
->DecodeABC
= DecodeABC_default
;
216 pabc
->MatrixABC
= Matrix3_default
;
220 * Set up a default color lookup table for a CIEBasedDEF[G] space. There is
221 * no specified default for this structure, so the values used here (aside
222 * from the input and output component numbers) are intended only to make
223 * the system fail in a predictable manner.
226 set_ctbl_defaults(gx_color_lookup_table
* plktblp
, int num_comps
)
230 plktblp
->n
= num_comps
;
231 plktblp
->m
= 3; /* always output CIE ABC */
232 for (i
= 0; i
< countof(plktblp
->dims
); i
++)
233 plktblp
->dims
[i
] = 0;
238 * Allocate a color space and its parameter structure.
239 * Return 0 if VMerror, otherwise the parameter structure.
242 build_cie_space(gs_color_space
** ppcspace
, const gs_color_space_type
* pcstype
,
243 gs_memory_type_ptr_t stype
, gs_memory_t
* pmem
)
245 gs_color_space
*pcspace
=
246 gs_alloc_struct(pmem
, gs_color_space
, &st_color_space
,
248 gs_cie_common_elements_t
*pdata
;
252 rc_alloc_struct_1(pdata
, gs_cie_common_elements_t
, stype
, pmem
,
254 gs_free_object(pmem
, pcspace
, "build_cie_space");
258 "build_cie_space(data)");
259 pcspace
->pmem
= pmem
;
260 pcspace
->type
= pcstype
;
262 return (void *)pdata
;
265 /* ------ Constructors ------ */
268 gs_cspace_build_CIEA(gs_color_space
** ppcspace
, void *client_data
,
272 build_cie_space(ppcspace
, &gs_color_space_type_CIEA
, &st_cie_a
, pmem
);
275 return_error(gs_error_VMerror
);
277 set_common_cie_defaults(&pciea
->common
, client_data
);
278 pciea
->common
.install_cspace
= gx_install_CIEA
;
279 pciea
->RangeA
= RangeA_default
;
280 pciea
->DecodeA
= DecodeA_default
;
281 pciea
->MatrixA
= MatrixA_default
;
283 (*ppcspace
)->params
.a
= pciea
;
288 gs_cspace_build_CIEABC(gs_color_space
** ppcspace
, void *client_data
,
292 build_cie_space(ppcspace
, &gs_color_space_type_CIEABC
, &st_cie_abc
,
296 return_error(gs_error_VMerror
);
298 set_cie_abc_defaults(pabc
, client_data
);
299 pabc
->common
.install_cspace
= gx_install_CIEABC
;
301 (*ppcspace
)->params
.abc
= pabc
;
306 gs_cspace_build_CIEDEF(gs_color_space
** ppcspace
, void *client_data
,
310 build_cie_space(ppcspace
, &gs_color_space_type_CIEDEF
, &st_cie_def
,
314 return_error(gs_error_VMerror
);
316 set_cie_abc_defaults((gs_cie_abc
*) pdef
, client_data
);
317 pdef
->common
.install_cspace
= gx_install_CIEDEF
;
318 pdef
->RangeDEF
= Range3_default
;
319 pdef
->DecodeDEF
= DecodeDEF_default
;
320 pdef
->RangeHIJ
= Range3_default
;
321 set_ctbl_defaults(&pdef
->Table
, 3);
323 (*ppcspace
)->params
.def
= pdef
;
328 gs_cspace_build_CIEDEFG(gs_color_space
** ppcspace
, void *client_data
,
332 build_cie_space(ppcspace
, &gs_color_space_type_CIEDEFG
, &st_cie_defg
,
336 return_error(gs_error_VMerror
);
338 set_cie_abc_defaults((gs_cie_abc
*) pdefg
, client_data
);
339 pdefg
->common
.install_cspace
= gx_install_CIEDEFG
;
340 pdefg
->RangeDEFG
= Range4_default
;
341 pdefg
->DecodeDEFG
= DecodeDEFG_default
;
342 pdefg
->RangeHIJK
= Range4_default
;
343 set_ctbl_defaults(&pdefg
->Table
, 4);
345 (*ppcspace
)->params
.defg
= pdefg
;
349 /* ------ Accessors ------ */
352 gs_cie_defx_set_lookup_table(gs_color_space
* pcspace
, int *pdims
,
353 const gs_const_string
* ptable
)
355 gx_color_lookup_table
*plktblp
;
357 switch (gs_color_space_get_index(pcspace
)) {
358 case gs_color_space_index_CIEDEF
:
359 plktblp
= &pcspace
->params
.def
->Table
;
361 case gs_color_space_index_CIEDEFG
:
362 plktblp
= &pcspace
->params
.defg
->Table
;
363 plktblp
->dims
[3] = pdims
[3];
366 return_error(gs_error_rangecheck
);
369 plktblp
->dims
[0] = pdims
[0];
370 plktblp
->dims
[1] = pdims
[1];
371 plktblp
->dims
[2] = pdims
[2];
372 plktblp
->table
= ptable
;