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

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.cpp

Issue 2467203003: Remove FX_BOOL from xfa. (Closed)
Patch Set: Created 4 years, 1 month 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/fxbarcode/qrcode/BC_QRCoderMaskUtil.h ('k') | xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2008 ZXing authors 8 * Copyright 2008 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 12 matching lines...) Expand all
23 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" 23 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h"
24 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" 24 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h"
25 #include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" 25 #include "xfa/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
26 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" 26 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h"
27 #include "xfa/fxbarcode/utils.h" 27 #include "xfa/fxbarcode/utils.h"
28 28
29 CBC_QRCoderMaskUtil::CBC_QRCoderMaskUtil() {} 29 CBC_QRCoderMaskUtil::CBC_QRCoderMaskUtil() {}
30 CBC_QRCoderMaskUtil::~CBC_QRCoderMaskUtil() {} 30 CBC_QRCoderMaskUtil::~CBC_QRCoderMaskUtil() {}
31 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1( 31 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(
32 CBC_CommonByteMatrix* matrix) { 32 CBC_CommonByteMatrix* matrix) {
33 return ApplyMaskPenaltyRule1Internal(matrix, TRUE) + 33 return ApplyMaskPenaltyRule1Internal(matrix, true) +
34 ApplyMaskPenaltyRule1Internal(matrix, FALSE); 34 ApplyMaskPenaltyRule1Internal(matrix, false);
35 } 35 }
36 36
37 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2( 37 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(
38 CBC_CommonByteMatrix* matrix) { 38 CBC_CommonByteMatrix* matrix) {
39 int32_t penalty = 0; 39 int32_t penalty = 0;
40 uint8_t* array = matrix->GetArray(); 40 uint8_t* array = matrix->GetArray();
41 int32_t width = matrix->GetWidth(); 41 int32_t width = matrix->GetWidth();
42 int32_t height = matrix->GetHeight(); 42 int32_t height = matrix->GetHeight();
43 for (int32_t y = 0; y < height - 1; y++) { 43 for (int32_t y = 0; y < height - 1; y++) {
44 for (int32_t x = 0; x < width - 1; x++) { 44 for (int32_t x = 0; x < width - 1; x++) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 for (int32_t x = 0; x < width; ++x) { 115 for (int32_t x = 0; x < width; ++x) {
116 if (array[y * width + x] == 1) { 116 if (array[y * width + x] == 1) {
117 numDarkCells += 1; 117 numDarkCells += 1;
118 } 118 }
119 } 119 }
120 } 120 }
121 int32_t numTotalCells = matrix->GetHeight() * matrix->GetWidth(); 121 int32_t numTotalCells = matrix->GetHeight() * matrix->GetWidth();
122 double darkRatio = (double)numDarkCells / numTotalCells; 122 double darkRatio = (double)numDarkCells / numTotalCells;
123 return abs((int32_t)(darkRatio * 100 - 50) / 5) * 5 * 10; 123 return abs((int32_t)(darkRatio * 100 - 50) / 5) * 5 * 10;
124 } 124 }
125 FX_BOOL CBC_QRCoderMaskUtil::GetDataMaskBit(int32_t maskPattern, 125 bool CBC_QRCoderMaskUtil::GetDataMaskBit(int32_t maskPattern,
126 int32_t x, 126 int32_t x,
127 int32_t y, 127 int32_t y,
128 int32_t& e) { 128 int32_t& e) {
129 if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) { 129 if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) {
130 e = (BCExceptionInvalidateMaskPattern); 130 e = (BCExceptionInvalidateMaskPattern);
131 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); 131 BC_EXCEPTION_CHECK_ReturnValue(e, false);
132 } 132 }
133 int32_t intermediate = 0, temp = 0; 133 int32_t intermediate = 0, temp = 0;
134 switch (maskPattern) { 134 switch (maskPattern) {
135 case 0: 135 case 0:
136 intermediate = (y + x) & 0x1; 136 intermediate = (y + x) & 0x1;
137 break; 137 break;
138 case 1: 138 case 1:
139 intermediate = y & 0x1; 139 intermediate = y & 0x1;
140 break; 140 break;
141 case 2: 141 case 2:
(...skipping 12 matching lines...) Expand all
154 case 6: 154 case 6:
155 temp = y * x; 155 temp = y * x;
156 intermediate = (((temp & 0x1) + (temp % 3)) & 0x1); 156 intermediate = (((temp & 0x1) + (temp % 3)) & 0x1);
157 break; 157 break;
158 case 7: 158 case 7:
159 temp = y * x; 159 temp = y * x;
160 intermediate = (((temp % 3) + ((y + x) & 0x1)) & 0x1); 160 intermediate = (((temp % 3) + ((y + x) & 0x1)) & 0x1);
161 break; 161 break;
162 default: { 162 default: {
163 e = BCExceptionInvalidateMaskPattern; 163 e = BCExceptionInvalidateMaskPattern;
164 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); 164 BC_EXCEPTION_CHECK_ReturnValue(e, false);
165 } 165 }
166 } 166 }
167 return intermediate == 0; 167 return intermediate == 0;
168 } 168 }
169 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1Internal( 169 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1Internal(
170 CBC_CommonByteMatrix* matrix, 170 CBC_CommonByteMatrix* matrix,
171 FX_BOOL isHorizontal) { 171 bool isHorizontal) {
172 int32_t penalty = 0; 172 int32_t penalty = 0;
173 int32_t numSameBitCells = 0; 173 int32_t numSameBitCells = 0;
174 int32_t prevBit = -1; 174 int32_t prevBit = -1;
175 int32_t width = matrix->GetWidth(); 175 int32_t width = matrix->GetWidth();
176 int32_t height = matrix->GetHeight(); 176 int32_t height = matrix->GetHeight();
177 int32_t iLimit = isHorizontal ? height : width; 177 int32_t iLimit = isHorizontal ? height : width;
178 int32_t jLimit = isHorizontal ? width : height; 178 int32_t jLimit = isHorizontal ? width : height;
179 uint8_t* array = matrix->GetArray(); 179 uint8_t* array = matrix->GetArray();
180 for (int32_t i = 0; i < iLimit; ++i) { 180 for (int32_t i = 0; i < iLimit; ++i) {
181 for (int32_t j = 0; j < jLimit; ++j) { 181 for (int32_t j = 0; j < jLimit; ++j) {
182 int32_t bit = isHorizontal ? array[i * width + j] : array[j * width + i]; 182 int32_t bit = isHorizontal ? array[i * width + j] : array[j * width + i];
183 if (bit == prevBit) { 183 if (bit == prevBit) {
184 numSameBitCells += 1; 184 numSameBitCells += 1;
185 if (numSameBitCells == 5) { 185 if (numSameBitCells == 5) {
186 penalty += 3; 186 penalty += 3;
187 } else if (numSameBitCells > 5) { 187 } else if (numSameBitCells > 5) {
188 penalty += 1; 188 penalty += 1;
189 } 189 }
190 } else { 190 } else {
191 numSameBitCells = 1; 191 numSameBitCells = 1;
192 prevBit = bit; 192 prevBit = bit;
193 } 193 }
194 } 194 }
195 numSameBitCells = 0; 195 numSameBitCells = 0;
196 } 196 }
197 return penalty; 197 return penalty;
198 } 198 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h ('k') | xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698