2 |
- |
1 |
/* Copyright (C) 1995, 1996, 1997, 1998, 1999 Aladdin Enterprises. All rights reserved.
|
|
|
2 |
|
|
|
3 |
This software is provided AS-IS with no warranty, either express or
|
|
|
4 |
implied.
|
|
|
5 |
|
|
|
6 |
This software is distributed under license and may not be copied,
|
|
|
7 |
modified or distributed except as expressly authorized under the terms
|
|
|
8 |
of the license contained in the file LICENSE in this distribution.
|
|
|
9 |
|
|
|
10 |
For more information about licensing, please refer to
|
|
|
11 |
http://www.ghostscript.com/licensing/. For information on
|
|
|
12 |
commercial licensing, go to http://www.artifex.com/licensing/ or
|
|
|
13 |
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
|
|
|
14 |
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
/* $Id: gsbittab.c,v 1.5 2002/06/16 05:48:55 lpd Exp $ */
|
|
|
18 |
/* Tables for bit operations */
|
|
|
19 |
#include "stdpre.h"
|
|
|
20 |
#include "gsbittab.h"
|
|
|
21 |
|
|
|
22 |
/* ---------------- Byte processing tables ---------------- */
|
|
|
23 |
|
|
|
24 |
/*
|
|
|
25 |
* byte_reverse_bits[B] = the byte B with the order of bits reversed.
|
|
|
26 |
*/
|
|
|
27 |
const byte byte_reverse_bits[256] = {
|
|
|
28 |
bit_table_8(0, 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80)
|
|
|
29 |
};
|
|
|
30 |
|
|
|
31 |
/*
|
|
|
32 |
* byte_right_mask[N] = a byte with N trailing 1s, 0 <= N <= 8.
|
|
|
33 |
*/
|
|
|
34 |
const byte byte_right_mask[9] = {
|
|
|
35 |
0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff
|
|
|
36 |
};
|
|
|
37 |
|
|
|
38 |
/*
|
|
|
39 |
* byte_count_bits[B] = the number of 1-bits in a byte with value B.
|
|
|
40 |
*/
|
|
|
41 |
const byte byte_count_bits[256] = {
|
|
|
42 |
bit_table_8(0, 1, 1, 1, 1, 1, 1, 1, 1)
|
|
|
43 |
};
|
|
|
44 |
|
|
|
45 |
/* ---------------- Scanning tables ---------------- */
|
|
|
46 |
|
|
|
47 |
/*
|
|
|
48 |
* byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the
|
|
|
49 |
* run of 1-bits starting at bit N in a byte with value B,
|
|
|
50 |
* numbering the bits in the byte as 01234567. If the run includes
|
|
|
51 |
* the low-order bit (i.e., might be continued into a following byte),
|
|
|
52 |
* the run length is increased by 8.
|
|
|
53 |
*/
|
|
|
54 |
|
|
|
55 |
#define t8(n) n,n,n,n,n+1,n+1,n+2,n+11
|
|
|
56 |
#define r8(n) n,n,n,n,n,n,n,n
|
|
|
57 |
#define r16(n) r8(n),r8(n)
|
|
|
58 |
#define r32(n) r16(n),r16(n)
|
|
|
59 |
#define r64(n) r32(n),r32(n)
|
|
|
60 |
#define r128(n) r64(n),r64(n)
|
|
|
61 |
const byte byte_bit_run_length_0[256] = {
|
|
|
62 |
r128(0), r64(1), r32(2), r16(3), r8(4), t8(5)
|
|
|
63 |
};
|
|
|
64 |
const byte byte_bit_run_length_1[256] = {
|
|
|
65 |
r64(0), r32(1), r16(2), r8(3), t8(4),
|
|
|
66 |
r64(0), r32(1), r16(2), r8(3), t8(4)
|
|
|
67 |
};
|
|
|
68 |
const byte byte_bit_run_length_2[256] = {
|
|
|
69 |
r32(0), r16(1), r8(2), t8(3),
|
|
|
70 |
r32(0), r16(1), r8(2), t8(3),
|
|
|
71 |
r32(0), r16(1), r8(2), t8(3),
|
|
|
72 |
r32(0), r16(1), r8(2), t8(3)
|
|
|
73 |
};
|
|
|
74 |
const byte byte_bit_run_length_3[256] = {
|
|
|
75 |
r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
|
|
|
76 |
r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
|
|
|
77 |
r16(0), r8(1), t8(2), r16(0), r8(1), t8(2),
|
|
|
78 |
r16(0), r8(1), t8(2), r16(0), r8(1), t8(2)
|
|
|
79 |
};
|
|
|
80 |
const byte byte_bit_run_length_4[256] = {
|
|
|
81 |
r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
|
|
|
82 |
r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
|
|
|
83 |
r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
|
|
|
84 |
r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1),
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
#define rr8(a,b,c,d,e,f,g,h)\
|
|
|
88 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
89 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
90 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
91 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
92 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
93 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
94 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h,\
|
|
|
95 |
a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h, a,b,c,d,e,f,g,h
|
|
|
96 |
const byte byte_bit_run_length_5[256] = {
|
|
|
97 |
rr8(0, 0, 0, 0, 1, 1, 2, 11)
|
|
|
98 |
};
|
|
|
99 |
const byte byte_bit_run_length_6[256] = {
|
|
|
100 |
rr8(0, 0, 1, 10, 0, 0, 1, 10)
|
|
|
101 |
};
|
|
|
102 |
const byte byte_bit_run_length_7[256] = {
|
|
|
103 |
rr8(0, 9, 0, 9, 0, 9, 0, 9)
|
|
|
104 |
};
|
|
|
105 |
|
|
|
106 |
/* Pointer tables indexed by bit number. */
|
|
|
107 |
|
|
|
108 |
const byte *const byte_bit_run_length[8] = {
|
|
|
109 |
byte_bit_run_length_0, byte_bit_run_length_1,
|
|
|
110 |
byte_bit_run_length_2, byte_bit_run_length_3,
|
|
|
111 |
byte_bit_run_length_4, byte_bit_run_length_5,
|
|
|
112 |
byte_bit_run_length_6, byte_bit_run_length_7
|
|
|
113 |
};
|
|
|
114 |
const byte *const byte_bit_run_length_neg[8] = {
|
|
|
115 |
byte_bit_run_length_0, byte_bit_run_length_7,
|
|
|
116 |
byte_bit_run_length_6, byte_bit_run_length_5,
|
|
|
117 |
byte_bit_run_length_4, byte_bit_run_length_3,
|
|
|
118 |
byte_bit_run_length_2, byte_bit_run_length_1
|
|
|
119 |
};
|
|
|
120 |
|
|
|
121 |
/*
|
|
|
122 |
* byte_acegbdfh_to_abcdefgh[acegbdfh] = abcdefgh, where the letters
|
|
|
123 |
* denote the individual bits of the byte.
|
|
|
124 |
*/
|
|
|
125 |
const byte byte_acegbdfh_to_abcdefgh[256] = {
|
|
|
126 |
bit_table_8(0, 0x80, 0x20, 0x08, 0x02, 0x40, 0x10, 0x04, 0x01)
|
|
|
127 |
};
|
|
|
128 |
|
|
|
129 |
/* Some C compilers insist on having executable code in every file.... */
|
|
|
130 |
void gsbittab_dummy(void); /* for picky compilers */
|
|
|
131 |
void
|
|
|
132 |
gsbittab_dummy(void)
|
|
|
133 |
{
|
|
|
134 |
}
|