1 #ident "$Id: run_tbl.c,v 4.1 1997/01/12 14:54:22 gert Exp $ Copyright (c) 1994 Gert Doering"
2
3 /* run_tbl.c
4 *
5 * this file is part of the mgetty+sendfax distribution
6 *
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...)
11 */
12
13 #include "ugly.h"
14
15 static unsigned char tab[9] = { 0x00,
16 0x01, 0x03, 0x07, 0x0f,
17 0x1f, 0x3f, 0x7f, 0xff };
18
19 char w_rtab[8][256];
20 char b_rtab[8][256];
21
_P0(void)22 void make_run_tables _P0( void )
23 {
24 int i, j, k, m; /* byte = kkkjjjmm, "j" starts at bit "i" */
25 int mask; /* black mask (all ones), start bit i, j bits wide */
26
27 for ( i=0; i<8; i++ ) /* for (all starting bits) */
28 {
29 for ( j=i+1; j>=0; j-- ) /* for (all possible run lengths) */
30 {
31 mask = tab[j] << ((i-j)+1);
32
33 if ( i == 7 ) /* no fill bits to the left */
34 {
35 if ( j == i+1 ) /* no fill bits to the right */
36 {
37 w_rtab[i][0 ] = j;
38 b_rtab[i][mask] = j;
39 }
40 else /* fill bits to the right */
41 for ( m = ( 1 << (i-j) ) -1 ; m >= 0; m-- )
42 {
43 w_rtab[i][0 + (1<<(i-j)) + m ] = j;
44 b_rtab[i][mask+ 0 + m ] = j;
45 }
46 }
47 else /* i != 7 -> fill higher bits */
48 for ( k = (0x80>>i) -1; k>= 0; k-- )
49 {
50 if ( j == i+1 ) /* no noise to the right */
51 {
52 w_rtab[i][ (k << (i+1)) + 0 ] = j;
53 b_rtab[i][ (k << (i+1)) + mask ] = j;
54 }
55 else /* fill bits to left + right */
56 for ( m = ( 1 << (i-j) ) -1; m >= 0; m-- )
57 {
58 w_rtab[i][ (k << (i+1)) + 0 + (1<<(i-j)) + m ] = j;
59 b_rtab[i][ (k << (i+1)) + mask + 0 + m ] = j;
60 }
61 } /* end for (k) [noise left of top bit] */
62 } /* end for (j) [span] */
63 } /* end for (i) [top bit] */
64 }
65
66