1 /* Copyright (C) 1997, 2000 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: gscpixel.c,v 1.13 2004/08/19 19:33:09 stefan Exp $ */
18 /* DevicePixel color space and operation definition */
19 #include "gx.h"
20 #include "gserrors.h"
21 #include "gsrefct.h"
22 #include "gxcspace.h"
23 #include "gscpixel.h"
24 #include "gxdevice.h"
25 #include "gxistate.h"
26 #include "gsovrc.h"
27 #include "gsstate.h"
28 #include "gzstate.h"
29 #include "stream.h"
30
31 /* Define the DevicePixel color space type. */
32 private cs_proc_restrict_color(gx_restrict_DevicePixel);
33 private cs_proc_remap_concrete_color(gx_remap_concrete_DevicePixel);
34 private cs_proc_concretize_color(gx_concretize_DevicePixel);
35 private cs_proc_set_overprint(gx_set_overprint_DevicePixel);
36 private cs_proc_serialize(gx_serialize_DevicePixel);
37 private const gs_color_space_type gs_color_space_type_DevicePixel = {
38 gs_color_space_index_DevicePixel, true, false,
39 &st_base_color_space, gx_num_components_1,
40 gx_no_base_space,
41 gx_init_paint_1, gx_restrict_DevicePixel,
42 gx_same_concrete_space,
43 gx_concretize_DevicePixel, gx_remap_concrete_DevicePixel,
44 gx_default_remap_color, gx_no_install_cspace,
45 gx_set_overprint_DevicePixel,
46 gx_no_adjust_cspace_count, gx_no_adjust_color_count,
47 gx_serialize_DevicePixel,
48 gx_cspace_is_linear_default
49 };
50
51 /* Initialize a DevicePixel color space. */
52 int
gs_cspace_init_DevicePixel(gs_memory_t * mem,gs_color_space * pcs,int depth)53 gs_cspace_init_DevicePixel(gs_memory_t *mem, gs_color_space * pcs, int depth)
54 {
55 switch (depth) {
56 case 1:
57 case 2:
58 case 4:
59 case 8:
60 case 16:
61 case 24:
62 case 32:
63 break;
64 default:
65 return_error(gs_error_rangecheck);
66 }
67 gs_cspace_init(pcs, &gs_color_space_type_DevicePixel, mem, false);
68 pcs->params.pixel.depth = depth;
69 return 0;
70 }
71
72 /* ------ Internal routines ------ */
73
74 /* Force a DevicePixel color into legal range. */
75 private void
gx_restrict_DevicePixel(gs_client_color * pcc,const gs_color_space * pcs)76 gx_restrict_DevicePixel(gs_client_color * pcc, const gs_color_space * pcs)
77 {
78 /****** NOT ENOUGH BITS IN float OR frac ******/
79 floatp pixel = pcc->paint.values[0];
80 ulong max_value = (1L << pcs->params.pixel.depth) - 1;
81
82 pcc->paint.values[0] = (pixel < 0 ? 0 : min(pixel, max_value));
83 }
84
85
86 /* Remap a DevicePixel color. */
87
88 private int
gx_concretize_DevicePixel(const gs_client_color * pc,const gs_color_space * pcs,frac * pconc,const gs_imager_state * pis)89 gx_concretize_DevicePixel(const gs_client_color * pc, const gs_color_space * pcs,
90 frac * pconc, const gs_imager_state * pis)
91 {
92 /****** NOT ENOUGH BITS IN float OR frac ******/
93 pconc[0] = (frac) (ulong) pc->paint.values[0];
94 return 0;
95 }
96
97 private int
gx_remap_concrete_DevicePixel(const frac * pconc,const gs_color_space * pcs,gx_device_color * pdc,const gs_imager_state * pis,gx_device * dev,gs_color_select_t select)98 gx_remap_concrete_DevicePixel(const frac * pconc, const gs_color_space * pcs,
99 gx_device_color * pdc, const gs_imager_state * pis, gx_device * dev,
100 gs_color_select_t select)
101 {
102 color_set_pure(pdc, pconc[0] & ((1 << dev->color_info.depth) - 1));
103 return 0;
104 }
105
106 /* DevicePixel disables overprint */
107 private int
gx_set_overprint_DevicePixel(const gs_color_space * pcs,gs_state * pgs)108 gx_set_overprint_DevicePixel(const gs_color_space * pcs, gs_state * pgs)
109 {
110 gs_overprint_params_t params;
111
112 params.retain_any_comps = false;
113 pgs->effective_overprint_mode = 0;
114 return gs_state_update_overprint(pgs, ¶ms);
115 }
116
117
118 /* ---------------- Serialization. -------------------------------- */
119
120 private int
gx_serialize_DevicePixel(const gs_color_space * pcs,stream * s)121 gx_serialize_DevicePixel(const gs_color_space * pcs, stream * s)
122 {
123 const gs_device_pixel_params * p = &pcs->params.pixel;
124 uint n;
125 int code = gx_serialize_cspace_type(pcs, s);
126
127 if (code < 0)
128 return code;
129 return sputs(s, (const byte *)&p->depth, sizeof(p->depth), &n);
130 }
131