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

Side by Side Diff: xfa/src/fxbarcode/src/BC_UtilRSS.cpp

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

Powered by Google App Engine
This is Rietveld 408576698