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

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

Issue 1172793002: Merge to XFA: Use stdint.h types throughout PDFium. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 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
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 13 matching lines...) Expand all
24 #include "../common/BC_CommonByteMatrix.h" 24 #include "../common/BC_CommonByteMatrix.h"
25 #include "BC_QRCoderErrorCorrectionLevel.h" 25 #include "BC_QRCoderErrorCorrectionLevel.h"
26 #include "BC_QRCoder.h" 26 #include "BC_QRCoder.h"
27 #include "BC_QRCoderMaskUtil.h" 27 #include "BC_QRCoderMaskUtil.h"
28 CBC_QRCoderMaskUtil::CBC_QRCoderMaskUtil() 28 CBC_QRCoderMaskUtil::CBC_QRCoderMaskUtil()
29 { 29 {
30 } 30 }
31 CBC_QRCoderMaskUtil::~CBC_QRCoderMaskUtil() 31 CBC_QRCoderMaskUtil::~CBC_QRCoderMaskUtil()
32 { 32 {
33 } 33 }
34 FX_INT32 CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(CBC_CommonByteMatrix* matrix ) 34 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(CBC_CommonByteMatrix* matrix)
35 { 35 {
36 return ApplyMaskPenaltyRule1Internal(matrix, TRUE) + 36 return ApplyMaskPenaltyRule1Internal(matrix, TRUE) +
37 ApplyMaskPenaltyRule1Internal(matrix, FALSE); 37 ApplyMaskPenaltyRule1Internal(matrix, FALSE);
38 } 38 }
39 FX_INT32 CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(CBC_CommonByteMatrix* matrix ) 39 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(CBC_CommonByteMatrix* matrix)
40 { 40 {
41 FX_INT32 penalty = 0; 41 int32_t penalty = 0;
42 FX_BYTE* array = matrix->GetArray(); 42 uint8_t* array = matrix->GetArray();
43 FX_INT32 width = matrix->GetWidth(); 43 int32_t width = matrix->GetWidth();
44 FX_INT32 height = matrix->GetHeight(); 44 int32_t height = matrix->GetHeight();
45 for(FX_INT32 y = 0; y < height - 1; y++) { 45 for(int32_t y = 0; y < height - 1; y++) {
46 for(FX_INT32 x = 0; x < width - 1; x++) { 46 for(int32_t x = 0; x < width - 1; x++) {
47 FX_INT32 value = array[y * width + x]; 47 int32_t value = array[y * width + x];
48 if(value == array[y * width + x + 1] && 48 if(value == array[y * width + x + 1] &&
49 value == array[(y + 1) * width + x] && 49 value == array[(y + 1) * width + x] &&
50 value == array[(y + 1) * width + x + 1]) { 50 value == array[(y + 1) * width + x + 1]) {
51 penalty ++; 51 penalty ++;
52 } 52 }
53 } 53 }
54 } 54 }
55 return 3 * penalty; 55 return 3 * penalty;
56 } 56 }
57 FX_INT32 CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3(CBC_CommonByteMatrix* matrix ) 57 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3(CBC_CommonByteMatrix* matrix)
58 { 58 {
59 FX_INT32 penalty = 0; 59 int32_t penalty = 0;
60 FX_BYTE* array = matrix->GetArray(); 60 uint8_t* array = matrix->GetArray();
61 FX_INT32 width = matrix->GetWidth(); 61 int32_t width = matrix->GetWidth();
62 FX_INT32 height = matrix->GetHeight(); 62 int32_t height = matrix->GetHeight();
63 for (FX_INT32 y = 0; y < height; ++y) { 63 for (int32_t y = 0; y < height; ++y) {
64 for (FX_INT32 x = 0; x < width; ++x) { 64 for (int32_t x = 0; x < width; ++x) {
65 if (x == 0 && ((y >= 0 && y <= 6) || (y >= height - 7 && y <= height - 1))) { 65 if (x == 0 && ((y >= 0 && y <= 6) || (y >= height - 7 && y <= height - 1))) {
66 continue; 66 continue;
67 } 67 }
68 if (x == width - 7 && (y >= 0 && y <= 6)) { 68 if (x == width - 7 && (y >= 0 && y <= 6)) {
69 continue; 69 continue;
70 } 70 }
71 if (y == 0 && ((x >= 0 && x <= 6) || (x >= width - 7 && x <= width - 1))) { 71 if (y == 0 && ((x >= 0 && x <= 6) || (x >= width - 7 && x <= width - 1))) {
72 continue; 72 continue;
73 } 73 }
74 if (y == height - 7 && (x >= 0 && x <= 6)) { 74 if (y == height - 7 && (x >= 0 && x <= 6)) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 array[(y - 1) * width + x] == 0 && 111 array[(y - 1) * width + x] == 0 &&
112 array[(y - 2) * width + x] == 0 && 112 array[(y - 2) * width + x] == 0 &&
113 array[(y - 3) * width + x] == 0 && 113 array[(y - 3) * width + x] == 0 &&
114 array[(y - 4) * width + x] == 0))) { 114 array[(y - 4) * width + x] == 0))) {
115 penalty += 40; 115 penalty += 40;
116 } 116 }
117 } 117 }
118 } 118 }
119 return penalty; 119 return penalty;
120 } 120 }
121 FX_INT32 CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(CBC_CommonByteMatrix* matrix ) 121 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(CBC_CommonByteMatrix* matrix)
122 { 122 {
123 FX_INT32 numDarkCells = 0; 123 int32_t numDarkCells = 0;
124 FX_BYTE* array = matrix->GetArray(); 124 uint8_t* array = matrix->GetArray();
125 FX_INT32 width = matrix->GetWidth(); 125 int32_t width = matrix->GetWidth();
126 FX_INT32 height = matrix->GetHeight(); 126 int32_t height = matrix->GetHeight();
127 for (FX_INT32 y = 0; y < height; ++y) { 127 for (int32_t y = 0; y < height; ++y) {
128 for (FX_INT32 x = 0; x < width; ++x) { 128 for (int32_t x = 0; x < width; ++x) {
129 if (array[y * width + x] == 1) { 129 if (array[y * width + x] == 1) {
130 numDarkCells += 1; 130 numDarkCells += 1;
131 } 131 }
132 } 132 }
133 } 133 }
134 FX_INT32 numTotalCells = matrix->GetHeight() * matrix->GetWidth(); 134 int32_t numTotalCells = matrix->GetHeight() * matrix->GetWidth();
135 double darkRatio = (double) numDarkCells / numTotalCells; 135 double darkRatio = (double) numDarkCells / numTotalCells;
136 return abs( (FX_INT32) (darkRatio * 100 - 50) / 5 ) * 5 * 10; 136 return abs( (int32_t) (darkRatio * 100 - 50) / 5 ) * 5 * 10;
137 } 137 }
138 FX_BOOL CBC_QRCoderMaskUtil::GetDataMaskBit(FX_INT32 maskPattern, FX_INT32 x, FX _INT32 y, FX_INT32 &e) 138 FX_BOOL CBC_QRCoderMaskUtil::GetDataMaskBit(int32_t maskPattern, int32_t x, int3 2_t y, int32_t &e)
139 { 139 {
140 if(!CBC_QRCoder::IsValidMaskPattern(maskPattern)) { 140 if(!CBC_QRCoder::IsValidMaskPattern(maskPattern)) {
141 e = (BCExceptionInvalidateMaskPattern); 141 e = (BCExceptionInvalidateMaskPattern);
142 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); 142 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
143 } 143 }
144 FX_INT32 intermediate = 0, temp = 0; 144 int32_t intermediate = 0, temp = 0;
145 switch(maskPattern) { 145 switch(maskPattern) {
146 case 0: 146 case 0:
147 intermediate = (y + x) & 0x1; 147 intermediate = (y + x) & 0x1;
148 break; 148 break;
149 case 1: 149 case 1:
150 intermediate = y & 0x1; 150 intermediate = y & 0x1;
151 break; 151 break;
152 case 2: 152 case 2:
153 intermediate = x % 3; 153 intermediate = x % 3;
154 break; 154 break;
(...skipping 15 matching lines...) Expand all
170 temp = y * x; 170 temp = y * x;
171 intermediate = (((temp % 3) + ((y + x) & 0x1)) & 0x1); 171 intermediate = (((temp % 3) + ((y + x) & 0x1)) & 0x1);
172 break; 172 break;
173 default: { 173 default: {
174 e = BCExceptionInvalidateMaskPattern; 174 e = BCExceptionInvalidateMaskPattern;
175 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE); 175 BC_EXCEPTION_CHECK_ReturnValue(e, FALSE);
176 } 176 }
177 } 177 }
178 return intermediate == 0; 178 return intermediate == 0;
179 } 179 }
180 FX_INT32 CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1Internal(CBC_CommonByteMatrix * matrix, FX_BOOL isHorizontal) 180 int32_t CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1Internal(CBC_CommonByteMatrix* matrix, FX_BOOL isHorizontal)
181 { 181 {
182 FX_INT32 penalty = 0; 182 int32_t penalty = 0;
183 FX_INT32 numSameBitCells = 0; 183 int32_t numSameBitCells = 0;
184 FX_INT32 prevBit = -1; 184 int32_t prevBit = -1;
185 FX_INT32 width = matrix->GetWidth(); 185 int32_t width = matrix->GetWidth();
186 FX_INT32 height = matrix->GetHeight(); 186 int32_t height = matrix->GetHeight();
187 FX_INT32 iLimit = isHorizontal ? height : width; 187 int32_t iLimit = isHorizontal ? height : width;
188 FX_INT32 jLimit = isHorizontal ? width : height; 188 int32_t jLimit = isHorizontal ? width : height;
189 FX_BYTE* array = matrix->GetArray(); 189 uint8_t* array = matrix->GetArray();
190 for (FX_INT32 i = 0; i < iLimit; ++i) { 190 for (int32_t i = 0; i < iLimit; ++i) {
191 for (FX_INT32 j = 0; j < jLimit; ++j) { 191 for (int32_t j = 0; j < jLimit; ++j) {
192 FX_INT32 bit = isHorizontal ? array[i * width + j] : array[j * width + i]; 192 int32_t bit = isHorizontal ? array[i * width + j] : array[j * width + i];
193 if (bit == prevBit) { 193 if (bit == prevBit) {
194 numSameBitCells += 1; 194 numSameBitCells += 1;
195 if (numSameBitCells == 5) { 195 if (numSameBitCells == 5) {
196 penalty += 3; 196 penalty += 3;
197 } else if (numSameBitCells > 5) { 197 } else if (numSameBitCells > 5) {
198 penalty += 1; 198 penalty += 1;
199 } 199 }
200 } else { 200 } else {
201 numSameBitCells = 1; 201 numSameBitCells = 1;
202 prevBit = bit; 202 prevBit = bit;
203 } 203 }
204 } 204 }
205 numSameBitCells = 0; 205 numSameBitCells = 0;
206 } 206 }
207 return penalty; 207 return penalty;
208 } 208 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/qrcode/BC_QRCoderMaskUtil.h ('k') | xfa/src/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698