| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
| 7 /* | 7 /* |
| 8 * Copyright 2007 ZXing authors | 8 * Copyright 2007 ZXing authors |
| 9 * | 9 * |
| 10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 #include "../barcode.h" | 23 #include "../barcode.h" |
| 24 #include "../common/BC_CommonBitMatrix.h" | 24 #include "../common/BC_CommonBitMatrix.h" |
| 25 #include "BC_QRCoderVersion.h" | 25 #include "BC_QRCoderVersion.h" |
| 26 #include "BC_QRCoderFormatInformation.h" | 26 #include "BC_QRCoderFormatInformation.h" |
| 27 #include "BC_QRDataMask.h" | 27 #include "BC_QRDataMask.h" |
| 28 #include "BC_QRBitMatrixParser.h" | 28 #include "BC_QRBitMatrixParser.h" |
| 29 CBC_QRBitMatrixParser::CBC_QRBitMatrixParser() | 29 CBC_QRBitMatrixParser::CBC_QRBitMatrixParser() |
| 30 { | 30 { |
| 31 } | 31 } |
| 32 void CBC_QRBitMatrixParser::Init(CBC_CommonBitMatrix *bitMatrix, FX_INT32 &e) | 32 void CBC_QRBitMatrixParser::Init(CBC_CommonBitMatrix *bitMatrix, int32_t &e) |
| 33 { | 33 { |
| 34 m_dimension = bitMatrix->GetDimension(e); | 34 m_dimension = bitMatrix->GetDimension(e); |
| 35 BC_EXCEPTION_CHECK_ReturnVoid(e); | 35 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 36 m_tempBitMatrix = bitMatrix; | 36 m_tempBitMatrix = bitMatrix; |
| 37 if(m_dimension < 21 || (m_dimension & 0x03) != 1) { | 37 if(m_dimension < 21 || (m_dimension & 0x03) != 1) { |
| 38 e = BCExceptionRead; | 38 e = BCExceptionRead; |
| 39 BC_EXCEPTION_CHECK_ReturnVoid(e); | 39 BC_EXCEPTION_CHECK_ReturnVoid(e); |
| 40 } | 40 } |
| 41 m_bitMatrix = m_tempBitMatrix; | 41 m_bitMatrix = m_tempBitMatrix; |
| 42 m_parsedFormatInfo = NULL; | 42 m_parsedFormatInfo = NULL; |
| 43 m_version = NULL; | 43 m_version = NULL; |
| 44 } | 44 } |
| 45 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() | 45 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() |
| 46 { | 46 { |
| 47 if(m_parsedFormatInfo != NULL) { | 47 if(m_parsedFormatInfo != NULL) { |
| 48 delete m_parsedFormatInfo; | 48 delete m_parsedFormatInfo; |
| 49 m_parsedFormatInfo = NULL; | 49 m_parsedFormatInfo = NULL; |
| 50 } | 50 } |
| 51 m_version = NULL; | 51 m_version = NULL; |
| 52 } | 52 } |
| 53 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation(FX_IN
T32 &e) | 53 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation(int32
_t &e) |
| 54 { | 54 { |
| 55 if(m_parsedFormatInfo != NULL) { | 55 if(m_parsedFormatInfo != NULL) { |
| 56 return m_parsedFormatInfo; | 56 return m_parsedFormatInfo; |
| 57 } | 57 } |
| 58 FX_INT32 formatInfoBits = 0; | 58 int32_t formatInfoBits = 0; |
| 59 FX_INT32 j; | 59 int32_t j; |
| 60 for( j = 0; j < 6; j++) { | 60 for( j = 0; j < 6; j++) { |
| 61 formatInfoBits = CopyBit(8, j, formatInfoBits); | 61 formatInfoBits = CopyBit(8, j, formatInfoBits); |
| 62 } | 62 } |
| 63 formatInfoBits = CopyBit(8, 7, formatInfoBits); | 63 formatInfoBits = CopyBit(8, 7, formatInfoBits); |
| 64 formatInfoBits = CopyBit(8, 8, formatInfoBits); | 64 formatInfoBits = CopyBit(8, 8, formatInfoBits); |
| 65 formatInfoBits = CopyBit(7, 8, formatInfoBits); | 65 formatInfoBits = CopyBit(7, 8, formatInfoBits); |
| 66 for(FX_INT32 i = 5; i >= 0; i--) { | 66 for(int32_t i = 5; i >= 0; i--) { |
| 67 formatInfoBits = CopyBit(i, 8, formatInfoBits); | 67 formatInfoBits = CopyBit(i, 8, formatInfoBits); |
| 68 } | 68 } |
| 69 m_parsedFormatInfo = CBC_QRCoderFormatInformation::DecodeFormatInformation(f
ormatInfoBits); | 69 m_parsedFormatInfo = CBC_QRCoderFormatInformation::DecodeFormatInformation(f
ormatInfoBits); |
| 70 if(m_parsedFormatInfo != NULL) { | 70 if(m_parsedFormatInfo != NULL) { |
| 71 return m_parsedFormatInfo; | 71 return m_parsedFormatInfo; |
| 72 } | 72 } |
| 73 FX_INT32 dimension = m_bitMatrix->GetDimension(e); | 73 int32_t dimension = m_bitMatrix->GetDimension(e); |
| 74 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 74 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 75 formatInfoBits = 0; | 75 formatInfoBits = 0; |
| 76 FX_INT32 iMin = dimension - 8; | 76 int32_t iMin = dimension - 8; |
| 77 for(j = dimension - 1; j >= iMin; j--) { | 77 for(j = dimension - 1; j >= iMin; j--) { |
| 78 formatInfoBits = CopyBit(j, 8, formatInfoBits); | 78 formatInfoBits = CopyBit(j, 8, formatInfoBits); |
| 79 } | 79 } |
| 80 for(FX_INT32 k = dimension - 7; k < dimension; k++) { | 80 for(int32_t k = dimension - 7; k < dimension; k++) { |
| 81 formatInfoBits = CopyBit(8, k , formatInfoBits); | 81 formatInfoBits = CopyBit(8, k , formatInfoBits); |
| 82 } | 82 } |
| 83 m_parsedFormatInfo = CBC_QRCoderFormatInformation::DecodeFormatInformation(f
ormatInfoBits); | 83 m_parsedFormatInfo = CBC_QRCoderFormatInformation::DecodeFormatInformation(f
ormatInfoBits); |
| 84 if(m_parsedFormatInfo != NULL) { | 84 if(m_parsedFormatInfo != NULL) { |
| 85 return m_parsedFormatInfo; | 85 return m_parsedFormatInfo; |
| 86 } | 86 } |
| 87 e = BCExceptionRead; | 87 e = BCExceptionRead; |
| 88 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 88 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 89 return NULL; | 89 return NULL; |
| 90 } | 90 } |
| 91 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(FX_INT32 &e) | 91 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t &e) |
| 92 { | 92 { |
| 93 if(m_version != NULL) { | 93 if(m_version != NULL) { |
| 94 return m_version; | 94 return m_version; |
| 95 } | 95 } |
| 96 FX_INT32 dimension = m_bitMatrix->GetDimension(e); | 96 int32_t dimension = m_bitMatrix->GetDimension(e); |
| 97 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 97 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 98 FX_INT32 provisionVersion = (dimension - 17) >> 2; | 98 int32_t provisionVersion = (dimension - 17) >> 2; |
| 99 if(provisionVersion <= 6) { | 99 if(provisionVersion <= 6) { |
| 100 CBC_QRCoderVersion* qrv = CBC_QRCoderVersion::GetVersionForNumber(provis
ionVersion, e); | 100 CBC_QRCoderVersion* qrv = CBC_QRCoderVersion::GetVersionForNumber(provis
ionVersion, e); |
| 101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 101 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 102 return qrv; | 102 return qrv; |
| 103 } | 103 } |
| 104 FX_INT32 versionBits = 0; | 104 int32_t versionBits = 0; |
| 105 for (FX_INT32 i = 5; i >= 0; i--) { | 105 for (int32_t i = 5; i >= 0; i--) { |
| 106 FX_INT32 jMin = dimension - 11; | 106 int32_t jMin = dimension - 11; |
| 107 for (FX_INT32 j = dimension - 9; j >= jMin; j--) { | 107 for (int32_t j = dimension - 9; j >= jMin; j--) { |
| 108 versionBits = CopyBit(i, j, versionBits); | 108 versionBits = CopyBit(i, j, versionBits); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 111 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
| 112 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 112 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 113 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { | 113 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { |
| 114 return m_version; | 114 return m_version; |
| 115 } | 115 } |
| 116 versionBits = 0; | 116 versionBits = 0; |
| 117 for (FX_INT32 j = 5; j >= 0; j--) { | 117 for (int32_t j = 5; j >= 0; j--) { |
| 118 FX_INT32 iMin = dimension - 11; | 118 int32_t iMin = dimension - 11; |
| 119 for (FX_INT32 i = dimension - 9; i >= iMin; i--) { | 119 for (int32_t i = dimension - 9; i >= iMin; i--) { |
| 120 versionBits = CopyBit(i, j, versionBits); | 120 versionBits = CopyBit(i, j, versionBits); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 123 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
| 124 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 124 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 125 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { | 125 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { |
| 126 return m_version; | 126 return m_version; |
| 127 } | 127 } |
| 128 e = BCExceptionRead; | 128 e = BCExceptionRead; |
| 129 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 129 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 130 return NULL; | 130 return NULL; |
| 131 } | 131 } |
| 132 FX_INT32 CBC_QRBitMatrixParser::CopyBit(FX_INT32 i, FX_INT32 j, FX_INT32 version
Bits) | 132 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, int32_t j, int32_t versionBits
) |
| 133 { | 133 { |
| 134 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; | 134 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; |
| 135 } | 135 } |
| 136 CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(FX_INT32 &e) | 136 CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(int32_t &e) |
| 137 { | 137 { |
| 138 CBC_QRCoderFormatInformation *formatInfo = ReadFormatInformation(e); | 138 CBC_QRCoderFormatInformation *formatInfo = ReadFormatInformation(e); |
| 139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL) | 139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL) |
| 140 CBC_QRCoderVersion *version = ReadVersion(e)
; | 140 CBC_QRCoderVersion *version = ReadVersion(e)
; |
| 141 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 141 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 142 CBC_QRDataMask» » *dataMask» » = CBC_QRDataMask::ForRef
erence((FX_INT32)(formatInfo->GetDataMask()), e); | 142 CBC_QRDataMask» » *dataMask» » = CBC_QRDataMask::ForRef
erence((int32_t)(formatInfo->GetDataMask()), e); |
| 143 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 143 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 144 FX_INT32» » » » dimension» » = m_bitMatrix->G
etDimension(e); | 144 int32_t» » » » dimension» » = m_bitMatrix->G
etDimension(e); |
| 145 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 145 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 146 dataMask->UnmaskBitMatirx(m_bitMatrix, dimension); | 146 dataMask->UnmaskBitMatirx(m_bitMatrix, dimension); |
| 147 CBC_CommonBitMatrix* cbm = version->BuildFunctionPattern(e); | 147 CBC_CommonBitMatrix* cbm = version->BuildFunctionPattern(e); |
| 148 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 148 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 149 CBC_AutoPtr<CBC_CommonBitMatrix > functionPattern(cbm); | 149 CBC_AutoPtr<CBC_CommonBitMatrix > functionPattern(cbm); |
| 150 FX_BOOL readingUp = TRUE; | 150 FX_BOOL readingUp = TRUE; |
| 151 CFX_ByteArray * temp = FX_NEW CFX_ByteArray; | 151 CFX_ByteArray * temp = FX_NEW CFX_ByteArray; |
| 152 temp->SetSize(version->GetTotalCodeWords()); | 152 temp->SetSize(version->GetTotalCodeWords()); |
| 153 CBC_AutoPtr<CFX_ByteArray> result(temp); | 153 CBC_AutoPtr<CFX_ByteArray> result(temp); |
| 154 FX_INT32» » » » resultOffset = 0; | 154 int32_t» » » » resultOffset = 0; |
| 155 FX_INT32» » » » currentByte» = 0; | 155 int32_t» » » » currentByte» = 0; |
| 156 FX_INT32» » » » bitsRead» » = 0; | 156 int32_t» » » » bitsRead» » = 0; |
| 157 for(FX_INT32 j = dimension - 1; j > 0; j -= 2) { | 157 for(int32_t j = dimension - 1; j > 0; j -= 2) { |
| 158 if(j == 6) { | 158 if(j == 6) { |
| 159 j--; | 159 j--; |
| 160 } | 160 } |
| 161 for(FX_INT32 count = 0; count < dimension; count++) { | 161 for(int32_t count = 0; count < dimension; count++) { |
| 162 FX_INT32 i = readingUp ? dimension - 1 - count : count; | 162 int32_t i = readingUp ? dimension - 1 - count : count; |
| 163 for(FX_INT32 col = 0; col < 2; col++) { | 163 for(int32_t col = 0; col < 2; col++) { |
| 164 if(!functionPattern->Get(j - col, i)) { | 164 if(!functionPattern->Get(j - col, i)) { |
| 165 bitsRead++; | 165 bitsRead++; |
| 166 currentByte <<= 1; | 166 currentByte <<= 1; |
| 167 if(m_bitMatrix->Get(j - col, i)) { | 167 if(m_bitMatrix->Get(j - col, i)) { |
| 168 currentByte |= 1; | 168 currentByte |= 1; |
| 169 } | 169 } |
| 170 if(bitsRead == 8) { | 170 if(bitsRead == 8) { |
| 171 (*result)[resultOffset++] = (FX_BYTE) currentByte; | 171 (*result)[resultOffset++] = (uint8_t) currentByte; |
| 172 bitsRead = 0; | 172 bitsRead = 0; |
| 173 currentByte = 0; | 173 currentByte = 0; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 readingUp ^= TRUE; | 178 readingUp ^= TRUE; |
| 179 } | 179 } |
| 180 if(resultOffset != version->GetTotalCodeWords()) { | 180 if(resultOffset != version->GetTotalCodeWords()) { |
| 181 e = BCExceptionRead; | 181 e = BCExceptionRead; |
| 182 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 182 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 183 } | 183 } |
| 184 return result.release(); | 184 return result.release(); |
| 185 } | 185 } |
| OLD | NEW |