coverage.c
1.31 KB
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
#include "graphic.h"
/*-----------------------------------------*/
do_coverage( px, sl, sr, mask)
int px;
struct MS_subpixel *sl, *sr;
int *mask;
{
int lmask = 0, rmask = 0;
int sx;
int i, j;
j = 1 << (AA_SP_COUNT-1);
for(i=0; i<AA_SP_COUNT; i++) {
lmask = lmask << AA_SP_SHFT;
rmask = rmask << AA_SP_SHFT;
/* valid subpixel */
if (sl->xv & j) {
/* pixel after this subpixel, fully covered */
if (px > sl->xi[i]) lmask |= AA_SP_MASK;
else if (px == sl->xi[i]) {
/* extract the subpixel x coordinate, increment if fraction not zero */
sx = (sl->xf[i]) >> (EW_X_FRAC_SHFT - AA_SP_BITS);
lmask |= sp_decode_b[sx];
}
}
if (sr->xv & j) {
if (px < sr->xi[i]) rmask |= AA_SP_MASK;
else if (px == sr->xi[i]) {
sx = (sr->xf[i]) >> (EW_X_FRAC_SHFT - AA_SP_BITS);
rmask |= sp_decode_e[sx];
}
}
j = j >> 1;
}
*mask = lmask & rmask;
}
/*-----------------------------------------*/
mask_to_count( mask, count)
int mask, *count;
{
int i, j = 1, k = 0;
for (i=0; i<(AA_SP_COUNT*AA_SP_COUNT); i++) {
if (mask & j) k++;
j = j << 1;
}
*count = k;
}
/*-----------------------------------------*/
mask_to_alpha( mask, alpha)
int mask, *alpha;
{
int count;
mask_to_count( mask, &count);
*alpha = (int)((float)count/(float)(AA_SP_COUNT*AA_SP_COUNT)
*(float)ALPHA_MAX);
}
/*-----------------------------------------*/