summaryrefslogtreecommitdiff
path: root/xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp
diff options
context:
space:
mode:
authorBo Xu <bo_xu@foxitsoftware.com>2015-01-09 17:27:21 -0800
committerBo Xu <bo_xu@foxitsoftware.com>2015-01-09 17:27:21 -0800
commita902979f7c6a39fbdd8e9fc1b2ce00553b655eeb (patch)
tree854a51dbf1577ee8493db769ba7c8ab07cc72140 /xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp
parent5f21e9ddd181fc344f8d6070351858f98a25547e (diff)
downloadpdfium-a902979f7c6a39fbdd8e9fc1b2ce00553b655eeb.tar.xz
Organize barcode codes into modules.
Previously all the files in barcode are lumped together. The naming of some files are inconsistent, leading to difficult understanding of the structure. Now files are grouped based on different barcode type like in zxing. This also matches what it looks like in other xfa folders. The file names in each folder could be further modified to be consistent. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/842043002
Diffstat (limited to 'xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp')
-rw-r--r--xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp128
1 files changed, 128 insertions, 0 deletions
diff --git a/xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp b/xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp
new file mode 100644
index 0000000000..8783078690
--- /dev/null
+++ b/xfa/src/fxbarcode/qrcode/BC_QRGridSampler.cpp
@@ -0,0 +1,128 @@
+// 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 "../barcode.h"
+#include "../common/BC_CommonPerspectiveTransform.h"
+#include "../common/BC_CommonBitMatrix.h"
+#include "BC_QRGridSampler.h"
+CBC_QRGridSampler CBC_QRGridSampler::m_gridSampler;
+CBC_QRGridSampler::CBC_QRGridSampler()
+{
+}
+CBC_QRGridSampler::~CBC_QRGridSampler()
+{
+}
+CBC_QRGridSampler &CBC_QRGridSampler::GetInstance()
+{
+ return m_gridSampler;
+}
+void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix *image, CFX_FloatArray *points, FX_INT32 &e)
+{
+ FX_INT32 width = image->GetWidth();
+ FX_INT32 height = image->GetHeight();
+ FX_BOOL nudged = TRUE;
+ FX_INT32 offset;
+ for (offset = 0; offset < points->GetSize() && nudged; offset += 2) {
+ FX_INT32 x = (FX_INT32) (*points)[offset];
+ FX_INT32 y = (FX_INT32) (*points)[offset + 1];
+ if (x < -1 || x > width || y < -1 || y > height) {
+ e = BCExceptionRead;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ nudged = FALSE;
+ if (x == -1) {
+ (*points)[offset] = 0.0f;
+ nudged = TRUE;
+ } else if (x == width) {
+ (*points)[offset] = (FX_FLOAT)(width - 1);
+ nudged = TRUE;
+ }
+ if (y == -1) {
+ (*points)[offset + 1] = 0.0f;
+ nudged = TRUE;
+ } else if (y == height) {
+ (*points)[offset + 1] = (FX_FLOAT)(height - 1);
+ nudged = TRUE;
+ }
+ }
+ nudged = TRUE;
+ for (offset = (*points).GetSize() - 2; offset >= 0 && nudged; offset -= 2) {
+ FX_INT32 x = (FX_INT32) (*points)[offset];
+ FX_INT32 y = (FX_INT32) (*points)[offset + 1];
+ if (x < -1 || x > width || y < -1 || y > height) {
+ e = BCExceptionRead;
+ BC_EXCEPTION_CHECK_ReturnVoid(e);
+ }
+ nudged = FALSE;
+ if (x == -1) {
+ (*points)[offset] = 0.0f;
+ nudged = TRUE;
+ } else if (x == width) {
+ (*points)[offset] = (FX_FLOAT)(width - 1);
+ nudged = TRUE;
+ }
+ if (y == -1) {
+ (*points)[offset + 1] = 0.0f;
+ nudged = TRUE;
+ } else if (y == height) {
+ (*points)[offset + 1] = (FX_FLOAT)(height - 1);
+ nudged = TRUE;
+ }
+ }
+}
+CBC_CommonBitMatrix *CBC_QRGridSampler::SampleGrid(CBC_CommonBitMatrix *image, FX_INT32 dimensionX, FX_INT32 dimensionY,
+ FX_FLOAT p1ToX, FX_FLOAT p1ToY,
+ FX_FLOAT p2ToX, FX_FLOAT p2ToY,
+ FX_FLOAT p3ToX, FX_FLOAT p3ToY,
+ FX_FLOAT p4ToX, FX_FLOAT p4ToY,
+ FX_FLOAT p1FromX, FX_FLOAT p1FromY,
+ FX_FLOAT p2FromX, FX_FLOAT p2FromY,
+ FX_FLOAT p3FromX, FX_FLOAT p3FromY,
+ FX_FLOAT p4FromX, FX_FLOAT p4FromY, FX_INT32 &e)
+{
+ CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform(CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral(
+ p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY,
+ p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY));
+ CBC_CommonBitMatrix *tempBitM = FX_NEW CBC_CommonBitMatrix();
+ tempBitM->Init(dimensionX, dimensionY);
+ CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM);
+ CFX_FloatArray points;
+ points.SetSize(dimensionX << 1);
+ for (FX_INT32 y = 0; y < dimensionY; y++) {
+ FX_INT32 max = points.GetSize();
+ FX_FLOAT iValue = (FX_FLOAT) (y + 0.5f);
+ FX_INT32 x;
+ for (x = 0; x < max; x += 2) {
+ points[x] = (FX_FLOAT) ((x >> 1) + 0.5f);
+ points[x + 1] = iValue;
+ }
+ transform->TransformPoints(&points);
+ CheckAndNudgePoints(image, &points, e);
+ BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ for (x = 0; x < max; x += 2) {
+ if (image->Get((FX_INT32) points[x], (FX_INT32) points[x + 1])) {
+ bits->Set(x >> 1, y);
+ }
+ }
+ }
+ return bits.release();
+}