1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
void
libglitter_per_channel_desaturate_double(double *restrict *rasters, size_t nrasters, size_t rowsize, size_t cellsize,
size_t width, size_t height, const double *restrict saturations,
const double *restrict primary_ys)
{
size_t y, x, ch, raster_y, raster_i;
double intensity;
rowsize *= cellsize;
if (nrasters == 3) {
double *raster1 = rasters[0], saturation1 = saturations[0];
double *raster2 = rasters[1], saturation2 = saturations[1];
double *raster3 = rasters[2], saturation3 = saturations[2];
double primary1_y = primary_ys ? primary_ys[0] : (double)0.212673370378408277403536885686;
double primary2_y = primary_ys ? primary_ys[1] : (double)0.715151730491031756287156895269;
double primary3_y = primary_ys ? primary_ys[2] : (double)0.072174899130559869164791564344;
for (y = 0, raster_y = 0; y < height; y++, raster_y += rowsize) {
for (x = 0, raster_i = raster_y; x < width; x++, raster_i += cellsize) {
intensity = raster1[raster_i] * primary1_y;
intensity += raster2[raster_i] * primary2_y;
intensity += raster3[raster_i] * primary3_y;
raster1[raster_i] = fma(raster1[raster_i] - intensity, saturation1, intensity);
raster2[raster_i] = fma(raster2[raster_i] - intensity, saturation2, intensity);
raster3[raster_i] = fma(raster3[raster_i] - intensity, saturation3, intensity);
}
}
} else {
for (y = 0, raster_y = 0; y < height; y++, raster_y += rowsize) {
for (x = 0, raster_i = raster_y; x < width; x++, raster_i += cellsize) {
intensity = 0;
for (ch = 0; ch < nrasters; ch++)
intensity += rasters[ch][raster_i] * primary_ys[ch];
for (ch = 0; ch < nrasters; ch++)
rasters[ch][raster_i] = fma(rasters[ch][raster_i] - intensity, saturations[ch], intensity);
}
}
}
}
#else
#define TOLERANCE 0.0001
#define RY 0.212673370378408277403536885686
#define GY 0.715151730491031756287156895269
#define BY 0.072174899130559869164791564344
static int
eq(double a, double b)
{
double r = a - b;
return (r < 0 ? -r : r) < TOLERANCE;
}
int
main(void)
{
double zeroes[2 * 6 * 3];
double raster1[2 * 6 * 3];
double raster2[2 * 6 * 3];
double raster3[2 * 6 * 3];
double *rasters[3], saturations[3], primary_ys[3];
size_t i;
#define POS(Y, X) ((Y) * 6 * 3 + (X) * 3)
#define ASSERT2(A, B) do { ASSERT(A); ASSERT(B); } while (0)
#define ASSERT3(A, B, C) do { ASSERT(A); ASSERT(B); ASSERT(C); } while (0)
memset(zeroes, 0, sizeof(zeroes));
for (i = 0; i <= 2; i++) {
double v = (double)i / 2;
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = v, raster2[POS(0, 0)] = v;
raster1[POS(0, 1)] = v, raster2[POS(0, 1)] = v;
raster1[POS(0, 2)] = v, raster2[POS(0, 2)] = v;
raster1[POS(0, 3)] = v, raster2[POS(0, 3)] = v;
raster1[POS(1, 0)] = v, raster2[POS(1, 0)] = v;
raster1[POS(1, 1)] = v, raster2[POS(1, 1)] = v;
raster1[POS(1, 2)] = v, raster2[POS(1, 2)] = v;
raster1[POS(1, 3)] = v, raster2[POS(1, 3)] = v;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
primary_ys[0] = 0.75;
primary_ys[1] = 0.25;
libglitter_per_channel_desaturate_double(rasters, 2, 6, 3, 4, 2, saturations, primary_ys);
ASSERT2(raster1[POS(0, 0)] == v, raster2[POS(0, 0)] == v);
ASSERT2(raster1[POS(0, 1)] == v, raster2[POS(0, 1)] == v);
ASSERT2(raster1[POS(0, 2)] == v, raster2[POS(0, 2)] == v);
ASSERT2(raster1[POS(0, 3)] == v, raster2[POS(0, 3)] == v);
ASSERT2(raster1[POS(1, 0)] == v, raster2[POS(1, 0)] == v);
ASSERT2(raster1[POS(1, 1)] == v, raster2[POS(1, 1)] == v);
ASSERT2(raster1[POS(1, 2)] == v, raster2[POS(1, 2)] == v);
ASSERT2(raster1[POS(1, 3)] == v, raster2[POS(1, 3)] == v);
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = v, raster2[POS(0, 0)] = v, raster3[POS(0, 0)] = v;
raster1[POS(0, 1)] = v, raster2[POS(0, 1)] = v, raster3[POS(0, 1)] = v;
raster1[POS(0, 2)] = v, raster2[POS(0, 2)] = v, raster3[POS(0, 2)] = v;
raster1[POS(0, 3)] = v, raster2[POS(0, 3)] = v, raster3[POS(0, 3)] = v;
raster1[POS(1, 0)] = v, raster2[POS(1, 0)] = v, raster3[POS(1, 0)] = v;
raster1[POS(1, 1)] = v, raster2[POS(1, 1)] = v, raster3[POS(1, 1)] = v;
raster1[POS(1, 2)] = v, raster2[POS(1, 2)] = v, raster3[POS(1, 2)] = v;
raster1[POS(1, 3)] = v, raster2[POS(1, 3)] = v, raster3[POS(1, 3)] = v;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
saturations[2] = 0.125;
primary_ys[0] = 0.375;
primary_ys[1] = 0.50;
primary_ys[2] = 0.125;
libglitter_per_channel_desaturate_double(rasters, 3, 6, 3, 4, 2, saturations, primary_ys);
ASSERT3(raster1[POS(0, 0)] == v, raster2[POS(0, 0)] == v, raster3[POS(0, 0)] == v);
ASSERT3(raster1[POS(0, 1)] == v, raster2[POS(0, 1)] == v, raster3[POS(0, 1)] == v);
ASSERT3(raster1[POS(0, 2)] == v, raster2[POS(0, 2)] == v, raster3[POS(0, 2)] == v);
ASSERT3(raster1[POS(0, 3)] == v, raster2[POS(0, 3)] == v, raster3[POS(0, 3)] == v);
ASSERT3(raster1[POS(1, 0)] == v, raster2[POS(1, 0)] == v, raster3[POS(1, 0)] == v);
ASSERT3(raster1[POS(1, 1)] == v, raster2[POS(1, 1)] == v, raster3[POS(1, 1)] == v);
ASSERT3(raster1[POS(1, 2)] == v, raster2[POS(1, 2)] == v, raster3[POS(1, 2)] == v);
ASSERT3(raster1[POS(1, 3)] == v, raster2[POS(1, 3)] == v, raster3[POS(1, 3)] == v);
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0, raster3[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0, raster3[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0, raster3[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0, raster3[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0, raster3[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0, raster3[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0, raster3[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0, raster3[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = v, raster2[POS(0, 0)] = v, raster3[POS(0, 0)] = v;
raster1[POS(0, 1)] = v, raster2[POS(0, 1)] = v, raster3[POS(0, 1)] = v;
raster1[POS(0, 2)] = v, raster2[POS(0, 2)] = v, raster3[POS(0, 2)] = v;
raster1[POS(0, 3)] = v, raster2[POS(0, 3)] = v, raster3[POS(0, 3)] = v;
raster1[POS(1, 0)] = v, raster2[POS(1, 0)] = v, raster3[POS(1, 0)] = v;
raster1[POS(1, 1)] = v, raster2[POS(1, 1)] = v, raster3[POS(1, 1)] = v;
raster1[POS(1, 2)] = v, raster2[POS(1, 2)] = v, raster3[POS(1, 2)] = v;
raster1[POS(1, 3)] = v, raster2[POS(1, 3)] = v, raster3[POS(1, 3)] = v;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
saturations[2] = 0.125;
primary_ys[0] = 0.375;
primary_ys[1] = 0.5;
primary_ys[2] = 0.125;
libglitter_per_channel_desaturate_double(rasters, 3, 6, 3, 4, 2, saturations, NULL);
ASSERT3(eq(raster1[POS(0, 0)], v), eq(raster2[POS(0, 0)], v), eq(raster3[POS(0, 0)], v));
ASSERT3(eq(raster1[POS(0, 1)], v), eq(raster2[POS(0, 1)], v), eq(raster3[POS(0, 1)], v));
ASSERT3(eq(raster1[POS(0, 2)], v), eq(raster2[POS(0, 2)], v), eq(raster3[POS(0, 2)], v));
ASSERT3(eq(raster1[POS(0, 3)], v), eq(raster2[POS(0, 3)], v), eq(raster3[POS(0, 3)], v));
ASSERT3(eq(raster1[POS(1, 0)], v), eq(raster2[POS(1, 0)], v), eq(raster3[POS(1, 0)], v));
ASSERT3(eq(raster1[POS(1, 1)], v), eq(raster2[POS(1, 1)], v), eq(raster3[POS(1, 1)], v));
ASSERT3(eq(raster1[POS(1, 2)], v), eq(raster2[POS(1, 2)], v), eq(raster3[POS(1, 2)], v));
ASSERT3(eq(raster1[POS(1, 3)], v), eq(raster2[POS(1, 3)], v), eq(raster3[POS(1, 3)], v));
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0, raster3[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0, raster3[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0, raster3[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0, raster3[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0, raster3[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0, raster3[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0, raster3[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0, raster3[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
}
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = 4, raster2[POS(0, 0)] = 8;
raster1[POS(0, 1)] = 16, raster2[POS(0, 1)] = 2;
raster1[POS(0, 2)] = 1, raster2[POS(0, 2)] = 8;
raster1[POS(0, 3)] = 32, raster2[POS(0, 3)] = 4;
raster1[POS(1, 0)] = 8, raster2[POS(1, 0)] = 8;
raster1[POS(1, 1)] = -4, raster2[POS(1, 1)] = 2;
raster1[POS(1, 2)] = 16, raster2[POS(1, 2)] = -16;
raster1[POS(1, 3)] = 8, raster2[POS(1, 3)] = 2;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
primary_ys[0] = 0.75;
primary_ys[1] = 0.25;
libglitter_per_channel_desaturate_double(rasters, 2, 6, 3, 4, 2, saturations, primary_ys);
#define G(x, y) ((x) * 0.75 + (y) * 0.25)
#define X(x, y) (((x) - G(x, y)) * 0.5 + G(x, y))
#define Y(x, y) (((y) - G(x, y)) * 0.25 + G(x, y))
ASSERT2(raster1[POS(0, 0)] == X(4, 8), raster2[POS(0, 0)] == Y(4, 8));
ASSERT2(raster1[POS(0, 1)] == X(16, 2), raster2[POS(0, 1)] == Y(16, 2));
ASSERT2(raster1[POS(0, 2)] == X(1, 8), raster2[POS(0, 2)] == Y(1, 8));
ASSERT2(raster1[POS(0, 3)] == X(32, 4), raster2[POS(0, 3)] == Y(32, 4));
ASSERT2(raster1[POS(1, 0)] == X(8, 8), raster2[POS(1, 0)] == Y(8, 8));
ASSERT2(raster1[POS(1, 1)] == X(-4, 2), raster2[POS(1, 1)] == Y(-4, 2));
ASSERT2(raster1[POS(1, 2)] == X(16, -16), raster2[POS(1, 2)] == Y(16, -16));
ASSERT2(raster1[POS(1, 3)] == X(8, 2), raster2[POS(1, 3)] == Y(8, 2));
#undef G
#undef X
#undef Y
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = 4, raster2[POS(0, 0)] = 8, raster3[POS(0, 0)] = 4;
raster1[POS(0, 1)] = 16, raster2[POS(0, 1)] = 2, raster3[POS(0, 1)] = 16;
raster1[POS(0, 2)] = 1, raster2[POS(0, 2)] = 8, raster3[POS(0, 2)] = 2;
raster1[POS(0, 3)] = 32, raster2[POS(0, 3)] = 4, raster3[POS(0, 3)] = 8;
raster1[POS(1, 0)] = 8, raster2[POS(1, 0)] = 8, raster3[POS(1, 0)] = 8;
raster1[POS(1, 1)] = -4, raster2[POS(1, 1)] = 2, raster3[POS(1, 1)] = 16;
raster1[POS(1, 2)] = 16, raster2[POS(1, 2)] = -16, raster3[POS(1, 2)] = -16;
raster1[POS(1, 3)] = 8, raster2[POS(1, 3)] = 2, raster3[POS(1, 3)] = 4;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
saturations[2] = 0.125;
primary_ys[0] = 0.375;
primary_ys[1] = 0.5;
primary_ys[2] = 0.125;
libglitter_per_channel_desaturate_double(rasters, 3, 6, 3, 4, 2, saturations, primary_ys);
#define G(x, y, z) ((x) * 0.375 + (y) * 0.5 + (z) * 0.125)
#define X(x, y, z) (((x) - G(x, y, z)) * 0.5 + G(x, y, z))
#define Y(x, y, z) (((y) - G(x, y, z)) * 0.25 + G(x, y, z))
#define Z(x, y, z) (((z) - G(x, y, z)) * 0.125 + G(x, y, z))
ASSERT3(raster1[POS(0, 0)] == X(4, 8, 4), raster2[POS(0, 0)] == Y(4, 8, 4), raster3[POS(0, 0)] == Z(4, 8, 4));
ASSERT3(raster1[POS(0, 1)] == X(16, 2, 16), raster2[POS(0, 1)] == Y(16, 2, 16), raster3[POS(0, 1)] == Z(16, 2, 16));
ASSERT3(raster1[POS(0, 2)] == X(1, 8, 2), raster2[POS(0, 2)] == Y(1, 8, 2), raster3[POS(0, 2)] == Z(1, 8, 2));
ASSERT3(raster1[POS(0, 3)] == X(32, 4, 8), raster2[POS(0, 3)] == Y(32, 4, 8), raster3[POS(0, 3)] == Z(32, 4, 8));
ASSERT3(raster1[POS(1, 0)] == X(8, 8, 8), raster2[POS(1, 0)] == Y(8, 8, 8), raster3[POS(1, 0)] == Z(8, 8, 8));
ASSERT3(raster1[POS(1, 1)] == X(-4, 2, 16), raster2[POS(1, 1)] == Y(-4, 2, 16), raster3[POS(1, 1)] == Z(-4, 2, 16));
ASSERT3(raster1[POS(1, 2)] == X(16, -16, -16), raster2[POS(1, 2)] == Y(16, -16, -16), raster3[POS(1, 2)] == Z(16, -16, -16));
ASSERT3(raster1[POS(1, 3)] == X(8, 2, 4), raster2[POS(1, 3)] == Y(8, 2, 4), raster3[POS(1, 3)] == Z(8, 2, 4));
#undef G
#undef X
#undef Y
#undef Z
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0, raster3[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0, raster3[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0, raster3[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0, raster3[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0, raster3[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0, raster3[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0, raster3[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0, raster3[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
memset(raster1, 0, sizeof(raster1));
memset(raster2, 0, sizeof(raster2));
memset(raster3, 0, sizeof(raster3));
raster1[POS(0, 0)] = 4, raster2[POS(0, 0)] = 8, raster3[POS(0, 0)] = 4;
raster1[POS(0, 1)] = 16, raster2[POS(0, 1)] = 2, raster3[POS(0, 1)] = 16;
raster1[POS(0, 2)] = 1, raster2[POS(0, 2)] = 8, raster3[POS(0, 2)] = 2;
raster1[POS(0, 3)] = 32, raster2[POS(0, 3)] = 4, raster3[POS(0, 3)] = 8;
raster1[POS(1, 0)] = 8, raster2[POS(1, 0)] = 8, raster3[POS(1, 0)] = 8;
raster1[POS(1, 1)] = -4, raster2[POS(1, 1)] = 2, raster3[POS(1, 1)] = 16;
raster1[POS(1, 2)] = 16, raster2[POS(1, 2)] = -16, raster3[POS(1, 2)] = -16;
raster1[POS(1, 3)] = 8, raster2[POS(1, 3)] = 2, raster3[POS(1, 3)] = 4;
rasters[0] = raster1;
rasters[1] = raster2;
rasters[2] = raster3;
saturations[0] = 0.5;
saturations[1] = 0.25;
saturations[2] = 0.125;
libglitter_per_channel_desaturate_double(rasters, 3, 6, 3, 4, 2, saturations, NULL);
#define G(x, y, z) ((x) * RY + (y) * GY + (z) * BY)
#define X(x, y, z) (((x) - G(x, y, z)) * 0.5 + G(x, y, z))
#define Y(x, y, z) (((y) - G(x, y, z)) * 0.25 + G(x, y, z))
#define Z(x, y, z) (((z) - G(x, y, z)) * 0.125 + G(x, y, z))
ASSERT(eq(raster1[POS(0, 0)], X(4, 8, 4)));
ASSERT(eq(raster1[POS(0, 1)], X(16, 2, 16)));
ASSERT(eq(raster1[POS(0, 2)], X(1, 8, 2)));
ASSERT(eq(raster1[POS(0, 3)], X(32, 4, 8)));
ASSERT(eq(raster1[POS(1, 0)], X(8, 8, 8)));
ASSERT(eq(raster1[POS(1, 1)], X(-4, 2, 16)));
ASSERT(eq(raster1[POS(1, 2)], X(16, -16, -16)));
ASSERT(eq(raster1[POS(1, 3)], X(8, 2, 4)));
ASSERT(eq(raster2[POS(0, 0)], Y(4, 8, 4)));
ASSERT(eq(raster2[POS(0, 1)], Y(16, 2, 16)));
ASSERT(eq(raster2[POS(0, 2)], Y(1, 8, 2)));
ASSERT(eq(raster2[POS(0, 3)], Y(32, 4, 8)));
ASSERT(eq(raster2[POS(1, 0)], Y(8, 8, 8)));
ASSERT(eq(raster2[POS(1, 1)], Y(-4, 2, 16)));
ASSERT(eq(raster2[POS(1, 2)], Y(16, -16, -16)));
ASSERT(eq(raster2[POS(1, 3)], Y(8, 2, 4)));
ASSERT(eq(raster3[POS(0, 0)], Z(4, 8, 4)));
ASSERT(eq(raster3[POS(0, 1)], Z(16, 2, 16)));
ASSERT(eq(raster3[POS(0, 2)], Z(1, 8, 2)));
ASSERT(eq(raster3[POS(0, 3)], Z(32, 4, 8)));
ASSERT(eq(raster3[POS(1, 0)], Z(8, 8, 8)));
ASSERT(eq(raster3[POS(1, 1)], Z(-4, 2, 16)));
ASSERT(eq(raster3[POS(1, 2)], Z(16, -16, -16)));
ASSERT(eq(raster3[POS(1, 3)], Z(8, 2, 4)));
#undef G
#undef X
#undef Y
#undef Z
raster1[POS(0, 0)] = 0, raster2[POS(0, 0)] = 0, raster3[POS(0, 0)] = 0;
raster1[POS(0, 1)] = 0, raster2[POS(0, 1)] = 0, raster3[POS(0, 1)] = 0;
raster1[POS(0, 2)] = 0, raster2[POS(0, 2)] = 0, raster3[POS(0, 2)] = 0;
raster1[POS(0, 3)] = 0, raster2[POS(0, 3)] = 0, raster3[POS(0, 3)] = 0;
raster1[POS(1, 0)] = 0, raster2[POS(1, 0)] = 0, raster3[POS(1, 0)] = 0;
raster1[POS(1, 1)] = 0, raster2[POS(1, 1)] = 0, raster3[POS(1, 1)] = 0;
raster1[POS(1, 2)] = 0, raster2[POS(1, 2)] = 0, raster3[POS(1, 2)] = 0;
raster1[POS(1, 3)] = 0, raster2[POS(1, 3)] = 0, raster3[POS(1, 3)] = 0;
ASSERT(!memcmp(raster1, zeroes, sizeof(raster1)));
ASSERT(!memcmp(raster2, zeroes, sizeof(raster2)));
ASSERT(!memcmp(raster3, zeroes, sizeof(raster3)));
return 0;
}
#endif
|