| 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"); |
| 11 * you may not use this file except in compliance with the License. | 11 * you may not use this file except in compliance with the License. |
| 12 * You may obtain a copy of the License at | 12 * You may obtain a copy of the License at |
| 13 * | 13 * |
| 14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 * | 15 * |
| 16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
| 17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
| 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
| 20 * limitations under the License. | 20 * limitations under the License. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #include "xfa/src/fxbarcode/qrcode/BC_QRGridSampler.h" |
| 24 |
| 25 #include <memory> |
| 26 |
| 23 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" | 27 #include "xfa/src/fxbarcode/common/BC_CommonBitMatrix.h" |
| 24 #include "xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.h" | 28 #include "xfa/src/fxbarcode/common/BC_CommonPerspectiveTransform.h" |
| 25 #include "xfa/src/fxbarcode/qrcode/BC_QRGridSampler.h" | |
| 26 #include "xfa/src/fxbarcode/utils.h" | 29 #include "xfa/src/fxbarcode/utils.h" |
| 27 | 30 |
| 28 CBC_QRGridSampler CBC_QRGridSampler::m_gridSampler; | 31 CBC_QRGridSampler CBC_QRGridSampler::m_gridSampler; |
| 29 | 32 |
| 30 CBC_QRGridSampler::CBC_QRGridSampler() {} | 33 CBC_QRGridSampler::CBC_QRGridSampler() {} |
| 31 CBC_QRGridSampler::~CBC_QRGridSampler() {} | 34 CBC_QRGridSampler::~CBC_QRGridSampler() {} |
| 32 CBC_QRGridSampler& CBC_QRGridSampler::GetInstance() { | 35 CBC_QRGridSampler& CBC_QRGridSampler::GetInstance() { |
| 33 return m_gridSampler; | 36 return m_gridSampler; |
| 34 } | 37 } |
| 35 void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix* image, | 38 void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix* image, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 FX_FLOAT p4ToY, | 103 FX_FLOAT p4ToY, |
| 101 FX_FLOAT p1FromX, | 104 FX_FLOAT p1FromX, |
| 102 FX_FLOAT p1FromY, | 105 FX_FLOAT p1FromY, |
| 103 FX_FLOAT p2FromX, | 106 FX_FLOAT p2FromX, |
| 104 FX_FLOAT p2FromY, | 107 FX_FLOAT p2FromY, |
| 105 FX_FLOAT p3FromX, | 108 FX_FLOAT p3FromX, |
| 106 FX_FLOAT p3FromY, | 109 FX_FLOAT p3FromY, |
| 107 FX_FLOAT p4FromX, | 110 FX_FLOAT p4FromX, |
| 108 FX_FLOAT p4FromY, | 111 FX_FLOAT p4FromY, |
| 109 int32_t& e) { | 112 int32_t& e) { |
| 110 CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform( | 113 std::unique_ptr<CBC_CommonPerspectiveTransform> transform( |
| 111 CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral( | 114 CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral( |
| 112 p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, | 115 p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, p1FromX, |
| 113 p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); | 116 p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY)); |
| 114 CBC_CommonBitMatrix* tempBitM = new CBC_CommonBitMatrix(); | 117 std::unique_ptr<CBC_CommonBitMatrix> bits(new CBC_CommonBitMatrix()); |
| 115 tempBitM->Init(dimensionX, dimensionY); | 118 bits->Init(dimensionX, dimensionY); |
| 116 CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM); | |
| 117 CFX_FloatArray points; | 119 CFX_FloatArray points; |
| 118 points.SetSize(dimensionX << 1); | 120 points.SetSize(dimensionX << 1); |
| 119 for (int32_t y = 0; y < dimensionY; y++) { | 121 for (int32_t y = 0; y < dimensionY; y++) { |
| 120 int32_t max = points.GetSize(); | 122 int32_t max = points.GetSize(); |
| 121 FX_FLOAT iValue = (FX_FLOAT)(y + 0.5f); | 123 FX_FLOAT iValue = (FX_FLOAT)(y + 0.5f); |
| 122 int32_t x; | 124 int32_t x; |
| 123 for (x = 0; x < max; x += 2) { | 125 for (x = 0; x < max; x += 2) { |
| 124 points[x] = (FX_FLOAT)((x >> 1) + 0.5f); | 126 points[x] = (FX_FLOAT)((x >> 1) + 0.5f); |
| 125 points[x + 1] = iValue; | 127 points[x + 1] = iValue; |
| 126 } | 128 } |
| 127 transform->TransformPoints(&points); | 129 transform->TransformPoints(&points); |
| 128 CheckAndNudgePoints(image, &points, e); | 130 CheckAndNudgePoints(image, &points, e); |
| 129 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 131 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
| 130 for (x = 0; x < max; x += 2) { | 132 for (x = 0; x < max; x += 2) { |
| 131 if (image->Get((int32_t)points[x], (int32_t)points[x + 1])) { | 133 if (image->Get((int32_t)points[x], (int32_t)points[x + 1])) { |
| 132 bits->Set(x >> 1, y); | 134 bits->Set(x >> 1, y); |
| 133 } | 135 } |
| 134 } | 136 } |
| 135 } | 137 } |
| 136 return bits.release(); | 138 return bits.release(); |
| 137 } | 139 } |
| OLD | NEW |