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

Side by Side Diff: xfa/fxbarcode/datamatrix/BC_SymbolInfo.cpp

Issue 2048983002: Get rid of NULLs in xfa/fxbarcode/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: more cleanup Created 4 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 2006 Jeremias Maerki 8 * Copyright 2006 Jeremias Maerki
9 * 9 *
10 * Licensed under the Apache License, Version 2.0 (the "License"); 10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with 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 12 * You may obtain a copy of the License at
13 * 13 *
14 * http://www.apache.org/licenses/LICENSE-2.0 14 * http://www.apache.org/licenses/LICENSE-2.0
15 * 15 *
16 * Unless required by applicable law or agreed to in writing, software 16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS, 17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and 19 * See the License for the specific language governing permissions and
20 * limitations under the License. 20 * limitations under the License.
21 */ 21 */
22 22
23 #include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h"
24
23 #include "xfa/fxbarcode/BC_Dimension.h" 25 #include "xfa/fxbarcode/BC_Dimension.h"
24 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h" 26 #include "xfa/fxbarcode/common/BC_CommonBitMatrix.h"
25 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h" 27 #include "xfa/fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h"
26 #include "xfa/fxbarcode/datamatrix/BC_Encoder.h" 28 #include "xfa/fxbarcode/datamatrix/BC_Encoder.h"
27 #include "xfa/fxbarcode/datamatrix/BC_SymbolInfo.h"
28 #include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h" 29 #include "xfa/fxbarcode/datamatrix/BC_SymbolShapeHint.h"
29 30
30 #define SYMBOLS_COUNT 30 31 namespace {
31 32
32 CBC_SymbolInfo* CBC_SymbolInfo::m_PROD_SYMBOLS[30] = { 33 const size_t kSymbolsCount = 30;
33 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 34
34 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 35 CBC_SymbolInfo* g_symbols[kSymbolsCount] = {
35 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; 36 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
36 CBC_SymbolInfo* CBC_SymbolInfo::m_symbols[30] = { 37 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
37 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 38 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
38 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 39 nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
39 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; 40
41 } // namespace
42
40 void CBC_SymbolInfo::Initialize() { 43 void CBC_SymbolInfo::Initialize() {
41 m_PROD_SYMBOLS[0] = new CBC_SymbolInfo(FALSE, 3, 5, 8, 8, 1); 44 g_symbols[0] = new CBC_SymbolInfo(FALSE, 3, 5, 8, 8, 1);
42 m_PROD_SYMBOLS[1] = new CBC_SymbolInfo(FALSE, 5, 7, 10, 10, 1); 45 g_symbols[1] = new CBC_SymbolInfo(FALSE, 5, 7, 10, 10, 1);
43 m_PROD_SYMBOLS[2] = new CBC_SymbolInfo(TRUE, 5, 7, 16, 6, 1); 46 g_symbols[2] = new CBC_SymbolInfo(TRUE, 5, 7, 16, 6, 1);
44 m_PROD_SYMBOLS[3] = new CBC_SymbolInfo(FALSE, 8, 10, 12, 12, 1); 47 g_symbols[3] = new CBC_SymbolInfo(FALSE, 8, 10, 12, 12, 1);
45 m_PROD_SYMBOLS[4] = new CBC_SymbolInfo(TRUE, 10, 11, 14, 6, 2); 48 g_symbols[4] = new CBC_SymbolInfo(TRUE, 10, 11, 14, 6, 2);
46 m_PROD_SYMBOLS[5] = new CBC_SymbolInfo(FALSE, 12, 12, 14, 14, 1); 49 g_symbols[5] = new CBC_SymbolInfo(FALSE, 12, 12, 14, 14, 1);
47 m_PROD_SYMBOLS[6] = new CBC_SymbolInfo(TRUE, 16, 14, 24, 10, 1); 50 g_symbols[6] = new CBC_SymbolInfo(TRUE, 16, 14, 24, 10, 1);
48 m_PROD_SYMBOLS[7] = new CBC_SymbolInfo(FALSE, 18, 14, 16, 16, 1); 51 g_symbols[7] = new CBC_SymbolInfo(FALSE, 18, 14, 16, 16, 1);
49 m_PROD_SYMBOLS[8] = new CBC_SymbolInfo(FALSE, 22, 18, 18, 18, 1); 52 g_symbols[8] = new CBC_SymbolInfo(FALSE, 22, 18, 18, 18, 1);
50 m_PROD_SYMBOLS[9] = new CBC_SymbolInfo(TRUE, 22, 18, 16, 10, 2); 53 g_symbols[9] = new CBC_SymbolInfo(TRUE, 22, 18, 16, 10, 2);
51 m_PROD_SYMBOLS[10] = new CBC_SymbolInfo(FALSE, 30, 20, 20, 20, 1); 54 g_symbols[10] = new CBC_SymbolInfo(FALSE, 30, 20, 20, 20, 1);
52 m_PROD_SYMBOLS[11] = new CBC_SymbolInfo(TRUE, 32, 24, 16, 14, 2); 55 g_symbols[11] = new CBC_SymbolInfo(TRUE, 32, 24, 16, 14, 2);
53 m_PROD_SYMBOLS[12] = new CBC_SymbolInfo(FALSE, 36, 24, 22, 22, 1); 56 g_symbols[12] = new CBC_SymbolInfo(FALSE, 36, 24, 22, 22, 1);
54 m_PROD_SYMBOLS[13] = new CBC_SymbolInfo(FALSE, 44, 28, 24, 24, 1); 57 g_symbols[13] = new CBC_SymbolInfo(FALSE, 44, 28, 24, 24, 1);
55 m_PROD_SYMBOLS[14] = new CBC_SymbolInfo(TRUE, 49, 28, 22, 14, 2); 58 g_symbols[14] = new CBC_SymbolInfo(TRUE, 49, 28, 22, 14, 2);
56 m_PROD_SYMBOLS[15] = new CBC_SymbolInfo(FALSE, 62, 36, 14, 14, 4); 59 g_symbols[15] = new CBC_SymbolInfo(FALSE, 62, 36, 14, 14, 4);
57 m_PROD_SYMBOLS[16] = new CBC_SymbolInfo(FALSE, 86, 42, 16, 16, 4); 60 g_symbols[16] = new CBC_SymbolInfo(FALSE, 86, 42, 16, 16, 4);
58 m_PROD_SYMBOLS[17] = new CBC_SymbolInfo(FALSE, 114, 48, 18, 18, 4); 61 g_symbols[17] = new CBC_SymbolInfo(FALSE, 114, 48, 18, 18, 4);
59 m_PROD_SYMBOLS[18] = new CBC_SymbolInfo(FALSE, 144, 56, 20, 20, 4); 62 g_symbols[18] = new CBC_SymbolInfo(FALSE, 144, 56, 20, 20, 4);
60 m_PROD_SYMBOLS[19] = new CBC_SymbolInfo(FALSE, 174, 68, 22, 22, 4); 63 g_symbols[19] = new CBC_SymbolInfo(FALSE, 174, 68, 22, 22, 4);
61 m_PROD_SYMBOLS[20] = new CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 42); 64 g_symbols[20] = new CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 42);
62 m_PROD_SYMBOLS[21] = new CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140, 56); 65 g_symbols[21] = new CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140, 56);
63 m_PROD_SYMBOLS[22] = new CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92, 36); 66 g_symbols[22] = new CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92, 36);
64 m_PROD_SYMBOLS[23] = new CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114, 48); 67 g_symbols[23] = new CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114, 48);
65 m_PROD_SYMBOLS[24] = new CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144, 56); 68 g_symbols[24] = new CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144, 56);
66 m_PROD_SYMBOLS[25] = new CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174, 68); 69 g_symbols[25] = new CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174, 68);
67 m_PROD_SYMBOLS[26] = new CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136, 56); 70 g_symbols[26] = new CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136, 56);
68 m_PROD_SYMBOLS[27] = 71 g_symbols[27] = new CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175, 68);
69 new CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175, 68); 72 g_symbols[28] = new CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163, 62);
70 m_PROD_SYMBOLS[28] = 73 g_symbols[29] = new CBC_DataMatrixSymbolInfo144();
71 new CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163, 62); 74 }
72 m_PROD_SYMBOLS[29] = new CBC_DataMatrixSymbolInfo144(); 75
73 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { 76 void CBC_SymbolInfo::Finalize() {
74 m_symbols[i] = m_PROD_SYMBOLS[i]; 77 for (size_t i = 0; i < kSymbolsCount; i++) {
78 delete g_symbols[i];
79 g_symbols[i] = nullptr;
75 } 80 }
76 } 81 }
77 void CBC_SymbolInfo::Finalize() { 82
78 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) {
79 delete m_PROD_SYMBOLS[i];
80 m_PROD_SYMBOLS[i] = NULL;
81 m_symbols[i] = NULL;
82 }
83 }
84 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, 83 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular,
85 int32_t dataCapacity, 84 int32_t dataCapacity,
86 int32_t errorCodewords, 85 int32_t errorCodewords,
87 int32_t matrixWidth, 86 int32_t matrixWidth,
88 int32_t matrixHeight, 87 int32_t matrixHeight,
89 int32_t dataRegions) { 88 int32_t dataRegions) {
90 m_rectangular = rectangular; 89 m_rectangular = rectangular;
91 m_dataCapacity = dataCapacity; 90 m_dataCapacity = dataCapacity;
92 m_errorCodewords = errorCodewords; 91 m_errorCodewords = errorCodewords;
93 m_matrixWidth = matrixWidth; 92 m_matrixWidth = matrixWidth;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 FX_BOOL allowRectangular, 126 FX_BOOL allowRectangular,
128 FX_BOOL fail, 127 FX_BOOL fail,
129 int32_t& e) { 128 int32_t& e) {
130 SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; 129 SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE;
131 return lookup(dataCodewords, shape, fail, e); 130 return lookup(dataCodewords, shape, fail, e);
132 } 131 }
133 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, 132 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords,
134 SymbolShapeHint shape, 133 SymbolShapeHint shape,
135 FX_BOOL fail, 134 FX_BOOL fail,
136 int32_t& e) { 135 int32_t& e) {
137 return lookup(dataCodewords, shape, NULL, NULL, fail, e); 136 return lookup(dataCodewords, shape, nullptr, nullptr, fail, e);
138 } 137 }
139 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, 138 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords,
140 SymbolShapeHint shape, 139 SymbolShapeHint shape,
141 CBC_Dimension* minSize, 140 CBC_Dimension* minSize,
142 CBC_Dimension* maxSize, 141 CBC_Dimension* maxSize,
143 FX_BOOL fail, 142 FX_BOOL fail,
144 int32_t& e) { 143 int32_t& e) {
145 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { 144 for (size_t i = 0; i < kSymbolsCount; i++) {
146 CBC_SymbolInfo* symbol = m_symbols[i]; 145 CBC_SymbolInfo* symbol = g_symbols[i];
147 if (shape == FORCE_SQUARE && symbol->m_rectangular) { 146 if (shape == FORCE_SQUARE && symbol->m_rectangular) {
148 continue; 147 continue;
149 } 148 }
150 if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) { 149 if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) {
151 continue; 150 continue;
152 } 151 }
153 if (minSize && (symbol->getSymbolWidth(e) < minSize->getWidth() || 152 if (minSize && (symbol->getSymbolWidth(e) < minSize->getWidth() ||
154 symbol->getSymbolHeight(e) < minSize->getHeight())) { 153 symbol->getSymbolHeight(e) < minSize->getHeight())) {
155 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 154 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
156 continue; 155 continue;
157 } 156 }
158 if (maxSize && (symbol->getSymbolWidth(e) > maxSize->getWidth() || 157 if (maxSize && (symbol->getSymbolWidth(e) > maxSize->getWidth() ||
159 symbol->getSymbolHeight(e) > maxSize->getHeight())) { 158 symbol->getSymbolHeight(e) > maxSize->getHeight())) {
160 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 159 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
161 continue; 160 continue;
162 } 161 }
163 if (dataCodewords <= symbol->m_dataCapacity) { 162 if (dataCodewords <= symbol->m_dataCapacity) {
164 return symbol; 163 return symbol;
165 } 164 }
166 } 165 }
167 if (fail) { 166 if (fail) {
168 e = BCExceptionIllegalDataCodewords; 167 e = BCExceptionIllegalDataCodewords;
169 return NULL; 168 return nullptr;
170 } 169 }
dsinclair 2016/06/09 18:40:06 nit: returns nullptr in both cases, remove?
Lei Zhang 2016/06/09 22:31:47 Done.
171 return NULL; 170 return nullptr;
172 } 171 }
173 int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) { 172 int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t& e) {
174 switch (m_dataRegions) { 173 switch (m_dataRegions) {
175 case 1: 174 case 1:
176 return 1; 175 return 1;
177 case 2: 176 case 2:
178 return 2; 177 return 2;
179 case 4: 178 case 4:
180 return 2; 179 return 2;
181 case 16: 180 case 16:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 } 220 }
222 int32_t CBC_SymbolInfo::getInterleavedBlockCount() { 221 int32_t CBC_SymbolInfo::getInterleavedBlockCount() {
223 return m_dataCapacity / m_rsBlockData; 222 return m_dataCapacity / m_rsBlockData;
224 } 223 }
225 int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) { 224 int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) {
226 return m_rsBlockData; 225 return m_rsBlockData;
227 } 226 }
228 int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) { 227 int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) {
229 return m_rsBlockError; 228 return m_rsBlockError;
230 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698