1
/* #ident "@(#)run_tbl.c 3.1 95/08/30 Copyright (c) 1994 Gert Doering" */
5
* this file is part of the mgetty+sendfax distribution
7
* compute a set of arrays that will speed up finding the run length
8
* of black or white bits in a byte enourmously
9
* (I do not include the array as it is larger than the source and
10
* computation is fast enough - 0.005 secs on my machine...)
13
static unsigned char tab[9] = { 0x00,
14
0x01, 0x03, 0x07, 0x0f,
15
0x1f, 0x3f, 0x7f, 0xff };
20
void make_run_tables ( void )
22
int i, j, k, m; /* byte = kkkjjjmm, "j" starts at bit "i" */
23
int mask; /* black mask (all ones), start bit i, j bits wide */
25
for ( i=0; i<8; i++ ) /* for (all starting bits) */
27
for ( j=i+1; j>=0; j-- ) /* for (all possible run lengths) */
29
mask = tab[j] << ((i-j)+1);
31
if ( i == 7 ) /* no fill bits to the left */
33
if ( j == i+1 ) /* no fill bits to the right */
38
else /* fill bits to the right */
39
for ( m = ( 1 << (i-j) ) -1 ; m >= 0; m-- )
41
w_rtab[i][0 + (1<<(i-j)) + m ] = j;
42
b_rtab[i][mask+ 0 + m ] = j;
45
else /* i != 7 -> fill higher bits */
46
for ( k = (0x80>>i) -1; k>= 0; k-- )
48
if ( j == i+1 ) /* no noise to the right */
50
w_rtab[i][ (k << (i+1)) + 0 ] = j;
51
b_rtab[i][ (k << (i+1)) + mask ] = j;
53
else /* fill bits to left + right */
54
for ( m = ( 1 << (i-j) ) -1; m >= 0; m-- )
56
w_rtab[i][ (k << (i+1)) + 0 + (1<<(i-j)) + m ] = j;
57
b_rtab[i][ (k << (i+1)) + mask + 0 + m ] = j;
59
} /* end for (k) [noise left of top bit] */
60
} /* end for (j) [span] */
61
} /* end for (i) [top bit] */