OLD | NEW |
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"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 m_PROD_SYMBOLS[20] = FX_NEW CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 4
2); | 55 m_PROD_SYMBOLS[20] = FX_NEW CBC_SymbolInfo(FALSE, 204, 84, 24, 24, 4, 102, 4
2); |
56 m_PROD_SYMBOLS[21] = FX_NEW CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140,
56); | 56 m_PROD_SYMBOLS[21] = FX_NEW CBC_SymbolInfo(FALSE, 280, 112, 14, 14, 16, 140,
56); |
57 m_PROD_SYMBOLS[22] = FX_NEW CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92,
36); | 57 m_PROD_SYMBOLS[22] = FX_NEW CBC_SymbolInfo(FALSE, 368, 144, 16, 16, 16, 92,
36); |
58 m_PROD_SYMBOLS[23] = FX_NEW CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114,
48); | 58 m_PROD_SYMBOLS[23] = FX_NEW CBC_SymbolInfo(FALSE, 456, 192, 18, 18, 16, 114,
48); |
59 m_PROD_SYMBOLS[24] = FX_NEW CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144,
56); | 59 m_PROD_SYMBOLS[24] = FX_NEW CBC_SymbolInfo(FALSE, 576, 224, 20, 20, 16, 144,
56); |
60 m_PROD_SYMBOLS[25] = FX_NEW CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174,
68); | 60 m_PROD_SYMBOLS[25] = FX_NEW CBC_SymbolInfo(FALSE, 696, 272, 22, 22, 16, 174,
68); |
61 m_PROD_SYMBOLS[26] = FX_NEW CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136,
56); | 61 m_PROD_SYMBOLS[26] = FX_NEW CBC_SymbolInfo(FALSE, 816, 336, 24, 24, 16, 136,
56); |
62 m_PROD_SYMBOLS[27] = FX_NEW CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175
, 68); | 62 m_PROD_SYMBOLS[27] = FX_NEW CBC_SymbolInfo(FALSE, 1050, 408, 18, 18, 36, 175
, 68); |
63 m_PROD_SYMBOLS[28] = FX_NEW CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163
, 62); | 63 m_PROD_SYMBOLS[28] = FX_NEW CBC_SymbolInfo(FALSE, 1304, 496, 20, 20, 36, 163
, 62); |
64 m_PROD_SYMBOLS[29] = FX_NEW CBC_DataMatrixSymbolInfo144(); | 64 m_PROD_SYMBOLS[29] = FX_NEW CBC_DataMatrixSymbolInfo144(); |
65 for (FX_INT32 i = 0; i < SYMBOLS_COUNT; i++) { | 65 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { |
66 m_symbols[i] = m_PROD_SYMBOLS[i]; | 66 m_symbols[i] = m_PROD_SYMBOLS[i]; |
67 } | 67 } |
68 } | 68 } |
69 void CBC_SymbolInfo::Finalize() | 69 void CBC_SymbolInfo::Finalize() |
70 { | 70 { |
71 for (FX_INT32 i = 0; i < SYMBOLS_COUNT; i++) { | 71 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { |
72 delete m_PROD_SYMBOLS[i]; | 72 delete m_PROD_SYMBOLS[i]; |
73 m_PROD_SYMBOLS[i] = NULL; | 73 m_PROD_SYMBOLS[i] = NULL; |
74 m_symbols[i] = NULL; | 74 m_symbols[i] = NULL; |
75 } | 75 } |
76 } | 76 } |
77 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, FX_INT32 dataCapacity, FX_IN
T32 errorCodewords, FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 dataRe
gions) | 77 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, int32_t dataCapacity, int32_
t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, int32_t dataRegions
) |
78 { | 78 { |
79 m_rectangular = rectangular; | 79 m_rectangular = rectangular; |
80 m_dataCapacity = dataCapacity; | 80 m_dataCapacity = dataCapacity; |
81 m_errorCodewords = errorCodewords; | 81 m_errorCodewords = errorCodewords; |
82 m_matrixWidth = matrixWidth; | 82 m_matrixWidth = matrixWidth; |
83 m_matrixHeight = matrixHeight; | 83 m_matrixHeight = matrixHeight; |
84 m_dataRegions = dataRegions; | 84 m_dataRegions = dataRegions; |
85 m_rsBlockData = dataCapacity; | 85 m_rsBlockData = dataCapacity; |
86 m_rsBlockError = errorCodewords; | 86 m_rsBlockError = errorCodewords; |
87 } | 87 } |
88 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, FX_INT32 dataCapacity, FX_IN
T32 errorCodewords, FX_INT32 matrixWidth, FX_INT32 matrixHeight, FX_INT32 dataRe
gions, | 88 CBC_SymbolInfo::CBC_SymbolInfo(FX_BOOL rectangular, int32_t dataCapacity, int32_
t errorCodewords, int32_t matrixWidth, int32_t matrixHeight, int32_t dataRegions
, |
89 FX_INT32 rsBlockData, FX_INT32 rsBlockError) | 89 int32_t rsBlockData, int32_t rsBlockError) |
90 { | 90 { |
91 m_rectangular = rectangular; | 91 m_rectangular = rectangular; |
92 m_dataCapacity = dataCapacity; | 92 m_dataCapacity = dataCapacity; |
93 m_errorCodewords = errorCodewords; | 93 m_errorCodewords = errorCodewords; |
94 m_matrixWidth = matrixWidth; | 94 m_matrixWidth = matrixWidth; |
95 m_matrixHeight = matrixHeight; | 95 m_matrixHeight = matrixHeight; |
96 m_dataRegions = dataRegions; | 96 m_dataRegions = dataRegions; |
97 m_rsBlockData = rsBlockData; | 97 m_rsBlockData = rsBlockData; |
98 m_rsBlockError = rsBlockError; | 98 m_rsBlockError = rsBlockError; |
99 } | 99 } |
100 CBC_SymbolInfo::~CBC_SymbolInfo() | 100 CBC_SymbolInfo::~CBC_SymbolInfo() |
101 { | 101 { |
102 } | 102 } |
103 | 103 |
104 CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, FX_INT32 &e) | 104 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, int32_t &e) |
105 { | 105 { |
106 return lookup(dataCodewords, FORCE_NONE, TRUE, e); | 106 return lookup(dataCodewords, FORCE_NONE, TRUE, e); |
107 } | 107 } |
108 CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint s
hape, FX_INT32 &e) | 108 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint sh
ape, int32_t &e) |
109 { | 109 { |
110 return lookup(dataCodewords, shape, TRUE, e); | 110 return lookup(dataCodewords, shape, TRUE, e); |
111 } | 111 } |
112 CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, FX_BOOL allowRect
angular, FX_BOOL fail, FX_INT32 &e) | 112 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, FX_BOOL allowRecta
ngular, FX_BOOL fail, int32_t &e) |
113 { | 113 { |
114 SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; | 114 SymbolShapeHint shape = allowRectangular ? FORCE_NONE : FORCE_SQUARE; |
115 return lookup(dataCodewords, shape, fail, e); | 115 return lookup(dataCodewords, shape, fail, e); |
116 } | 116 } |
117 CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint s
hape, FX_BOOL fail, FX_INT32 &e) | 117 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint sh
ape, FX_BOOL fail, int32_t &e) |
118 { | 118 { |
119 return lookup(dataCodewords, shape, NULL, NULL, fail, e); | 119 return lookup(dataCodewords, shape, NULL, NULL, fail, e); |
120 } | 120 } |
121 CBC_SymbolInfo* CBC_SymbolInfo::lookup(FX_INT32 dataCodewords, SymbolShapeHint s
hape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_BOOL fail, FX_INT32 &e) | 121 CBC_SymbolInfo* CBC_SymbolInfo::lookup(int32_t dataCodewords, SymbolShapeHint sh
ape, CBC_Dimension* minSize, CBC_Dimension* maxSize, FX_BOOL fail, int32_t &e) |
122 { | 122 { |
123 for (FX_INT32 i = 0; i < SYMBOLS_COUNT; i++) { | 123 for (int32_t i = 0; i < SYMBOLS_COUNT; i++) { |
124 CBC_SymbolInfo* symbol = m_symbols[i]; | 124 CBC_SymbolInfo* symbol = m_symbols[i]; |
125 if (shape == FORCE_SQUARE && symbol->m_rectangular) { | 125 if (shape == FORCE_SQUARE && symbol->m_rectangular) { |
126 continue; | 126 continue; |
127 } | 127 } |
128 if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) { | 128 if (shape == FORCE_RECTANGLE && !symbol->m_rectangular) { |
129 continue; | 129 continue; |
130 } | 130 } |
131 if (minSize != NULL && (symbol->getSymbolWidth(e) < minSize->getWidth()
|| symbol->getSymbolHeight(e) < minSize->getHeight())) { | 131 if (minSize != NULL && (symbol->getSymbolWidth(e) < minSize->getWidth()
|| symbol->getSymbolHeight(e) < minSize->getHeight())) { |
132 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 132 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
133 continue; | 133 continue; |
134 } | 134 } |
135 if (maxSize != NULL && (symbol->getSymbolWidth(e) > maxSize->getWidth()
|| symbol->getSymbolHeight(e) > maxSize->getHeight())) { | 135 if (maxSize != NULL && (symbol->getSymbolWidth(e) > maxSize->getWidth()
|| symbol->getSymbolHeight(e) > maxSize->getHeight())) { |
136 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 136 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); |
137 continue; | 137 continue; |
138 } | 138 } |
139 if (dataCodewords <= symbol->m_dataCapacity) { | 139 if (dataCodewords <= symbol->m_dataCapacity) { |
140 return symbol; | 140 return symbol; |
141 } | 141 } |
142 } | 142 } |
143 if (fail) { | 143 if (fail) { |
144 e = BCExceptionIllegalDataCodewords; | 144 e = BCExceptionIllegalDataCodewords; |
145 return NULL; | 145 return NULL; |
146 } | 146 } |
147 return NULL; | 147 return NULL; |
148 } | 148 } |
149 FX_INT32 CBC_SymbolInfo::getHorizontalDataRegions(FX_INT32 &e) | 149 int32_t CBC_SymbolInfo::getHorizontalDataRegions(int32_t &e) |
150 { | 150 { |
151 switch (m_dataRegions) { | 151 switch (m_dataRegions) { |
152 case 1: | 152 case 1: |
153 return 1; | 153 return 1; |
154 case 2: | 154 case 2: |
155 return 2; | 155 return 2; |
156 case 4: | 156 case 4: |
157 return 2; | 157 return 2; |
158 case 16: | 158 case 16: |
159 return 4; | 159 return 4; |
160 case 36: | 160 case 36: |
161 return 6; | 161 return 6; |
162 default: | 162 default: |
163 e = BCExceptionCannotHandleThisNumberOfDataRegions; | 163 e = BCExceptionCannotHandleThisNumberOfDataRegions; |
164 return 0; | 164 return 0; |
165 } | 165 } |
166 } | 166 } |
167 FX_INT32 CBC_SymbolInfo::getVerticalDataRegions(FX_INT32 &e) | 167 int32_t CBC_SymbolInfo::getVerticalDataRegions(int32_t &e) |
168 { | 168 { |
169 switch (m_dataRegions) { | 169 switch (m_dataRegions) { |
170 case 1: | 170 case 1: |
171 return 1; | 171 return 1; |
172 case 2: | 172 case 2: |
173 return 1; | 173 return 1; |
174 case 4: | 174 case 4: |
175 return 2; | 175 return 2; |
176 case 16: | 176 case 16: |
177 return 4; | 177 return 4; |
178 case 36: | 178 case 36: |
179 return 6; | 179 return 6; |
180 default: | 180 default: |
181 e = BCExceptionCannotHandleThisNumberOfDataRegions; | 181 e = BCExceptionCannotHandleThisNumberOfDataRegions; |
182 return 0; | 182 return 0; |
183 } | 183 } |
184 } | 184 } |
185 FX_INT32 CBC_SymbolInfo::getSymbolDataWidth(FX_INT32 &e) | 185 int32_t CBC_SymbolInfo::getSymbolDataWidth(int32_t &e) |
186 { | 186 { |
187 return getHorizontalDataRegions(e) * m_matrixWidth; | 187 return getHorizontalDataRegions(e) * m_matrixWidth; |
188 } | 188 } |
189 FX_INT32 CBC_SymbolInfo::getSymbolDataHeight(FX_INT32 &e) | 189 int32_t CBC_SymbolInfo::getSymbolDataHeight(int32_t &e) |
190 { | 190 { |
191 return getVerticalDataRegions(e) * m_matrixHeight; | 191 return getVerticalDataRegions(e) * m_matrixHeight; |
192 } | 192 } |
193 FX_INT32 CBC_SymbolInfo::getSymbolWidth(FX_INT32 &e) | 193 int32_t CBC_SymbolInfo::getSymbolWidth(int32_t &e) |
194 { | 194 { |
195 return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2); | 195 return getSymbolDataWidth(e) + (getHorizontalDataRegions(e) * 2); |
196 } | 196 } |
197 FX_INT32 CBC_SymbolInfo::getSymbolHeight(FX_INT32 &e) | 197 int32_t CBC_SymbolInfo::getSymbolHeight(int32_t &e) |
198 { | 198 { |
199 return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2); | 199 return getSymbolDataHeight(e) + (getVerticalDataRegions(e) * 2); |
200 } | 200 } |
201 FX_INT32 CBC_SymbolInfo::getCodewordCount() | 201 int32_t CBC_SymbolInfo::getCodewordCount() |
202 { | 202 { |
203 return m_dataCapacity + m_errorCodewords; | 203 return m_dataCapacity + m_errorCodewords; |
204 } | 204 } |
205 FX_INT32 CBC_SymbolInfo::getInterleavedBlockCount() | 205 int32_t CBC_SymbolInfo::getInterleavedBlockCount() |
206 { | 206 { |
207 return m_dataCapacity / m_rsBlockData; | 207 return m_dataCapacity / m_rsBlockData; |
208 } | 208 } |
209 FX_INT32 CBC_SymbolInfo::getDataLengthForInterleavedBlock(FX_INT32 index) | 209 int32_t CBC_SymbolInfo::getDataLengthForInterleavedBlock(int32_t index) |
210 { | 210 { |
211 return m_rsBlockData; | 211 return m_rsBlockData; |
212 } | 212 } |
213 FX_INT32 CBC_SymbolInfo::getErrorLengthForInterleavedBlock(FX_INT32 index) | 213 int32_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock(int32_t index) |
214 { | 214 { |
215 return m_rsBlockError; | 215 return m_rsBlockError; |
216 } | 216 } |
217 CFX_WideString CBC_SymbolInfo::toString(FX_INT32 &e) | 217 CFX_WideString CBC_SymbolInfo::toString(int32_t &e) |
218 { | 218 { |
219 CFX_WideString sb; | 219 CFX_WideString sb; |
220 sb += (FX_LPWSTR)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:"); | 220 sb += (FX_LPWSTR)(m_rectangular ? "Rectangular Symbol:" : "Square Symbol:"); |
221 sb += (FX_LPWSTR)" data region "; | 221 sb += (FX_LPWSTR)" data region "; |
222 sb += m_matrixWidth; | 222 sb += m_matrixWidth; |
223 sb += (FX_WCHAR)'x'; | 223 sb += (FX_WCHAR)'x'; |
224 sb += m_matrixHeight; | 224 sb += m_matrixHeight; |
225 sb += (FX_LPWSTR)", symbol size "; | 225 sb += (FX_LPWSTR)", symbol size "; |
226 sb += getSymbolWidth(e); | 226 sb += getSymbolWidth(e); |
227 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); | 227 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); |
228 sb += (FX_WCHAR)'x'; | 228 sb += (FX_WCHAR)'x'; |
229 sb += getSymbolHeight(e); | 229 sb += getSymbolHeight(e); |
230 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); | 230 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); |
231 sb += (FX_LPWSTR)", symbol data size "; | 231 sb += (FX_LPWSTR)", symbol data size "; |
232 sb += getSymbolDataWidth(e); | 232 sb += getSymbolDataWidth(e); |
233 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); | 233 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); |
234 sb += (FX_WCHAR)'x'; | 234 sb += (FX_WCHAR)'x'; |
235 sb += getSymbolDataHeight(e); | 235 sb += getSymbolDataHeight(e); |
236 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); | 236 BC_EXCEPTION_CHECK_ReturnValue(e, (FX_LPWSTR)""); |
237 sb += (FX_LPWSTR)", codewords "; | 237 sb += (FX_LPWSTR)", codewords "; |
238 sb += m_dataCapacity; | 238 sb += m_dataCapacity; |
239 sb += (FX_WCHAR)'+'; | 239 sb += (FX_WCHAR)'+'; |
240 sb += m_errorCodewords; | 240 sb += m_errorCodewords; |
241 return sb; | 241 return sb; |
242 } | 242 } |
OLD | NEW |