/src/ghostpdl/base/gscpixel.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 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, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* DevicePixel color space and operation definition */ |
18 | | #include "gx.h" |
19 | | #include "gserrors.h" |
20 | | #include "gsrefct.h" |
21 | | #include "gxcspace.h" |
22 | | #include "gscpixel.h" |
23 | | #include "gxdevice.h" |
24 | | #include "gxgstate.h" |
25 | | #include "gsovrc.h" |
26 | | #include "gsstate.h" |
27 | | #include "gzstate.h" |
28 | | #include "stream.h" |
29 | | |
30 | | /* Define the DevicePixel color space type. */ |
31 | | static cs_proc_restrict_color(gx_restrict_DevicePixel); |
32 | | static cs_proc_remap_concrete_color(gx_remap_concrete_DevicePixel); |
33 | | static cs_proc_concretize_color(gx_concretize_DevicePixel); |
34 | | static cs_proc_set_overprint(gx_set_overprint_DevicePixel); |
35 | | static cs_proc_serialize(gx_serialize_DevicePixel); |
36 | | static const gs_color_space_type gs_color_space_type_DevicePixel = { |
37 | | gs_color_space_index_DevicePixel, true, false, |
38 | | &st_base_color_space, gx_num_components_1, |
39 | | gx_init_paint_1, gx_restrict_DevicePixel, |
40 | | gx_same_concrete_space, |
41 | | gx_concretize_DevicePixel, gx_remap_concrete_DevicePixel, |
42 | | gx_default_remap_color, gx_no_install_cspace, |
43 | | gx_set_overprint_DevicePixel, |
44 | | NULL, gx_no_adjust_color_count, |
45 | | gx_serialize_DevicePixel, |
46 | | gx_cspace_is_linear_default, gx_polarity_unknown |
47 | | }; |
48 | | |
49 | | /* Create a DevicePixel color space. */ |
50 | | int |
51 | | gs_cspace_new_DevicePixel(gs_memory_t *mem, gs_color_space **ppcs, int depth) |
52 | 3.06k | { |
53 | 3.06k | gs_color_space *pcs; |
54 | | |
55 | 3.06k | switch (depth) { |
56 | 52 | case 1: |
57 | 52 | case 2: |
58 | 57 | case 4: |
59 | 3.06k | case 8: |
60 | 3.06k | case 16: |
61 | 3.06k | case 24: |
62 | 3.06k | case 32: |
63 | 3.06k | break; |
64 | 0 | default: |
65 | 0 | return_error(gs_error_rangecheck); |
66 | 3.06k | } |
67 | 3.06k | pcs = gs_cspace_alloc(mem, &gs_color_space_type_DevicePixel); |
68 | 3.06k | if (pcs == NULL) |
69 | 0 | return_error(gs_error_VMerror); |
70 | 3.06k | pcs->params.pixel.depth = depth; |
71 | 3.06k | *ppcs = pcs; |
72 | 3.06k | return 0; |
73 | 3.06k | } |
74 | | |
75 | | /* ------ Internal routines ------ */ |
76 | | |
77 | | /* Force a DevicePixel color into legal range. */ |
78 | | static void |
79 | | gx_restrict_DevicePixel(gs_client_color * pcc, const gs_color_space * pcs) |
80 | 0 | { |
81 | | /****** NOT ENOUGH BITS IN float OR frac ******/ |
82 | 0 | double pixel = pcc->paint.values[0]; |
83 | 0 | ulong max_value = (1L << pcs->params.pixel.depth) - 1; |
84 | |
|
85 | 0 | pcc->paint.values[0] = (pixel < 0 ? 0 : min(pixel, max_value)); |
86 | 0 | } |
87 | | |
88 | | /* Remap a DevicePixel color. */ |
89 | | |
90 | | static int |
91 | | gx_concretize_DevicePixel(const gs_client_color * pc, const gs_color_space * pcs, |
92 | | frac * pconc, const gs_gstate * pgs, gx_device *dev) |
93 | 0 | { |
94 | | /****** NOT ENOUGH BITS IN float OR frac ******/ |
95 | 0 | pconc[0] = (frac) (ulong) pc->paint.values[0]; |
96 | 0 | return 0; |
97 | 0 | } |
98 | | |
99 | | static int |
100 | | gx_remap_concrete_DevicePixel(const gs_color_space * pcs, const frac * pconc, |
101 | | gx_device_color * pdc, const gs_gstate * pgs, |
102 | | gx_device * dev, gs_color_select_t select, |
103 | | const cmm_dev_profile_t *dev_profile) |
104 | 0 | { |
105 | 0 | color_set_pure(pdc, pconc[0] & ((1 << dev->color_info.depth) - 1)); |
106 | 0 | return 0; |
107 | 0 | } |
108 | | |
109 | | /* DevicePixel disables overprint */ |
110 | | static int |
111 | | gx_set_overprint_DevicePixel(const gs_color_space * pcs, gs_gstate * pgs) |
112 | 0 | { |
113 | 0 | gs_overprint_params_t params = { 0 }; |
114 | |
|
115 | 0 | params.retain_any_comps = false; |
116 | 0 | params.effective_opm = pgs->color[0].effective_opm = 0; |
117 | 0 | params.is_fill_color = pgs->is_fill_color; |
118 | 0 | return gs_gstate_update_overprint(pgs, ¶ms); |
119 | 0 | } |
120 | | |
121 | | /* ---------------- Serialization. -------------------------------- */ |
122 | | |
123 | | static int |
124 | | gx_serialize_DevicePixel(const gs_color_space * pcs, stream * s) |
125 | 0 | { |
126 | 0 | const gs_device_pixel_params * p = &pcs->params.pixel; |
127 | 0 | uint n; |
128 | 0 | int code = gx_serialize_cspace_type(pcs, s); |
129 | |
|
130 | 0 | if (code < 0) |
131 | 0 | return code; |
132 | 0 | return sputs(s, (const byte *)&p->depth, sizeof(p->depth), &n); |
133 | 0 | } |