2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
36
* Redistributions of source code must retain the above copyright notice,
37
this list of conditions and the following disclaimer.
38
* Redistributions in binary form must reproduce the above copyright notice,
39
this list of conditions and the following disclaimer in the documentation
40
and/or other materials provided with the distribution.
41
* Neither the name of the Cognitive Technologies nor the names of its
42
contributors may be used to endorse or promote products derived from this
43
software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64
extern const Word8 bit_byte[8];
65
extern const Word8 lbit_byte[8];
66
extern const Word16 bit_word[16];
67
extern const Word16 lbit_word[16];
68
extern const Word8 right_0[256];
69
extern const Word8 left_0[256];
70
extern const Word8 bit0_cnt[256];
71
extern const Word8 bit1_cnt[256];
72
extern const Word8 first_bit0_pos[256];
73
extern const Word8 first_bit1_pos[256];
76
#define hi_byte( some_word ) ( *( ((Word8*)&some_word) +1 ) )
77
#define low_byte( some_word ) ( (Word8)some_word )
79
#define hi_byte( some_word ) ( (Word8)some_word )
80
#define low_byte( some_word ) ( *( ((Word8*)&some_word) +1 ) )
83
#define hi_byte( some_word ) ( ((Word16)some_word)>>8 )
84
#define low_byte( some_word ) ( (Word8)some_word )
86
#define left_byte( some_word ) ( low_byte( some_word ) )
87
#define right_byte( some_word ) ( hi_byte( some_word ) )
89
#define lr_word( le_byte, ri_byte ) ( (ri_byte << 8) + le_byte )
90
#define hl_word( hi_byte, lo_byte ) ( (hi_byte << 8) + lo_byte )
92
#define FIRST_BIT_IN_BYTE( bb ) ( first_bit1_pos[ bb ] ) // 0..7; 8 if none
94
#define set_bit_to_1( to_word, bit_num ) ( (to_word) |= bit_word[ bit_num ] )
95
#define set_bit_to_0( to_word, bit_num ) ( (to_word) &= ~bit_word[ bit_num ] )
96
#define is_bit( in_word, bit_num ) ( (in_word) & bit_word[ bit_num ] )
98
// for reversed data images (TIFF 'II')
99
#define set_bit_to_1_inv( to_word, bit_num ) ( (to_word) |= lbit_word[ bit_num ] )
100
#define set_bit_to_0_inv( to_word, bit_num ) ( (to_word) &= ~lbit_word[ bit_num ] )
101
#define is_bit_inv( in_word, bit_num ) ( (in_word) & lbit_word[ bit_num ] )
102
// returns 0x0000 if bit "i" is 0 in "in_word"
104
#define bit0_count( in_word ) \
105
( bit0_cnt[ hi_byte(in_word) ] + bit0_cnt[ low_byte(in_word) ] )
106
#define bit1_count( in_word ) \
107
( bit1_cnt[ hi_byte(in_word) ] + bit1_cnt[ low_byte(in_word) ] )
109
#define left_part_0( of_word ) \
110
( left_byte( of_word ) ? \
111
lr_word( left_0[ left_byte(of_word) ], 0xFF ) \
112
: lr_word( 0x00, left_0[ right_byte(of_word) ] ) \
115
#define right_part_0( of_word ) \
116
( right_byte( of_word ) ? \
117
lr_word( 0xFF, right_0[ right_byte(of_word) ]) \
118
: lr_word( right_0[ left_byte(of_word) ], 0x00 ) \
121
#endif // __BIT_FUNC_H