Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: xfa/src/fxbarcode/src/BC_QRGridSampler.cpp

Issue 842043002: Organize barcode codes into modules. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/src/fxbarcode/src/BC_QRFinderPatternFinder.cpp ('k') | xfa/src/fxbarcode/src/BC_Reader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows:
7 /*
8 * Copyright 2007 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (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
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #include "barcode.h"
24 #include "include/BC_CommonPerspectiveTransform.h"
25 #include "include/BC_CommonBitMatrix.h"
26 #include "include/BC_QRGridSampler.h"
27 CBC_QRGridSampler CBC_QRGridSampler::m_gridSampler;
28 CBC_QRGridSampler::CBC_QRGridSampler()
29 {
30 }
31 CBC_QRGridSampler::~CBC_QRGridSampler()
32 {
33 }
34 CBC_QRGridSampler &CBC_QRGridSampler::GetInstance()
35 {
36 return m_gridSampler;
37 }
38 void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix *image, CFX_Floa tArray *points, FX_INT32 &e)
39 {
40 FX_INT32 width = image->GetWidth();
41 FX_INT32 height = image->GetHeight();
42 FX_BOOL nudged = TRUE;
43 FX_INT32 offset;
44 for (offset = 0; offset < points->GetSize() && nudged; offset += 2) {
45 FX_INT32 x = (FX_INT32) (*points)[offset];
46 FX_INT32 y = (FX_INT32) (*points)[offset + 1];
47 if (x < -1 || x > width || y < -1 || y > height) {
48 e = BCExceptionRead;
49 BC_EXCEPTION_CHECK_ReturnVoid(e);
50 }
51 nudged = FALSE;
52 if (x == -1) {
53 (*points)[offset] = 0.0f;
54 nudged = TRUE;
55 } else if (x == width) {
56 (*points)[offset] = (FX_FLOAT)(width - 1);
57 nudged = TRUE;
58 }
59 if (y == -1) {
60 (*points)[offset + 1] = 0.0f;
61 nudged = TRUE;
62 } else if (y == height) {
63 (*points)[offset + 1] = (FX_FLOAT)(height - 1);
64 nudged = TRUE;
65 }
66 }
67 nudged = TRUE;
68 for (offset = (*points).GetSize() - 2; offset >= 0 && nudged; offset -= 2) {
69 FX_INT32 x = (FX_INT32) (*points)[offset];
70 FX_INT32 y = (FX_INT32) (*points)[offset + 1];
71 if (x < -1 || x > width || y < -1 || y > height) {
72 e = BCExceptionRead;
73 BC_EXCEPTION_CHECK_ReturnVoid(e);
74 }
75 nudged = FALSE;
76 if (x == -1) {
77 (*points)[offset] = 0.0f;
78 nudged = TRUE;
79 } else if (x == width) {
80 (*points)[offset] = (FX_FLOAT)(width - 1);
81 nudged = TRUE;
82 }
83 if (y == -1) {
84 (*points)[offset + 1] = 0.0f;
85 nudged = TRUE;
86 } else if (y == height) {
87 (*points)[offset + 1] = (FX_FLOAT)(height - 1);
88 nudged = TRUE;
89 }
90 }
91 }
92 CBC_CommonBitMatrix *CBC_QRGridSampler::SampleGrid(CBC_CommonBitMatrix *image, F X_INT32 dimensionX, FX_INT32 dimensionY,
93 FX_FLOAT p1ToX, FX_FLOAT p1ToY,
94 FX_FLOAT p2ToX, FX_FLOAT p2ToY,
95 FX_FLOAT p3ToX, FX_FLOAT p3ToY,
96 FX_FLOAT p4ToX, FX_FLOAT p4ToY,
97 FX_FLOAT p1FromX, FX_FLOAT p1FromY,
98 FX_FLOAT p2FromX, FX_FLOAT p2FromY,
99 FX_FLOAT p3FromX, FX_FLOAT p3FromY,
100 FX_FLOAT p4FromX, FX_FLOAT p4FromY, FX_INT32 &e)
101 {
102 CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform(CBC_CommonPerspectiveT ransform::QuadrilateralToQuadrilateral(
103 p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY,
104 p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p 4FromY));
105 CBC_CommonBitMatrix *tempBitM = FX_NEW CBC_CommonBitMatrix();
106 tempBitM->Init(dimensionX, dimensionY);
107 CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM);
108 CFX_FloatArray points;
109 points.SetSize(dimensionX << 1);
110 for (FX_INT32 y = 0; y < dimensionY; y++) {
111 FX_INT32 max = points.GetSize();
112 FX_FLOAT iValue = (FX_FLOAT) (y + 0.5f);
113 FX_INT32 x;
114 for (x = 0; x < max; x += 2) {
115 points[x] = (FX_FLOAT) ((x >> 1) + 0.5f);
116 points[x + 1] = iValue;
117 }
118 transform->TransformPoints(&points);
119 CheckAndNudgePoints(image, &points, e);
120 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
121 for (x = 0; x < max; x += 2) {
122 if (image->Get((FX_INT32) points[x], (FX_INT32) points[x + 1])) {
123 bits->Set(x >> 1, y);
124 }
125 }
126 }
127 return bits.release();
128 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_QRFinderPatternFinder.cpp ('k') | xfa/src/fxbarcode/src/BC_Reader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698