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"); |
(...skipping 17 matching lines...) Expand all Loading... |
28 CBC_QRGridSampler::CBC_QRGridSampler() | 28 CBC_QRGridSampler::CBC_QRGridSampler() |
29 { | 29 { |
30 } | 30 } |
31 CBC_QRGridSampler::~CBC_QRGridSampler() | 31 CBC_QRGridSampler::~CBC_QRGridSampler() |
32 { | 32 { |
33 } | 33 } |
34 CBC_QRGridSampler &CBC_QRGridSampler::GetInstance() | 34 CBC_QRGridSampler &CBC_QRGridSampler::GetInstance() |
35 { | 35 { |
36 return m_gridSampler; | 36 return m_gridSampler; |
37 } | 37 } |
38 void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix *image, CFX_Floa
tArray *points, FX_INT32 &e) | 38 void CBC_QRGridSampler::CheckAndNudgePoints(CBC_CommonBitMatrix *image, CFX_Floa
tArray *points, int32_t &e) |
39 { | 39 { |
40 FX_INT32 width = image->GetWidth(); | 40 int32_t width = image->GetWidth(); |
41 FX_INT32 height = image->GetHeight(); | 41 int32_t height = image->GetHeight(); |
42 FX_BOOL nudged = TRUE; | 42 FX_BOOL nudged = TRUE; |
43 FX_INT32 offset; | 43 int32_t offset; |
44 for (offset = 0; offset < points->GetSize() && nudged; offset += 2) { | 44 for (offset = 0; offset < points->GetSize() && nudged; offset += 2) { |
45 FX_INT32 x = (FX_INT32) (*points)[offset]; | 45 int32_t x = (int32_t) (*points)[offset]; |
46 FX_INT32 y = (FX_INT32) (*points)[offset + 1]; | 46 int32_t y = (int32_t) (*points)[offset + 1]; |
47 if (x < -1 || x > width || y < -1 || y > height) { | 47 if (x < -1 || x > width || y < -1 || y > height) { |
48 e = BCExceptionRead; | 48 e = BCExceptionRead; |
49 BC_EXCEPTION_CHECK_ReturnVoid(e); | 49 BC_EXCEPTION_CHECK_ReturnVoid(e); |
50 } | 50 } |
51 nudged = FALSE; | 51 nudged = FALSE; |
52 if (x == -1) { | 52 if (x == -1) { |
53 (*points)[offset] = 0.0f; | 53 (*points)[offset] = 0.0f; |
54 nudged = TRUE; | 54 nudged = TRUE; |
55 } else if (x == width) { | 55 } else if (x == width) { |
56 (*points)[offset] = (FX_FLOAT)(width - 1); | 56 (*points)[offset] = (FX_FLOAT)(width - 1); |
57 nudged = TRUE; | 57 nudged = TRUE; |
58 } | 58 } |
59 if (y == -1) { | 59 if (y == -1) { |
60 (*points)[offset + 1] = 0.0f; | 60 (*points)[offset + 1] = 0.0f; |
61 nudged = TRUE; | 61 nudged = TRUE; |
62 } else if (y == height) { | 62 } else if (y == height) { |
63 (*points)[offset + 1] = (FX_FLOAT)(height - 1); | 63 (*points)[offset + 1] = (FX_FLOAT)(height - 1); |
64 nudged = TRUE; | 64 nudged = TRUE; |
65 } | 65 } |
66 } | 66 } |
67 nudged = TRUE; | 67 nudged = TRUE; |
68 for (offset = (*points).GetSize() - 2; offset >= 0 && nudged; offset -= 2) { | 68 for (offset = (*points).GetSize() - 2; offset >= 0 && nudged; offset -= 2) { |
69 FX_INT32 x = (FX_INT32) (*points)[offset]; | 69 int32_t x = (int32_t) (*points)[offset]; |
70 FX_INT32 y = (FX_INT32) (*points)[offset + 1]; | 70 int32_t y = (int32_t) (*points)[offset + 1]; |
71 if (x < -1 || x > width || y < -1 || y > height) { | 71 if (x < -1 || x > width || y < -1 || y > height) { |
72 e = BCExceptionRead; | 72 e = BCExceptionRead; |
73 BC_EXCEPTION_CHECK_ReturnVoid(e); | 73 BC_EXCEPTION_CHECK_ReturnVoid(e); |
74 } | 74 } |
75 nudged = FALSE; | 75 nudged = FALSE; |
76 if (x == -1) { | 76 if (x == -1) { |
77 (*points)[offset] = 0.0f; | 77 (*points)[offset] = 0.0f; |
78 nudged = TRUE; | 78 nudged = TRUE; |
79 } else if (x == width) { | 79 } else if (x == width) { |
80 (*points)[offset] = (FX_FLOAT)(width - 1); | 80 (*points)[offset] = (FX_FLOAT)(width - 1); |
81 nudged = TRUE; | 81 nudged = TRUE; |
82 } | 82 } |
83 if (y == -1) { | 83 if (y == -1) { |
84 (*points)[offset + 1] = 0.0f; | 84 (*points)[offset + 1] = 0.0f; |
85 nudged = TRUE; | 85 nudged = TRUE; |
86 } else if (y == height) { | 86 } else if (y == height) { |
87 (*points)[offset + 1] = (FX_FLOAT)(height - 1); | 87 (*points)[offset + 1] = (FX_FLOAT)(height - 1); |
88 nudged = TRUE; | 88 nudged = TRUE; |
89 } | 89 } |
90 } | 90 } |
91 } | 91 } |
92 CBC_CommonBitMatrix *CBC_QRGridSampler::SampleGrid(CBC_CommonBitMatrix *image, F
X_INT32 dimensionX, FX_INT32 dimensionY, | 92 CBC_CommonBitMatrix *CBC_QRGridSampler::SampleGrid(CBC_CommonBitMatrix *image, i
nt32_t dimensionX, int32_t dimensionY, |
93 FX_FLOAT p1ToX, FX_FLOAT p1ToY, | 93 FX_FLOAT p1ToX, FX_FLOAT p1ToY, |
94 FX_FLOAT p2ToX, FX_FLOAT p2ToY, | 94 FX_FLOAT p2ToX, FX_FLOAT p2ToY, |
95 FX_FLOAT p3ToX, FX_FLOAT p3ToY, | 95 FX_FLOAT p3ToX, FX_FLOAT p3ToY, |
96 FX_FLOAT p4ToX, FX_FLOAT p4ToY, | 96 FX_FLOAT p4ToX, FX_FLOAT p4ToY, |
97 FX_FLOAT p1FromX, FX_FLOAT p1FromY, | 97 FX_FLOAT p1FromX, FX_FLOAT p1FromY, |
98 FX_FLOAT p2FromX, FX_FLOAT p2FromY, | 98 FX_FLOAT p2FromX, FX_FLOAT p2FromY, |
99 FX_FLOAT p3FromX, FX_FLOAT p3FromY, | 99 FX_FLOAT p3FromX, FX_FLOAT p3FromY, |
100 FX_FLOAT p4FromX, FX_FLOAT p4FromY, FX_INT32 &e) | 100 FX_FLOAT p4FromX, FX_FLOAT p4FromY, int32_t &e) |
101 { | 101 { |
102 CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform(CBC_CommonPerspectiveT
ransform::QuadrilateralToQuadrilateral( | 102 CBC_AutoPtr<CBC_CommonPerspectiveTransform> transform(CBC_CommonPerspectiveT
ransform::QuadrilateralToQuadrilateral( |
103 p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, | 103 p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, |
104 p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p
4FromY)); | 104 p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p
4FromY)); |
105 CBC_CommonBitMatrix *tempBitM = FX_NEW CBC_CommonBitMatrix(); | 105 CBC_CommonBitMatrix *tempBitM = FX_NEW CBC_CommonBitMatrix(); |
106 tempBitM->Init(dimensionX, dimensionY); | 106 tempBitM->Init(dimensionX, dimensionY); |
107 CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM); | 107 CBC_AutoPtr<CBC_CommonBitMatrix> bits(tempBitM); |
108 CFX_FloatArray points; | 108 CFX_FloatArray points; |
109 points.SetSize(dimensionX << 1); | 109 points.SetSize(dimensionX << 1); |
110 for (FX_INT32 y = 0; y < dimensionY; y++) { | 110 for (int32_t y = 0; y < dimensionY; y++) { |
111 FX_INT32 max = points.GetSize(); | 111 int32_t max = points.GetSize(); |
112 FX_FLOAT iValue = (FX_FLOAT) (y + 0.5f); | 112 FX_FLOAT iValue = (FX_FLOAT) (y + 0.5f); |
113 FX_INT32 x; | 113 int32_t x; |
114 for (x = 0; x < max; x += 2) { | 114 for (x = 0; x < max; x += 2) { |
115 points[x] = (FX_FLOAT) ((x >> 1) + 0.5f); | 115 points[x] = (FX_FLOAT) ((x >> 1) + 0.5f); |
116 points[x + 1] = iValue; | 116 points[x + 1] = iValue; |
117 } | 117 } |
118 transform->TransformPoints(&points); | 118 transform->TransformPoints(&points); |
119 CheckAndNudgePoints(image, &points, e); | 119 CheckAndNudgePoints(image, &points, e); |
120 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 120 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
121 for (x = 0; x < max; x += 2) { | 121 for (x = 0; x < max; x += 2) { |
122 if (image->Get((FX_INT32) points[x], (FX_INT32) points[x + 1])) { | 122 if (image->Get((int32_t) points[x], (int32_t) points[x + 1])) { |
123 bits->Set(x >> 1, y); | 123 bits->Set(x >> 1, y); |
124 } | 124 } |
125 } | 125 } |
126 } | 126 } |
127 return bits.release(); | 127 return bits.release(); |
128 } | 128 } |
OLD | NEW |