00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef _GAN_BIT_ARRAY_H
00030 #define _GAN_BIT_ARRAY_H
00031
00032 #include <stdio.h>
00033 #include <gandalf/common/misc_defs.h>
00034 #include <gandalf/common/allocate.h>
00035 #include <gandalf/common/memory_stack.h>
00036
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif
00040
00052
00053 typedef gan_uint32 Gan_BitWord;
00054 #define GAN_BITWORD_SIZE 32
00055 #define GAN_BITWORD_FULL (gan_uint32) GAN_UINT32_MAX
00056 #define GAN_MSB_SET (gan_uint32) (1<<31)
00057 #define GAN_LSB_SET (gan_uint32) 1
00058
00059
00063 typedef enum {GAN_WORD_ALIGNMENT, GAN_BYTE_ALIGNMENT, GAN_BIT_ALIGNMENT}
00064 Gan_Alignment;
00065
00067 typedef struct Gan_BitArray
00068 {
00069 Gan_BitWord *data;
00070 unsigned int no_bits;
00071 unsigned int no_words;
00072
00073
00074 unsigned int words_alloc;
00075
00076
00077 Gan_Bool data_alloc;
00078
00079
00080 Gan_MemoryStack *memory_stack;
00081
00082
00083 Gan_Bool alloc;
00084 } Gan_BitArray;
00085
00086 Gan_BitArray *gan_bit_array_form_data ( Gan_BitArray *ba,
00087 Gan_BitWord *data, unsigned data_words,
00088 unsigned int no_bits );
00089 Gan_BitArray *gan_bit_array_ms_form ( Gan_MemoryStack *ms, Gan_BitArray *ba,
00090 unsigned int no_bits );
00091 Gan_Bool gan_bit_array_set_size ( Gan_BitArray *ba, unsigned int no_bits );
00092 void gan_bit_array_free ( Gan_BitArray *ba );
00093 void gan_bit_array_free_va ( Gan_BitArray *ba, ... );
00094
00095
00096
00097 Gan_Bool gan_bit_array_invert_i ( Gan_BitArray *ba );
00098 Gan_BitArray *gan_bit_array_invert_s ( const Gan_BitArray *ba );
00099 Gan_Bool gan_bit_array_and_i ( Gan_BitArray *ba_dst, const Gan_BitArray *ba );
00100 Gan_Bool gan_bit_array_nand_i ( Gan_BitArray *ba_dst, const Gan_BitArray *ba );
00101 Gan_Bool gan_bit_array_or_i ( Gan_BitArray *ba_dst, const Gan_BitArray *ba );
00102 Gan_Bool gan_bit_array_eor_i ( Gan_BitArray *ba_dst, const Gan_BitArray *ba );
00103 Gan_Bool gan_bit_array_andnot_i ( Gan_BitArray *ba_dst, const Gan_BitArray *ba );
00104 Gan_BitArray *gan_bit_array_and_s ( const Gan_BitArray *ba1, const Gan_BitArray *ba2 );
00105 Gan_BitArray *gan_bit_array_nand_s ( const Gan_BitArray *ba1, const Gan_BitArray *ba2 );
00106 Gan_BitArray *gan_bit_array_or_s ( const Gan_BitArray *ba1, const Gan_BitArray *ba2 );
00107 Gan_BitArray *gan_bit_array_eor_s ( const Gan_BitArray *ba1, const Gan_BitArray *ba2 );
00108 Gan_BitArray *gan_bit_array_andnot_s ( const Gan_BitArray *ba1, const Gan_BitArray *ba2 );
00109
00110
00111 Gan_Bool gan_bit_array_insert ( const Gan_BitArray *source, unsigned int offset_s,
00112 Gan_BitArray *dest, unsigned int offset_d,
00113 unsigned int no_bits );
00114
00115
00116 Gan_Bool gan_bit_array_fill ( Gan_BitArray *ba, Gan_Bool val );
00117
00118
00119 Gan_Bool gan_bit_array_copy_q ( const Gan_BitArray *ba_source,
00120 Gan_BitArray *ba_dest );
00121 Gan_BitArray *gan_bit_array_copy_s ( const Gan_BitArray *ba_source );
00122
00123 Gan_BitArray *gan_bit_array_expand_q ( const Gan_BitArray *ba,
00124 const Gan_BitArray *ref_ba,
00125 Gan_BitArray *exp_ba );
00126 Gan_BitArray *gan_bit_array_expand_s ( const Gan_BitArray *ba,
00127 const Gan_BitArray *ref_ba );
00128
00129
00130 Gan_Bool gan_bit_array_dilate_q ( Gan_BitArray *ba_source,
00131 unsigned int no_bits,
00132 Gan_BitArray *ba_dest );
00133 Gan_BitArray *gan_bit_array_dilate_s ( Gan_BitArray *ba,
00134 unsigned int no_bits );
00135
00136
00137 Gan_Bool gan_bit_array_shift_q ( Gan_BitArray *ba_source,
00138 int no_bits,
00139 Gan_BitArray *ba_dest );
00140 Gan_BitArray *gan_bit_array_shift_s ( Gan_BitArray *ba,
00141 int no_bits );
00142
00143
00144 unsigned int gan_bit_array_get_first_set_bit(Gan_BitArray *ba);
00145
00146
00147 Gan_Bool gan_bit_array_fill_part ( Gan_BitArray *ba, unsigned int offset,
00148 unsigned int no_bits, Gan_Bool val );
00149
00150
00151 Gan_Bool gan_bit_array_invert_part ( Gan_BitArray *ba, unsigned int offset,
00152 unsigned int no_bits );
00153
00154
00155 void gan_bit_array_fprint ( FILE *fp, const Gan_BitArray *ba, int indent );
00156
00160 unsigned GAN_NO_BITWORDS ( unsigned no_bits );
00161
00165 Gan_BitArray *
00166 gan_bit_array_form ( Gan_BitArray *ba, unsigned int no_bits );
00167
00171 Gan_BitArray *gan_bit_array_alloc ( unsigned int no_bits );
00172
00176 Gan_BitArray *gan_bit_array_ms_malloc ( unsigned int no_bits );
00177
00184 Gan_Bool gan_bit_array_print ( const Gan_BitArray *bit_array, int indent );
00185
00189 Gan_Bool gan_bit_array_set_bit ( Gan_BitArray *bit_array, int pos );
00190
00194 Gan_Bool gan_bit_array_get_bit ( const Gan_BitArray *bit_array, int pos );
00195
00199 Gan_Bool gan_bit_array_clear_bit ( Gan_BitArray *bit_array, int pos );
00200
00204 Gan_Bool
00205 gan_bit_array_twiddle_bit ( Gan_BitArray *bit_array, int pos, Gan_Bool val );
00206
00207
00211 Gan_Bool
00212 gan_bit_array_invert_bit ( Gan_BitArray *bit_array, int pos );
00213
00223 Gan_Bool *gan_bit_array_dilate_i ( Gan_BitArray *ba, unsigned int no_pixels );
00224
00233 #ifdef __cplusplus
00234 }
00235 #endif
00236
00237 #endif