1 /* Copyright (C) 2001-2012 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., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Interface to tables for bit operations */ 18 19 #ifndef gsbittab_INCLUDED 20 # define gsbittab_INCLUDED 21 22 /* 23 * Generate tables for transforming 2, 4, 6, or 8 bits. 24 */ 25 #define btab2_(v0,v2,v1)\ 26 v0,v1+v0,v2+v0,v2+v1+v0 27 #define bit_table_2(v0,v2,v1) btab2_(v0,v2,v1) 28 #define btab4_(v0,v8,v4,v2,v1)\ 29 btab2_(v0,v2,v1), btab2_(v4+v0,v2,v1),\ 30 btab2_(v8+v0,v2,v1), btab2_(v8+v4+v0,v2,v1) 31 #define bit_table_4(v0,v8,v4,v2,v1) btab4_(v0,v8,v4,v2,v1) 32 #define btab6_(v0,v20,v10,v8,v4,v2,v1)\ 33 btab4_(v0,v8,v4,v2,v1), btab4_(v10+v0,v8,v4,v2,v1),\ 34 btab4_(v20+v0,v8,v4,v2,v1), btab4_(v20+v10+v0,v8,v4,v2,v1) 35 #define bit_table_6(v0,v20,v10,v8,v4,v2,v1) btab6_(v0,v20,v10,v8,v4,v2,v1) 36 #define bit_table_8(v0,v80,v40,v20,v10,v8,v4,v2,v1)\ 37 btab6_(v0,v20,v10,v8,v4,v2,v1), btab6_(v40+v0,v20,v10,v8,v4,v2,v1),\ 38 btab6_(v80+v0,v20,v10,v8,v4,v2,v1), btab6_(v80+v40+v0,v20,v10,v8,v4,v2,v1) 39 40 /* 41 * byte_reverse_bits[B] = the byte B with the order of bits reversed. 42 */ 43 extern const byte byte_reverse_bits[256]; 44 45 /* 46 * byte_right_mask[N] = a byte with N trailing 1s, 0 <= N <= 8. 47 */ 48 extern const byte byte_right_mask[9]; 49 50 /* 51 * byte_count_bits[B] = the number of 1-bits in a byte with value B. 52 */ 53 extern const byte byte_count_bits[256]; 54 55 /* 56 * byte_bit_run_length_N[B], for 0 <= N <= 7, gives the length of the 57 * run of 1-bits starting at bit N in a byte with value B, 58 * numbering the bits in the byte as 01234567. If the run includes 59 * the low-order bit (i.e., might be continued into a following byte), 60 * the run length is increased by 8. 61 */ 62 extern const byte 63 byte_bit_run_length_0[256], byte_bit_run_length_1[256], 64 byte_bit_run_length_2[256], byte_bit_run_length_3[256], 65 byte_bit_run_length_4[256], byte_bit_run_length_5[256], 66 byte_bit_run_length_6[256], byte_bit_run_length_7[256]; 67 68 /* 69 * byte_bit_run_length[N] points to byte_bit_run_length_N. 70 * byte_bit_run_length_neg[N] = byte_bit_run_length[-N & 7]. 71 */ 72 extern const byte *const byte_bit_run_length[8]; 73 extern const byte *const byte_bit_run_length_neg[8]; 74 75 /* 76 * byte_acegbdfh_to_abcdefgh[acegbdfh] = abcdefgh, where the letters 77 * denote the individual bits of the byte. 78 */ 79 extern const byte byte_acegbdfh_to_abcdefgh[256]; 80 81 #endif /* gsbittab_INCLUDED */ 82