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 23 matching lines...) Expand all Loading... |
34 m_tempBitMatrix = bitMatrix; | 34 m_tempBitMatrix = bitMatrix; |
35 if (m_dimension < 21 || (m_dimension & 0x03) != 1) { | 35 if (m_dimension < 21 || (m_dimension & 0x03) != 1) { |
36 e = BCExceptionRead; | 36 e = BCExceptionRead; |
37 BC_EXCEPTION_CHECK_ReturnVoid(e); | 37 BC_EXCEPTION_CHECK_ReturnVoid(e); |
38 } | 38 } |
39 m_bitMatrix = m_tempBitMatrix; | 39 m_bitMatrix = m_tempBitMatrix; |
40 m_parsedFormatInfo = NULL; | 40 m_parsedFormatInfo = NULL; |
41 m_version = NULL; | 41 m_version = NULL; |
42 } | 42 } |
43 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() { | 43 CBC_QRBitMatrixParser::~CBC_QRBitMatrixParser() { |
44 if (m_parsedFormatInfo != NULL) { | 44 delete m_parsedFormatInfo; |
45 delete m_parsedFormatInfo; | |
46 m_parsedFormatInfo = NULL; | |
47 } | |
48 m_version = NULL; | |
49 } | 45 } |
50 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation( | 46 CBC_QRCoderFormatInformation* CBC_QRBitMatrixParser::ReadFormatInformation( |
51 int32_t& e) { | 47 int32_t& e) { |
52 if (m_parsedFormatInfo != NULL) { | 48 if (m_parsedFormatInfo) { |
53 return m_parsedFormatInfo; | 49 return m_parsedFormatInfo; |
54 } | 50 } |
55 int32_t formatInfoBits = 0; | 51 int32_t formatInfoBits = 0; |
56 int32_t j; | 52 int32_t j; |
57 for (j = 0; j < 6; j++) { | 53 for (j = 0; j < 6; j++) { |
58 formatInfoBits = CopyBit(8, j, formatInfoBits); | 54 formatInfoBits = CopyBit(8, j, formatInfoBits); |
59 } | 55 } |
60 formatInfoBits = CopyBit(8, 7, formatInfoBits); | 56 formatInfoBits = CopyBit(8, 7, formatInfoBits); |
61 formatInfoBits = CopyBit(8, 8, formatInfoBits); | 57 formatInfoBits = CopyBit(8, 8, formatInfoBits); |
62 formatInfoBits = CopyBit(7, 8, formatInfoBits); | 58 formatInfoBits = CopyBit(7, 8, formatInfoBits); |
63 for (int32_t i = 5; i >= 0; i--) { | 59 for (int32_t i = 5; i >= 0; i--) { |
64 formatInfoBits = CopyBit(i, 8, formatInfoBits); | 60 formatInfoBits = CopyBit(i, 8, formatInfoBits); |
65 } | 61 } |
66 m_parsedFormatInfo = | 62 m_parsedFormatInfo = |
67 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); | 63 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); |
68 if (m_parsedFormatInfo != NULL) { | 64 if (m_parsedFormatInfo) { |
69 return m_parsedFormatInfo; | 65 return m_parsedFormatInfo; |
70 } | 66 } |
71 int32_t dimension = m_bitMatrix->GetDimension(e); | 67 int32_t dimension = m_bitMatrix->GetDimension(e); |
72 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 68 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
73 formatInfoBits = 0; | 69 formatInfoBits = 0; |
74 int32_t iMin = dimension - 8; | 70 int32_t iMin = dimension - 8; |
75 for (j = dimension - 1; j >= iMin; j--) { | 71 for (j = dimension - 1; j >= iMin; j--) { |
76 formatInfoBits = CopyBit(j, 8, formatInfoBits); | 72 formatInfoBits = CopyBit(j, 8, formatInfoBits); |
77 } | 73 } |
78 for (int32_t k = dimension - 7; k < dimension; k++) { | 74 for (int32_t k = dimension - 7; k < dimension; k++) { |
79 formatInfoBits = CopyBit(8, k, formatInfoBits); | 75 formatInfoBits = CopyBit(8, k, formatInfoBits); |
80 } | 76 } |
81 m_parsedFormatInfo = | 77 m_parsedFormatInfo = |
82 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); | 78 CBC_QRCoderFormatInformation::DecodeFormatInformation(formatInfoBits); |
83 if (m_parsedFormatInfo != NULL) { | 79 if (m_parsedFormatInfo) { |
84 return m_parsedFormatInfo; | 80 return m_parsedFormatInfo; |
85 } | 81 } |
86 e = BCExceptionRead; | 82 e = BCExceptionRead; |
87 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 83 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
88 return NULL; | 84 return NULL; |
89 } | 85 } |
90 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) { | 86 CBC_QRCoderVersion* CBC_QRBitMatrixParser::ReadVersion(int32_t& e) { |
91 if (m_version != NULL) { | 87 if (m_version) { |
92 return m_version; | 88 return m_version; |
93 } | 89 } |
94 int32_t dimension = m_bitMatrix->GetDimension(e); | 90 int32_t dimension = m_bitMatrix->GetDimension(e); |
95 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 91 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
96 int32_t provisionVersion = (dimension - 17) >> 2; | 92 int32_t provisionVersion = (dimension - 17) >> 2; |
97 if (provisionVersion <= 6) { | 93 if (provisionVersion <= 6) { |
98 CBC_QRCoderVersion* qrv = | 94 CBC_QRCoderVersion* qrv = |
99 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e); | 95 CBC_QRCoderVersion::GetVersionForNumber(provisionVersion, e); |
100 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 96 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
101 return qrv; | 97 return qrv; |
102 } | 98 } |
103 int32_t versionBits = 0; | 99 int32_t versionBits = 0; |
104 for (int32_t i = 5; i >= 0; i--) { | 100 for (int32_t i = 5; i >= 0; i--) { |
105 int32_t jMin = dimension - 11; | 101 int32_t jMin = dimension - 11; |
106 for (int32_t j = dimension - 9; j >= jMin; j--) { | 102 for (int32_t j = dimension - 9; j >= jMin; j--) { |
107 versionBits = CopyBit(i, j, versionBits); | 103 versionBits = CopyBit(i, j, versionBits); |
108 } | 104 } |
109 } | 105 } |
110 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 106 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
111 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 107 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
112 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { | 108 if (m_version && m_version->GetDimensionForVersion() == dimension) { |
113 return m_version; | 109 return m_version; |
114 } | 110 } |
115 versionBits = 0; | 111 versionBits = 0; |
116 for (int32_t j = 5; j >= 0; j--) { | 112 for (int32_t j = 5; j >= 0; j--) { |
117 int32_t iMin = dimension - 11; | 113 int32_t iMin = dimension - 11; |
118 for (int32_t i = dimension - 9; i >= iMin; i--) { | 114 for (int32_t i = dimension - 9; i >= iMin; i--) { |
119 versionBits = CopyBit(i, j, versionBits); | 115 versionBits = CopyBit(i, j, versionBits); |
120 } | 116 } |
121 } | 117 } |
122 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); | 118 m_version = CBC_QRCoderVersion::DecodeVersionInformation(versionBits, e); |
123 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 119 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
124 if (m_version != NULL && m_version->GetDimensionForVersion() == dimension) { | 120 if (m_version && m_version->GetDimensionForVersion() == dimension) { |
125 return m_version; | 121 return m_version; |
126 } | 122 } |
127 e = BCExceptionRead; | 123 e = BCExceptionRead; |
128 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 124 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
129 return NULL; | 125 return NULL; |
130 } | 126 } |
131 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, | 127 int32_t CBC_QRBitMatrixParser::CopyBit(int32_t i, |
132 int32_t j, | 128 int32_t j, |
133 int32_t versionBits) { | 129 int32_t versionBits) { |
134 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; | 130 return m_bitMatrix->Get(j, i) ? (versionBits << 1) | 0x1 : versionBits << 1; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 172 } |
177 } | 173 } |
178 readingUp ^= TRUE; | 174 readingUp ^= TRUE; |
179 } | 175 } |
180 if (resultOffset != version->GetTotalCodeWords()) { | 176 if (resultOffset != version->GetTotalCodeWords()) { |
181 e = BCExceptionRead; | 177 e = BCExceptionRead; |
182 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 178 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
183 } | 179 } |
184 return result.release(); | 180 return result.release(); |
185 } | 181 } |
OLD | NEW |