Debian Codegraph @

src/main/dither-eventone.c

raw symbols SCIP
1 /*
2 *
3 * EvenTone dither implementation for Gimp-Print
4 *
5 * Copyright 2002-2003 Mark Tomlinson ([email protected])
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 *
20 * This code uses the Eventone dither algorithm. This is described
21 * at the website http://www.artofcode.com/eventone/
22 * This algorithm is covered by US Patents 5,055,942 and 5,917,614
23 * and was invented by Raph Levien <[email protected]>
24 * It was made available to be used free of charge in GPL-licensed
25 */
26
27 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:411:9`!
28 #include <config.h>cxx . . $ `<file>/config.h`/
29 #endif
30 #include <gutenprint/gutenprint.h>cxx . . $ `<file>/include/gutenprint/gutenprint.h`/
31 #include "gutenprint-internal.h"cxx . . $ `<file>/src/main/gutenprint-internal.h`/
32 #include <gutenprint/gutenprint-intl-internal.h>cxx . . $ `<file>/include/gutenprint/gutenprint-intl-internal.h`/
33 #include <string.h>
34 #include <math.h>
35 #include <limits.h>
36 #include "dither-impl.h"cxx . . $ `<file>/src/main/dither-impl.h`/
37 #include "dither-inlined-functions.h"cxx . . $ `<file>/src/main/dither-inlined-functions.h`/
38
39 typedef structcxx . . $ $anonymous_type_6909a6ea18c11111_0#
40 {
41 int dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx.;
42 int dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy.;
43 int r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq.;
44 } distance_tcxx . . $ distance_t#;
45
46 typedef structcxx . . $ $anonymous_type_6909a6ea18c11111_1#
47 {
48 int d2xcxx . . $ $anonymous_type_6909a6ea18c11111_1#d2x.;
49 int d2ycxx . . $ $anonymous_type_6909a6ea18c11111_1#d2y.;
50 distance_tcxx . . $ distance_t# d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
51 int aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#aspect.;
52 int unitone_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#unitone_aspect.;
53 int physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect.;
54 int diff_factorcxx . . $ $anonymous_type_6909a6ea18c11111_1#diff_factor.;
55 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.;
56 double transitioncxx . . $ $anonymous_type_6909a6ea18c11111_1#transition.; /* Exponential scaling for transition region */
57 stp_dither_matrix_impl_tcxx . . $ stp_dither_matrix_impl_t# transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.;
58 } eventone_tcxx . . $ eventone_t#;
59
60 typedef struct shade_segmentcxx . . $ shade_segment#
61 {
62 distance_tcxx . . $ distance_t# discxx . . $ shade_segment#dis.;
63 distance_tcxx . . $ distance_t# *et_discxx . . $ shade_segment#et_dis.;
64 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# lowercxx . . $ shade_segment#lower.;
65 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# uppercxx . . $ shade_segment#upper.;
66 int share_this_channelcxx . . $ shade_segment#share_this_channel.;
67 } shade_distance_tcxx . . $ shade_distance_t#;
68
69
70 #define EVEN_C1cxx . . $ `src/main/dither-eventone.c:70:9`! 256
71 #define EVEN_C2cxx . . $ `src/main/dither-eventone.c:71:9`! (EVEN_C1cxx . . $ `src/main/dither-eventone.c:70:9`! * sqrt(3.0) / 2.0)
72 #define UNITONE_C1cxx . . $ `src/main/dither-eventone.c:72:9`! 16384
73 #define UNITONE_C2cxx . . $ `src/main/dither-eventone.c:73:9`! (UNITONE_C1cxx . . $ `src/main/dither-eventone.c:72:9`! * sqrt(3.0) / 2.0)
74
75 static void
76 free_eventone_datacxx . . $ free_eventone_data(eba3149742ad601b).(stpi_dither_tcxx . . $ stpi_dither_t# *d)
77 {
78 int i;
79 eventone_tcxx . . $ eventone_t# *et = (eventone_tcxx . . $ eventone_t# *) (d->aux_datacxx . . $ dither#aux_data.);
80 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
81 {
82 if (CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).aux_datacxx . . $ dither_channel#aux_data.)
83 {
84 shade_distance_tcxx . . $ shade_distance_t# *shade = (shade_distance_tcxx . . $ shade_distance_t# *) CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d,i).aux_datacxx . . $ dither_channel#aux_data.;
85 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(shade->et_dis);
86 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).aux_data);
87 }
88 }
89 if (et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.)
90 {
91 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.;
92 shade_distance_tcxx . . $ shade_distance_t# *shade = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
93 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(shade->et_dis);
94 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(dc->aux_data);
95 stpi_dither_channel_destroycxx . . $ stpi_dither_channel_destroy(ddba87c1765ba781).(dc);
96 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(et->dummy_channel);
97 }
98 if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!)
99 stp_dither_matrix_destroycxx . . $ stp_dither_matrix_destroy(68c7be79061d109b).(&(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.));
100 STP_SAFE_FREEcxx . . $ `include/gutenprint/util.h:210:9`!(et);
101 }
102
103 static void
104 et_setupcxx . . $ et_setup(eba3149742ad601b).(stpi_dither_tcxx . . $ stpi_dither_t# *d)
105 {
106 int size = 2 * MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`! + ((d->dst_widthcxx . . $ dither#dst_width. + 7) & ~7);
107 static const int diff_factors[] = {1, 10, 16, 23, 32};
108 eventone_tcxx . . $ eventone_t# *et = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(eventone_tcxx . . $ eventone_t#));
109 int xa, ya;
110 int i;
111 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
112 {
113 CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).error_rowscxx . . $ dither_channel#error_rows. = 1;
114 CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).errscxx . . $ dither_channel#errs. = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(1 * sizeof(int *));
115 CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).errscxx . . $ dither_channel#errs.[0] = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(size * sizeof(int));
116 }
117 if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!)
118 {
119 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t#));
120 stp_dither_matrix_clonecxx . . $ stp_dither_matrix_clone(1b0edb5d3301f384).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), &(dc->dithermatcxx . . $ dither_channel#dithermat.), 0, 0);
121 et->transitioncxx . . $ $anonymous_type_6909a6ea18c11111_1#transition. = 0.7;
122 stp_dither_matrix_destroycxx . . $ stp_dither_matrix_destroy(68c7be79061d109b).(&(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.));
123 stp_dither_matrix_copycxx . . $ stp_dither_matrix_copy(c86f8c2fec3b92f5).(&(d->dither_matrixcxx . . $ dither#dither_matrix.), &(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.));
124 stp_dither_matrix_scale_exponentiallycxx . . $ stp_dither_matrix_scale_exponentially(6c2f9d30bd1a050e).(&(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.), et->transitioncxx . . $ $anonymous_type_6909a6ea18c11111_1#transition.);
125 stp_dither_matrix_clonecxx . . $ stp_dither_matrix_clone(1b0edb5d3301f384).(&(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.), &(dc->pickcxx . . $ dither_channel#pick.), 0, 0);
126 dc->error_rowscxx . . $ dither_channel#error_rows. = 1;
127 dc->errscxx . . $ dither_channel#errs. = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(1 * sizeof(int *));
128 dc->errscxx . . $ dither_channel#errs.[0] = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(size * sizeof(int));
129 et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel. = dc;
130 }
131
132 xa = d->x_aspectcxx . . $ dither#x_aspect. / d->y_aspectcxx . . $ dither#y_aspect.;
133 if (xa == 0)
134 xa = 1;
135 et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq..dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx. = xa * xa;
136 et->d2xcxx . . $ $anonymous_type_6909a6ea18c11111_1#d2x. = 2 * et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq..dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx.;
137
138 ya = d->y_aspectcxx . . $ dither#y_aspect. / d->x_aspectcxx . . $ dither#x_aspect.;
139 if (ya == 0)
140 ya = 1;
141 et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq..dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy. = ya * ya;
142 et->d2ycxx . . $ $anonymous_type_6909a6ea18c11111_1#d2y. = 2 * et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq..dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy.;
143
144 et->aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#aspect. = EVEN_C2cxx . . $ `src/main/dither-eventone.c:71:9`! / (xa * ya);
145 et->unitone_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#unitone_aspect. = UNITONE_C2cxx . . $ `src/main/dither-eventone.c:73:9`! / (xa * ya);
146 et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. = 0;
147
148 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
149 {
150 int x;
151 shade_distance_tcxx . . $ shade_distance_t# *shade = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(shade_distance_tcxx . . $ shade_distance_t#));
152 shade->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
153 shade->et_discxx . . $ shade_segment#et_dis. = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(distance_tcxx . . $ distance_t#) * d->dst_widthcxx . . $ dither#dst_width.);
154 if (CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).darknesscxx . . $ dither_channel#darkness. > .1)
155 shade->share_this_channelcxx . . $ shade_segment#share_this_channel. = 1;
156 else
157 shade->share_this_channelcxx . . $ shade_segment#share_this_channel. = 0;
158 for (x = 0; x < d->dst_widthcxx . . $ dither#dst_width.; x++)
159 shade->et_discxx . . $ shade_segment#et_dis.[x] = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
160 CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).aux_datacxx . . $ dither_channel#aux_data. = shade;
161 }
162 if (et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.)
163 {
164 int x;
165 shade_distance_tcxx . . $ shade_distance_t# *shade = stp_zalloccxx . . $ stp_zalloc(bfcfa4d6b7f7ef64).(sizeof(shade_distance_tcxx . . $ shade_distance_t#));
166 shade->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
167 shade->et_discxx . . $ shade_segment#et_dis. = stp_malloccxx . . $ stp_malloc(bfcfa4d6b7f7ef64).(sizeof(distance_tcxx . . $ distance_t#) * d->dst_widthcxx . . $ dither#dst_width.);
168 for (x = 0; x < d->dst_widthcxx . . $ dither#dst_width.; x++)
169 shade->et_discxx . . $ shade_segment#et_dis.[x] = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
170 et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.->aux_datacxx . . $ dither_channel#aux_data. = shade;
171 }
172
173 et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. = d->y_aspectcxx . . $ dither#y_aspect. / d->x_aspectcxx . . $ dither#x_aspect.;
174 if (et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. >= 4)
175 et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. = 4;
176 else if (et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. >= 2)
177 et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. = 2;
178 else et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect. = 1;
179
180 et->diff_factorcxx . . $ $anonymous_type_6909a6ea18c11111_1#diff_factor. = diff_factors[et->physical_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#physical_aspect.];
181
182 d->aux_datacxx . . $ dither#aux_data. = et;
183 d->aux_freefunccxx . . $ dither#aux_freefunc. = free_eventone_datacxx . . $ free_eventone_data(eba3149742ad601b).;
184 }
185
186 static int
187 et_initializercxx . . $ et_initializer(346a1ce8e41bd438).(stpi_dither_tcxx . . $ stpi_dither_t# *d, int duplicate_line, int zero_mask)
188 {
189 int i;
190 eventone_tcxx . . $ eventone_t# *et;
191 if (!d->aux_datacxx . . $ dither#aux_data.)
192 et_setupcxx . . $ et_setup(eba3149742ad601b).(d);
193
194 et = (eventone_tcxx . . $ eventone_t# *) (d->aux_datacxx . . $ dither#aux_data.);
195 if (!duplicate_line)
196 {
197 if ((zero_mask & ((1 << CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d)) - 1)) !=
198 ((1 << CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d)) - 1))
199 d->last_line_was_emptycxx . . $ dither#last_line_was_empty. = 0;
200 else
201 d->last_line_was_emptycxx . . $ dither#last_line_was_empty.++;
202 }
203 else if (d->last_line_was_emptycxx . . $ dither#last_line_was_empty.)
204 d->last_line_was_emptycxx . . $ dither#last_line_was_empty.++;
205
206 if (d->last_line_was_emptycxx . . $ dither#last_line_was_empty. >= 5)
207 return 0;
208 else if (d->last_line_was_emptycxx . . $ dither#last_line_was_empty. == 4)
209 {
210 if (et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.)
211 memsetcxx . . $ memset(d1de1e4fb215f1c6).(et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.->errscxx . . $ dither_channel#errs.[0], 0, d->dst_widthcxx . . $ dither#dst_width. * sizeof(int));
212 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
213 memsetcxx . . $ memset(d1de1e4fb215f1c6).(CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).errscxx . . $ dither_channel#errs.[0], 0, d->dst_widthcxx . . $ dither#dst_width. * sizeof(int));
214 return 0;
215 }
216 for (i = 0; i < CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d); i++)
217 CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).vcxx . . $ dither_channel#v. = 0;
218 if (et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.)
219 et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.->vcxx . . $ dither_channel#v. = 0;
220 return 1;
221 }
222
223 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! void
224 advance_eventone_precxx . . $ advance_eventone_pre(9927a9af69697026).(shade_distance_tcxx . . $ shade_distance_t# *sp, eventone_tcxx . . $ eventone_t# *et, int x)
225 {
226 distance_tcxx . . $ distance_t# *etd = &sp->et_discxx . . $ shade_segment#et_dis.[x];
227 int t = sp->discxx . . $ shade_segment#dis..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. + sp->discxx . . $ shade_segment#dis..dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx.;
228 if (t <= etd->r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq.)
229 { /* Do eventone calculations */
230 sp->discxx . . $ shade_segment#dis..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. = t; /* Nearest pixel same as last one */
231 sp->discxx . . $ shade_segment#dis..dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx. += et->d2xcxx . . $ $anonymous_type_6909a6ea18c11111_1#d2x.;
232 }
233 else
234 sp->discxx . . $ shade_segment#dis. = *etd; /* Nearest pixel is from a previous line */
235 }
236
237 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! void
238 eventone_updatecxx . . $ eventone_update(c04982bad3b6240a).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, eventone_tcxx . . $ eventone_t# *et,
239 int x, int direction)
240 {
241 shade_distance_tcxx . . $ shade_distance_t# *sp = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
242 distance_tcxx . . $ distance_t# *etd = &sp->et_discxx . . $ shade_segment#et_dis.[x];
243 int t = etd->r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. + etd->dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy.; /* r^2 from dot above */
244 int u = sp->discxx . . $ shade_segment#dis..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. + sp->discxx . . $ shade_segment#dis..dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy.; /* r^2 from dot on this line */
245 (void)direction;
246
247 if (u < t)
248 { /* If dot from this line is close */
249 t = u; /* Use it instead */
250 etd->dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx. = sp->discxx . . $ shade_segment#dis..dxcxx . . $ $anonymous_type_6909a6ea18c11111_0#dx.;
251 etd->dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy. = sp->discxx . . $ shade_segment#dis..dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy.;
252 }
253 etd->dycxx . . $ $anonymous_type_6909a6ea18c11111_0#dy. += et->d2ycxx . . $ $anonymous_type_6909a6ea18c11111_1#d2y.;
254
255 if (t > 65535)
256 t = 65535; /* Do some hard limiting */
257 etd->r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. = t;
258 }
259
260 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! void
261 diffuse_errorcxx . . $ diffuse_error(c04982bad3b6240a).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, eventone_tcxx . . $ eventone_t# *et, int x, int direction)
262 {
263 /*
264 * Tests to date show that the second diffusion pattern works better
265 * than the first in most cases. The previous code is being left here
266 * in case it is later determined that the original code works better.
267 * -- rlk 20031101
268 */
269 #if 0
270 /* int fraction = (dc->v + (et->diff_factor>>1)) / et->diff_factor; */
271 int frac_2 = dc->v + dc->v;
272 int frac_3 = frac_2 + dc->v;
273 dc->errs[0][x + MAX_SPREAD] = frac_3;
274 dc->errs[0][x + MAX_SPREAD - direction] += frac_2;
275 dc->v -= (frac_2 + frac_3) / 16;
276 #else
277 dc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`!] = dc->vcxx . . $ dither_channel#v. * 3;
278 dc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`! - direction] += dc->vcxx . . $ dither_channel#v. * 5;
279 dc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`! - (direction * 2)] += dc->vcxx . . $ dither_channel#v. * 1;
280 dc->vcxx . . $ dither_channel#v. -= dc->vcxx . . $ dither_channel#v. * 9 / 16;
281 #endif
282 (void)et;
283 }
284
285 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! int
286 eventone_adjustcxx . . $ eventone_adjust(1c687df84ca48782).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, eventone_tcxx . . $ eventone_t# *et, int dither_point,
287 unsigned int desired)
288 {
289 if (dither_point <= 0)
290 return 0;
291 else if (dither_point >= 65535)
292 return 65535;
293 if (desired == 0)
294 dither_point = 0;
295 else
296 {
297 shade_distance_tcxx . . $ shade_distance_t# *shade = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
298 dither_point += shade->discxx . . $ shade_segment#dis..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. * et->aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#aspect. - (EVEN_C1cxx . . $ `src/main/dither-eventone.c:70:9`! * 65535) / desired;
299 if (dither_point > 65535)
300 dither_point = 65535;
301 else if (dither_point < 0)
302 dither_point = 0;
303 }
304 return dither_point;
305 }
306
307 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! int
308 unitone_adjustcxx . . $ unitone_adjust(1c687df84ca48782).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, eventone_tcxx . . $ eventone_t# *et,
309 int dither_point, unsigned int desired)
310 {
311 if (dither_point <= 0)
312 return INT_MINcxx . . $ `<external>/67164224788392828/limits.h:118:9`!;
313 else if (dither_point >= 65535)
314 return dither_point;
315 if (desired == 0)
316 dither_point = INT_MINcxx . . $ `<external>/67164224788392828/limits.h:118:9`!;
317 else
318 {
319 shade_distance_tcxx . . $ shade_distance_t# *shade = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
320 dither_point += shade->discxx . . $ shade_segment#dis..r_sqcxx . . $ $anonymous_type_6909a6ea18c11111_0#r_sq. * et->unitone_aspectcxx . . $ $anonymous_type_6909a6ea18c11111_1#unitone_aspect. -
321 (UNITONE_C1cxx . . $ `src/main/dither-eventone.c:72:9`! * 65535u) / desired;
322 }
323 return dither_point;
324 }
325
326
327 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! void
328 find_segmentcxx . . $ find_segment(8a962c9e6452dab0).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, unsigned inkval,
329 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *lower, stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *upper)
330 {
331 lower->rangecxx . . $ ink_defn#range. = 0;
332 lower->bitscxx . . $ ink_defn#bits. = 0;
333
334 if (dc->nlevelscxx . . $ dither_channel#nlevels. == 1)
335 {
336 upper->bitscxx . . $ ink_defn#bits. = dc->ink_listcxx . . $ dither_channel#ink_list.[1].bitscxx . . $ ink_defn#bits.;
337 upper->rangecxx . . $ ink_defn#range. = dc->ink_listcxx . . $ dither_channel#ink_list.[1].valuecxx . . $ ink_defn#value.;
338 }
339 else
340 {
341 int i;
342 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *ip;
343
344 for (i=0, ip = dc->ink_listcxx . . $ dither_channel#ink_list.; i < dc->nlevelscxx . . $ dither_channel#nlevels. - 1; i++, ip++)
345 {
346 if (ip->valuecxx . . $ ink_defn#value. > inkval)
347 break;
348 lower->bitscxx . . $ ink_defn#bits. = ip->bitscxx . . $ ink_defn#bits.;
349 lower->rangecxx . . $ ink_defn#range. = ip->valuecxx . . $ ink_defn#value.;
350 }
351
352 upper->bitscxx . . $ ink_defn#bits. = ip->bitscxx . . $ ink_defn#bits.;
353 upper->rangecxx . . $ ink_defn#range. = ip->valuecxx . . $ ink_defn#value.;
354 }
355 }
356
357 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! int
358 find_segment_and_ditherpointcxx . . $ find_segment_and_ditherpoint(145e816d347aa4d5).(stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc, unsigned inkval,
359 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *lower, stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *upper)
360 {
361 find_segmentcxx . . $ find_segment(8a962c9e6452dab0).(dc, inkval, lower, upper);
362 if (inkval <= lower->rangecxx . . $ ink_defn#range.)
363 return 0;
364 else if (inkval >= upper->rangecxx . . $ ink_defn#range.)
365 return 65535;
366 else
367 return (65535u * (inkval - lower->rangecxx . . $ ink_defn#range.)) / (upper->rangecxx . . $ ink_defn#range. - lower->rangecxx . . $ ink_defn#range.);
368 }
369
370 static inlinecxx . . $ `src/main/dither-impl.h:41:9`! void
371 print_inkcxx . . $ print_ink(21a3a45949c63496).(stpi_dither_tcxx . . $ stpi_dither_t# *d, unsigned char *tptr, const stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *ink,
372 unsigned char bit, int length)
373 {
374 int j;
375
376 if (tptr != 0)
377 {
378 tptr += d->ptr_offsetcxx . . $ dither#ptr_offset.;
379 switch(ink->bitscxx . . $ ink_defn#bits.)
380 {
381 case 1:
382 tptr[0] |= bit;
383 return;
384 case 2:
385 tptr[length] |= bit;
386 return;
387 case 3:
388 tptr[0] |= bit;
389 tptr[length] |= bit;
390 return;
391 default:
392 for (j=1; j <= ink->bitscxx . . $ ink_defn#bits.; j+=j, tptr += length)
393 {
394 if (j & ink->bitscxx . . $ ink_defn#bits.)
395 *tptr |= bit;
396 }
397 return;
398 }
399 }
400 }
401
402 void
403 stpi_dither_etcxx . . $ stpi_dither_et(525e4b1c00087d37).(stp_vars_tcxx . . $ stp_vars_t# *v,
404 int row,
405 const unsigned short *raw,
406 int duplicate_line,
407 int zero_mask,
408 const unsigned char *mask)
409 {
410 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
411 eventone_tcxx . . $ eventone_t# *et;
412
413 int x;
414 int length;
415 unsigned char bit;
416 int i;
417
418 int terminate;
419 int direction;
420 int xerror, xstep, xmod;
421 int channel_count = CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d);
422
423 if (!et_initializercxx . . $ et_initializer(346a1ce8e41bd438).(d, duplicate_line, zero_mask))
424 return;
425
426 et = (eventone_tcxx . . $ eventone_t# *) d->aux_datacxx . . $ dither#aux_data.;
427 if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & D_UNITONEcxx . . $ `src/main/dither-impl.h:54:9`!)
428 stp_dither_matrix_set_rowcxx . . $ stp_dither_matrix_set_row(befc66d6fe93ad5c).(&(et->transition_matrixcxx . . $ $anonymous_type_6909a6ea18c11111_1#transition_matrix.), row);
429
430 length = (d->dst_widthcxx . . $ dither#dst_width. + 7) / 8;
431
432 if (row & 1)
433 {
434 direction = 1;
435 x = 0;
436 terminate = d->dst_widthcxx . . $ dither#dst_width.;
437 d->ptr_offsetcxx . . $ dither#ptr_offset. = 0;
438 }
439 else
440 {
441 direction = -1;
442 x = d->dst_widthcxx . . $ dither#dst_width. - 1;
443 terminate = -1;
444 d->ptr_offsetcxx . . $ dither#ptr_offset. = length - 1;
445 raw += channel_count * (d->src_widthcxx . . $ dither#src_width. - 1);
446 }
447 bit = 1 << (7 - (x & 7));
448 xstep = channel_count * (d->src_widthcxx . . $ dither#src_width. / d->dst_widthcxx . . $ dither#dst_width.);
449 xmod = d->src_widthcxx . . $ dither#src_width. % d->dst_widthcxx . . $ dither#dst_width.;
450 xerror = (xmod * x) % d->dst_widthcxx . . $ dither#dst_width.;
451
452 for (; x != terminate; x += direction)
453 {
454
455 int point_error = 0;
456 int comparison = 32768;
457
458 if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & D_ORDERED_BASEcxx . . $ `src/main/dither-impl.h:48:9`!)
459 comparison += (ditherpointcxx . . $ ditherpoint(44214aea3cf6f5be).(d, &(d->dither_matrixcxx . . $ dither#dither_matrix.), x) / 16) - 2048;
460
461 for (i=0; i < channel_count; i++)
462 {
463 if (CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i).ptrcxx . . $ dither_channel#ptr.)
464 {
465 int inkspot;
466 int range_point;
467 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i);
468 shade_distance_tcxx . . $ shade_distance_t# *sp = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
469 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *inkp;
470 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# lower, upper;
471
472 advance_eventone_precxx . . $ advance_eventone_pre(9927a9af69697026).(sp, et, x);
473
474 /*
475 * Find which are the two candidate dot sizes.
476 * Rather than use the absolute value of the point to compute
477 * the error, we will use the relative value of the point within
478 * the range to find the two candidate dot sizes.
479 */
480 range_point =
481 find_segment_and_ditherpointcxx . . $ find_segment_and_ditherpoint(145e816d347aa4d5).(dc, raw[i], &lower, &upper);
482
483 /* Incorporate error data from previous line */
484 dc->vcxx . . $ dither_channel#v. += 2 * range_point + (dc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`!] + 8) / 16;
485 inkspot = dc->vcxx . . $ dither_channel#v. - range_point;
486
487 point_error += eventone_adjustcxx . . $ eventone_adjust(1c687df84ca48782).(dc, et, inkspot, range_point);
488
489 /* Determine whether to print the larger or smaller dot */
490 inkp = &lower;
491 if (point_error >= comparison)
492 {
493 point_error -= 65535;
494 inkp = &upper;
495 dc->vcxx . . $ dither_channel#v. -= 131070;
496 sp->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
497 }
498
499 /* Adjust the error to reflect the dot choice */
500 if (inkp->bitscxx . . $ ink_defn#bits.)
501 {
502 if (!mask || (*(mask + d->ptr_offsetcxx . . $ dither#ptr_offset.) & bit))
503 {
504 set_row_endscxx . . $ set_row_ends(64d265e6bb66a9f0).(dc, x);
505
506 /* Do the printing */
507 print_inkcxx . . $ print_ink(21a3a45949c63496).(d, dc->ptrcxx . . $ dither_channel#ptr., inkp, bit, length);
508 }
509 }
510
511 /* Spread the error around to the adjacent dots */
512 eventone_updatecxx . . $ eventone_update(c04982bad3b6240a).(dc, et, x, direction);
513 diffuse_errorcxx . . $ diffuse_error(c04982bad3b6240a).(dc, et, x, direction);
514 }
515 }
516 if (direction == 1)
517 ADVANCE_UNIDIRECTIONALcxx . . $ `src/main/dither-impl.h:199:9`!(d, bit, raw, channel_count, xerror, xstep, xmod);
518 else
519 ADVANCE_REVERSEcxx . . $ `src/main/dither-impl.h:220:9`!(d, bit, raw, channel_count, xerror, xstep, xmod);
520 }
521 if (direction == -1)
522 stpi_dither_reverse_row_endscxx . . $ stpi_dither_reverse_row_ends(eba3149742ad601b).(d);
523 }
524
525 void
526 stpi_dither_utcxx . . $ stpi_dither_ut(525e4b1c00087d37).(stp_vars_tcxx . . $ stp_vars_t# *v,
527 int row,
528 const unsigned short *raw,
529 int duplicate_line,
530 int zero_mask,
531 const unsigned char *mask)
532 {
533 stpi_dither_tcxx . . $ stpi_dither_t# *d = (stpi_dither_tcxx . . $ stpi_dither_t# *) stp_get_component_datacxx . . $ stp_get_component_data(2bc0070dfdce2f04).(v, "Dither");
534 eventone_tcxx . . $ eventone_t# *et;
535
536 int x;
537 int length;
538 unsigned char bit;
539 int i;
540
541 int terminate;
542 int direction;
543 int xerror, xstep, xmod;
544 int channel_count = CHANNEL_COUNTcxx . . $ `src/main/dither-impl.h:179:9`!(d);
545 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *ddc;
546
547 if (channel_count == 1)
548 {
549 stpi_dither_etcxx . . $ stpi_dither_et(525e4b1c00087d37).(v, row, raw, duplicate_line, zero_mask, mask);
550 return;
551 }
552
553 if (!et_initializercxx . . $ et_initializer(346a1ce8e41bd438).(d, duplicate_line, zero_mask))
554 return;
555
556 et = (eventone_tcxx . . $ eventone_t# *) d->aux_datacxx . . $ dither#aux_data.;
557 ddc = et->dummy_channelcxx . . $ $anonymous_type_6909a6ea18c11111_1#dummy_channel.;
558
559 length = (d->dst_widthcxx . . $ dither#dst_width. + 7) / 8;
560
561 if (row & 1)
562 {
563 direction = 1;
564 x = 0;
565 terminate = d->dst_widthcxx . . $ dither#dst_width.;
566 d->ptr_offsetcxx . . $ dither#ptr_offset. = 0;
567 }
568 else
569 {
570 direction = -1;
571 x = d->dst_widthcxx . . $ dither#dst_width. - 1;
572 terminate = -1;
573 d->ptr_offsetcxx . . $ dither#ptr_offset. = length - 1;
574 raw += channel_count * (d->src_widthcxx . . $ dither#src_width. - 1);
575 }
576 bit = 1 << (7 - (x & 7));
577 xstep = channel_count * (d->src_widthcxx . . $ dither#src_width. / d->dst_widthcxx . . $ dither#dst_width.);
578 xmod = d->src_widthcxx . . $ dither#src_width. % d->dst_widthcxx . . $ dither#dst_width.;
579 xerror = (xmod * x) % d->dst_widthcxx . . $ dither#dst_width.;
580
581 for (; x != terminate; x += direction)
582 {
583
584 shade_distance_tcxx . . $ shade_distance_t# *ssp = (shade_distance_tcxx . . $ shade_distance_t# *) ddc->aux_datacxx . . $ dither_channel#aux_data.;
585 int point_error = 0;
586 int total_error = 0;
587 int channels_to_print = 0;
588 int print_all_channels = 0;
589 int maximum_value = 0;
590 int comparison = 32768;
591 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *best_channel = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
592 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *second_best_channel = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
593 int best_channel_value = INT_MINcxx . . $ `<external>/67164224788392828/limits.h:118:9`!;
594 int second_best_channel_value = INT_MINcxx . . $ `<external>/67164224788392828/limits.h:118:9`!;
595 int random_value = ditherpointcxx . . $ ditherpoint(44214aea3cf6f5be).(d, &(d->dither_matrixcxx . . $ dither#dither_matrix.), x);
596
597 if (d->stpi_dither_typecxx . . $ dither#stpi_dither_type. & D_ORDERED_BASEcxx . . $ `src/main/dither-impl.h:48:9`!)
598 comparison += (random_value / 16) - 2048;
599
600
601 ddc->bcxx . . $ dither_channel#b. = 0;
602 advance_eventone_precxx . . $ advance_eventone_pre(9927a9af69697026).(ssp, et, x);
603
604 for (i=0; i < channel_count; i++)
605 {
606 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i);
607 if (dc->ptrcxx . . $ dither_channel#ptr.)
608 {
609 shade_distance_tcxx . . $ shade_distance_t# *sp = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
610
611 advance_eventone_precxx . . $ advance_eventone_pre(9927a9af69697026).(sp, et, x);
612
613 /*
614 * Find which are the two candidate dot sizes.
615 * Rather than use the absolute value of the point to compute
616 * the error, we will use the relative value of the point within
617 * the range to find the two candidate dot sizes.
618 */
619 dc->bcxx . . $ dither_channel#b. = find_segment_and_ditherpointcxx . . $ find_segment_and_ditherpoint(145e816d347aa4d5).(dc, raw[i],
620 &(sp->lowercxx . . $ shade_segment#lower.), &(sp->uppercxx . . $ shade_segment#upper.));
621 if (sp->share_this_channelcxx . . $ shade_segment#share_this_channel.)
622 {
623 if (dc->bcxx . . $ dither_channel#b. > maximum_value)
624 maximum_value = dc->bcxx . . $ dither_channel#b.;
625 ddc->bcxx . . $ dither_channel#b. += dc->bcxx . . $ dither_channel#b.;
626 }
627 /* Incorporate error data from previous line */
628 dc->vcxx . . $ dither_channel#v. += 2 * dc->bcxx . . $ dither_channel#b. + (dc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`!] + 8) / 16;
629 dc->ocxx . . $ dither_channel#o. = unitone_adjustcxx . . $ unitone_adjust(1c687df84ca48782).(dc, et, dc->vcxx . . $ dither_channel#v. - dc->bcxx . . $ dither_channel#b., dc->bcxx . . $ dither_channel#b.);
630 }
631 }
632
633 #if 0
634 if ((2 * (ddc->b - maximum_value)) < (3 * maximum_value))
635 print_all_channels = 1;
636 #endif
637
638 if (ddc->bcxx . . $ dither_channel#b. > 131070)
639 print_all_channels = 1;
640 else if (ddc->bcxx . . $ dither_channel#b. > 65535)
641 {
642 ddc->bcxx . . $ dither_channel#b. -= 65535;
643 channels_to_print = 1;
644 }
645
646 if (ddc->bcxx . . $ dither_channel#b. > 65535)
647 ddc->bcxx . . $ dither_channel#b. = 65535;
648
649 ddc->vcxx . . $ dither_channel#v. += 2 * ddc->bcxx . . $ dither_channel#b. + (ddc->errscxx . . $ dither_channel#errs.[0][x + MAX_SPREADcxx . . $ `src/main/dither-impl.h:76:9`!] + 8) / 16;
650 total_error += eventone_adjustcxx . . $ eventone_adjust(1c687df84ca48782).(ddc, et, ddc->vcxx . . $ dither_channel#v. - ddc->bcxx . . $ dither_channel#b., ddc->bcxx . . $ dither_channel#b.);
651 if (total_error >= comparison)
652 channels_to_print += 1;
653
654 if (!print_all_channels)
655 {
656 for (i=0; i < channel_count; i++)
657 {
658 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i);
659 shade_distance_tcxx . . $ shade_distance_t# *sp = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
660
661 if (dc->ptrcxx . . $ dither_channel#ptr.)
662 {
663
664 if (sp->share_this_channelcxx . . $ shade_segment#share_this_channel.)
665 {
666 if (dc->ocxx . . $ dither_channel#o. > best_channel_value)
667 {
668 second_best_channel = best_channel;
669 best_channel = dc;
670 second_best_channel_value = best_channel_value;
671 if (dc->ocxx . . $ dither_channel#o. >= 32768)
672 best_channel_value = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
673 else
674 best_channel_value = dc->ocxx . . $ dither_channel#o.;
675 }
676 else if (dc->ocxx . . $ dither_channel#o. > second_best_channel_value)
677 {
678 second_best_channel = dc;
679 if (dc->ocxx . . $ dither_channel#o. >= 32768)
680 second_best_channel_value = INT_MAXcxx . . $ `<external>/67164224788392828/limits.h:120:9`!;
681 else
682 second_best_channel_value = dc->ocxx . . $ dither_channel#o.;
683 }
684 }
685 }
686 }
687 }
688
689 for (i=0; i < channel_count; i++)
690 {
691 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i);
692 if (dc->ptrcxx . . $ dither_channel#ptr.)
693 {
694 /* Determine whether to print the larger or smaller dot */
695 shade_distance_tcxx . . $ shade_distance_t# *sp = (shade_distance_tcxx . . $ shade_distance_t# *) dc->aux_datacxx . . $ dither_channel#aux_data.;
696 stpi_ink_defn_tcxx . . $ stpi_ink_defn_t# *inkp = &(sp->lowercxx . . $ shade_segment#lower.);
697
698 if (dc->ocxx . . $ dither_channel#o. < 0)
699 dc->ocxx . . $ dither_channel#o. = 0;
700 else if (dc->ocxx . . $ dither_channel#o. > 65535)
701 dc->ocxx . . $ dither_channel#o. = 65535;
702 if (print_all_channels || !sp->share_this_channelcxx . . $ shade_segment#share_this_channel.)
703 {
704 point_error += dc->ocxx . . $ dither_channel#o.;
705 if (point_error >= comparison)
706 {
707 point_error -= 65535;
708 inkp = &(sp->uppercxx . . $ shade_segment#upper.);
709 dc->vcxx . . $ dither_channel#v. -= 131070;
710 sp->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
711 }
712 }
713 else if ((channels_to_print >= 1 && best_channel == dc) ||
714 (channels_to_print >= 2 && second_best_channel == dc))
715 {
716 inkp = &(sp->uppercxx . . $ shade_segment#upper.);
717 dc->vcxx . . $ dither_channel#v. -= 131070;
718 sp->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
719 }
720 if (inkp->bitscxx . . $ ink_defn#bits.)
721 {
722 if (!mask || (*(mask + d->ptr_offsetcxx . . $ dither#ptr_offset.) & bit))
723 {
724 set_row_endscxx . . $ set_row_ends(64d265e6bb66a9f0).(dc, x);
725
726 /* Do the printing */
727 print_inkcxx . . $ print_ink(21a3a45949c63496).(d, dc->ptrcxx . . $ dither_channel#ptr., inkp, bit, length);
728 }
729 }
730 }
731 }
732 if (total_error >= comparison)
733 {
734 ddc->vcxx . . $ dither_channel#v. -= 131070;
735 total_error -= 65535;
736 ssp->discxx . . $ shade_segment#dis. = et->d_sqcxx . . $ $anonymous_type_6909a6ea18c11111_1#d_sq.;
737 }
738
739 eventone_updatecxx . . $ eventone_update(c04982bad3b6240a).(ddc, et, x, direction);
740 diffuse_errorcxx . . $ diffuse_error(c04982bad3b6240a).(ddc, et, x, direction);
741 for (i=0; i < channel_count; i++)
742 {
743 stpi_dither_channel_tcxx . . $ stpi_dither_channel_t# *dc = &CHANNELcxx . . $ `src/main/dither-impl.h:178:9`!(d, i);
744 if (dc->ptrcxx . . $ dither_channel#ptr.)
745 {
746 /* Spread the error around to the adjacent dots */
747 eventone_updatecxx . . $ eventone_update(c04982bad3b6240a).(dc, et, x, direction);
748 diffuse_errorcxx . . $ diffuse_error(c04982bad3b6240a).(dc, et, x, direction);
749 }
750 }
751 if (direction == 1)
752 ADVANCE_UNIDIRECTIONALcxx . . $ `src/main/dither-impl.h:199:9`!(d, bit, raw, channel_count, xerror, xstep, xmod);
753 else
754 ADVANCE_REVERSEcxx . . $ `src/main/dither-impl.h:220:9`!(d, bit, raw, channel_count, xerror, xstep, xmod);
755 }
756 if (direction == -1)
757 stpi_dither_reverse_row_endscxx . . $ stpi_dither_reverse_row_ends(eba3149742ad601b).(d);
758 }