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

Side by Side Diff: xfa/src/fxbarcode/BC_UtilRSS.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
« no previous file with comments | « xfa/src/fxbarcode/BC_UtilRSS.h ('k') | xfa/src/fxbarcode/BC_Utils.cpp » ('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 2009 ZXing authors 8 * Copyright 2009 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 10 matching lines...) Expand all
21 */ 21 */
22 22
23 #include "barcode.h" 23 #include "barcode.h"
24 #include "BC_UtilRSS.h" 24 #include "BC_UtilRSS.h"
25 CBC_UtilRSS::CBC_UtilRSS() 25 CBC_UtilRSS::CBC_UtilRSS()
26 { 26 {
27 } 27 }
28 CBC_UtilRSS::~CBC_UtilRSS() 28 CBC_UtilRSS::~CBC_UtilRSS()
29 { 29 {
30 } 30 }
31 CFX_Int32Array *CBC_UtilRSS::GetRssWidths(FX_INT32 val, FX_INT32 n, FX_INT32 ele ments, FX_INT32 maxWidth, FX_BOOL noNarrow) 31 CFX_Int32Array *CBC_UtilRSS::GetRssWidths(int32_t val, int32_t n, int32_t elemen ts, int32_t maxWidth, FX_BOOL noNarrow)
32 { 32 {
33 CFX_Int32Array *iTemp = FX_NEW CFX_Int32Array; 33 CFX_Int32Array *iTemp = FX_NEW CFX_Int32Array;
34 iTemp->SetSize(elements); 34 iTemp->SetSize(elements);
35 CBC_AutoPtr<CFX_Int32Array > widths(iTemp); 35 CBC_AutoPtr<CFX_Int32Array > widths(iTemp);
36 FX_INT32 bar; 36 int32_t bar;
37 FX_INT32 narrowMask = 0; 37 int32_t narrowMask = 0;
38 for (bar = 0; bar < elements - 1; bar++) { 38 for (bar = 0; bar < elements - 1; bar++) {
39 narrowMask |= (1 << bar); 39 narrowMask |= (1 << bar);
40 FX_INT32 elmWidth = 1; 40 int32_t elmWidth = 1;
41 FX_INT32 subVal; 41 int32_t subVal;
42 while (TRUE) { 42 while (TRUE) {
43 subVal = Combins(n - elmWidth - 1, elements - bar - 2); 43 subVal = Combins(n - elmWidth - 1, elements - bar - 2);
44 if (noNarrow && (narrowMask == 0) && 44 if (noNarrow && (narrowMask == 0) &&
45 (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) { 45 (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
46 subVal -= Combins(n - elmWidth - (elements - bar), elements - ba r - 2); 46 subVal -= Combins(n - elmWidth - (elements - bar), elements - ba r - 2);
47 } 47 }
48 if (elements - bar - 1 > 1) { 48 if (elements - bar - 1 > 1) {
49 FX_INT32 lessVal = 0; 49 int32_t lessVal = 0;
50 for (FX_INT32 mxwElement = n - elmWidth - (elements - bar - 2); 50 for (int32_t mxwElement = n - elmWidth - (elements - bar - 2);
51 mxwElement > maxWidth; 51 mxwElement > maxWidth;
52 mxwElement--) { 52 mxwElement--) {
53 lessVal += Combins(n - elmWidth - mxwElement - 1, elements - bar - 3); 53 lessVal += Combins(n - elmWidth - mxwElement - 1, elements - bar - 3);
54 } 54 }
55 subVal -= lessVal * (elements - 1 - bar); 55 subVal -= lessVal * (elements - 1 - bar);
56 } else if (n - elmWidth > maxWidth) { 56 } else if (n - elmWidth > maxWidth) {
57 subVal--; 57 subVal--;
58 } 58 }
59 val -= subVal; 59 val -= subVal;
60 if (val < 0) { 60 if (val < 0) {
61 break; 61 break;
62 } 62 }
63 elmWidth++; 63 elmWidth++;
64 narrowMask &= ~(1 << bar); 64 narrowMask &= ~(1 << bar);
65 } 65 }
66 val += subVal; 66 val += subVal;
67 n -= elmWidth; 67 n -= elmWidth;
68 (*widths)[bar] = elmWidth; 68 (*widths)[bar] = elmWidth;
69 } 69 }
70 (*widths)[bar] = n; 70 (*widths)[bar] = n;
71 return widths.release(); 71 return widths.release();
72 } 72 }
73 FX_INT32 CBC_UtilRSS::GetRSSvalue(CFX_Int32Array &widths, FX_INT32 maxWidth, FX_ BOOL noNarrow) 73 int32_t CBC_UtilRSS::GetRSSvalue(CFX_Int32Array &widths, int32_t maxWidth, FX_BO OL noNarrow)
74 { 74 {
75 FX_INT32 elements = widths.GetSize(); 75 int32_t elements = widths.GetSize();
76 FX_INT32 n = 0; 76 int32_t n = 0;
77 for (FX_INT32 i = 0; i < elements; i++) { 77 for (int32_t i = 0; i < elements; i++) {
78 n += widths[i]; 78 n += widths[i];
79 } 79 }
80 FX_INT32 val = 0; 80 int32_t val = 0;
81 FX_INT32 narrowMask = 0; 81 int32_t narrowMask = 0;
82 for (FX_INT32 bar = 0; bar < elements - 1; bar++) { 82 for (int32_t bar = 0; bar < elements - 1; bar++) {
83 FX_INT32 elmWidth; 83 int32_t elmWidth;
84 for (elmWidth = 1, narrowMask |= (1 << bar); 84 for (elmWidth = 1, narrowMask |= (1 << bar);
85 elmWidth < widths[bar]; 85 elmWidth < widths[bar];
86 elmWidth++, narrowMask &= ~(1 << bar)) { 86 elmWidth++, narrowMask &= ~(1 << bar)) {
87 FX_INT32 subVal = Combins(n - elmWidth - 1, elements - bar - 2); 87 int32_t subVal = Combins(n - elmWidth - 1, elements - bar - 2);
88 if (noNarrow && (narrowMask == 0) && 88 if (noNarrow && (narrowMask == 0) &&
89 (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) { 89 (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
90 subVal -= Combins(n - elmWidth - (elements - bar), 90 subVal -= Combins(n - elmWidth - (elements - bar),
91 elements - bar - 2); 91 elements - bar - 2);
92 } 92 }
93 if (elements - bar - 1 > 1) { 93 if (elements - bar - 1 > 1) {
94 FX_INT32 lessVal = 0; 94 int32_t lessVal = 0;
95 for (FX_INT32 mxwElement = n - elmWidth - (elements - bar - 2); 95 for (int32_t mxwElement = n - elmWidth - (elements - bar - 2);
96 mxwElement > maxWidth; mxwElement--) { 96 mxwElement > maxWidth; mxwElement--) {
97 lessVal += Combins(n - elmWidth - mxwElement - 1, 97 lessVal += Combins(n - elmWidth - mxwElement - 1,
98 elements - bar - 3); 98 elements - bar - 3);
99 } 99 }
100 subVal -= lessVal * (elements - 1 - bar); 100 subVal -= lessVal * (elements - 1 - bar);
101 } else if (n - elmWidth > maxWidth) { 101 } else if (n - elmWidth > maxWidth) {
102 subVal--; 102 subVal--;
103 } 103 }
104 val += subVal; 104 val += subVal;
105 } 105 }
106 n -= elmWidth; 106 n -= elmWidth;
107 } 107 }
108 return val; 108 return val;
109 } 109 }
110 FX_INT32 CBC_UtilRSS::Combins(FX_INT32 n, FX_INT32 r) 110 int32_t CBC_UtilRSS::Combins(int32_t n, int32_t r)
111 { 111 {
112 FX_INT32 maxDenom; 112 int32_t maxDenom;
113 FX_INT32 minDenom; 113 int32_t minDenom;
114 if (n - r > r) { 114 if (n - r > r) {
115 minDenom = r; 115 minDenom = r;
116 maxDenom = n - r; 116 maxDenom = n - r;
117 } else { 117 } else {
118 minDenom = n - r; 118 minDenom = n - r;
119 maxDenom = r; 119 maxDenom = r;
120 } 120 }
121 FX_INT32 val = 1; 121 int32_t val = 1;
122 FX_INT32 j = 1; 122 int32_t j = 1;
123 for (FX_INT32 i = n; i > maxDenom; i--) { 123 for (int32_t i = n; i > maxDenom; i--) {
124 val *= i; 124 val *= i;
125 if (j <= minDenom) { 125 if (j <= minDenom) {
126 val /= j; 126 val /= j;
127 j++; 127 j++;
128 } 128 }
129 } 129 }
130 while (j <= minDenom) { 130 while (j <= minDenom) {
131 val /= j; 131 val /= j;
132 j++; 132 j++;
133 } 133 }
134 return val; 134 return val;
135 } 135 }
136 CFX_Int32Array *CBC_UtilRSS::Elements(CFX_Int32Array &eDist, FX_INT32 N, FX_INT3 2 K) 136 CFX_Int32Array *CBC_UtilRSS::Elements(CFX_Int32Array &eDist, int32_t N, int32_t K)
137 { 137 {
138 CFX_Int32Array *widths = FX_NEW CFX_Int32Array; 138 CFX_Int32Array *widths = FX_NEW CFX_Int32Array;
139 widths->SetSize(eDist.GetSize() + 2); 139 widths->SetSize(eDist.GetSize() + 2);
140 FX_INT32 twoK = K << 1; 140 int32_t twoK = K << 1;
141 (*widths)[0] = 1; 141 (*widths)[0] = 1;
142 FX_INT32 i; 142 int32_t i;
143 FX_INT32 minEven = 10; 143 int32_t minEven = 10;
144 FX_INT32 barSum = 1; 144 int32_t barSum = 1;
145 for (i = 1; i < twoK - 2; i += 2) { 145 for (i = 1; i < twoK - 2; i += 2) {
146 (*widths)[i] = eDist[i - 1] - (*widths)[i - 1]; 146 (*widths)[i] = eDist[i - 1] - (*widths)[i - 1];
147 (*widths)[i + 1] = eDist[i] - (*widths)[i]; 147 (*widths)[i + 1] = eDist[i] - (*widths)[i];
148 barSum += (*widths)[i] + (*widths)[i + 1]; 148 barSum += (*widths)[i] + (*widths)[i + 1];
149 if ((*widths)[i] < minEven) { 149 if ((*widths)[i] < minEven) {
150 minEven = (*widths)[i]; 150 minEven = (*widths)[i];
151 } 151 }
152 } 152 }
153 (*widths)[twoK - 1] = N - barSum; 153 (*widths)[twoK - 1] = N - barSum;
154 if ((*widths)[twoK - 1] < minEven) { 154 if ((*widths)[twoK - 1] < minEven) {
155 minEven = (*widths)[twoK - 1]; 155 minEven = (*widths)[twoK - 1];
156 } 156 }
157 if (minEven > 1) { 157 if (minEven > 1) {
158 for (i = 0; i < twoK; i += 2) { 158 for (i = 0; i < twoK; i += 2) {
159 (*widths)[i] += minEven - 1; 159 (*widths)[i] += minEven - 1;
160 (*widths)[i + 1] -= minEven - 1; 160 (*widths)[i + 1] -= minEven - 1;
161 } 161 }
162 } 162 }
163 return widths; 163 return widths;
164 } 164 }
OLDNEW
« no previous file with comments | « xfa/src/fxbarcode/BC_UtilRSS.h ('k') | xfa/src/fxbarcode/BC_Utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698