/src/ghostpdl/base/gsbittab.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2023 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco, |
13 | | CA 94129, USA, for further information. |
14 | | */ |
15 | | |
16 | | |
17 | | /* Tables for bit operations */ |
18 | | #include "stdpre.h" |
19 | | #include "gsbittab.h" |
20 | | |
21 | | /* ---------------- Byte processing tables ---------------- */ |
22 | | |
23 | | /* |
24 | | * byte_reverse_bits[B] = the byte B with the order of bits reversed. |
25 | | */ |
26 | | const byte byte_reverse_bits[256] = { |
27 | | bit_table_8(0, 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80) |
28 | | }; |
29 | | |
30 | | /* |
31 | | * byte_right_mask[N] = a byte with N trailing 1s, 0 <= N <= 8. |
32 | | */ |
33 | | const byte byte_right_mask[9] = { |
34 | | 0, 1, 3, 7, 0xf, 0x1f, 0x3f, 0x7f, 0xff |
35 | | }; |
36 | | |
37 | | /* |
38 | | * byte_count_bits[B] = the number of 1-bits in a byte with value B. |
39 | | */ |
40 | | const byte byte_count_bits[256] = { |
41 | | bit_table_8(0, 1, 1, 1, 1, 1, 1, 1, 1) |
42 | | }; |
43 | | |
44 | | /* ---------------- Scanning tables ---------------- */ |
45 | | |
46 | | /* |
47 | | * byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the |
48 | | * run of 1-bits starting at bit N in a byte with value B, |
49 | | * numbering the bits in the byte as 01234567. If the run includes |
50 | | * the low-order bit (i.e., might be continued into a following byte), |
51 | | * the run length is increased by 8. |
52 | | */ |
53 | | |
54 | | #define t8(n) n,n,n,n,n+1,n+1,n+2,n+11 |
55 | | #define r8(n) n,n,n,n,n,n,n,n |
56 | | #define r16(n) r8(n),r8(n) |
57 | | #define r32(n) r16(n),r16(n) |
58 | | #define r64(n) r32(n),r32(n) |
59 | | #define r128(n) r64(n),r64(n) |
60 | | const byte byte_bit_run_length_0[256] = { |
61 | | r128(0), r64(1), r32(2), r16(3), r8(4), t8(5) |
62 | | }; |
63 | | const byte byte_bit_run_length_1[256] = { |
64 | | r64(0), r32(1), r16(2), r8(3), t8(4), |
65 | | r64(0), r32(1), r16(2), r8(3), t8(4) |
66 | | }; |
67 | | const byte byte_bit_run_length_2[256] = { |
68 | | r32(0), r16(1), r8(2), t8(3), |
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 | | }; |
73 | | const byte byte_bit_run_length_3[256] = { |
74 | | r16(0), r8(1), t8(2), r16(0), r8(1), t8(2), |
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 | | }; |
79 | | const byte byte_bit_run_length_4[256] = { |
80 | | r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), r8(0), t8(1), |
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 | | }; |
85 | | |
86 | | #define rr8(a,b,c,d,e,f,g,h)\ |
87 | | 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,\ |
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 | | const byte byte_bit_run_length_5[256] = { |
96 | | rr8(0, 0, 0, 0, 1, 1, 2, 11) |
97 | | }; |
98 | | const byte byte_bit_run_length_6[256] = { |
99 | | rr8(0, 0, 1, 10, 0, 0, 1, 10) |
100 | | }; |
101 | | const byte byte_bit_run_length_7[256] = { |
102 | | rr8(0, 9, 0, 9, 0, 9, 0, 9) |
103 | | }; |
104 | | |
105 | | /* Pointer tables indexed by bit number. */ |
106 | | |
107 | | const byte *const byte_bit_run_length[8] = { |
108 | | byte_bit_run_length_0, byte_bit_run_length_1, |
109 | | byte_bit_run_length_2, byte_bit_run_length_3, |
110 | | byte_bit_run_length_4, byte_bit_run_length_5, |
111 | | byte_bit_run_length_6, byte_bit_run_length_7 |
112 | | }; |
113 | | const byte *const byte_bit_run_length_neg[8] = { |
114 | | byte_bit_run_length_0, byte_bit_run_length_7, |
115 | | byte_bit_run_length_6, byte_bit_run_length_5, |
116 | | byte_bit_run_length_4, byte_bit_run_length_3, |
117 | | byte_bit_run_length_2, byte_bit_run_length_1 |
118 | | }; |
119 | | |
120 | | /* |
121 | | * byte_acegbdfh_to_abcdefgh[acegbdfh] = abcdefgh, where the letters |
122 | | * denote the individual bits of the byte. |
123 | | */ |
124 | | const byte byte_acegbdfh_to_abcdefgh[256] = { |
125 | | bit_table_8(0, 0x80, 0x20, 0x08, 0x02, 0x40, 0x10, 0x04, 0x01) |
126 | | }; |
127 | | |
128 | | /* Some C compilers insist on having executable code in every file.... */ |
129 | | void gsbittab_dummy(void); /* for picky compilers */ |
130 | | void |
131 | | gsbittab_dummy(void) |
132 | 0 | { |
133 | 0 | } |