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

Side by Side Diff: xfa/src/fxbarcode/src/BC_CommonPerspectiveTransform.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
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 CBC_CommonPerspectiveTransform::CBC_CommonPerspectiveTransform(FX_FLOAT a11, FX_ FLOAT a21, FX_FLOAT a31,
26 FX_FLOAT a12, FX_FLOAT a22, FX_FLOAT a32,
27 FX_FLOAT a13, FX_FLOAT a23, FX_FLOAT a33) :
28 m_a11(a11), m_a21(a21), m_a31(a31),
29 m_a12(a12), m_a22(a22), m_a32(a32),
30 m_a13(a13), m_a23(a23), m_a33(a33)
31 {
32 }
33 CBC_CommonPerspectiveTransform::~CBC_CommonPerspectiveTransform()
34 {
35 }
36 CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::QuadrilateralToQ uadrilateral(FX_FLOAT x0, FX_FLOAT y0,
37 FX_FLOAT x1, FX_FLOAT y1,
38 FX_FLOAT x2, FX_FLOAT y2,
39 FX_FLOAT x3, FX_FLOAT y3,
40 FX_FLOAT x0p, FX_FLOAT y0p,
41 FX_FLOAT x1p, FX_FLOAT y1p,
42 FX_FLOAT x2p, FX_FLOAT y2p,
43 FX_FLOAT x3p, FX_FLOAT y3p)
44 {
45 CBC_AutoPtr<CBC_CommonPerspectiveTransform> qToS(QuadrilateralToSquare(x0, y 0, x1, y1, x2, y2, x3, y3));
46 CBC_AutoPtr<CBC_CommonPerspectiveTransform> sToQ(SquareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p));
47 return sToQ->Times(*(qToS.get()));
48 }
49 void CBC_CommonPerspectiveTransform::TransformPoints(CFX_FloatArray *points)
50 {
51 FX_INT32 max = points->GetSize();
52 FX_FLOAT a11 = m_a11;
53 FX_FLOAT a12 = m_a12;
54 FX_FLOAT a13 = m_a13;
55 FX_FLOAT a21 = m_a21;
56 FX_FLOAT a22 = m_a22;
57 FX_FLOAT a23 = m_a23;
58 FX_FLOAT a31 = m_a31;
59 FX_FLOAT a32 = m_a32;
60 FX_FLOAT a33 = m_a33;
61 FX_INT32 i;
62 for (i = 0; i < max; i += 2) {
63 FX_FLOAT x = (*points)[i];
64 FX_FLOAT y = (*points)[i + 1];
65 FX_FLOAT denominator = a13 * x + a23 * y + a33;
66 (*points)[i] = (a11 * x + a21 * y + a31) / denominator;
67 (*points)[i + 1] = (a12 * x + a22 * y + a32) / denominator;
68 }
69 }
70 CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::SquareToQuadrila teral(FX_FLOAT x0, FX_FLOAT y0,
71 FX_FLOAT x1, FX_FLOAT y1,
72 FX_FLOAT x2, FX_FLOAT y2,
73 FX_FLOAT x3, FX_FLOAT y3)
74 {
75 FX_FLOAT dy2 = y3 - y2;
76 FX_FLOAT dy3 = y0 - y1 + y2 - y3;
77 if ((dy2 == 0.0f) && (dy3 == 0.0f)) {
78 return FX_NEW CBC_CommonPerspectiveTransform(x1 - x0, x2 - x1, x0,
79 y1 - y0, y2 - y1, y0,
80 0.0f, 0.0f, 1.0f);
81 } else {
82 FX_FLOAT dx1 = x1 - x2;
83 FX_FLOAT dx2 = x3 - x2;
84 FX_FLOAT dx3 = x0 - x1 + x2 - x3;
85 FX_FLOAT dy1 = y1 - y2;
86 FX_FLOAT denominator = dx1 * dy2 - dx2 * dy1;
87 FX_FLOAT a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
88 FX_FLOAT a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
89 return FX_NEW CBC_CommonPerspectiveTransform(x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0,
90 y1 - y0 + a13 * y1, y3 - y0 + a23 * y3, y0,
91 a13, a23, 1.0f);
92 }
93 }
94 CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::QuadrilateralToS quare(FX_FLOAT x0, FX_FLOAT y0,
95 FX_FLOAT x1, FX_FLOAT y1,
96 FX_FLOAT x2, FX_FLOAT y2,
97 FX_FLOAT x3, FX_FLOAT y3)
98 {
99 CBC_AutoPtr<CBC_CommonPerspectiveTransform> temp1(SquareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3));
100 return temp1->BuildAdjoint();
101 }
102 CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::BuildAdjoint()
103 {
104 return FX_NEW CBC_CommonPerspectiveTransform(m_a22 * m_a33 - m_a23 * m_a32,
105 m_a23 * m_a31 - m_a21 * m_a33,
106 m_a21 * m_a32 - m_a22 * m_a31,
107 m_a13 * m_a32 - m_a12 * m_a33,
108 m_a11 * m_a33 - m_a13 * m_a31,
109 m_a12 * m_a31 - m_a11 * m_a32,
110 m_a12 * m_a23 - m_a13 * m_a22,
111 m_a13 * m_a21 - m_a11 * m_a23,
112 m_a11 * m_a22 - m_a12 * m_a21);
113 }
114 CBC_CommonPerspectiveTransform *CBC_CommonPerspectiveTransform::Times(CBC_Common PerspectiveTransform &other)
115 {
116 return FX_NEW CBC_CommonPerspectiveTransform(m_a11 * other.m_a11 + m_a21 * o ther.m_a12 + m_a31 * other.m_a13,
117 m_a11 * other.m_a21 + m_a21 * other.m_a22 + m_a31 * other.m_a23,
118 m_a11 * other.m_a31 + m_a21 * other.m_a32 + m_a31 * other.m_a33,
119 m_a12 * other.m_a11 + m_a22 * other.m_a12 + m_a32 * other.m_a13,
120 m_a12 * other.m_a21 + m_a22 * other.m_a22 + m_a32 * other.m_a23,
121 m_a12 * other.m_a31 + m_a22 * other.m_a32 + m_a32 * other.m_a33,
122 m_a13 * other.m_a11 + m_a23 * other.m_a12 + m_a33 * other.m_a13,
123 m_a13 * other.m_a21 + m_a23 * other.m_a22 + m_a33 * other.m_a23,
124 m_a13 * other.m_a31 + m_a23 * other.m_a32 + m_a33 * other.m_a33);
125 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/src/BC_CommonECI.cpp ('k') | xfa/src/fxbarcode/src/BC_DataMatrixBitMatrixParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698