WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / libhb / bits.h
blob80d9ce10b50d42c9297a34c0e2cb03542d397f95
1 /* bits.h
3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
8 */
10 #ifndef HB_BITS_H
11 #define HB_BITS_H
13 static inline int
14 allbits_set(uint32_t *bitmap, int num_words)
16 unsigned int i;
17 for( i = 0; i < num_words; i++ )
19 if( bitmap[i] != 0xFFFFFFFF )
20 return (0);
22 return (1);
25 static inline int
26 bit_is_set( uint32_t *bit_map, int bit_pos )
28 return( ( bit_map[bit_pos >> 5] & (0x1 << (bit_pos & 0x1F) ) ) != 0 );
31 static inline int
32 bit_is_clear( uint32_t *bit_map, int bit_pos )
34 return( ( bit_map[bit_pos >> 5] & ( 0x1 << (bit_pos & 0x1F) ) ) == 0 );
37 static inline void
38 bit_set( uint32_t *bit_map, int bit_pos )
40 bit_map[bit_pos >> 5] |= 0x1 << (bit_pos & 0x1F);
43 static inline void
44 bit_clear(uint32_t *bit_map, int bit_pos)
46 bit_map[bit_pos >> 5] &= ~( 0x1 << ( bit_pos & 0x1F ) );
49 static inline void
50 bit_nclear(uint32_t *bit_map, int start_pos, int stop_pos)
52 int start_word = start_pos >> 5;
53 int stop_word = stop_pos >> 5;
55 if ( start_word == stop_word )
58 bit_map[start_word] &= ( ( 0x7FFFFFFF >> ( 31 - (start_pos & 0x1F ) ) )
59 | ( 0xFFFFFFFE << ( stop_pos & 0x1F ) ) );
61 else
63 bit_map[start_word] &= ( 0x7FFFFFFF >> ( 31 - ( start_pos & 0x1F ) ) );
64 while (++start_word < stop_word)
65 bit_map[start_word] = 0;
66 bit_map[stop_word] &= 0xFFFFFFFE << ( stop_pos & 0x1F );
70 static inline void
71 bit_nset(uint32_t *bit_map, int start_pos, int stop_pos)
73 int start_word = start_pos >> 5;
74 int stop_word = stop_pos >> 5;
76 if ( start_word == stop_word )
78 bit_map[start_word] |= ( ( 0xFFFFFFFF << ( start_pos & 0x1F ) )
79 & ( 0xFFFFFFFF >> ( 31 - ( stop_pos & 0x1F ) ) ) );
81 else
83 bit_map[start_word] |= 0xFFFFFFFF << ( start_pos & 0x1F );
84 while (++start_word < stop_word)
85 bit_map[start_word] = 0xFFFFFFFF;
86 bit_map[stop_word] |= 0xFFFFFFFF >> ( 31 - ( stop_pos & 0x1F ) );
90 #endif /* HB_BITS_H */