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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
#include "fitz.h"
typedef unsigned char byte;
/* These C implementations use SWAR (SIMD-within-a-register) techniques. */
#define MASK 0xFF00FF00;
static void
path_w4i1o4_32bit(byte * restrict rgba,
byte * restrict src, byte cov, int len,
byte * restrict dst)
{
/* COLOR * coverage + DST * (256-coverage) = (COLOR - DST)*coverage + DST*256 */
unsigned int *dst32 = (unsigned int *)(void *)dst;
int alpha = rgba[3];
unsigned int rb = rgba[0] | (rgba[2] << 16);
unsigned int ga = rgba[1] | 0xFF0000;
if (alpha == 0)
return;
if (alpha != 255)
{
alpha += alpha>>7; /* alpha is now in the 0...256 range */
while (len--)
{
unsigned int ca, drb, dga, crb, cga;
cov += *src; *src++ = 0;
ca = cov + (cov>>7); /* ca is in 0...256 range */
ca = (ca*alpha)>>8; /* ca is is in 0...256 range */
drb = *dst32++;
if (ca != 0)
{
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga | (drb>>8);
dst32[-1] = drb;
}
}
}
else
{
while (len--)
{
unsigned int ca, drb, dga, crb, cga;
cov += *src; *src++ = 0;
ca = cov + (cov>>7); /* ca is in 0...256 range */
drb = *dst32++;
if (ca == 0)
continue;
if (ca == 255)
{
drb = (ga<<8) | rb;
}
else
{
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga |(drb>>8);
}
dst32[-1] = drb;
}
}
}
static void
text_w4i1o4_32bit(byte * restrict rgba,
byte * restrict src, int srcw,
byte * restrict dst, int dstw, int w0, int h)
{
unsigned int *dst32 = (unsigned int *)(void *)dst;
unsigned int alpha = rgba[3];
unsigned int rb = rgba[0] | (rgba[2] << 16);
unsigned int ga = rgba[1] | 0xFF0000;
if (alpha == 0)
return;
srcw -= w0;
dstw = (dstw>>2)-w0;
if (alpha != 255)
{
alpha += alpha>>7; /* alpha is now in the 0...256 range */
while (h--)
{
int w = w0;
while (w--)
{
unsigned int ca, drb, dga, crb, cga;
ca = *src++;
drb = *dst32++;
ca += ca>>7;
ca = (ca*alpha)>>8;
if (ca == 0)
continue;
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga | (drb>>8);
dst32[-1] = drb;
}
src += srcw;
dst32 += dstw;
}
}
else
{
while (h--)
{
int w = w0;
while (w--)
{
unsigned int ca, drb, dga, crb, cga;
ca = *src++;
drb = *dst32++;
ca += ca>>7;
if (ca == 0)
continue;
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga | (drb>>8);
dst32[-1] = drb;
}
src += srcw;
dst32 += dstw;
}
}
}
static void
img_4o4_32bit(byte * restrict src, byte cov, int len, byte * restrict dst,
fz_pixmap *image, int u, int v, int fa, int fb)
{
unsigned int *dst32 = (unsigned int *)(void *)dst;
unsigned int *samples = (unsigned int *)(void *)image->samples;
int w = image->w;
int h = image->h-1;
while (len--)
{
unsigned int a, a1, d, d1;
int sa;
cov += *src; *src = 0; src++;
/* (a,a1) = sampleargb(samples, w, h, u, v, argb); */
{
int ui, ui1, vi, vi1, ud, vd;
unsigned int b, b1, c, c1;
ui1 = 1;
ui = u >> 16;
if (ui < 0)
{
ui = 0;
ui1 = 0;
}
else if (ui >= w-1)
{
ui = w-1;
ui1 = 0;
}
vi1 = w;
vi = v >> 16;
if (vi < 0)
{
vi = 0;
vi1 = 0;
}
else if (vi >= h)
{
vi = h;
vi1 = 0;
}
ui += vi*w;
a = samples[ui];
b = samples[ui + ui1];
c = samples[ui + vi1];
d = samples[ui + ui1 + vi1];
ud = (u>>8) & 0xFF;
vd = (v>>8) & 0xFF;
ud = FZ_EXPAND(ud);
vd = FZ_EXPAND(vd);
/* (a,a1) = blend(a,b,ud) */
a1 = a & MASK;
a = (a<<8) & MASK;
b1 = (b>>8) & ~MASK;
b = b & ~MASK;
a = ((b -(a >>8)) * ud + a ) & MASK;
a1 = ((b1-(a1>>8)) * ud + a1) & MASK;
/* (c,c1) = blend(c,d,ud) */
c1 = c & MASK;
c = (c<<8) & MASK;
d1 = (d>>8) & ~MASK;
d = d & ~MASK;
c = ((d -(c >>8)) * ud + c ) & MASK;
c1 = ((d1-(c1>>8)) * ud + c1) & MASK;
/* (a,a1) = blend((a,a1),(c,c1),vd) */
a = (((c >>8)-(a >>8)) * vd + a ) & MASK;
a1 = (((c1>>8)-(a1>>8)) * vd + a1) & MASK;
}
sa = (a1>>24);
sa = FZ_COMBINE(FZ_EXPAND(sa), FZ_EXPAND(cov));
a1 |= 0xFF000000;
d = *dst32++;
d1 = d & MASK;
d = (d<<8) & MASK;
a = (((a >>8)-(d >>8)) * sa + d ) & MASK;
a1 = (((a1>>8)-(d1>>8)) * sa + d1) & MASK;
dst32[-1] = (a>>8) | a1;
u += fa;
v += fb;
}
}
static void
img_w4i1o4_32bit(byte *rgba, byte * restrict src, byte cov, int len,
byte * restrict dst, fz_pixmap *image, int u, int v, int fa, int fb)
{
byte *samples = image->samples;
int w = image->w;
int h = image->h-1;
int alpha = FZ_EXPAND(rgba[3]);
unsigned int rb = rgba[0] | (rgba[2] << 16);
unsigned int ga = rgba[1] | 0xFF0000;
unsigned int *dst32 = (unsigned int *)(void *)dst;
if (alpha == 0)
return;
if (alpha != 256)
{
while (len--)
{
unsigned int ca, drb, dga, crb, cga;
unsigned int a, b;
cov += *src; *src = 0; src++;
drb = *dst32++;
ca = FZ_COMBINE(FZ_EXPAND(cov), alpha);
if (ca != 0)
{
int ui, ui1, vi, vi1, ud, vd;
/* a = samplemask(samples, w, h, u, v); */
ui1 = 1;
ui = u >> 16;
if (ui < 0)
{
ui = 0;
ui1 = 0;
}
else if (ui >= w-1)
{
ui = w-1;
ui1 = 0;
}
vi1 = w;
vi = v >> 16;
if (vi < 0)
{
vi = 0;
vi1 = 0;
}
else if (vi >= h)
{
vi = h;
vi1 = 0;
}
ui += vi*w;
a = samples[ui];
b = samples[ui + ui1];
a |= samples[ui + vi1]<<16;
b |= samples[ui + ui1 + vi1]<<16;
ud = (u>>8) & 0xFF;
vd = (v>>8) & 0xFF;
ud = FZ_EXPAND(ud);
vd = FZ_EXPAND(vd);
/* a = blend(a,b,ud) */
a = ((b-a) * ud + (a<<8)) & MASK;
/* a = blend(a,a>>16,vd) */
a = (((a>>24)-(a>>8)) * vd + a);
a = (a>>8) & 0xFF;
ca = FZ_COMBINE(ca, FZ_EXPAND(a));
}
if (ca != 0)
{
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga | (drb>>8);
dst32[-1] = drb;
}
u += fa;
v += fb;
}
}
else
{
while (len--)
{
unsigned int ca, drb, dga, crb, cga;
unsigned int a, b;
cov += *src; *src = 0; src++;
drb = *dst32++;
if (cov != 0)
{
int ui, ui1, vi, vi1, ud, vd;
/* a = samplemask(samples, w, h, u, v); */
ui1 = 1;
ui = u >> 16;
if (ui < 0)
{
ui = 0;
ui1 = 0;
}
else if (ui >= w-1)
{
ui = w-1;
ui1 = 0;
}
vi1 = w;
vi = v >> 16;
if (vi < 0)
{
vi = 0;
vi1 = 0;
}
else if (vi >= h)
{
vi = h;
vi1 = 0;
}
ui += vi*w;
a = samples[ui];
b = samples[ui + ui1];
a |= samples[ui + vi1]<<16;
b |= samples[ui + ui1 + vi1]<<16;
ud = (u>>8) & 0xFF;
vd = (v>>8) & 0xFF;
ud = FZ_EXPAND(ud);
vd = FZ_EXPAND(vd);
/* a = blend(a,b,ud) */
a = ((b-a) * ud + (a<<8)) & MASK;
/* a = blend(a,a>>16,vd) */
a = (((a>>24)-(a>>8)) * vd + a);
a = (a>>8) & 0xFF;
ca = FZ_COMBINE(FZ_EXPAND(cov),FZ_EXPAND(a));
if (ca != 0)
{
if (ca == 256)
{
drb = (ga<<8) | rb;
}
else
{
dga = drb & MASK;
drb = (drb<<8) & MASK;
cga = ga - (dga>>8);
crb = rb - (drb>>8);
dga += cga * ca;
drb += crb * ca;
dga &= MASK;
drb &= MASK;
drb = dga | (drb>>8);
}
dst32[-1] = drb;
}
}
u += fa;
v += fb;
}
}
}
static void
img_1o1_32bit(byte * restrict src, byte cov, int len, byte * restrict dst,
fz_pixmap *image, int u, int v, int fa, int fb)
{
byte *samples = image->samples;
int w = image->w;
int h = image->h-1;
while (len--)
{
unsigned int a, b;
cov += *src; *src = 0; src++;
if (cov != 0)
{
int ui, ui1, vi, vi1, ud, vd;
/* sa = samplemask(samples, w, h, u, v); */
ui1 = 1;
ui = u >> 16;
if (ui < 0)
{
ui = 0;
ui1 = 0;
}
else if (ui >= w-1)
{
ui = w-1;
ui1 = 0;
}
vi1 = w;
vi = v >> 16;
if (vi < 0)
{
vi = 0;
vi1 = 0;
}
else if (vi >= h)
{
vi = h;
vi1 = 0;
}
ui += vi*w;
a = samples[ui];
b = samples[ui + ui1];
a |= samples[ui + vi1]<<16;
b |= samples[ui + ui1 + vi1]<<16;
ud = (u>>8) & 0xFF;
vd = (v>>8) & 0xFF;
ud = FZ_EXPAND(ud);
vd = FZ_EXPAND(vd);
/* a = blend(a,b,ud) */
a = ((b-a) * ud + (a<<8)) & MASK;
/* a = blend(a,a>>16,vd) */
a = (((a>>24)-(a>>8)) * vd + a);
a = (a>>8) & 0xFF;
a = FZ_COMBINE(FZ_EXPAND(a), FZ_EXPAND(cov));
if (a != 0)
{
if (a == 256)
dst[0] = 255;
else
dst[0] = FZ_BLEND(255, dst[0], a);
}
}
dst++;
u += fa;
v += fb;
}
}
void fz_accelerate(void)
{
if (sizeof(int) == 4 && sizeof(unsigned int) == 4 && !fz_isbigendian())
{
fz_path_w4i1o4 = path_w4i1o4_32bit;
fz_text_w4i1o4 = text_w4i1o4_32bit;
fz_img_4o4 = img_4o4_32bit;
fz_img_w4i1o4 = img_w4i1o4_32bit;
fz_img_1o1 = img_1o1_32bit;
}
if (sizeof(int) == 8)
{
}
#ifdef HAVE_CPUDEP
fz_acceleratearch();
#endif
}
|