1 #pragma once 2 /* 3 * Copyright 2016 Huy Cuong Nguyen 4 * Copyright 2016 ZXing authors 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 namespace ZXing { 20 namespace DataMatrix { 21 22 enum class SymbolShape; 23 24 class SymbolInfo 25 { 26 bool _rectangular; 27 int _dataCapacity; 28 int _errorCodewords; 29 int _matrixWidth; 30 int _matrixHeight; 31 int _dataRegions; 32 int _rsBlockData; 33 int _rsBlockError; 34 35 public: SymbolInfo(bool rectangular,int dataCapacity,int errorCodewords,int matrixWidth,int matrixHeight,int dataRegions)36 SymbolInfo(bool rectangular, int dataCapacity, int errorCodewords, int matrixWidth, int matrixHeight, int dataRegions) : 37 SymbolInfo(rectangular, dataCapacity, errorCodewords, matrixWidth, matrixHeight, dataRegions, dataCapacity, errorCodewords) {} 38 SymbolInfo(bool rectangular,int dataCapacity,int errorCodewords,int matrixWidth,int matrixHeight,int dataRegions,int rsBlockData,int rsBlockError)39 SymbolInfo(bool rectangular, int dataCapacity, int errorCodewords, int matrixWidth, int matrixHeight, int dataRegions, int rsBlockData, int rsBlockError) : 40 _rectangular(rectangular), _dataCapacity(dataCapacity), _errorCodewords(errorCodewords), 41 _matrixWidth(matrixWidth), _matrixHeight(matrixHeight), _dataRegions(dataRegions), 42 _rsBlockData(rsBlockData), _rsBlockError(rsBlockError) 43 { 44 } 45 46 static const SymbolInfo* Lookup(int dataCodewords); 47 static const SymbolInfo* Lookup(int dataCodewords, SymbolShape shape); 48 static const SymbolInfo* Lookup(int dataCodewords, bool allowRectangular); 49 static const SymbolInfo* Lookup(int dataCodewords, SymbolShape shape, int minWidth, int minHeight, int maxWidth, int maxHeight); 50 51 int horizontalDataRegions() const; 52 53 int verticalDataRegions() const; 54 symbolDataWidth()55 int symbolDataWidth() const { 56 return horizontalDataRegions() * _matrixWidth; 57 } 58 symbolDataHeight()59 int symbolDataHeight() const { 60 return verticalDataRegions() * _matrixHeight; 61 } 62 symbolWidth()63 int symbolWidth() const { 64 return symbolDataWidth() + (horizontalDataRegions() * 2); 65 } 66 symbolHeight()67 int symbolHeight() const { 68 return symbolDataHeight() + (verticalDataRegions() * 2); 69 } 70 matrixWidth()71 int matrixWidth() const { 72 return _matrixWidth; 73 } 74 matrixHeight()75 int matrixHeight() const { 76 return _matrixHeight; 77 } 78 codewordCount()79 int codewordCount() const { 80 return _dataCapacity + _errorCodewords; 81 } 82 interleavedBlockCount()83 int interleavedBlockCount() const { 84 if (_rsBlockData > 0) 85 return _dataCapacity / _rsBlockData; 86 return 10; // Symbol 144 87 } 88 dataCapacity()89 int dataCapacity() const { 90 return _dataCapacity; 91 } 92 errorCodewords()93 int errorCodewords() const { 94 return _errorCodewords; 95 } 96 dataLengthForInterleavedBlock(int index)97 int dataLengthForInterleavedBlock(int index) const { 98 if (_rsBlockData > 0) 99 return _rsBlockData; 100 return index <= 8 ? 156 : 155; // Symbol 144 101 } 102 errorLengthForInterleavedBlock()103 int errorLengthForInterleavedBlock() const { 104 return _rsBlockError; 105 } 106 }; 107 108 } // DataMatrix 109 } // ZXing 110