00001
00022 #ifndef __BCH_CODE__H__
00023 #define __BCH_CODE__H__
00024
00025 #include <ARToolKitPlus/config.h>
00026
00027 #include <vector>
00028
00029 namespace ARToolKitPlus {
00030
00031
00032
00033
00034 #define BCH_DEFAULT_M 6
00035 #define BCH_DEFAULT_LENGTH 36
00036 #define BCH_DEFAULT_T 4
00037 #define BCH_DEFAULT_K 12
00038
00039 #define BCH_MAX_M 6
00040 #define BCH_MAX_P 7 // MAX_M+1
00041 #define BCH_MAX_LUT 64 // 2^MAX_M
00042 #define BCH_MAX_SQ 8 // SQRT(MAX_LUT) -- (?)
00043
00044
00045
00046
00047 #if defined(_MSC_VER) || defined(_WIN32_WCE)
00048 typedef unsigned __int64 _64bits;
00049 #else
00050 typedef unsigned long long _64bits;
00051 #endif
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 class AR_EXPORT BCH
00068
00069 {
00070 public:
00071 BCH();
00072
00073 void encode(int encoded_bits[BCH_DEFAULT_LENGTH], const _64bits orig_n);
00074 bool decode(int &err_n, _64bits &orig_n, const int encoded_bits[BCH_DEFAULT_LENGTH]);
00075
00076 void encode(_64bits &encoded_n, const _64bits orig_n);
00077 bool decode(int &err_n, _64bits &orig_n, const _64bits encoded_n);
00078
00079 protected:
00080 BCH(int _m, int _length, int _t);
00081 void initialize(int _m, int _length, int _t);
00082 void generate_gf();
00083 bool gen_poly(int _t);
00084 void encode_bch(int *bb, const int *data);
00085 int decode_bch(int *recd);
00086
00087 int t;
00088 int m, n, length, k, d;
00089
00090 std::vector<int> p;
00091 std::vector<int> alpha_to;
00092 std::vector<int> index_of;
00093 std::vector<int> g;
00094
00095 std::vector<std::vector<int> > _elp;
00096 std::vector<int> _d;
00097 std::vector<int> _l;
00098 std::vector<int> _u_lu;
00099 std::vector<int> _s;
00100 std::vector<int> _root;
00101 std::vector<int> _loc;
00102 std::vector<int> _reg;
00103 };
00104
00105 }
00106
00107
00108 #endif // __BCH_CODE__H__