This is the sample program that can see the decode result of barcode data on Watson IoT.

Dependencies:   AsciiFont DisplayApp GR-PEACH_video LCD_shield_config LWIPBP3595Interface_STA_for_mbed-os USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BitMatrix.h Source File

BitMatrix.h

00001 // -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
00002 #ifndef __BIT_MATRIX_H__
00003 #define __BIT_MATRIX_H__
00004 
00005 /*
00006  *  BitMatrix.h
00007  *  zxing
00008  *
00009  *  Copyright 2010 ZXing authors All rights reserved.
00010  *
00011  * Licensed under the Apache License, Version 2.0 (the "License");
00012  * you may not use this file except in compliance with the License.
00013  * You may obtain a copy of the License at
00014  *
00015  *      http://www.apache.org/licenses/LICENSE-2.0
00016  *
00017  * Unless required by applicable law or agreed to in writing, software
00018  * distributed under the License is distributed on an "AS IS" BASIS,
00019  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020  * See the License for the specific language governing permissions and
00021  * limitations under the License.
00022  */
00023 
00024 #include <zxing/common/Counted.h>
00025 #include <zxing/common/BitArray.h>
00026 #include <zxing/common/Array.h>
00027 #include <limits>
00028 #if defined(__ICCARM__)             //
00029 #include <stddef.h> /*for size_t*/  //
00030 #endif                              //
00031 
00032 namespace zxing {
00033 
00034 class BitMatrix : public Counted {
00035 public:
00036   static const int bitsPerWord = std::numeric_limits<unsigned int>::digits;
00037 
00038 private:
00039   int width;
00040   int height;
00041   int rowSize;
00042   ArrayRef<int> bits;
00043 
00044 #define ZX_LOG_DIGITS(digits) \
00045     ((digits == 8) ? 3 : \
00046      ((digits == 16) ? 4 : \
00047       ((digits == 32) ? 5 : \
00048        ((digits == 64) ? 6 : \
00049         ((digits == 128) ? 7 : \
00050          (-1))))))
00051 
00052   static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
00053   static const int bitsMask = (1 << logBits) - 1;
00054 
00055 public:
00056   BitMatrix(int dimension);
00057   BitMatrix(int width, int height);
00058 
00059   ~BitMatrix();
00060 
00061   bool get(int x, int y) const {
00062     int offset = y * rowSize + (x >> logBits);
00063     return ((((unsigned)bits[offset]) >> (x & bitsMask)) & 1) != 0;
00064   }
00065 
00066   void set(int x, int y) {
00067     int offset = y * rowSize + (x >> logBits);
00068     bits[offset] |= 1 << (x & bitsMask);
00069   }
00070 
00071   void flip(int x, int y);
00072   void clear();
00073   void setRegion(int left, int top, int width, int height);
00074   Ref<BitArray> getRow(int y, Ref<BitArray> row);
00075 
00076   int getWidth() const;
00077   int getHeight() const;
00078 
00079   ArrayRef<int> getTopLeftOnBit() const;
00080   ArrayRef<int> getBottomRightOnBit() const;
00081 
00082   friend std::ostream& operator<<(std::ostream &out, const BitMatrix &bm);
00083   const char *description();
00084 
00085 private:
00086   inline void init(int, int);
00087 
00088   BitMatrix(const BitMatrix&);
00089   BitMatrix& operator =(const BitMatrix&);
00090 };
00091 
00092 }
00093 
00094 #endif // __BIT_MATRIX_H__