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

Side by Side Diff: xfa/fxbarcode/common/BC_CommonPerspectiveTransform.cpp

Issue 2071953002: Remove unused code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 6 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 "xfa/fxbarcode/common/BC_CommonPerspectiveTransform.h"
24
25 #include <memory>
26
27 #include "core/fxcrt/include/fx_basic.h"
28 #include "xfa/fxbarcode/utils.h"
29
30 CBC_CommonPerspectiveTransform::CBC_CommonPerspectiveTransform(FX_FLOAT a11,
31 FX_FLOAT a21,
32 FX_FLOAT a31,
33 FX_FLOAT a12,
34 FX_FLOAT a22,
35 FX_FLOAT a32,
36 FX_FLOAT a13,
37 FX_FLOAT a23,
38 FX_FLOAT a33)
39 : m_a11(a11),
40 m_a12(a12),
41 m_a13(a13),
42 m_a21(a21),
43 m_a22(a22),
44 m_a23(a23),
45 m_a31(a31),
46 m_a32(a32),
47 m_a33(a33) {}
48 CBC_CommonPerspectiveTransform::~CBC_CommonPerspectiveTransform() {}
49 CBC_CommonPerspectiveTransform*
50 CBC_CommonPerspectiveTransform::QuadrilateralToQuadrilateral(FX_FLOAT x0,
51 FX_FLOAT y0,
52 FX_FLOAT x1,
53 FX_FLOAT y1,
54 FX_FLOAT x2,
55 FX_FLOAT y2,
56 FX_FLOAT x3,
57 FX_FLOAT y3,
58 FX_FLOAT x0p,
59 FX_FLOAT y0p,
60 FX_FLOAT x1p,
61 FX_FLOAT y1p,
62 FX_FLOAT x2p,
63 FX_FLOAT y2p,
64 FX_FLOAT x3p,
65 FX_FLOAT y3p) {
66 std::unique_ptr<CBC_CommonPerspectiveTransform> qToS(
67 QuadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3));
68 std::unique_ptr<CBC_CommonPerspectiveTransform> sToQ(
69 SquareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p));
70 return sToQ->Times(*(qToS.get()));
71 }
72 void CBC_CommonPerspectiveTransform::TransformPoints(CFX_FloatArray* points) {
73 int32_t max = points->GetSize();
74 FX_FLOAT a11 = m_a11;
75 FX_FLOAT a12 = m_a12;
76 FX_FLOAT a13 = m_a13;
77 FX_FLOAT a21 = m_a21;
78 FX_FLOAT a22 = m_a22;
79 FX_FLOAT a23 = m_a23;
80 FX_FLOAT a31 = m_a31;
81 FX_FLOAT a32 = m_a32;
82 FX_FLOAT a33 = m_a33;
83 int32_t i;
84 for (i = 0; i < max; i += 2) {
85 FX_FLOAT x = (*points)[i];
86 FX_FLOAT y = (*points)[i + 1];
87 FX_FLOAT denominator = a13 * x + a23 * y + a33;
88 (*points)[i] = (a11 * x + a21 * y + a31) / denominator;
89 (*points)[i + 1] = (a12 * x + a22 * y + a32) / denominator;
90 }
91 }
92 CBC_CommonPerspectiveTransform*
93 CBC_CommonPerspectiveTransform::SquareToQuadrilateral(FX_FLOAT x0,
94 FX_FLOAT y0,
95 FX_FLOAT x1,
96 FX_FLOAT y1,
97 FX_FLOAT x2,
98 FX_FLOAT y2,
99 FX_FLOAT x3,
100 FX_FLOAT y3) {
101 FX_FLOAT dy2 = y3 - y2;
102 FX_FLOAT dy3 = y0 - y1 + y2 - y3;
103 if ((dy2 == 0.0f) && (dy3 == 0.0f)) {
104 return new CBC_CommonPerspectiveTransform(x1 - x0, x2 - x1, x0, y1 - y0,
105 y2 - y1, y0, 0.0f, 0.0f, 1.0f);
106 } else {
107 FX_FLOAT dx1 = x1 - x2;
108 FX_FLOAT dx2 = x3 - x2;
109 FX_FLOAT dx3 = x0 - x1 + x2 - x3;
110 FX_FLOAT dy1 = y1 - y2;
111 FX_FLOAT denominator = dx1 * dy2 - dx2 * dy1;
112 FX_FLOAT a13 = (dx3 * dy2 - dx2 * dy3) / denominator;
113 FX_FLOAT a23 = (dx1 * dy3 - dx3 * dy1) / denominator;
114 return new CBC_CommonPerspectiveTransform(
115 x1 - x0 + a13 * x1, x3 - x0 + a23 * x3, x0, y1 - y0 + a13 * y1,
116 y3 - y0 + a23 * y3, y0, a13, a23, 1.0f);
117 }
118 }
119 CBC_CommonPerspectiveTransform*
120 CBC_CommonPerspectiveTransform::QuadrilateralToSquare(FX_FLOAT x0,
121 FX_FLOAT y0,
122 FX_FLOAT x1,
123 FX_FLOAT y1,
124 FX_FLOAT x2,
125 FX_FLOAT y2,
126 FX_FLOAT x3,
127 FX_FLOAT y3) {
128 std::unique_ptr<CBC_CommonPerspectiveTransform> temp1(
129 SquareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3));
130 return temp1->BuildAdjoint();
131 }
132 CBC_CommonPerspectiveTransform* CBC_CommonPerspectiveTransform::BuildAdjoint() {
133 return new CBC_CommonPerspectiveTransform(
134 m_a22 * m_a33 - m_a23 * m_a32, m_a23 * m_a31 - m_a21 * m_a33,
135 m_a21 * m_a32 - m_a22 * m_a31, m_a13 * m_a32 - m_a12 * m_a33,
136 m_a11 * m_a33 - m_a13 * m_a31, m_a12 * m_a31 - m_a11 * m_a32,
137 m_a12 * m_a23 - m_a13 * m_a22, m_a13 * m_a21 - m_a11 * m_a23,
138 m_a11 * m_a22 - m_a12 * m_a21);
139 }
140 CBC_CommonPerspectiveTransform* CBC_CommonPerspectiveTransform::Times(
141 CBC_CommonPerspectiveTransform& other) {
142 return new CBC_CommonPerspectiveTransform(
143 m_a11 * other.m_a11 + m_a21 * other.m_a12 + m_a31 * other.m_a13,
144 m_a11 * other.m_a21 + m_a21 * other.m_a22 + m_a31 * other.m_a23,
145 m_a11 * other.m_a31 + m_a21 * other.m_a32 + m_a31 * other.m_a33,
146 m_a12 * other.m_a11 + m_a22 * other.m_a12 + m_a32 * other.m_a13,
147 m_a12 * other.m_a21 + m_a22 * other.m_a22 + m_a32 * other.m_a23,
148 m_a12 * other.m_a31 + m_a22 * other.m_a32 + m_a32 * other.m_a33,
149 m_a13 * other.m_a11 + m_a23 * other.m_a12 + m_a33 * other.m_a13,
150 m_a13 * other.m_a21 + m_a23 * other.m_a22 + m_a33 * other.m_a23,
151 m_a13 * other.m_a31 + m_a23 * other.m_a32 + m_a33 * other.m_a33);
152 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/common/BC_CommonPerspectiveTransform.h ('k') | xfa/fxbarcode/pdf417/BC_PDF417Codeword.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698