From a26153440b46b3b37b7e81435debb296f22769f4 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Thu, 16 Jun 2016 12:29:07 -0700 Subject: Remove barcode reading code. We never read barcodes, we only write them. Remove code related to barcode reading. Review-Url: https://codereview.chromium.org/2071633002 --- .../datamatrix/BC_DataMatrixBitMatrixParser.cpp | 378 ---------------- .../datamatrix/BC_DataMatrixBitMatrixParser.h | 46 -- .../datamatrix/BC_DataMatrixDataBlock.cpp | 103 ----- xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h | 33 -- .../BC_DataMatrixDecodedBitStreamParser.cpp | 473 --------------------- .../BC_DataMatrixDecodedBitStreamParser.h | 61 --- xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp | 109 ----- xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h | 32 -- xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp | 415 ------------------ xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h | 78 ---- xfa/fxbarcode/datamatrix/BC_DataMatrixReader.cpp | 66 --- xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h | 32 -- xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp | 191 --------- xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h | 75 ---- xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp | 1 - 15 files changed, 2093 deletions(-) delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixReader.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp delete mode 100644 xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h (limited to 'xfa/fxbarcode/datamatrix') diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp deleted file mode 100644 index 10d5a843e2..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.cpp +++ /dev/null @@ -1,378 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2007 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h" - -#include - -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" -#include "xfa/fxbarcode/utils.h" - -CBC_DataMatrixBitMatrixParser::CBC_DataMatrixBitMatrixParser() { - m_mappingBitMatrix = nullptr; - m_version = nullptr; - m_readMappingMatrix = nullptr; -} -void CBC_DataMatrixBitMatrixParser::Init(CBC_CommonBitMatrix* bitMatrix, - int32_t& e) { - int32_t dimension = bitMatrix->GetHeight(); - if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0) { - e = BCExceptionFormatException; - return; - } - m_version = ReadVersion(bitMatrix, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - m_mappingBitMatrix = ExtractDataRegion(bitMatrix, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - m_readMappingMatrix = new CBC_CommonBitMatrix(); - m_readMappingMatrix->Init(m_mappingBitMatrix->GetWidth(), - m_mappingBitMatrix->GetHeight()); -} -CBC_DataMatrixBitMatrixParser::~CBC_DataMatrixBitMatrixParser() { - delete m_mappingBitMatrix; - delete m_readMappingMatrix; -} -CBC_DataMatrixVersion* CBC_DataMatrixBitMatrixParser::GetVersion() { - return m_version; -} -CBC_DataMatrixVersion* CBC_DataMatrixBitMatrixParser::ReadVersion( - CBC_CommonBitMatrix* bitMatrix, - int32_t& e) { - int32_t rows = bitMatrix->GetHeight(); - int32_t columns = bitMatrix->GetWidth(); - CBC_DataMatrixVersion* temp = - CBC_DataMatrixVersion::GetVersionForDimensions(rows, columns, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - return temp; -} -CFX_ByteArray* CBC_DataMatrixBitMatrixParser::ReadCodewords(int32_t& e) { - std::unique_ptr result(new CFX_ByteArray()); - result->SetSize(m_version->GetTotalCodewords()); - int32_t resultOffset = 0; - int32_t row = 4; - int32_t column = 0; - int32_t numRows = m_mappingBitMatrix->GetHeight(); - int32_t numColumns = m_mappingBitMatrix->GetWidth(); - FX_BOOL corner1Read = FALSE; - FX_BOOL corner2Read = FALSE; - FX_BOOL corner3Read = FALSE; - FX_BOOL corner4Read = FALSE; - do { - if ((row == numRows) && (column == 0) && !corner1Read) { - (*result)[resultOffset++] = (uint8_t)ReadCorner1(numRows, numColumns); - row -= 2; - column += 2; - corner1Read = TRUE; - } else if ((row == numRows - 2) && (column == 0) && - ((numColumns & 0x03) != 0) && !corner2Read) { - (*result)[resultOffset++] = (uint8_t)ReadCorner2(numRows, numColumns); - row -= 2; - column += 2; - corner2Read = TRUE; - } else if ((row == numRows + 4) && (column == 2) && - ((numColumns & 0x07) == 0) && !corner3Read) { - (*result)[resultOffset++] = (uint8_t)ReadCorner3(numRows, numColumns); - row -= 2; - column += 2; - corner3Read = TRUE; - } else if ((row == numRows - 2) && (column == 0) && - ((numColumns & 0x07) == 4) && !corner4Read) { - (*result)[resultOffset++] = (uint8_t)ReadCorner4(numRows, numColumns); - row -= 2; - column += 2; - corner4Read = TRUE; - } else { - do { - if ((row < numRows) && (column >= 0) && - !m_readMappingMatrix->Get(column, row)) { - if (resultOffset < (*result).GetSize()) { - (*result)[resultOffset++] = - (uint8_t)ReadUtah(row, column, numRows, numColumns); - } - } - row -= 2; - column += 2; - } while ((row >= 0) && (column < numColumns)); - row += 1; - column += 3; - do { - if ((row >= 0) && (column < numColumns) && - !m_readMappingMatrix->Get(column, row)) { - if (resultOffset < (*result).GetSize()) { - (*result)[resultOffset++] = - (uint8_t)ReadUtah(row, column, numRows, numColumns); - } - } - row += 2; - column -= 2; - } while ((row < numRows) && (column >= 0)); - row += 3; - column += 1; - } - } while ((row < numRows) || (column < numColumns)); - if (resultOffset != m_version->GetTotalCodewords()) { - e = BCExceptionFormatException; - return nullptr; - } - return result.release(); -} -FX_BOOL CBC_DataMatrixBitMatrixParser::ReadModule(int32_t row, - int32_t column, - int32_t numRows, - int32_t numColumns) { - if (row < 0) { - row += numRows; - column += 4 - ((numRows + 4) & 0x07); - } - if (column < 0) { - column += numColumns; - row += 4 - ((numColumns + 4) & 0x07); - } - m_readMappingMatrix->Set(column, row); - return m_mappingBitMatrix->Get(column, row); -} -int32_t CBC_DataMatrixBitMatrixParser::ReadUtah(int32_t row, - int32_t column, - int32_t numRows, - int32_t numColumns) { - int32_t currentByte = 0; - if (ReadModule(row - 2, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row - 2, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row - 1, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row - 1, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row - 1, column, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row, column - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row, column - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(row, column, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; -} -int32_t CBC_DataMatrixBitMatrixParser::ReadCorner1(int32_t numRows, - int32_t numColumns) { - int32_t currentByte = 0; - if (ReadModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 1, 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 1, 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; -} -int32_t CBC_DataMatrixBitMatrixParser::ReadCorner2(int32_t numRows, - int32_t numColumns) { - int32_t currentByte = 0; - if (ReadModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 4, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; -} -int32_t CBC_DataMatrixBitMatrixParser::ReadCorner3(int32_t numRows, - int32_t numColumns) { - int32_t currentByte = 0; - if (ReadModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 3, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; -} -int32_t CBC_DataMatrixBitMatrixParser::ReadCorner4(int32_t numRows, - int32_t numColumns) { - int32_t currentByte = 0; - if (ReadModule(numRows - 3, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 2, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(numRows - 1, 0, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 2, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(0, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(1, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(2, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - currentByte <<= 1; - if (ReadModule(3, numColumns - 1, numRows, numColumns)) { - currentByte |= 1; - } - return currentByte; -} -CBC_CommonBitMatrix* CBC_DataMatrixBitMatrixParser::ExtractDataRegion( - CBC_CommonBitMatrix* bitMatrix, - int32_t& e) { - int32_t symbolSizeRows = m_version->GetSymbolSizeRows(); - int32_t symbolSizeColumns = m_version->GetSymbolSizeColumns(); - if (bitMatrix->GetHeight() != symbolSizeRows) { - e = BCExceptionCanNotCallGetDimensionOnNonSquareMatrix; - return nullptr; - } - int32_t dataRegionSizeRows = m_version->GetDataRegionSizeRows(); - int32_t dataRegionSizeColumns = m_version->GetDataRegionSizeColumns(); - int32_t numDataRegionsRow = symbolSizeRows / dataRegionSizeRows; - int32_t numDataRegionsColumn = symbolSizeColumns / dataRegionSizeColumns; - int32_t sizeDataRegionRow = numDataRegionsRow * dataRegionSizeRows; - int32_t sizeDataRegionColumn = numDataRegionsColumn * dataRegionSizeColumns; - CBC_CommonBitMatrix* bitMatrixWithoutAlignment = new CBC_CommonBitMatrix(); - bitMatrixWithoutAlignment->Init(sizeDataRegionColumn, sizeDataRegionRow); - int32_t dataRegionRow; - for (dataRegionRow = 0; dataRegionRow < numDataRegionsRow; ++dataRegionRow) { - int32_t dataRegionRowOffset = dataRegionRow * dataRegionSizeRows; - int32_t dataRegionColumn; - for (dataRegionColumn = 0; dataRegionColumn < numDataRegionsColumn; - ++dataRegionColumn) { - int32_t dataRegionColumnOffset = dataRegionColumn * dataRegionSizeColumns; - int32_t i; - for (i = 0; i < dataRegionSizeRows; ++i) { - int32_t readRowOffset = - dataRegionRow * (dataRegionSizeRows + 2) + 1 + i; - int32_t writeRowOffset = dataRegionRowOffset + i; - int32_t j; - for (j = 0; j < dataRegionSizeColumns; ++j) { - int32_t readColumnOffset = - dataRegionColumn * (dataRegionSizeColumns + 2) + 1 + j; - if (bitMatrix->Get(readColumnOffset, readRowOffset)) { - int32_t writeColumnOffset = dataRegionColumnOffset + j; - bitMatrixWithoutAlignment->Set(writeColumnOffset, writeRowOffset); - } - } - } - } - } - return bitMatrixWithoutAlignment; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h deleted file mode 100644 index 63540041e3..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXBITMATRIXPARSER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXBITMATRIXPARSER_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CBC_CommonBitMatrix; -class CBC_DataMatrixVersion; - -class CBC_DataMatrixBitMatrixParser { - public: - CBC_DataMatrixBitMatrixParser(); - virtual ~CBC_DataMatrixBitMatrixParser(); - - CBC_DataMatrixVersion* GetVersion(); - CFX_ByteArray* ReadCodewords(int32_t& e); - FX_BOOL ReadModule(int32_t row, - int32_t column, - int32_t numRows, - int32_t numColumns); - int32_t ReadUtah(int32_t row, - int32_t column, - int32_t numRows, - int32_t numColumns); - int32_t ReadCorner1(int32_t numRows, int32_t numColumns); - int32_t ReadCorner2(int32_t numRows, int32_t numColumns); - int32_t ReadCorner3(int32_t numRows, int32_t numColumns); - int32_t ReadCorner4(int32_t numRows, int32_t numColumns); - CBC_CommonBitMatrix* ExtractDataRegion(CBC_CommonBitMatrix* bitMatrix, - int32_t& e); - virtual void Init(CBC_CommonBitMatrix* bitMatrix, int32_t& e); - - private: - static CBC_DataMatrixVersion* ReadVersion(CBC_CommonBitMatrix* bitMatrix, - int32_t& e); - CBC_CommonBitMatrix* m_mappingBitMatrix; - CBC_CommonBitMatrix* m_readMappingMatrix; - CBC_DataMatrixVersion* m_version; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXBITMATRIXPARSER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp deleted file mode 100644 index e468cc42c3..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.cpp +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h" - -#include - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" -#include "xfa/fxbarcode/utils.h" - -CBC_DataMatrixDataBlock::~CBC_DataMatrixDataBlock() {} -CBC_DataMatrixDataBlock::CBC_DataMatrixDataBlock(int32_t numDataCodewords, - CFX_ByteArray* codewords) { - m_codewords.Copy(*codewords); - m_numDataCodewords = numDataCodewords; -} -CFX_ArrayTemplate* -CBC_DataMatrixDataBlock::GetDataBlocks(CFX_ByteArray* rawCodewords, - CBC_DataMatrixVersion* version, - int32_t& e) { - ECBlocks* ecBlocks = version->GetECBlocks(); - int32_t totalBlocks = 0; - const CFX_ArrayTemplate& ecBlockArray = ecBlocks->GetECBlocks(); - for (int32_t i = 0; i < ecBlockArray.GetSize(); i++) { - totalBlocks += ecBlockArray[i]->GetCount(); - } - std::unique_ptr> result( - new CFX_ArrayTemplate()); - result->SetSize(totalBlocks); - int32_t numResultBlocks = 0; - for (int32_t j = 0; j < ecBlockArray.GetSize(); j++) { - for (int32_t i = 0; i < ecBlockArray[j]->GetCount(); i++) { - int32_t numDataCodewords = ecBlockArray[j]->GetDataCodewords(); - int32_t numBlockCodewords = ecBlocks->GetECCodewords() + numDataCodewords; - CFX_ByteArray codewords; - codewords.SetSize(numBlockCodewords); - (*result)[numResultBlocks++] = - new CBC_DataMatrixDataBlock(numDataCodewords, &codewords); - codewords.SetSize(0); - } - } - int32_t longerBlocksNumDataCodewords = - (*result)[0]->GetCodewords()->GetSize() - ecBlocks->GetECCodewords(); - int32_t rawCodewordsOffset = 0; - for (int32_t i = 0; i < longerBlocksNumDataCodewords - 1; i++) { - for (int32_t j = 0; j < numResultBlocks; j++) { - if (rawCodewordsOffset < rawCodewords->GetSize()) { - (*result)[j]->GetCodewords()->operator[](i) = - (*rawCodewords)[rawCodewordsOffset++]; - } - } - } - const bool specialVersion = version->GetVersionNumber() == 24; - int32_t numLongerBlocks = specialVersion ? 8 : numResultBlocks; - for (int32_t j = 0; j < numLongerBlocks; j++) { - if (rawCodewordsOffset < rawCodewords->GetSize()) { - (*result)[j]->GetCodewords()->operator[](longerBlocksNumDataCodewords - - 1) = - (*rawCodewords)[rawCodewordsOffset++]; - } - } - for (int32_t i = longerBlocksNumDataCodewords; - i < (*result)[0]->GetCodewords()->GetSize(); i++) { - for (int32_t j = 0; j < numResultBlocks; j++) { - int32_t iOffset = specialVersion && j > 7 ? i - 1 : i; - if (rawCodewordsOffset < rawCodewords->GetSize()) { - (*result)[j]->GetCodewords()->operator[](iOffset) = - (*rawCodewords)[rawCodewordsOffset++]; - } - } - } - if (rawCodewordsOffset != rawCodewords->GetSize()) { - e = BCExceptionIllegalArgument; - return nullptr; - } - return result.release(); -} - -int32_t CBC_DataMatrixDataBlock::GetNumDataCodewords() { - return m_numDataCodewords; -} -CFX_ByteArray* CBC_DataMatrixDataBlock::GetCodewords() { - return &m_codewords; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h deleted file mode 100644 index 782e5ed319..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDATABLOCK_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDATABLOCK_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CBC_DataMatrixVersion; - -class CBC_DataMatrixDataBlock final { - public: - ~CBC_DataMatrixDataBlock(); - - int32_t GetNumDataCodewords(); - CFX_ByteArray* GetCodewords(); - - static CFX_ArrayTemplate* GetDataBlocks( - CFX_ByteArray* rawCodewords, - CBC_DataMatrixVersion* version, - int32_t& e); - - private: - CBC_DataMatrixDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords); - - int32_t m_numDataCodewords; - CFX_ByteArray m_codewords; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDATABLOCK_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp deleted file mode 100644 index 292a1de2f7..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.cpp +++ /dev/null @@ -1,473 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/common/BC_CommonBitSource.h" -#include "xfa/fxbarcode/common/BC_CommonDecoderResult.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h" - -const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::C40_BASIC_SET_CHARS[] = { - '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', - 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; -const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::C40_SHIFT2_SET_CHARS[] = { - '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', - '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_'}; -const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::TEXT_BASIC_SET_CHARS[] = { - '*', '*', '*', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', - 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; -const FX_CHAR CBC_DataMatrixDecodedBitStreamParser::TEXT_SHIFT3_SET_CHARS[] = { - '\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', - 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', - 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', 127}; -const int32_t CBC_DataMatrixDecodedBitStreamParser::PAD_ENCODE = 0; -const int32_t CBC_DataMatrixDecodedBitStreamParser::ASCII_ENCODE = 1; -const int32_t CBC_DataMatrixDecodedBitStreamParser::C40_ENCODE = 2; -const int32_t CBC_DataMatrixDecodedBitStreamParser::TEXT_ENCODE = 3; -const int32_t CBC_DataMatrixDecodedBitStreamParser::ANSIX12_ENCODE = 4; -const int32_t CBC_DataMatrixDecodedBitStreamParser::EDIFACT_ENCODE = 5; -const int32_t CBC_DataMatrixDecodedBitStreamParser::BASE256_ENCODE = 6; -CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser() {} -CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser() {} - -CBC_CommonDecoderResult* CBC_DataMatrixDecodedBitStreamParser::Decode( - CFX_ByteArray& bytes, - int32_t& e) { - CBC_CommonBitSource bits(&bytes); - CFX_ByteString result; - CFX_ByteString resultTrailer; - CFX_Int32Array byteSegments; - int32_t mode = ASCII_ENCODE; - do { - if (mode == 1) { - mode = DecodeAsciiSegment(&bits, result, resultTrailer, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - } else { - switch (mode) { - case 2: - DecodeC40Segment(&bits, result, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - break; - case 3: - DecodeTextSegment(&bits, result, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - break; - case 4: - DecodeAnsiX12Segment(&bits, result, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - break; - case 5: - DecodeEdifactSegment(&bits, result, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - break; - case 6: - DecodeBase256Segment(&bits, result, byteSegments, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - break; - default: - e = BCExceptionFormatException; - return nullptr; - } - mode = ASCII_ENCODE; - } - } while (mode != PAD_ENCODE && bits.Available() > 0); - if (resultTrailer.GetLength() > 0) { - result += resultTrailer; - } - CBC_CommonDecoderResult* tempCp = new CBC_CommonDecoderResult(); - tempCp->Init(bytes, result, byteSegments, nullptr, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - return tempCp; -} - -int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - CFX_ByteString& resultTrailer, - int32_t& e) { - FX_CHAR buffer[128]; - FX_BOOL upperShift = FALSE; - do { - int32_t oneByte = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnValue(e, 0); - if (oneByte == 0) { - e = BCExceptionFormatException; - return 0; - } else if (oneByte <= 128) { - oneByte = upperShift ? oneByte + 128 : oneByte; - upperShift = FALSE; - result += ((FX_CHAR)(oneByte - 1)); - return ASCII_ENCODE; - } else if (oneByte == 129) { - return PAD_ENCODE; - } else if (oneByte <= 229) { - int32_t value = oneByte - 130; - FXSYS_itoa(value, buffer, 10); - if (value < 10) { - result += '0'; - buffer[1] = '\0'; - } else { - buffer[2] = '\0'; - } - result += buffer; - } else if (oneByte == 230) { - return C40_ENCODE; - } else if (oneByte == 231) { - return BASE256_ENCODE; - } else if (oneByte == 232 || oneByte == 233 || oneByte == 234) { - } else if (oneByte == 235) { - upperShift = TRUE; - } else if (oneByte == 236) { - result += "[)>"; - result += 0x1E; - result += "05"; - result += 0x1D; - resultTrailer.Insert(0, 0x1E); - resultTrailer.Insert(0 + 1, 0x04); - } else if (oneByte == 237) { - result += "[)>"; - result += 0x1E; - result += "06"; - result += 0x1D; - resultTrailer.Insert(0, 0x1E); - resultTrailer.Insert(0 + 1, 0x04); - } else if (oneByte == 238) { - return ANSIX12_ENCODE; - } else if (oneByte == 239) { - return TEXT_ENCODE; - } else if (oneByte == 240) { - return EDIFACT_ENCODE; - } else if (oneByte == 241) { - } else if (oneByte >= 242) { - if (oneByte == 254 && bits->Available() == 0) { - } else { - e = BCExceptionFormatException; - return 0; - } - } - } while (bits->Available() > 0); - return ASCII_ENCODE; -} -void CBC_DataMatrixDecodedBitStreamParser::DecodeC40Segment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e) { - FX_BOOL upperShift = FALSE; - CFX_Int32Array cValues; - cValues.SetSize(3); - do { - if (bits->Available() == 8) { - return; - } - int32_t firstByte = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - if (firstByte == 254) { - return; - } - int32_t tempp = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - ParseTwoBytes(firstByte, tempp, cValues); - int32_t shift = 0; - int32_t i; - for (i = 0; i < 3; i++) { - int32_t cValue = cValues[i]; - switch (shift) { - case 0: - if (cValue < 3) { - shift = cValue + 1; - } else if (cValue < 27) { - FX_CHAR c40char = C40_BASIC_SET_CHARS[cValue]; - if (upperShift) { - result += (FX_CHAR)(c40char + 128); - upperShift = FALSE; - } else { - result += c40char; - } - } else { - e = BCExceptionFormatException; - return; - } - break; - case 1: - if (upperShift) { - result += (FX_CHAR)(cValue + 128); - upperShift = FALSE; - } else { - result += cValue; - } - shift = 0; - break; - case 2: - if (cValue < 27) { - FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue]; - if (upperShift) { - result += (FX_CHAR)(c40char + 128); - upperShift = FALSE; - } else { - result += c40char; - } - } else if (cValue == 27) { - e = BCExceptionFormatException; - return; - } else if (cValue == 30) { - upperShift = TRUE; - } else { - e = BCExceptionFormatException; - return; - } - shift = 0; - break; - case 3: - if (upperShift) { - result += (FX_CHAR)(cValue + 224); - upperShift = FALSE; - } else { - result += (FX_CHAR)(cValue + 96); - } - shift = 0; - break; - default: - // Should never be reached. - e = BCExceptionFormatException; - return; - } - } - } while (bits->Available() > 0); -} -void CBC_DataMatrixDecodedBitStreamParser::DecodeTextSegment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e) { - FX_BOOL upperShift = FALSE; - CFX_Int32Array cValues; - cValues.SetSize(3); - int32_t shift = 0; - do { - if (bits->Available() == 8) { - return; - } - int32_t firstByte = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - if (firstByte == 254) { - return; - } - int32_t inTp = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - ParseTwoBytes(firstByte, inTp, cValues); - for (int32_t i = 0; i < 3; i++) { - int32_t cValue = cValues[i]; - switch (shift) { - case 0: - if (cValue < 3) { - shift = cValue + 1; - } else if (cValue < 40) { - FX_CHAR textChar = TEXT_BASIC_SET_CHARS[cValue]; - if (upperShift) { - result += (FX_CHAR)(textChar + 128); - upperShift = FALSE; - } else { - result += textChar; - } - } else { - e = BCExceptionFormatException; - return; - } - break; - case 1: - if (upperShift) { - result += (FX_CHAR)(cValue + 128); - upperShift = FALSE; - } else { - result += cValue; - } - shift = 0; - break; - case 2: - if (cValue < 27) { - FX_CHAR c40char = C40_SHIFT2_SET_CHARS[cValue]; - if (upperShift) { - result += (FX_CHAR)(c40char + 128); - upperShift = FALSE; - } else { - result += c40char; - } - } else if (cValue == 27) { - e = BCExceptionFormatException; - return; - } else if (cValue == 30) { - upperShift = TRUE; - } else { - e = BCExceptionFormatException; - return; - } - shift = 0; - break; - case 3: - if (cValue < 19) { - FX_CHAR textChar = TEXT_SHIFT3_SET_CHARS[cValue]; - if (upperShift) { - result += (FX_CHAR)(textChar + 128); - upperShift = FALSE; - } else { - result += textChar; - } - shift = 0; - } else { - e = BCExceptionFormatException; - return; - } - break; - default: - // Should never be reached. - e = BCExceptionFormatException; - return; - } - } - } while (bits->Available() > 0); -} -void CBC_DataMatrixDecodedBitStreamParser::DecodeAnsiX12Segment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e) { - CFX_Int32Array cValues; - cValues.SetSize(3); - do { - if (bits->Available() == 8) { - return; - } - int32_t firstByte = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - if (firstByte == 254) { - return; - } - int32_t iTemp1 = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - ParseTwoBytes(firstByte, iTemp1, cValues); - int32_t i; - for (i = 0; i < 3; i++) { - int32_t cValue = cValues[i]; - if (cValue == 0) { - BC_FX_ByteString_Append(result, 1, '\r'); - } else if (cValue == 1) { - BC_FX_ByteString_Append(result, 1, '*'); - } else if (cValue == 2) { - BC_FX_ByteString_Append(result, 1, '>'); - } else if (cValue == 3) { - BC_FX_ByteString_Append(result, 1, ' '); - } else if (cValue < 14) { - BC_FX_ByteString_Append(result, 1, (FX_CHAR)(cValue + 44)); - } else if (cValue < 40) { - BC_FX_ByteString_Append(result, 1, (FX_CHAR)(cValue + 51)); - } else { - e = BCExceptionFormatException; - return; - } - } - } while (bits->Available() > 0); -} -void CBC_DataMatrixDecodedBitStreamParser::ParseTwoBytes( - int32_t firstByte, - int32_t secondByte, - CFX_Int32Array& result) { - int32_t fullBitValue = (firstByte << 8) + secondByte - 1; - int32_t temp = fullBitValue / 1600; - result[0] = temp; - fullBitValue -= temp * 1600; - temp = fullBitValue / 40; - result[1] = temp; - result[2] = fullBitValue - temp * 40; -} - -void CBC_DataMatrixDecodedBitStreamParser::DecodeEdifactSegment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e) { - FX_CHAR buffer[128]; - FX_BOOL unlatch = FALSE; - do { - if (bits->Available() <= 16) - return; - - for (int32_t i = 0; i < 4; i++) { - int32_t edifactValue = bits->ReadBits(6, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - if (edifactValue == 0x1F) - unlatch = TRUE; - - if (!unlatch) { - if ((edifactValue & 32) == 0) - edifactValue |= 64; - result += FXSYS_itoa(edifactValue, buffer, 10); - } - } - } while (!unlatch && bits->Available() > 0); -} - -void CBC_DataMatrixDecodedBitStreamParser::DecodeBase256Segment( - CBC_CommonBitSource* bits, - CFX_ByteString& result, - CFX_Int32Array& byteSegments, - int32_t& e) { - int32_t codewordPosition = 1 + bits->getByteOffset(); - int32_t iTmp = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - int32_t d1 = Unrandomize255State(iTmp, codewordPosition++); - int32_t count; - if (d1 == 0) { - count = bits->Available() / 8; - } else if (d1 < 250) { - count = d1; - } else { - int32_t iTmp3 = bits->ReadBits(8, e); - BC_EXCEPTION_CHECK_ReturnVoid(e); - count = 250 * (d1 - 249) + Unrandomize255State(iTmp3, codewordPosition++); - } - if (count < 0) { - e = BCExceptionFormatException; - return; - } - CFX_ByteArray* bytes = new CFX_ByteArray(); - bytes->SetSize(count); - int32_t i; - for (i = 0; i < count; i++) { - if (bits->Available() < 8) { - e = BCExceptionFormatException; - delete bytes; - return; - } - int32_t iTemp5 = bits->ReadBits(8, e); - if (e != BCExceptionNO) { - delete bytes; - return; - } - bytes->SetAt(i, Unrandomize255State(iTemp5, codewordPosition++)); - } - BC_FX_ByteString_Append(result, *bytes); - delete bytes; -} -uint8_t CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State( - int32_t randomizedBase256Codeword, - int32_t base256CodewordPosition) { - int32_t pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; - int32_t tempVariable = randomizedBase256Codeword - pseudoRandomNumber; - return (uint8_t)(tempVariable >= 0 ? tempVariable : tempVariable + 256); -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h deleted file mode 100644 index 4ff6776826..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_ - -class CBC_CommonDecoderResult; -class CBC_CommonBitSource; - -class CBC_DataMatrixDecodedBitStreamParser { - public: - CBC_DataMatrixDecodedBitStreamParser(); - virtual ~CBC_DataMatrixDecodedBitStreamParser(); - - static CBC_CommonDecoderResult* Decode(CFX_ByteArray& bytes, int32_t& e); - - private: - static int32_t DecodeAsciiSegment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - CFX_ByteString& resultTrailer, - int32_t& e); - static void DecodeC40Segment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e); - static void DecodeTextSegment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e); - static void DecodeAnsiX12Segment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e); - static void ParseTwoBytes(int32_t firstByte, - int32_t secondByte, - CFX_Int32Array& result); - static void DecodeEdifactSegment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - int32_t& e); - static void DecodeBase256Segment(CBC_CommonBitSource* bits, - CFX_ByteString& result, - CFX_Int32Array& byteSegments, - int32_t& e); - static uint8_t Unrandomize255State(int32_t randomizedBase256Codeword, - int32_t base256CodewordPosition); - - static const FX_CHAR C40_BASIC_SET_CHARS[]; - static const FX_CHAR C40_SHIFT2_SET_CHARS[]; - - static const FX_CHAR TEXT_BASIC_SET_CHARS[]; - static const FX_CHAR TEXT_SHIFT3_SET_CHARS[]; - static const int32_t PAD_ENCODE; - static const int32_t ASCII_ENCODE; - static const int32_t C40_ENCODE; - static const int32_t TEXT_ENCODE; - static const int32_t ANSIX12_ENCODE; - static const int32_t EDIFACT_ENCODE; - static const int32_t BASE256_ENCODE; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODEDBITSTREAMPARSER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp deleted file mode 100644 index 5bfd51b09a..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2007 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h" - -#include - -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonDecoder.h" -#include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixBitMatrixParser.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDataBlock.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDecodedBitStreamParser.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" - -CBC_DataMatrixDecoder::CBC_DataMatrixDecoder() { - m_rsDecoder = nullptr; -} -void CBC_DataMatrixDecoder::Init() { - m_rsDecoder = - new CBC_ReedSolomonDecoder(CBC_ReedSolomonGF256::DataMatrixField); -} -CBC_DataMatrixDecoder::~CBC_DataMatrixDecoder() { - delete m_rsDecoder; -} - -CBC_CommonDecoderResult* CBC_DataMatrixDecoder::Decode( - CBC_CommonBitMatrix* bits, - int32_t& e) { - CBC_DataMatrixBitMatrixParser parser; - parser.Init(bits, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - CBC_DataMatrixVersion* version = parser.GetVersion(); - std::unique_ptr codewords(parser.ReadCodewords(e)); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - CFX_ArrayTemplate* dataBlocks = - CBC_DataMatrixDataBlock::GetDataBlocks(codewords.get(), version, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - int32_t dataBlocksCount = dataBlocks->GetSize(); - int32_t totalBytes = 0; - for (int32_t i = 0; i < dataBlocksCount; i++) { - totalBytes += (*dataBlocks)[i]->GetNumDataCodewords(); - } - CFX_ByteArray resultBytes; - resultBytes.SetSize(totalBytes); - for (int32_t j = 0; j < dataBlocksCount; j++) { - CFX_ByteArray* codewordBytes = (*dataBlocks)[j]->GetCodewords(); - int32_t numDataCodewords = (*dataBlocks)[j]->GetNumDataCodewords(); - CorrectErrors(*codewordBytes, numDataCodewords, e); - if (e != BCExceptionNO) { - for (int32_t i = 0; i < dataBlocks->GetSize(); i++) { - delete (*dataBlocks)[i]; - } - delete dataBlocks; - return nullptr; - } - for (int32_t i = 0; i < numDataCodewords; i++) { - resultBytes[i * dataBlocksCount + j] = (*codewordBytes)[i]; - } - } - for (int32_t i = 0; i < (dataBlocks->GetSize()); i++) { - delete (*dataBlocks)[i]; - } - delete dataBlocks; - CBC_CommonDecoderResult* resultR = - CBC_DataMatrixDecodedBitStreamParser::Decode(resultBytes, e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - return resultR; -} - -void CBC_DataMatrixDecoder::CorrectErrors(CFX_ByteArray& codewordBytes, - int32_t numDataCodewords, - int32_t& e) { - int32_t numCodewords = codewordBytes.GetSize(); - CFX_Int32Array codewordsInts; - codewordsInts.SetSize(numCodewords); - int32_t i; - for (i = 0; i < numCodewords; i++) { - codewordsInts[i] = codewordBytes[i] & 0xFF; - } - int32_t numECCodewords = codewordBytes.GetSize() - numDataCodewords; - m_rsDecoder->Decode(&codewordsInts, numECCodewords, e); - if (e != BCExceptionNO) { - e = BCExceptionChecksumException; - return; - } - for (i = 0; i < numDataCodewords; i++) { - codewordBytes[i] = (uint8_t)codewordsInts[i]; - } -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h deleted file mode 100644 index 38d3fe5bf7..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODER_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CBC_ReedSolomonDecoder; -class CBC_CommonDecoderResult; -class CBC_CommonBitMatrix; - -class CBC_DataMatrixDecoder { - public: - CBC_DataMatrixDecoder(); - virtual ~CBC_DataMatrixDecoder(); - - CBC_CommonDecoderResult* Decode(CBC_CommonBitMatrix* bits, int32_t& e); - - virtual void Init(); - - private: - void CorrectErrors(CFX_ByteArray& codewordBytes, - int32_t numDataCodewords, - int32_t& e); - CBC_ReedSolomonDecoder* m_rsDecoder; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDECODER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp deleted file mode 100644 index d34515310e..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.cpp +++ /dev/null @@ -1,415 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2008 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h" - -#include -#include - -#include "xfa/fxbarcode/BC_ResultPoint.h" -#include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" -#include "xfa/fxbarcode/common/BC_WhiteRectangleDetector.h" -#include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" -#include "xfa/fxbarcode/qrcode/BC_QRFinderPatternFinder.h" -#include "xfa/fxbarcode/qrcode/BC_QRGridSampler.h" -#include "xfa/fxbarcode/utils.h" - -const int32_t CBC_DataMatrixDetector::INTEGERS[5] = {0, 1, 2, 3, 4}; -CBC_DataMatrixDetector::CBC_DataMatrixDetector(CBC_CommonBitMatrix* image) - : m_image(image), m_rectangleDetector(nullptr) {} -void CBC_DataMatrixDetector::Init(int32_t& e) { - m_rectangleDetector = new CBC_WhiteRectangleDetector(m_image); - m_rectangleDetector->Init(e); - BC_EXCEPTION_CHECK_ReturnVoid(e); -} -CBC_DataMatrixDetector::~CBC_DataMatrixDetector() { - delete m_rectangleDetector; -} - -CBC_QRDetectorResult* CBC_DataMatrixDetector::Detect(int32_t& e) { - CFX_ArrayTemplate* cornerPoints = - m_rectangleDetector->Detect(e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - CBC_ResultPoint* pointA = (*cornerPoints)[0]; - CBC_ResultPoint* pointB = (*cornerPoints)[1]; - CBC_ResultPoint* pointC = (*cornerPoints)[2]; - CBC_ResultPoint* pointD = (*cornerPoints)[3]; - delete cornerPoints; - - CFX_ArrayTemplate transitions; - transitions.Add(TransitionsBetween(pointA, pointB)); - transitions.Add(TransitionsBetween(pointA, pointC)); - transitions.Add(TransitionsBetween(pointB, pointD)); - transitions.Add(TransitionsBetween(pointC, pointD)); - std::sort(transitions.GetData(), - transitions.GetData() + transitions.GetSize(), - [](const CBC_ResultPointsAndTransitions* a, - const CBC_ResultPointsAndTransitions* b) { - return a->GetTransitions() < b->GetTransitions(); - }); - delete transitions[2]; - delete transitions[3]; - - CBC_ResultPointsAndTransitions* lSideOne = transitions[0]; - CBC_ResultPointsAndTransitions* lSideTwo = transitions[1]; - CFX_MapPtrTemplate pointCount; - Increment(pointCount, lSideOne->GetFrom()); - Increment(pointCount, lSideOne->GetTo()); - Increment(pointCount, lSideTwo->GetFrom()); - Increment(pointCount, lSideTwo->GetTo()); - delete transitions[1]; - delete transitions[0]; - transitions.RemoveAll(); - CBC_ResultPoint* maybeTopLeft = nullptr; - CBC_ResultPoint* bottomLeft = nullptr; - CBC_ResultPoint* maybeBottomRight = nullptr; - FX_POSITION itBegin = pointCount.GetStartPosition(); - while (itBegin) { - CBC_ResultPoint* key = 0; - int32_t value = 0; - pointCount.GetNextAssoc(itBegin, key, value); - if (value == 2) { - bottomLeft = key; - } else { - if (maybeBottomRight) { - maybeTopLeft = key; - } else { - maybeBottomRight = key; - } - } - } - if (!maybeTopLeft || !bottomLeft || !maybeBottomRight) { - delete pointA; - delete pointB; - delete pointC; - delete pointD; - e = BCExceptionNotFound; - return nullptr; - } - CFX_ArrayTemplate corners; - corners.SetSize(3); - corners[0] = maybeTopLeft; - corners[1] = bottomLeft; - corners[2] = maybeBottomRight; - OrderBestPatterns(&corners); - CBC_ResultPoint* bottomRight = corners[0]; - bottomLeft = corners[1]; - CBC_ResultPoint* topLeft = corners[2]; - CBC_ResultPoint* topRight = nullptr; - int32_t value; - if (!pointCount.Lookup(pointA, value)) { - topRight = pointA; - } else if (!pointCount.Lookup(pointB, value)) { - topRight = pointB; - } else if (!pointCount.Lookup(pointC, value)) { - topRight = pointC; - } else { - topRight = pointD; - } - int32_t dimensionTop = std::unique_ptr( - TransitionsBetween(topLeft, topRight)) - ->GetTransitions(); - int32_t dimensionRight = std::unique_ptr( - TransitionsBetween(bottomRight, topRight)) - ->GetTransitions(); - if ((dimensionTop & 0x01) == 1) { - dimensionTop++; - } - dimensionTop += 2; - if ((dimensionRight & 0x01) == 1) { - dimensionRight++; - } - dimensionRight += 2; - std::unique_ptr bits; - std::unique_ptr correctedTopRight; - if (4 * dimensionTop >= 7 * dimensionRight || - 4 * dimensionRight >= 7 * dimensionTop) { - correctedTopRight.reset( - CorrectTopRightRectangular(bottomLeft, bottomRight, topLeft, topRight, - dimensionTop, dimensionRight)); - if (!correctedTopRight.get()) { - correctedTopRight.reset(topRight); - } else { - delete topRight; - topRight = nullptr; - } - dimensionTop = std::unique_ptr( - TransitionsBetween(topLeft, correctedTopRight.get())) - ->GetTransitions(); - dimensionRight = - std::unique_ptr( - TransitionsBetween(bottomRight, correctedTopRight.get())) - ->GetTransitions(); - if ((dimensionTop & 0x01) == 1) { - dimensionTop++; - } - if ((dimensionRight & 0x01) == 1) { - dimensionRight++; - } - bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, - correctedTopRight.get(), dimensionTop, dimensionRight, - e)); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - } else { - int32_t dimension = std::min(dimensionRight, dimensionTop); - correctedTopRight.reset( - CorrectTopRight(bottomLeft, bottomRight, topLeft, topRight, dimension)); - if (!correctedTopRight.get()) { - correctedTopRight.reset(topRight); - } else { - delete topRight; - topRight = nullptr; - } - int32_t dimensionCorrected = - std::max(std::unique_ptr( - TransitionsBetween(topLeft, correctedTopRight.get())) - ->GetTransitions(), - std::unique_ptr( - TransitionsBetween(bottomRight, correctedTopRight.get())) - ->GetTransitions()); - dimensionCorrected++; - if ((dimensionCorrected & 0x01) == 1) { - dimensionCorrected++; - } - bits.reset(SampleGrid(m_image, topLeft, bottomLeft, bottomRight, - correctedTopRight.get(), dimensionCorrected, - dimensionCorrected, e)); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - } - CFX_ArrayTemplate* result = - new CFX_ArrayTemplate(); - result->SetSize(4); - result->Add(topLeft); - result->Add(bottomLeft); - result->Add(bottomRight); - result->Add(correctedTopRight.release()); - return new CBC_QRDetectorResult(bits.release(), result); -} -CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRightRectangular( - CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* topRight, - int32_t dimensionTop, - int32_t dimensionRight) { - FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimensionTop; - int32_t norm = Distance(topLeft, topRight); - FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm; - FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm; - std::unique_ptr c1(new CBC_ResultPoint( - topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); - corr = Distance(bottomLeft, topLeft) / (FX_FLOAT)dimensionRight; - norm = Distance(bottomRight, topRight); - cos = (topRight->GetX() - bottomRight->GetX()) / norm; - sin = (topRight->GetY() - bottomRight->GetY()) / norm; - std::unique_ptr c2(new CBC_ResultPoint( - topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); - if (!IsValid(c1.get())) { - if (IsValid(c2.get())) { - return c2.release(); - } - return nullptr; - } else if (!IsValid(c2.get())) { - return c1.release(); - } - int32_t l1 = FXSYS_abs(dimensionTop - - std::unique_ptr( - TransitionsBetween(topLeft, c1.get())) - ->GetTransitions()) + - FXSYS_abs(dimensionRight - - std::unique_ptr( - TransitionsBetween(bottomRight, c1.get())) - ->GetTransitions()); - int32_t l2 = FXSYS_abs(dimensionTop - - std::unique_ptr( - TransitionsBetween(topLeft, c2.get())) - ->GetTransitions()) + - FXSYS_abs(dimensionRight - - std::unique_ptr( - TransitionsBetween(bottomRight, c2.get())) - ->GetTransitions()); - if (l1 <= l2) { - return c1.release(); - } - return c2.release(); -} -CBC_ResultPoint* CBC_DataMatrixDetector::CorrectTopRight( - CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* topRight, - int32_t dimension) { - FX_FLOAT corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension; - int32_t norm = Distance(topLeft, topRight); - FX_FLOAT cos = (topRight->GetX() - topLeft->GetX()) / norm; - FX_FLOAT sin = (topRight->GetY() - topLeft->GetY()) / norm; - std::unique_ptr c1(new CBC_ResultPoint( - topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); - corr = Distance(bottomLeft, bottomRight) / (FX_FLOAT)dimension; - norm = Distance(bottomRight, topRight); - cos = (topRight->GetX() - bottomRight->GetX()) / norm; - sin = (topRight->GetY() - bottomRight->GetY()) / norm; - std::unique_ptr c2(new CBC_ResultPoint( - topRight->GetX() + corr * cos, topRight->GetY() + corr * sin)); - if (!IsValid(c1.get())) { - if (IsValid(c2.get())) { - return c2.release(); - } - return nullptr; - } else if (!IsValid(c2.get())) { - return c1.release(); - } - int32_t l1 = FXSYS_abs(std::unique_ptr( - TransitionsBetween(topLeft, c1.get())) - ->GetTransitions() - - std::unique_ptr( - TransitionsBetween(bottomRight, c1.get())) - ->GetTransitions()); - int32_t l2 = FXSYS_abs(std::unique_ptr( - TransitionsBetween(topLeft, c2.get())) - ->GetTransitions() - - std::unique_ptr( - TransitionsBetween(bottomRight, c2.get())) - ->GetTransitions()); - return l1 <= l2 ? c1.release() : c2.release(); -} -FX_BOOL CBC_DataMatrixDetector::IsValid(CBC_ResultPoint* p) { - return p->GetX() >= 0 && p->GetX() < m_image->GetWidth() && p->GetY() > 0 && - p->GetY() < m_image->GetHeight(); -} -int32_t CBC_DataMatrixDetector::Round(FX_FLOAT d) { - return (int32_t)(d + 0.5f); -} -int32_t CBC_DataMatrixDetector::Distance(CBC_ResultPoint* a, - CBC_ResultPoint* b) { - return Round( - (FX_FLOAT)sqrt((a->GetX() - b->GetX()) * (a->GetX() - b->GetX()) + - (a->GetY() - b->GetY()) * (a->GetY() - b->GetY()))); -} -void CBC_DataMatrixDetector::Increment( - CFX_MapPtrTemplate& table, - CBC_ResultPoint* key) { - int32_t value; - if (table.Lookup(key, value)) { - table.SetAt(key, INTEGERS[value + 1]); - } else { - table.SetAt(key, INTEGERS[1]); - } -} -CBC_CommonBitMatrix* CBC_DataMatrixDetector::SampleGrid( - CBC_CommonBitMatrix* image, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topRight, - int32_t dimensionX, - int32_t dimensionY, - int32_t& e) { - CBC_QRGridSampler& sampler = CBC_QRGridSampler::GetInstance(); - CBC_CommonBitMatrix* cbm = sampler.SampleGrid( - image, dimensionX, dimensionY, 0.5f, 0.5f, dimensionX - 0.5f, 0.5f, - dimensionX - 0.5f, dimensionY - 0.5f, 0.5f, dimensionY - 0.5f, - topLeft->GetX(), topLeft->GetY(), topRight->GetX(), topRight->GetY(), - bottomRight->GetX(), bottomRight->GetY(), bottomLeft->GetX(), - bottomLeft->GetY(), e); - BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); - return cbm; -} -CBC_ResultPointsAndTransitions* CBC_DataMatrixDetector::TransitionsBetween( - CBC_ResultPoint* from, - CBC_ResultPoint* to) { - int32_t fromX = (int32_t)from->GetX(); - int32_t fromY = (int32_t)from->GetY(); - int32_t toX = (int32_t)to->GetX(); - int32_t toY = (int32_t)to->GetY(); - FX_BOOL steep = FXSYS_abs(toY - fromY) > FXSYS_abs(toX - fromX); - if (steep) { - int32_t temp = fromX; - fromX = fromY; - fromY = temp; - temp = toX; - toX = toY; - toY = temp; - } - int32_t dx = FXSYS_abs(toX - fromX); - int32_t dy = FXSYS_abs(toY - fromY); - int32_t error = -dx >> 1; - int32_t ystep = fromY < toY ? 1 : -1; - int32_t xstep = fromX < toX ? 1 : -1; - int32_t transitions = 0; - FX_BOOL inBlack = m_image->Get(steep ? fromY : fromX, steep ? fromX : fromY); - for (int32_t x = fromX, y = fromY; x != toX; x += xstep) { - FX_BOOL isBlack = m_image->Get(steep ? y : x, steep ? x : y); - if (isBlack != inBlack) { - transitions++; - inBlack = isBlack; - } - error += dy; - if (error > 0) { - if (y == toY) { - break; - } - y += ystep; - error -= dx; - } - } - return new CBC_ResultPointsAndTransitions(from, to, transitions); -} -void CBC_DataMatrixDetector::OrderBestPatterns( - CFX_ArrayTemplate* patterns) { - FX_FLOAT abDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[1]); - FX_FLOAT bcDistance = (FX_FLOAT)Distance((*patterns)[1], (*patterns)[2]); - FX_FLOAT acDistance = (FX_FLOAT)Distance((*patterns)[0], (*patterns)[2]); - CBC_ResultPoint *topLeft, *topRight, *bottomLeft; - if (bcDistance >= abDistance && bcDistance >= acDistance) { - topLeft = (*patterns)[0]; - topRight = (*patterns)[1]; - bottomLeft = (*patterns)[2]; - } else if (acDistance >= bcDistance && acDistance >= abDistance) { - topLeft = (*patterns)[1]; - topRight = (*patterns)[0]; - bottomLeft = (*patterns)[2]; - } else { - topLeft = (*patterns)[2]; - topRight = (*patterns)[0]; - bottomLeft = (*patterns)[1]; - } - if ((bottomLeft->GetY() - topLeft->GetY()) * - (topRight->GetX() - topLeft->GetX()) < - (bottomLeft->GetX() - topLeft->GetX()) * - (topRight->GetY() - topLeft->GetY())) { - CBC_ResultPoint* temp = topRight; - topRight = bottomLeft; - bottomLeft = temp; - } - (*patterns)[0] = bottomLeft; - (*patterns)[1] = topLeft; - (*patterns)[2] = topRight; -} - -CBC_ResultPointsAndTransitions::CBC_ResultPointsAndTransitions( - CBC_ResultPoint* from, - CBC_ResultPoint* to, - int32_t transitions) - : m_from(from), m_to(to), m_transitions(transitions) {} - -CBC_ResultPointsAndTransitions::~CBC_ResultPointsAndTransitions() {} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h deleted file mode 100644 index d06b051554..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDETECTOR_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDETECTOR_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CBC_CommonBitMatrix; -class CBC_DataMatrixDetector; -class CBC_QRDetectorResult; -class CBC_ResultPoint; -class CBC_WhiteRectangleDetector; - -class CBC_ResultPointsAndTransitions { - public: - CBC_ResultPointsAndTransitions(CBC_ResultPoint* from, - CBC_ResultPoint* to, - int32_t transitions); - ~CBC_ResultPointsAndTransitions(); - - CBC_ResultPoint* GetFrom() const { return m_from; } - CBC_ResultPoint* GetTo() const { return m_to; } - int32_t GetTransitions() const { return m_transitions; } - - private: - CBC_ResultPoint* m_from; - CBC_ResultPoint* m_to; - int32_t m_transitions; -}; - -class CBC_DataMatrixDetector { - public: - CBC_DataMatrixDetector(CBC_CommonBitMatrix* image); - virtual ~CBC_DataMatrixDetector(); - - CBC_QRDetectorResult* Detect(int32_t& e); - CBC_ResultPoint* CorrectTopRightRectangular(CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* topRight, - int32_t dimensionTop, - int32_t dimensionRight); - CBC_ResultPoint* CorrectTopRight(CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* topRight, - int32_t dimension); - CBC_CommonBitMatrix* SampleGrid(CBC_CommonBitMatrix* image, - CBC_ResultPoint* topLeft, - CBC_ResultPoint* bottomLeft, - CBC_ResultPoint* bottomRight, - CBC_ResultPoint* topRight, - int32_t dimensionX, - int32_t dimensionY, - int32_t& e); - CBC_ResultPointsAndTransitions* TransitionsBetween(CBC_ResultPoint* from, - CBC_ResultPoint* to); - FX_BOOL IsValid(CBC_ResultPoint* p); - int32_t Distance(CBC_ResultPoint* a, CBC_ResultPoint* b); - void Increment(CFX_MapPtrTemplate& table, - CBC_ResultPoint* key); - int32_t Round(FX_FLOAT d); - void OrderBestPatterns(CFX_ArrayTemplate* patterns); - - virtual void Init(int32_t& e); - - private: - static const int32_t INTEGERS[5]; - - CBC_CommonBitMatrix* m_image; - CBC_WhiteRectangleDetector* m_rectangleDetector; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXDETECTOR_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.cpp deleted file mode 100644 index 7c1ba96a46..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2007 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h" - -#include - -#include "xfa/fxbarcode/BC_BinaryBitmap.h" -#include "xfa/fxbarcode/BC_Reader.h" -#include "xfa/fxbarcode/common/BC_CommonDecoderResult.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDecoder.h" -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixDetector.h" -#include "xfa/fxbarcode/qrcode/BC_QRDetectorResult.h" -#include "xfa/fxbarcode/utils.h" - -CBC_DataMatrixReader::CBC_DataMatrixReader() { - m_decoder = nullptr; -} -void CBC_DataMatrixReader::Init() { - m_decoder = new CBC_DataMatrixDecoder; - m_decoder->Init(); -} -CBC_DataMatrixReader::~CBC_DataMatrixReader() { - delete m_decoder; -} -CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap* image, - int32_t hints, - int32_t& e) { - CBC_CommonBitMatrix* cdr = image->GetBlackMatrix(e); - BC_EXCEPTION_CHECK_ReturnValue(e, ""); - CBC_DataMatrixDetector detector(cdr); - detector.Init(e); - BC_EXCEPTION_CHECK_ReturnValue(e, ""); - std::unique_ptr detectorResult(detector.Detect(e)); - BC_EXCEPTION_CHECK_ReturnValue(e, ""); - std::unique_ptr decodeResult( - m_decoder->Decode(detectorResult->GetBits(), e)); - BC_EXCEPTION_CHECK_ReturnValue(e, ""); - return decodeResult->GetText(); -} - -CFX_ByteString CBC_DataMatrixReader::Decode(CBC_BinaryBitmap* image, - int32_t& e) { - CFX_ByteString bs = Decode(image, 0, e); - BC_EXCEPTION_CHECK_ReturnValue(e, ""); - return bs; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h deleted file mode 100644 index c7a0995dcb..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixReader.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXREADER_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXREADER_H_ - -#include "xfa/fxbarcode/BC_Reader.h" - -class CBC_BinaryBitmap; -class CBC_DataMatrixDecoder; - -class CBC_DataMatrixReader : public CBC_Reader { - public: - CBC_DataMatrixReader(); - ~CBC_DataMatrixReader() override; - - // CBC_Reader - CFX_ByteString Decode(CBC_BinaryBitmap* image, int32_t& e) override; - CFX_ByteString Decode(CBC_BinaryBitmap* image, - int hints, - int32_t& e) override; - - virtual void Init(); - - private: - CBC_DataMatrixDecoder* m_decoder; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXREADER_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp deleted file mode 100644 index 29fb792ced..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -// Original code is licensed as follows: -/* - * Copyright 2007 ZXing authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h" -#include "xfa/fxbarcode/utils.h" - -CFX_ArrayTemplate* CBC_DataMatrixVersion::VERSIONS = - nullptr; - -void CBC_DataMatrixVersion::Initialize() { - VERSIONS = new CFX_ArrayTemplate(); -} -void CBC_DataMatrixVersion::Finalize() { - for (int32_t i = 0; i < VERSIONS->GetSize(); i++) { - delete VERSIONS->GetAt(i); - } - VERSIONS->RemoveAll(); - delete VERSIONS; -} -CBC_DataMatrixVersion::CBC_DataMatrixVersion(int32_t versionNumber, - int32_t symbolSizeRows, - int32_t symbolSizeColumns, - int32_t dataRegionSizeRows, - int32_t dataRegionSizeColumns, - ECBlocks* ecBlocks) { - m_versionNumber = versionNumber; - m_symbolSizeRows = symbolSizeRows; - m_symbolSizeColumns = symbolSizeColumns; - m_dataRegionSizeRows = dataRegionSizeRows; - m_dataRegionSizeColumns = dataRegionSizeColumns; - m_ecBlocks = ecBlocks; - int32_t total = 0; - int32_t ecCodewords = ecBlocks->GetECCodewords(); - const CFX_ArrayTemplate& ecbArray = ecBlocks->GetECBlocks(); - for (int32_t i = 0; i < ecbArray.GetSize(); i++) { - total += ecbArray[i]->GetCount() * - (ecbArray[i]->GetDataCodewords() + ecCodewords); - } - m_totalCodewords = total; -} -CBC_DataMatrixVersion::~CBC_DataMatrixVersion() { - delete m_ecBlocks; -} -int32_t CBC_DataMatrixVersion::GetVersionNumber() { - return m_versionNumber; -} -int32_t CBC_DataMatrixVersion::GetSymbolSizeRows() { - return m_symbolSizeRows; -} -int32_t CBC_DataMatrixVersion::GetSymbolSizeColumns() { - return m_symbolSizeColumns; -} -int32_t CBC_DataMatrixVersion::GetDataRegionSizeRows() { - return m_dataRegionSizeRows; -} -int32_t CBC_DataMatrixVersion::GetDataRegionSizeColumns() { - return m_dataRegionSizeColumns; -} -int32_t CBC_DataMatrixVersion::GetTotalCodewords() { - return m_totalCodewords; -} -ECBlocks* CBC_DataMatrixVersion::GetECBlocks() { - return m_ecBlocks; -} -void CBC_DataMatrixVersion::ReleaseAll() { - for (int32_t i = 0; i < VERSIONS->GetSize(); i++) { - delete VERSIONS->GetAt(i); - } - VERSIONS->RemoveAll(); -} -CBC_DataMatrixVersion* CBC_DataMatrixVersion::GetVersionForDimensions( - int32_t numRows, - int32_t numColumns, - int32_t& e) { - if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) { - e = BCExceptionNotFound; - return nullptr; - } - if (VERSIONS->GetSize() == 0) { - VERSIONS->Add(new CBC_DataMatrixVersion(1, 10, 10, 8, 8, - new ECBlocks(5, new ECB(1, 3)))); - VERSIONS->Add(new CBC_DataMatrixVersion(2, 12, 12, 10, 10, - new ECBlocks(7, new ECB(1, 5)))); - VERSIONS->Add(new CBC_DataMatrixVersion(3, 14, 14, 12, 12, - new ECBlocks(10, new ECB(1, 8)))); - VERSIONS->Add(new CBC_DataMatrixVersion(4, 16, 16, 14, 14, - new ECBlocks(12, new ECB(1, 12)))); - VERSIONS->Add(new CBC_DataMatrixVersion(5, 18, 18, 16, 16, - new ECBlocks(14, new ECB(1, 18)))); - VERSIONS->Add(new CBC_DataMatrixVersion(6, 20, 20, 18, 18, - new ECBlocks(18, new ECB(1, 22)))); - VERSIONS->Add(new CBC_DataMatrixVersion(7, 22, 22, 20, 20, - new ECBlocks(20, new ECB(1, 30)))); - VERSIONS->Add(new CBC_DataMatrixVersion(8, 24, 24, 22, 22, - new ECBlocks(24, new ECB(1, 36)))); - VERSIONS->Add(new CBC_DataMatrixVersion(9, 26, 26, 24, 24, - new ECBlocks(28, new ECB(1, 44)))); - VERSIONS->Add(new CBC_DataMatrixVersion(10, 32, 32, 14, 14, - new ECBlocks(36, new ECB(1, 62)))); - VERSIONS->Add(new CBC_DataMatrixVersion(11, 36, 36, 16, 16, - new ECBlocks(42, new ECB(1, 86)))); - VERSIONS->Add(new CBC_DataMatrixVersion(12, 40, 40, 18, 18, - new ECBlocks(48, new ECB(1, 114)))); - VERSIONS->Add(new CBC_DataMatrixVersion(13, 44, 44, 20, 20, - new ECBlocks(56, new ECB(1, 144)))); - VERSIONS->Add(new CBC_DataMatrixVersion(14, 48, 48, 22, 22, - new ECBlocks(68, new ECB(1, 174)))); - VERSIONS->Add(new CBC_DataMatrixVersion(15, 52, 52, 24, 24, - new ECBlocks(42, new ECB(2, 102)))); - VERSIONS->Add(new CBC_DataMatrixVersion(16, 64, 64, 14, 14, - new ECBlocks(56, new ECB(2, 140)))); - VERSIONS->Add(new CBC_DataMatrixVersion(17, 72, 72, 16, 16, - new ECBlocks(36, new ECB(4, 92)))); - VERSIONS->Add(new CBC_DataMatrixVersion(18, 80, 80, 18, 18, - new ECBlocks(48, new ECB(4, 114)))); - VERSIONS->Add(new CBC_DataMatrixVersion(19, 88, 88, 20, 20, - new ECBlocks(56, new ECB(4, 144)))); - VERSIONS->Add(new CBC_DataMatrixVersion(20, 96, 96, 22, 22, - new ECBlocks(68, new ECB(4, 174)))); - VERSIONS->Add(new CBC_DataMatrixVersion(21, 104, 104, 24, 24, - new ECBlocks(56, new ECB(6, 136)))); - VERSIONS->Add(new CBC_DataMatrixVersion(22, 120, 120, 18, 18, - new ECBlocks(68, new ECB(6, 175)))); - VERSIONS->Add(new CBC_DataMatrixVersion(23, 132, 132, 20, 20, - new ECBlocks(62, new ECB(8, 163)))); - VERSIONS->Add(new CBC_DataMatrixVersion( - 24, 144, 144, 22, 22, - new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))); - VERSIONS->Add(new CBC_DataMatrixVersion(25, 8, 18, 6, 16, - new ECBlocks(7, new ECB(1, 5)))); - VERSIONS->Add(new CBC_DataMatrixVersion(26, 8, 32, 6, 14, - new ECBlocks(11, new ECB(1, 10)))); - VERSIONS->Add(new CBC_DataMatrixVersion(27, 12, 26, 10, 24, - new ECBlocks(14, new ECB(1, 16)))); - VERSIONS->Add(new CBC_DataMatrixVersion(28, 12, 36, 10, 16, - new ECBlocks(18, new ECB(1, 22)))); - VERSIONS->Add(new CBC_DataMatrixVersion(29, 16, 36, 14, 16, - new ECBlocks(24, new ECB(1, 32)))); - VERSIONS->Add(new CBC_DataMatrixVersion(30, 16, 48, 14, 22, - new ECBlocks(28, new ECB(1, 49)))); - } - int32_t numVersions = VERSIONS->GetSize(); - for (int32_t i = 0; i < numVersions; ++i) { - if ((*VERSIONS)[i]->m_symbolSizeRows == numRows && - (*VERSIONS)[i]->m_symbolSizeColumns == numColumns) { - return (*VERSIONS)[i]; - } - } - e = BCExceptionNotFound; - return nullptr; -} - -ECB::ECB(int32_t count, int32_t dataCodewords) - : m_count(count), m_dataCodewords(dataCodewords) {} - -ECBlocks::ECBlocks(int32_t ecCodewords, ECB* ecBlocks) - : m_ecCodewords(ecCodewords) { - m_ecBlocksArray.Add(ecBlocks); -} - -ECBlocks::ECBlocks(int32_t ecCodewords, ECB* ecBlocks1, ECB* ecBlocks2) - : m_ecCodewords(ecCodewords) { - m_ecBlocksArray.Add(ecBlocks1); - m_ecBlocksArray.Add(ecBlocks2); -} - -ECBlocks::~ECBlocks() { - for (int32_t i = 0; i < m_ecBlocksArray.GetSize(); i++) - delete m_ecBlocksArray[i]; -} diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h b/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h deleted file mode 100644 index 9bbf7f7b72..0000000000 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixVersion.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXVERSION_H_ -#define XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXVERSION_H_ - -#include "core/fxcrt/include/fx_basic.h" - -class CBC_DataMatrixVersion; - -class ECB { - public: - ECB(int32_t count, int32_t dataCodewords); - - int32_t GetCount() const { return m_count; } - int32_t GetDataCodewords() const { return m_dataCodewords; } - - private: - int32_t m_count; - int32_t m_dataCodewords; -}; - -class ECBlocks { - public: - ECBlocks(int32_t ecCodewords, ECB* ecBlocks); - ECBlocks(int32_t ecCodewords, ECB* ecBlocks1, ECB* ecBlocks2); - ~ECBlocks(); - - int32_t GetECCodewords() { return m_ecCodewords; } - const CFX_ArrayTemplate& GetECBlocks() { return m_ecBlocksArray; } - - private: - int32_t m_ecCodewords; - CFX_ArrayTemplate m_ecBlocksArray; -}; - -class CBC_DataMatrixVersion { - public: - CBC_DataMatrixVersion(int32_t versionNumber, - int32_t symbolSizeRows, - int32_t symbolSizeColumns, - int32_t dataRegionSizeRows, - int32_t dataRegionSizeColumns, - ECBlocks* ecBlocks); - virtual ~CBC_DataMatrixVersion(); - - static void Initialize(); - static void Finalize(); - int32_t GetVersionNumber(); - int32_t GetSymbolSizeRows(); - int32_t GetSymbolSizeColumns(); - int32_t GetDataRegionSizeRows(); - int32_t GetDataRegionSizeColumns(); - int32_t GetTotalCodewords(); - ECBlocks* GetECBlocks(); - static CBC_DataMatrixVersion* GetVersionForDimensions(int32_t numRows, - int32_t numColumns, - int32_t& e); - static void ReleaseAll(); - - private: - int32_t m_versionNumber; - int32_t m_symbolSizeRows; - int32_t m_symbolSizeColumns; - int32_t m_dataRegionSizeRows; - int32_t m_dataRegionSizeColumns; - ECBlocks* m_ecBlocks; - int32_t m_totalCodewords; - static CFX_ArrayTemplate* VERSIONS; -}; - -#endif // XFA_FXBARCODE_DATAMATRIX_BC_DATAMATRIXVERSION_H_ diff --git a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp b/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp index f056ece258..6263b7fbe5 100644 --- a/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp +++ b/xfa/fxbarcode/datamatrix/BC_DataMatrixWriter.cpp @@ -20,7 +20,6 @@ * limitations under the License. */ -#include "xfa/fxbarcode/BC_BinaryBitmap.h" #include "xfa/fxbarcode/BC_Dimension.h" #include "xfa/fxbarcode/BC_TwoDimWriter.h" #include "xfa/fxbarcode/BC_UtilCodingConvert.h" -- cgit v1.2.3