Debian Codegraph @

src/main/dither-inks.c

raw symbols SCIP
1 /*
2 *
3 * Print plug-in driver utility functions for the GIMP.
4 *
5 * Copyright 1997-2000 Michael Sweet ([email protected]) and
6 * Robert Krawitz ([email protected])
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 *
21 * Revision History:
22 *
23 * See ChangeLog
24 */
25
26 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
27 #include <config.h>cxx . . $ `<file>/config.h`/
28 #endif
29 #include <gutenprint/gutenprint.h>cxx . . $ `<file>/include/gutenprint/gutenprint.h`/
30 #include "gutenprint-internal.h"cxx . . $ `<file>/src/main/gutenprint-internal.h`/
31 #include <gutenprint/gutenprint-intl-internal.h>cxx . . $ `<file>/include/gutenprint/gutenprint-intl-internal.h`/
32 #ifdef HAVE_LIMITS_Hcxx . . $ `config.h:94:9`!
33 #include <limits.h>
34 #endif
35 #include <math.h>
36 #include <string.h>
37 #include "dither-impl.h"cxx . . $ `<file>/src/main/dither-impl.h`/
38
39 int
40 stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(stp_vars_tcxx . . $ stp_vars_t# *v, unsigned channel,
41 unsigned subchannel)
42 {
43 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
44 unsigned chan_idx;
45 if (!d)
46 return -1;
47 if (channel >= d->channel_countcxx . . $ dither#channel_count.)
48 return -1;
49 if (subchannel >= d->subchannel_countcxx . . $ dither#subchannel_count.[channel])
50 return -1;
51 chan_idx = d->channel_indexcxx . . $ dither#channel_index.[channel];
52 return chan_idx + subchannel;
53 }
54
55 unsigned char *
56 stp_dither_get_channelcxx . . $ stp_dither_get_channel(ee4943665e6fee3b).(stp_vars_tcxx . . $ stp_vars_t# *v, unsigned channel, unsigned subchannel)
57 {
58 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
59 int place = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, channel, subchannel);
60 if (place >= 0)
61 return d->channelcxx . . $ dither#channel.[place].ptrcxx . . $ dither_channel#ptr.;
62 else
63 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
64 }
65
66 static void
67 insert_channelcxx . . $ insert_channel(467bf2d1f5eb6437).(stp_vars_tcxx . . $ stp_vars_t# *v, stpi_dither_tcxx . . $ stpi_dither_t# *d, int channel)
68 {
69 unsigned oc = d->channel_countcxx . . $ dither#channel_count.;
70 int i;
71 (void)v;
72
73 d->channel_indexcxx . . $ dither#channel_index. =
74 stp_realloccxx . . $ stp_realloc(417ab160f6baadc6). (d->channel_indexcxx . . $ dither#channel_index., sizeof(unsigned) * (channel + 1));
75 d->subchannel_countcxx . . $ dither#subchannel_count. =
76 stp_realloccxx . . $ stp_realloc(417ab160f6baadc6). (d->subchannel_countcxx . . $ dither#subchannel_count., sizeof(unsigned) * (channel + 1));
77 for (i = oc; i < channel + 1; i++)
78 {
79 if (oc == 0)
80 d->channel_indexcxx . . $ dither#channel_index.[i] = 0;
81 else
82 d->channel_indexcxx . . $ dither#channel_index.[i] =
83 d->channel_indexcxx . . $ dither#channel_index.[oc - 1] + d->subchannel_countcxx . . $ dither#subchannel_count.[oc - 1];
84 d->subchannel_countcxx . . $ dither#subchannel_count.[i] = 0;
85 }
86 d->channel_countcxx . . $ dither#channel_count. = channel + 1;
87 }
88
89 void
90 stpi_dither_channel_destroycxx . . $ stpi_dither_channel_destroy(ddba87c1765ba781).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *channel)
91 {
92 int i;
93 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(channel->ink_list);
94 if (channel->errscxx . . $ dither_channel#errs.)
95 {
96 for (i = 0; i < channel->error_rowscxx . . $ dither_channel#error_rows.; i++)
97 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(channel->errs[i]);
98 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(channel->errs);
99 }
100 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(channel->ranges);
101 stp_dither_matrix_destroycxx . . $ stp_dither_matrix_destroy(68c7be79061d109b).(&(channel->pickcxx . . $ dither_channel#pick.));
102 stp_dither_matrix_destroycxx . . $ stp_dither_matrix_destroy(68c7be79061d109b).(&(channel->dithermatcxx . . $ dither_channel#dithermat.));
103 }
104
105 static void
106 initialize_channelcxx . . $ initialize_channel(9e1f5dddaee1574e).(stp_vars_tcxx . . $ stp_vars_t# *v, int channel, int subchannel)
107 {
108 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
109 int idx = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, channel, subchannel);
110 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, idx));
111 stp_shade_tcxx . . $ stp_shade_t# shade;
112 stp_dotsize_tcxx . . $ stp_dotsize_t# dot;
113 STPI_ASSERTcxx . . $ `src/main/gutenprint-internal.h:58:9`!(idx >= 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
114 memsetcxx . . $ memset(d1de1e4fb215f1c6).(dc, 0, sizeof(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t#));
115 stp_dither_matrix_clonecxx . . $ stp_dither_matrix_clone(1b0edb5d3301f384).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), &(dc->dithermatcxx . . $ dither_channel#dithermat.), 0, 0);
116 shade.dot_sizescxx . . $ stp_shade#dot_sizes. = &dot;
117 shade.valuecxx . . $ stp_shade#value. = 1.0;
118 shade.numsizescxx . . $ stp_shade#numsizes. = 1;
119 dot.bit_patterncxx . . $ stp_dotsize#bit_pattern. = 1;
120 dot.valuecxx . . $ stp_dotsize#value. = 1.0;
121 stp_dither_set_inks_fullcxx . . $ stp_dither_set_inks_full(c3fa7fa481f2d18c).(v, channel, 1, &shade, 1.0, 1.0);
122 }
123
124 static void
125 insert_subchannelcxx . . $ insert_subchannel(371769ea40547cc7).(stp_vars_tcxx . . $ stp_vars_t# *v, stpi_dither_tcxx . . $ stpi_dither_t# *d, int channel, int subchannel)
126 {
127 int i;
128 unsigned oc = d->subchannel_countcxx . . $ dither#subchannel_count.[channel];
129 unsigned increment = subchannel - oc + 1;
130 unsigned old_place = d->channel_indexcxx . . $ dither#channel_index.[channel] + oc;
131 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *nc =
132 stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t#) *
133 (d->total_channel_countcxx . . $ dither#total_channel_count. + increment));
134
135 if (d->channelcxx . . $ dither#channel.)
136 {
137 /*
138 * Copy the old channels, including all subchannels of the current
139 * channel that already existed.
140 */
141 memcpycxx . . $ memcpy(cc817cb175f282d).(nc, d->channelcxx . . $ dither#channel., sizeof(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t#) * old_place);
142 if (old_place < d->total_channel_countcxx . . $ dither#total_channel_count.)
143 /*
144 * If we're inserting a new subchannel in the middle somewhere,
145 * we need to move everything else up
146 */
147 memcpycxx . . $ memcpy(cc817cb175f282d).(nc + old_place + increment, d->channelcxx . . $ dither#channel. + old_place,
148 (sizeof(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t#) *
149 (d->total_channel_countcxx . . $ dither#total_channel_count. - old_place)));
150 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d->channelcxx . . $ dither#channel.);
151 }
152 d->channelcxx . . $ dither#channel. = nc;
153 if (channel < d->channel_countcxx . . $ dither#channel_count. - 1)
154 /* Now fix up the subchannel offsets */
155 for (i = channel + 1; i < d->channel_countcxx . . $ dither#channel_count.; i++)
156 d->channel_indexcxx . . $ dither#channel_index.[i] += increment;
157 d->subchannel_countcxx . . $ dither#subchannel_count.[channel] = subchannel + 1;
158 d->total_channel_countcxx . . $ dither#total_channel_count. += increment;
159 for (i = oc; i < oc + increment; i++)
160 initialize_channelcxx . . $ initialize_channel(9e1f5dddaee1574e).(v, channel, i);
161 }
162
163 void
164 stpi_dither_finalizecxx . . $ stpi_dither_finalize(1a97b8462f9f913c).(stp_vars_tcxx . . $ stp_vars_t# *v)
165 {
166 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
167 if (!d->finalizedcxx . . $ dither#finalized.)
168 {
169 int i;
170 unsigned rc = 1 + (unsigned) ceil(sqrt(CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d)));
171 unsigned x_n = d->dither_matrixcxx . . $ dither#dither_matrix..x_sizecxx . . $ dither_matrix_impl#x_size. / rc;
172 unsigned y_n = d->dither_matrixcxx . . $ dither#dither_matrix..y_sizecxx . . $ dither_matrix_impl#y_size. / rc;
173 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
174 {
175 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i));
176 stp_dither_matrix_clonecxx . . $ stp_dither_matrix_clone(1b0edb5d3301f384).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), &(dc->dithermatcxx . . $ dither_channel#dithermat.),
177 x_n * (i % rc), y_n * (i / rc));
178 stp_dither_matrix_clonecxx . . $ stp_dither_matrix_clone(1b0edb5d3301f384).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), &(dc->pickcxx . . $ dither_channel#pick.),
179 x_n * (i % rc), y_n * (i / rc));
180 }
181 d->finalizedcxx . . $ dither#finalized. = 1;
182 }
183 }
184
185 void
186 stp_dither_add_channelcxx . . $ stp_dither_add_channel(4bbde36c7860b58e).(stp_vars_tcxx . . $ stp_vars_t# *v, unsigned char *data,
187 unsigned channel, unsigned subchannel)
188 {
189 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
190 int idx;
191 if (channel >= d->channel_countcxx . . $ dither#channel_count.)
192 insert_channelcxx . . $ insert_channel(467bf2d1f5eb6437).(v, d, channel);
193 if (subchannel >= d->subchannel_countcxx . . $ dither#subchannel_count.[channel])
194 insert_subchannelcxx . . $ insert_subchannel(371769ea40547cc7).(v, d, channel, subchannel);
195 idx = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, channel, subchannel);
196 STPI_ASSERTcxx . . $ `src/main/gutenprint-internal.h:58:9`!(idx >= 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
197 d->channelcxx . . $ dither#channel.[idx].ptrcxx . . $ dither_channel#ptr. = data;
198 }
199
200 static void
201 stpi_dither_finalize_rangescxx . . $ stpi_dither_finalize_ranges(fa6f0c81da06cf5c).(stp_vars_tcxx . . $ stp_vars_t# *v, stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc)
202 {
203 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
204 int i;
205 unsigned lbit = dc->bit_maxcxx . . $ dither_channel#bit_max.;
206 dc->signif_bitscxx . . $ dither_channel#signif_bits. = 0;
207 while (lbit > 0)
208 {
209 dc->signif_bitscxx . . $ dither_channel#signif_bits.++;
210 lbit >>= 1;
211 }
212
213 for (i = 0; i < dc->nlevelscxx . . $ dither_channel#nlevels.; i++)
214 {
215 if (dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->bitscxx . . $ ink_defn#bits. == dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper.->bitscxx . . $ ink_defn#bits.)
216 dc->rangescxx . . $ dither_channel#ranges.[i].is_same_inkcxx . . $ dither_segment#is_same_ink. = 1;
217 else
218 dc->rangescxx . . $ dither_channel#ranges.[i].is_same_inkcxx . . $ dither_segment#is_same_ink. = 0;
219 if (dc->rangescxx . . $ dither_channel#ranges.[i].range_spancxx . . $ dither_segment#range_span. > 0 && dc->rangescxx . . $ dither_channel#ranges.[i].value_spancxx . . $ dither_segment#value_span. > 0)
220 dc->rangescxx . . $ dither_channel#ranges.[i].is_equalcxx . . $ dither_segment#is_equal. = 0;
221 else
222 dc->rangescxx . . $ dither_channel#ranges.[i].is_equalcxx . . $ dither_segment#is_equal. = 1;
223
224 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
225 " level %d value[0] %d value[1] %d range[0] %d range[1] %d\n",
226 i, dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->valuecxx . . $ ink_defn#value., dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper.->valuecxx . . $ ink_defn#value.,
227 dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->rangecxx . . $ ink_defn#range., dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper.->rangecxx . . $ ink_defn#range.);
228 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
229 " bits[0] %d bits[1] %d\n",
230 dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->bitscxx . . $ ink_defn#bits., dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper.->bitscxx . . $ ink_defn#bits.);
231 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
232 " rangespan %d valuespan %d same_ink %d equal %d\n",
233 dc->rangescxx . . $ dither_channel#ranges.[i].range_spancxx . . $ dither_segment#range_span., dc->rangescxx . . $ dither_channel#ranges.[i].value_spancxx . . $ dither_segment#value_span.,
234 dc->rangescxx . . $ dither_channel#ranges.[i].is_same_inkcxx . . $ dither_segment#is_same_ink., dc->rangescxx . . $ dither_channel#ranges.[i].is_equalcxx . . $ dither_segment#is_equal.);
235 if (i > 0 && dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->rangecxx . . $ ink_defn#range. >= d->adaptive_limitcxx . . $ dither#adaptive_limit.)
236 {
237 d->adaptive_limitcxx . . $ dither#adaptive_limit. = dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower.->rangecxx . . $ ink_defn#range. + 1;
238 if (d->adaptive_limitcxx . . $ dither#adaptive_limit. > 65535)
239 d->adaptive_limitcxx . . $ dither#adaptive_limit. = 65535;
240 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v, "Setting adaptive limit to %d\n",
241 d->adaptive_limitcxx . . $ dither#adaptive_limit.);
242 }
243 }
244 for (i = 0; i <= dc->nlevelscxx . . $ dither_channel#nlevels.; i++)
245 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
246 " ink_list[%d] range %d value %d bits %d\n",
247 i, dc->ink_listcxx . . $ dither_channel#ink_list.[i].rangecxx . . $ ink_defn#range.,
248 dc->ink_listcxx . . $ dither_channel#ink_list.[i].valuecxx . . $ ink_defn#value., dc->ink_listcxx . . $ dither_channel#ink_list.[i].bitscxx . . $ ink_defn#bits.);
249 if (dc->nlevelscxx . . $ dither_channel#nlevels. == 1 && dc->rangescxx . . $ dither_channel#ranges.[0].uppercxx . . $ dither_segment#upper.->bitscxx . . $ ink_defn#bits. == 1)
250 dc->very_fastcxx . . $ dither_channel#very_fast. = 1;
251 else
252 dc->very_fastcxx . . $ dither_channel#very_fast. = 0;
253
254 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
255 " bit_max %d signif_bits %d\n", dc->bit_maxcxx . . $ dither_channel#bit_max., dc->signif_bitscxx . . $ dither_channel#signif_bits.);
256 }
257
258 static void
259 stpi_dither_set_rangescxx . . $ stpi_dither_set_ranges(137559fd4b3c9b49).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, const stp_shade_tcxx . . $ stp_shade_t# *shade,
260 double density, double darkness)
261 {
262 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
263 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, color));
264 const stp_dotsize_tcxx . . $ stp_dotsize_t# *ranges = shade->dot_sizescxx . . $ stp_shade#dot_sizes.;
265 int nlevels = shade->numsizescxx . . $ stp_shade#numsizes.;
266 int i;
267
268 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(dc->ranges);
269 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(dc->ink_list);
270
271 dc->nlevelscxx . . $ dither_channel#nlevels. = nlevels > 1 ? nlevels + 1 : nlevels;
272 dc->rangescxx . . $ dither_channel#ranges. = (stpi_dither_segment_tcxx . . $ stpi_dither_segment_t# *)
273 stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(dc->nlevelscxx . . $ dither_channel#nlevels. * sizeof(stpi_dither_segment_tcxx . . $ stpi_dither_segment_t#));
274 dc->ink_listcxx . . $ dither_channel#ink_list. = (stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *)
275 stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).((dc->nlevelscxx . . $ dither_channel#nlevels. + 1) * sizeof(stpi_ink_defn_tcxx . . $ stpi_ink_defn_t#));
276 dc->bit_maxcxx . . $ dither_channel#bit_max. = 0;
277 dc->densitycxx . . $ dither_channel#density. = density * 65535;
278 dc->darknesscxx . . $ dither_channel#darkness. = darkness;
279 stp_init_debug_messagescxx . . $ stp_init_debug_messages(1a97b8462f9f913c).(v);
280 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
281 "stpi_dither_set_ranges channel %d nlevels %d density %f darkness %f\n",
282 color, nlevels, density, darkness);
283 for (i = 0; i < nlevels; i++)
284 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
285 " level %d value %f pattern %x\n", i,
286 ranges[i].valuecxx . . $ stp_dotsize#value., ranges[i].bit_patterncxx . . $ stp_dotsize#bit_pattern.);
287 dc->rangescxx . . $ dither_channel#ranges.[0].lowercxx . . $ dither_segment#lower. = &dc->ink_listcxx . . $ dither_channel#ink_list.[0];
288 dc->rangescxx . . $ dither_channel#ranges.[0].uppercxx . . $ dither_segment#upper. = &dc->ink_listcxx . . $ dither_channel#ink_list.[1];
289 dc->ink_listcxx . . $ dither_channel#ink_list.[0].rangecxx . . $ ink_defn#range. = 0;
290 dc->ink_listcxx . . $ dither_channel#ink_list.[0].valuecxx . . $ ink_defn#value. = 0;
291 dc->ink_listcxx . . $ dither_channel#ink_list.[0].bitscxx . . $ ink_defn#bits. = 0;
292 if (nlevels == 1)
293 dc->ink_listcxx . . $ dither_channel#ink_list.[1].rangecxx . . $ ink_defn#range. = 65535;
294 else
295 dc->ink_listcxx . . $ dither_channel#ink_list.[1].rangecxx . . $ ink_defn#range. = ranges[0].valuecxx . . $ stp_dotsize#value. * 65535.0 * density;
296 if (dc->ink_listcxx . . $ dither_channel#ink_list.[1].rangecxx . . $ ink_defn#range. > 65535)
297 dc->ink_listcxx . . $ dither_channel#ink_list.[1].rangecxx . . $ ink_defn#range. = 65535;
298 dc->ink_listcxx . . $ dither_channel#ink_list.[1].valuecxx . . $ ink_defn#value. = ranges[0].valuecxx . . $ stp_dotsize#value. * 65535.0;
299 if (dc->ink_listcxx . . $ dither_channel#ink_list.[1].valuecxx . . $ ink_defn#value. > 65535)
300 dc->ink_listcxx . . $ dither_channel#ink_list.[1].valuecxx . . $ ink_defn#value. = 65535;
301 dc->ink_listcxx . . $ dither_channel#ink_list.[1].bitscxx . . $ ink_defn#bits. = ranges[0].bit_patterncxx . . $ stp_dotsize#bit_pattern.;
302 if (ranges[0].bit_patterncxx . . $ stp_dotsize#bit_pattern. > dc->bit_maxcxx . . $ dither_channel#bit_max.)
303 dc->bit_maxcxx . . $ dither_channel#bit_max. = ranges[0].bit_patterncxx . . $ stp_dotsize#bit_pattern.;
304 dc->rangescxx . . $ dither_channel#ranges.[0].range_spancxx . . $ dither_segment#range_span. = dc->rangescxx . . $ dither_channel#ranges.[0].uppercxx . . $ dither_segment#upper.->rangecxx . . $ ink_defn#range.;
305 dc->rangescxx . . $ dither_channel#ranges.[0].value_spancxx . . $ dither_segment#value_span. = dc->rangescxx . . $ dither_channel#ranges.[0].uppercxx . . $ dither_segment#upper.->valuecxx . . $ ink_defn#value.;
306 if (dc->nlevelscxx . . $ dither_channel#nlevels. > 1)
307 {
308 for (i = 1; i < nlevels; i++)
309 {
310 int l = i + 1;
311 dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower. = &dc->ink_listcxx . . $ dither_channel#ink_list.[i];
312 dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper. = &dc->ink_listcxx . . $ dither_channel#ink_list.[l];
313
314 dc->ink_listcxx . . $ dither_channel#ink_list.[l].rangecxx . . $ ink_defn#range. =
315 (ranges[i].valuecxx . . $ stp_dotsize#value. + ranges[i].valuecxx . . $ stp_dotsize#value.) * 32768.0 * density;
316 if (dc->ink_listcxx . . $ dither_channel#ink_list.[l].rangecxx . . $ ink_defn#range. > 65535)
317 dc->ink_listcxx . . $ dither_channel#ink_list.[l].rangecxx . . $ ink_defn#range. = 65535;
318 dc->ink_listcxx . . $ dither_channel#ink_list.[l].valuecxx . . $ ink_defn#value. = ranges[i].valuecxx . . $ stp_dotsize#value. * 65535.0;
319 if (dc->ink_listcxx . . $ dither_channel#ink_list.[l].valuecxx . . $ ink_defn#value. > 65535)
320 dc->ink_listcxx . . $ dither_channel#ink_list.[l].valuecxx . . $ ink_defn#value. = 65535;
321 dc->ink_listcxx . . $ dither_channel#ink_list.[l].bitscxx . . $ ink_defn#bits. = ranges[i].bit_patterncxx . . $ stp_dotsize#bit_pattern.;
322 if (ranges[i].bit_patterncxx . . $ stp_dotsize#bit_pattern. > dc->bit_maxcxx . . $ dither_channel#bit_max.)
323 dc->bit_maxcxx . . $ dither_channel#bit_max. = ranges[i].bit_patterncxx . . $ stp_dotsize#bit_pattern.;
324 dc->rangescxx . . $ dither_channel#ranges.[i].range_spancxx . . $ dither_segment#range_span. =
325 dc->ink_listcxx . . $ dither_channel#ink_list.[l].rangecxx . . $ ink_defn#range. - dc->ink_listcxx . . $ dither_channel#ink_list.[i].rangecxx . . $ ink_defn#range.;
326 dc->rangescxx . . $ dither_channel#ranges.[i].value_spancxx . . $ dither_segment#value_span. =
327 dc->ink_listcxx . . $ dither_channel#ink_list.[l].valuecxx . . $ ink_defn#value. - dc->ink_listcxx . . $ dither_channel#ink_list.[i].valuecxx . . $ ink_defn#value.;
328 }
329 dc->rangescxx . . $ dither_channel#ranges.[i].lowercxx . . $ dither_segment#lower. = &dc->ink_listcxx . . $ dither_channel#ink_list.[i];
330 dc->rangescxx . . $ dither_channel#ranges.[i].uppercxx . . $ dither_segment#upper. = &dc->ink_listcxx . . $ dither_channel#ink_list.[i+1];
331 dc->ink_listcxx . . $ dither_channel#ink_list.[i+1] = dc->ink_listcxx . . $ dither_channel#ink_list.[i];
332 dc->ink_listcxx . . $ dither_channel#ink_list.[i+1].rangecxx . . $ ink_defn#range. = 65535;
333 dc->rangescxx . . $ dither_channel#ranges.[i].range_spancxx . . $ dither_segment#range_span. =
334 dc->ink_listcxx . . $ dither_channel#ink_list.[i+1].rangecxx . . $ ink_defn#range. - dc->ink_listcxx . . $ dither_channel#ink_list.[i].rangecxx . . $ ink_defn#range.;
335 dc->rangescxx . . $ dither_channel#ranges.[i].value_spancxx . . $ dither_segment#value_span. =
336 dc->ink_listcxx . . $ dither_channel#ink_list.[i+1].valuecxx . . $ ink_defn#value. - dc->ink_listcxx . . $ dither_channel#ink_list.[i].valuecxx . . $ ink_defn#value.;
337 }
338 stpi_dither_finalize_rangescxx . . $ stpi_dither_finalize_ranges(fa6f0c81da06cf5c).(v, dc);
339 stp_flush_debug_messagescxx . . $ stp_flush_debug_messages(1a97b8462f9f913c).(v);
340 }
341
342 void
343 stp_dither_set_inks_simplecxx . . $ stp_dither_set_inks_simple(4254c7b92a2614d5).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, int nlevels,
344 const double *levels, double density,
345 double darkness)
346 {
347 stp_shade_tcxx . . $ stp_shade_t# s;
348 stp_dotsize_tcxx . . $ stp_dotsize_t# *d = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(nlevels * sizeof(stp_dotsize_tcxx . . $ stp_dotsize_t#));
349 int i;
350 s.dot_sizescxx . . $ stp_shade#dot_sizes. = d;
351 s.valuecxx . . $ stp_shade#value. = 65535.0;
352 s.numsizescxx . . $ stp_shade#numsizes. = nlevels;
353
354 for (i = 0; i < nlevels; i++)
355 {
356 d[i].bit_patterncxx . . $ stp_dotsize#bit_pattern. = i + 1;
357 d[i].valuecxx . . $ stp_dotsize#value. = levels[i];
358 }
359 stp_dither_set_inks_fullcxx . . $ stp_dither_set_inks_full(c3fa7fa481f2d18c).(v, color, 1, &s, density, darkness);
360 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(d);
361 }
362
363 void
364 stp_dither_set_inks_fullcxx . . $ stp_dither_set_inks_full(c3fa7fa481f2d18c).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, int nshades,
365 const stp_shade_tcxx . . $ stp_shade_t# *shades, double density,
366 double darkness)
367 {
368 int i;
369 int idx;
370
371 stp_channel_reset_channelcxx . . $ stp_channel_reset_channel(c8b26ae77f1a10bd).(v, color);
372
373 for (i = nshades - 1; i >= 0; i--)
374 {
375 int subchannel = nshades - i - 1;
376 idx = stpi_dither_translate_channelcxx . . $ stpi_dither_translate_channel(5ddaaec62fc0a803).(v, color, subchannel);
377 STPI_ASSERTcxx . . $ `src/main/gutenprint-internal.h:58:9`!(idx >= 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
378
379 stp_channel_addcxx . . $ stp_channel_add(be410e6e969dd53f).(v, color, subchannel, shades[i].valuecxx . . $ stp_shade#value.);
380 if (idx >= 0)
381 stpi_dither_set_rangescxx . . $ stpi_dither_set_ranges(137559fd4b3c9b49).(v, idx, &shades[i], density,
382 shades[i].valuecxx . . $ stp_shade#value. * darkness);
383 stp_dprintfcxx . . $ stp_dprintf(13526ca24396f6ac).(STP_DBG_INKcxx . . $ `include/gutenprint/util.h:168:9`!, v,
384 " shade %d value %f\n",
385 i, shades[i].valuecxx . . $ stp_shade#value.);
386 }
387 }
388
389 void
390 stp_dither_set_inkscxx . . $ stp_dither_set_inks(9d9d4be92768298a).(stp_vars_tcxx . . $ stp_vars_t# *v, int color, double density, double darkness,
391 int nshades, const double *svalues,
392 int ndotsizes, const double *dvalues)
393 {
394 int i, j;
395 stp_shade_tcxx . . $ stp_shade_t# *shades = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(stp_shade_tcxx . . $ stp_shade_t#) * nshades);
396 stp_dotsize_tcxx . . $ stp_dotsize_t# *dotsizes = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(stp_dotsize_tcxx . . $ stp_dotsize_t#) * ndotsizes);
397 j = 0;
398 for (i = 0; i < ndotsizes; i++)
399 {
400 /* Skip over any zero-valued dot sizes */
401 if (dvalues[i] > 0)
402 {
403 dotsizes[j].valuecxx . . $ stp_dotsize#value. = dvalues[i];
404 dotsizes[j].bit_patterncxx . . $ stp_dotsize#bit_pattern. = i + 1;
405 j++;
406 }
407 }
408 for (i = 0; i < nshades; i++)
409 {
410 shades[i].valuecxx . . $ stp_shade#value. = svalues[i];
411 shades[i].numsizescxx . . $ stp_shade#numsizes. = j;
412 shades[i].dot_sizescxx . . $ stp_shade#dot_sizes. = dotsizes;
413 }
414 stp_dither_set_inks_fullcxx . . $ stp_dither_set_inks_full(c3fa7fa481f2d18c).(v, color, nshades, shades, density, darkness);
415 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(dotsizes);
416 stp_freecxx . . $ stp_free(5d22bdacc48458e8).(shades);
417 }