coverage.c 1.31 KB

#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);
}
/*-----------------------------------------*/