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 22 matching lines...) Expand all Loading... |
33 CBC_QRBitMatrixParser::CBC_QRBitMatrixParser() {} | 33 CBC_QRBitMatrixParser::CBC_QRBitMatrixParser() {} |
34 void CBC_QRBitMatrixParser::Init(CBC_CommonBitMatrix* bitMatrix, int32_t& e) { | 34 void CBC_QRBitMatrixParser::Init(CBC_CommonBitMatrix* bitMatrix, int32_t& e) { |
35 m_dimension = bitMatrix->GetDimension(e); | 35 m_dimension = bitMatrix->GetDimension(e); |
36 BC_EXCEPTION_CHECK_ReturnVoid(e); | 36 BC_EXCEPTION_CHECK_ReturnVoid(e); |
37 m_tempBitMatrix = bitMatrix; | 37 m_tempBitMatrix = bitMatrix; |
38 if (m_dimension < 21 || (m_dimension & 0x03) != 1) { | 38 if (m_dimension < 21 || (m_dimension & 0x03) != 1) { |
39 e = BCExceptionRead; | 39 e = BCExceptionRead; |
40 BC_EXCEPTION_CHECK_ReturnVoid(e); | 40 BC_EXCEPTION_CHECK_ReturnVoid(e); |
41 } | 41 } |
42 m_bitMatrix = m_tempBitMatrix; | 42 m_bitMatrix = m_tempBitMatrix; |
43 m_parsedFormatInfo = NULL; | 43 m_parsedFormatInfo = nullptr; |
44 m_version = NULL; | 44 m_version = nullptr; |
45 } | 45 } |
46 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() { | 46 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() { |
47 delete m_parsedFormatInfo; | 47 delete m_parsedFormatInfo; |
48 } | 48 } |
49 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation( | 49 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation( |
50 int32_t& e) { | 50 int32_t& e) { |
51 if (m_parsedFormatInfo) { | 51 if (m_parsedFormatInfo) { |
52 return m_parsedFormatInfo; | 52 return m_parsedFormatInfo; |
53 } | 53 } |
54 int32_t formatInfoBits = 0; | 54 int32_t formatInfoBits = 0; |
55 int32_t j; | 55 int32_t j; |
56 for (j = 0; j < 6; j++) { | 56 for (j = 0; j < 6; j++) { |
57 formatInfoBits = CopyBit(8, j, formatInfoBits); | 57 formatInfoBits = CopyBit(8, j, formatInfoBits); |
58 } | 58 } |
59 formatInfoBits = CopyBit(8, 7, formatInfoBits); | 59 formatInfoBits = CopyBit(8, 7, formatInfoBits); |
60 formatInfoBits = CopyBit(8, 8, formatInfoBits); | 60 formatInfoBits = CopyBit(8, 8, formatInfoBits); |
61 formatInfoBits = CopyBit(7, 8, formatInfoBits); | 61 formatInfoBits = CopyBit(7, 8, formatInfoBits); |
62 for (int32_t i = 5; i >= 0; i--) { | 62 for (int32_t i = 5; i >= 0; i--) { |
63 formatInfoBits = CopyBit(i, 8, formatInfoBits); | 63 formatInfoBits = CopyBit(i, 8, formatInfoBits); |
64 } | 64 } |
65 m_parsedFormatInfo = | 65 m_parsedFormatInfo = |
66 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); | 66 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); |
67 if (m_parsedFormatInfo) { | 67 if (m_parsedFormatInfo) { |
68 return m_parsedFormatInfo; | 68 return m_parsedFormatInfo; |
69 } | 69 } |
70 int32_t dimension = m_bitMatrix->GetDimension(e); | 70 int32_t dimension = m_bitMatrix->GetDimension(e); |
71 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 71 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
72 formatInfoBits = 0; | 72 formatInfoBits = 0; |
73 int32_t iMin = dimension - 8; | 73 int32_t iMin = dimension - 8; |
74 for (j = dimension - 1; j >= iMin; j--) { | 74 for (j = dimension - 1; j >= iMin; j--) { |
75 formatInfoBits = CopyBit(j, 8, formatInfoBits); | 75 formatInfoBits = CopyBit(j, 8, formatInfoBits); |
76 } | 76 } |
77 for (int32_t k = dimension - 7; k < dimension; k++) { | 77 for (int32_t k = dimension - 7; k < dimension; k++) { |
78 formatInfoBits = CopyBit(8, k, formatInfoBits); | 78 formatInfoBits = CopyBit(8, k, formatInfoBits); |
79 } | 79 } |
80 m_parsedFormatInfo = | 80 m_parsedFormatInfo = |
81 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); | 81 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); |
82 if (m_parsedFormatInfo) { | 82 if (m_parsedFormatInfo) { |
83 return m_parsedFormatInfo; | 83 return m_parsedFormatInfo; |
84 } | 84 } |
85 e = BCExceptionRead; | 85 e = BCExceptionRead; |
86 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 86 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
87 return NULL; | 87 return nullptr; |
88 } | 88 } |
89 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) { | 89 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) { |
90 if (m_version) { | 90 if (m_version) { |
91 return m_version; | 91 return m_version; |
92 } | 92 } |
93 int32_t dimension = m_bitMatrix->GetDimension(e); | 93 int32_t dimension = m_bitMatrix->GetDimension(e); |
94 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 94 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
95 int32_t provisionVersion = (dimension - 17) >> 2; | 95 int32_t provisionVersion = (dimension - 17) >> 2; |
96 if (provisionVersion <= 6) { | 96 if (provisionVersion <= 6) { |
97 CBC_QRCoderVersion* qrv = | 97 CBC_QRCoderVersion* qrv = |
98 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e); | 98 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e); |
99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 99 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
100 return qrv; | 100 return qrv; |
101 } | 101 } |
102 int32_t versionBits = 0; | 102 int32_t versionBits = 0; |
103 for (int32_t i = 5; i >= 0; i--) { | 103 for (int32_t i = 5; i >= 0; i--) { |
104 int32_t jMin = dimension - 11; | 104 int32_t jMin = dimension - 11; |
105 for (int32_t j = dimension - 9; j >= jMin; j--) { | 105 for (int32_t j = dimension - 9; j >= jMin; j--) { |
106 versionBits = CopyBit(i, j, versionBits); | 106 versionBits = CopyBit(i, j, versionBits); |
107 } | 107 } |
108 } | 108 } |
109 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 109 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 110 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
111 if (m_version && m_version->GetDimensionForVersion() == dimension) { | 111 if (m_version && m_version->GetDimensionForVersion() == dimension) { |
112 return m_version; | 112 return m_version; |
113 } | 113 } |
114 versionBits = 0; | 114 versionBits = 0; |
115 for (int32_t j = 5; j >= 0; j--) { | 115 for (int32_t j = 5; j >= 0; j--) { |
116 int32_t iMin = dimension - 11; | 116 int32_t iMin = dimension - 11; |
117 for (int32_t i = dimension - 9; i >= iMin; i--) { | 117 for (int32_t i = dimension - 9; i >= iMin; i--) { |
118 versionBits = CopyBit(i, j, versionBits); | 118 versionBits = CopyBit(i, j, versionBits); |
119 } | 119 } |
120 } | 120 } |
121 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 121 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
122 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 122 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
123 if (m_version && m_version->GetDimensionForVersion() == dimension) { | 123 if (m_version && m_version->GetDimensionForVersion() == dimension) { |
124 return m_version; | 124 return m_version; |
125 } | 125 } |
126 e = BCExceptionRead; | 126 e = BCExceptionRead; |
127 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 127 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
128 return NULL; | 128 return nullptr; |
129 } | 129 } |
130 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, | 130 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, |
131 int32_t j, | 131 int32_t j, |
132 int32_t versionBits) { | 132 int32_t versionBits) { |
133 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; | 133 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; |
134 } | 134 } |
135 CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(int32_t& e) { | 135 CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(int32_t& e) { |
136 CBC_QRCoderFormatInformation* formatInfo = ReadFormatInformation(e); | 136 CBC_QRCoderFormatInformation* formatInfo = ReadFormatInformation(e); |
137 BC_EXCEPTION_CHECK_ReturnValue(e, NULL) CBC_QRCoderVersion* version = | 137 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr) CBC_QRCoderVersion* version = |
138 ReadVersion(e); | 138 ReadVersion(e); |
139 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 139 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
140 CBC_QRDataMask* dataMask = | 140 CBC_QRDataMask* dataMask = |
141 CBC_QRDataMask::ForReference((int32_t)(formatInfo->GetDataMask()), e); | 141 CBC_QRDataMask::ForReference((int32_t)(formatInfo->GetDataMask()), e); |
142 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 142 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
143 int32_t dimension = m_bitMatrix->GetDimension(e); | 143 int32_t dimension = m_bitMatrix->GetDimension(e); |
144 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 144 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
145 dataMask->UnmaskBitMatrix(m_bitMatrix, dimension); | 145 dataMask->UnmaskBitMatrix(m_bitMatrix, dimension); |
146 std::unique_ptr<CBC_CommonBitMatrix> functionPattern( | 146 std::unique_ptr<CBC_CommonBitMatrix> functionPattern( |
147 version->BuildFunctionPattern(e)); | 147 version->BuildFunctionPattern(e)); |
148 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 148 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
149 FX_BOOL readingUp = TRUE; | 149 FX_BOOL readingUp = TRUE; |
150 std::unique_ptr<CFX_ByteArray> result(new CFX_ByteArray); | 150 std::unique_ptr<CFX_ByteArray> result(new CFX_ByteArray); |
151 result->SetSize(version->GetTotalCodeWords()); | 151 result->SetSize(version->GetTotalCodeWords()); |
152 int32_t resultOffset = 0; | 152 int32_t resultOffset = 0; |
153 int32_t currentByte = 0; | 153 int32_t currentByte = 0; |
154 int32_t bitsRead = 0; | 154 int32_t bitsRead = 0; |
155 for (int32_t j = dimension - 1; j > 0; j -= 2) { | 155 for (int32_t j = dimension - 1; j > 0; j -= 2) { |
156 if (j == 6) { | 156 if (j == 6) { |
157 j--; | 157 j--; |
158 } | 158 } |
(...skipping 11 matching lines...) Expand all Loading... |
170 bitsRead = 0; | 170 bitsRead = 0; |
171 currentByte = 0; | 171 currentByte = 0; |
172 } | 172 } |
173 } | 173 } |
174 } | 174 } |
175 } | 175 } |
176 readingUp ^= TRUE; | 176 readingUp ^= TRUE; |
177 } | 177 } |
178 if (resultOffset != version->GetTotalCodeWords()) { | 178 if (resultOffset != version->GetTotalCodeWords()) { |
179 e = BCExceptionRead; | 179 e = BCExceptionRead; |
180 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 180 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
181 } | 181 } |
182 return result.release(); | 182 return result.release(); |
183 } | 183 } |
OLD | NEW |