Fork of https://developer.mbed.org/teams/Renesas/code/GR-PEACH_mbed-os-client-ZXingSample/

Committer:
Osamu Nakamura
Date:
Fri Jan 12 15:41:00 2018 +0900
Revision:
0:2f8d4a574b4e
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Osamu Nakamura 0:2f8d4a574b4e 1 // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
Osamu Nakamura 0:2f8d4a574b4e 2 #ifndef __BIT_MATRIX_H__
Osamu Nakamura 0:2f8d4a574b4e 3 #define __BIT_MATRIX_H__
Osamu Nakamura 0:2f8d4a574b4e 4
Osamu Nakamura 0:2f8d4a574b4e 5 /*
Osamu Nakamura 0:2f8d4a574b4e 6 * BitMatrix.h
Osamu Nakamura 0:2f8d4a574b4e 7 * zxing
Osamu Nakamura 0:2f8d4a574b4e 8 *
Osamu Nakamura 0:2f8d4a574b4e 9 * Copyright 2010 ZXing authors All rights reserved.
Osamu Nakamura 0:2f8d4a574b4e 10 *
Osamu Nakamura 0:2f8d4a574b4e 11 * Licensed under the Apache License, Version 2.0 (the "License");
Osamu Nakamura 0:2f8d4a574b4e 12 * you may not use this file except in compliance with the License.
Osamu Nakamura 0:2f8d4a574b4e 13 * You may obtain a copy of the License at
Osamu Nakamura 0:2f8d4a574b4e 14 *
Osamu Nakamura 0:2f8d4a574b4e 15 * http://www.apache.org/licenses/LICENSE-2.0
Osamu Nakamura 0:2f8d4a574b4e 16 *
Osamu Nakamura 0:2f8d4a574b4e 17 * Unless required by applicable law or agreed to in writing, software
Osamu Nakamura 0:2f8d4a574b4e 18 * distributed under the License is distributed on an "AS IS" BASIS,
Osamu Nakamura 0:2f8d4a574b4e 19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Osamu Nakamura 0:2f8d4a574b4e 20 * See the License for the specific language governing permissions and
Osamu Nakamura 0:2f8d4a574b4e 21 * limitations under the License.
Osamu Nakamura 0:2f8d4a574b4e 22 */
Osamu Nakamura 0:2f8d4a574b4e 23
Osamu Nakamura 0:2f8d4a574b4e 24 #include <zxing/common/Counted.h>
Osamu Nakamura 0:2f8d4a574b4e 25 #include <zxing/common/BitArray.h>
Osamu Nakamura 0:2f8d4a574b4e 26 #include <zxing/common/Array.h>
Osamu Nakamura 0:2f8d4a574b4e 27 #include <limits>
Osamu Nakamura 0:2f8d4a574b4e 28 #if defined(__ICCARM__) //
Osamu Nakamura 0:2f8d4a574b4e 29 #include <stddef.h> /*for size_t*/ //
Osamu Nakamura 0:2f8d4a574b4e 30 #endif //
Osamu Nakamura 0:2f8d4a574b4e 31
Osamu Nakamura 0:2f8d4a574b4e 32 namespace zxing {
Osamu Nakamura 0:2f8d4a574b4e 33
Osamu Nakamura 0:2f8d4a574b4e 34 class BitMatrix : public Counted {
Osamu Nakamura 0:2f8d4a574b4e 35 public:
Osamu Nakamura 0:2f8d4a574b4e 36 static const int bitsPerWord = std::numeric_limits<unsigned int>::digits;
Osamu Nakamura 0:2f8d4a574b4e 37
Osamu Nakamura 0:2f8d4a574b4e 38 private:
Osamu Nakamura 0:2f8d4a574b4e 39 int width;
Osamu Nakamura 0:2f8d4a574b4e 40 int height;
Osamu Nakamura 0:2f8d4a574b4e 41 int rowSize;
Osamu Nakamura 0:2f8d4a574b4e 42 ArrayRef<int> bits;
Osamu Nakamura 0:2f8d4a574b4e 43
Osamu Nakamura 0:2f8d4a574b4e 44 #define ZX_LOG_DIGITS(digits) \
Osamu Nakamura 0:2f8d4a574b4e 45 ((digits == 8) ? 3 : \
Osamu Nakamura 0:2f8d4a574b4e 46 ((digits == 16) ? 4 : \
Osamu Nakamura 0:2f8d4a574b4e 47 ((digits == 32) ? 5 : \
Osamu Nakamura 0:2f8d4a574b4e 48 ((digits == 64) ? 6 : \
Osamu Nakamura 0:2f8d4a574b4e 49 ((digits == 128) ? 7 : \
Osamu Nakamura 0:2f8d4a574b4e 50 (-1))))))
Osamu Nakamura 0:2f8d4a574b4e 51
Osamu Nakamura 0:2f8d4a574b4e 52 static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
Osamu Nakamura 0:2f8d4a574b4e 53 static const int bitsMask = (1 << logBits) - 1;
Osamu Nakamura 0:2f8d4a574b4e 54
Osamu Nakamura 0:2f8d4a574b4e 55 public:
Osamu Nakamura 0:2f8d4a574b4e 56 BitMatrix(int dimension);
Osamu Nakamura 0:2f8d4a574b4e 57 BitMatrix(int width, int height);
Osamu Nakamura 0:2f8d4a574b4e 58
Osamu Nakamura 0:2f8d4a574b4e 59 ~BitMatrix();
Osamu Nakamura 0:2f8d4a574b4e 60
Osamu Nakamura 0:2f8d4a574b4e 61 bool get(int x, int y) const {
Osamu Nakamura 0:2f8d4a574b4e 62 int offset = y * rowSize + (x >> logBits);
Osamu Nakamura 0:2f8d4a574b4e 63 return ((((unsigned)bits[offset]) >> (x & bitsMask)) & 1) != 0;
Osamu Nakamura 0:2f8d4a574b4e 64 }
Osamu Nakamura 0:2f8d4a574b4e 65
Osamu Nakamura 0:2f8d4a574b4e 66 void set(int x, int y) {
Osamu Nakamura 0:2f8d4a574b4e 67 int offset = y * rowSize + (x >> logBits);
Osamu Nakamura 0:2f8d4a574b4e 68 bits[offset] |= 1 << (x & bitsMask);
Osamu Nakamura 0:2f8d4a574b4e 69 }
Osamu Nakamura 0:2f8d4a574b4e 70
Osamu Nakamura 0:2f8d4a574b4e 71 void flip(int x, int y);
Osamu Nakamura 0:2f8d4a574b4e 72 void clear();
Osamu Nakamura 0:2f8d4a574b4e 73 void setRegion(int left, int top, int width, int height);
Osamu Nakamura 0:2f8d4a574b4e 74 Ref<BitArray> getRow(int y, Ref<BitArray> row);
Osamu Nakamura 0:2f8d4a574b4e 75
Osamu Nakamura 0:2f8d4a574b4e 76 int getWidth() const;
Osamu Nakamura 0:2f8d4a574b4e 77 int getHeight() const;
Osamu Nakamura 0:2f8d4a574b4e 78
Osamu Nakamura 0:2f8d4a574b4e 79 ArrayRef<int> getTopLeftOnBit() const;
Osamu Nakamura 0:2f8d4a574b4e 80 ArrayRef<int> getBottomRightOnBit() const;
Osamu Nakamura 0:2f8d4a574b4e 81
Osamu Nakamura 0:2f8d4a574b4e 82 friend std::ostream& operator<<(std::ostream &out, const BitMatrix &bm);
Osamu Nakamura 0:2f8d4a574b4e 83 const char *description();
Osamu Nakamura 0:2f8d4a574b4e 84
Osamu Nakamura 0:2f8d4a574b4e 85 private:
Osamu Nakamura 0:2f8d4a574b4e 86 inline void init(int, int);
Osamu Nakamura 0:2f8d4a574b4e 87
Osamu Nakamura 0:2f8d4a574b4e 88 BitMatrix(const BitMatrix&);
Osamu Nakamura 0:2f8d4a574b4e 89 BitMatrix& operator =(const BitMatrix&);
Osamu Nakamura 0:2f8d4a574b4e 90 };
Osamu Nakamura 0:2f8d4a574b4e 91
Osamu Nakamura 0:2f8d4a574b4e 92 }
Osamu Nakamura 0:2f8d4a574b4e 93
Osamu Nakamura 0:2f8d4a574b4e 94 #endif // __BIT_MATRIX_H__