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 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 18 matching lines...) Expand all Loading... |
29 #include "BC_PDF417DecodedBitStreamParser.h" | 29 #include "BC_PDF417DecodedBitStreamParser.h" |
30 #define TEXT_COMPACTION_MODE_LATCH 900 | 30 #define TEXT_COMPACTION_MODE_LATCH 900 |
31 #define BYTE_COMPACTION_MODE_LATCH 901 | 31 #define BYTE_COMPACTION_MODE_LATCH 901 |
32 #define NUMERIC_COMPACTION_MODE_LATCH 902 | 32 #define NUMERIC_COMPACTION_MODE_LATCH 902 |
33 #define BYTE_COMPACTION_MODE_LATCH_6 924 | 33 #define BYTE_COMPACTION_MODE_LATCH_6 924 |
34 #define BEGIN_MACRO_PDF417_CONTROL_BLOCK 928 | 34 #define BEGIN_MACRO_PDF417_CONTROL_BLOCK 928 |
35 #define BEGIN_MACRO_PDF417_OPTIONAL_FIELD 923 | 35 #define BEGIN_MACRO_PDF417_OPTIONAL_FIELD 923 |
36 #define MACRO_PDF417_TERMINATOR 922 | 36 #define MACRO_PDF417_TERMINATOR 922 |
37 #define MODE_SHIFT_TO_BYTE_COMPACTION_MODE 913 | 37 #define MODE_SHIFT_TO_BYTE_COMPACTION_MODE 913 |
38 | 38 |
39 FX_INT32 CBC_DecodedBitStreamPaser::MAX_NUMERIC_CODEWORDS = 15; | 39 int32_t CBC_DecodedBitStreamPaser::MAX_NUMERIC_CODEWORDS = 15; |
40 FX_INT32 CBC_DecodedBitStreamPaser::NUMBER_OF_SEQUENCE_CODEWORDS = 2; | 40 int32_t CBC_DecodedBitStreamPaser::NUMBER_OF_SEQUENCE_CODEWORDS = 2; |
41 FX_INT32 CBC_DecodedBitStreamPaser::PL = 25; | 41 int32_t CBC_DecodedBitStreamPaser::PL = 25; |
42 FX_INT32 CBC_DecodedBitStreamPaser::LL = 27; | 42 int32_t CBC_DecodedBitStreamPaser::LL = 27; |
43 FX_INT32 CBC_DecodedBitStreamPaser::AS = 27; | 43 int32_t CBC_DecodedBitStreamPaser::AS = 27; |
44 FX_INT32 CBC_DecodedBitStreamPaser::ML = 28; | 44 int32_t CBC_DecodedBitStreamPaser::ML = 28; |
45 FX_INT32 CBC_DecodedBitStreamPaser::AL = 28; | 45 int32_t CBC_DecodedBitStreamPaser::AL = 28; |
46 FX_INT32 CBC_DecodedBitStreamPaser::PS = 29; | 46 int32_t CBC_DecodedBitStreamPaser::PS = 29; |
47 FX_INT32 CBC_DecodedBitStreamPaser::PAL = 29; | 47 int32_t CBC_DecodedBitStreamPaser::PAL = 29; |
48 FX_CHAR CBC_DecodedBitStreamPaser::PUNCT_CHARS[29] = { | 48 FX_CHAR CBC_DecodedBitStreamPaser::PUNCT_CHARS[29] = { |
49 ';', '<', '>', '@', '[', '\\', '}', '_', '`', '~', '!', | 49 ';', '<', '>', '@', '[', '\\', '}', '_', '`', '~', '!', |
50 '\r', '\t', ',', ':', '\n', '-', '.', '$', '/', '"', '|', '*', | 50 '\r', '\t', ',', ':', '\n', '-', '.', '$', '/', '"', '|', '*', |
51 '(', ')', '?', '{', '}', '\'' | 51 '(', ')', '?', '{', '}', '\'' |
52 }; | 52 }; |
53 FX_CHAR CBC_DecodedBitStreamPaser::MIXED_CHARS[30] = { | 53 FX_CHAR CBC_DecodedBitStreamPaser::MIXED_CHARS[30] = { |
54 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '&', | 54 '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '&', |
55 '\r', '\t', ',', ':', '#', '-', '.', '$', '/', '+', '%', '*', | 55 '\r', '\t', ',', ':', '#', '-', '.', '$', '/', '+', '%', '*', |
56 '=', '^' | 56 '=', '^' |
57 }; | 57 }; |
58 void CBC_DecodedBitStreamPaser::Initialize() | 58 void CBC_DecodedBitStreamPaser::Initialize() |
59 { | 59 { |
60 } | 60 } |
61 void CBC_DecodedBitStreamPaser::Finalize() | 61 void CBC_DecodedBitStreamPaser::Finalize() |
62 { | 62 { |
63 } | 63 } |
64 CBC_DecodedBitStreamPaser::CBC_DecodedBitStreamPaser() | 64 CBC_DecodedBitStreamPaser::CBC_DecodedBitStreamPaser() |
65 { | 65 { |
66 } | 66 } |
67 CBC_DecodedBitStreamPaser::~CBC_DecodedBitStreamPaser() | 67 CBC_DecodedBitStreamPaser::~CBC_DecodedBitStreamPaser() |
68 { | 68 { |
69 } | 69 } |
70 CBC_CommonDecoderResult* CBC_DecodedBitStreamPaser::decode(CFX_Int32Array &codew
ords, CFX_ByteString ecLevel, FX_INT32 &e) | 70 CBC_CommonDecoderResult* CBC_DecodedBitStreamPaser::decode(CFX_Int32Array &codew
ords, CFX_ByteString ecLevel, int32_t &e) |
71 { | 71 { |
72 CFX_ByteString result; | 72 CFX_ByteString result; |
73 FX_INT32 codeIndex = 1; | 73 int32_t codeIndex = 1; |
74 FX_INT32 code = codewords.GetAt(codeIndex); | 74 int32_t code = codewords.GetAt(codeIndex); |
75 codeIndex++; | 75 codeIndex++; |
76 CBC_PDF417ResultMetadata* resultMetadata = FX_NEW CBC_PDF417ResultMetadata; | 76 CBC_PDF417ResultMetadata* resultMetadata = FX_NEW CBC_PDF417ResultMetadata; |
77 while (codeIndex < codewords[0]) { | 77 while (codeIndex < codewords[0]) { |
78 switch (code) { | 78 switch (code) { |
79 case TEXT_COMPACTION_MODE_LATCH: | 79 case TEXT_COMPACTION_MODE_LATCH: |
80 codeIndex = textCompaction(codewords, codeIndex, result); | 80 codeIndex = textCompaction(codewords, codeIndex, result); |
81 break; | 81 break; |
82 case BYTE_COMPACTION_MODE_LATCH: | 82 case BYTE_COMPACTION_MODE_LATCH: |
83 codeIndex = byteCompaction(code, codewords, codeIndex, result); | 83 codeIndex = byteCompaction(code, codewords, codeIndex, result); |
84 break; | 84 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 CFX_PtrArray byteSegments; | 121 CFX_PtrArray byteSegments; |
122 CBC_CommonDecoderResult *tempCd = FX_NEW CBC_CommonDecoderResult(); | 122 CBC_CommonDecoderResult *tempCd = FX_NEW CBC_CommonDecoderResult(); |
123 tempCd->Init(rawBytes, result, byteSegments, ecLevel, e); | 123 tempCd->Init(rawBytes, result, byteSegments, ecLevel, e); |
124 if (e != BCExceptionNO) { | 124 if (e != BCExceptionNO) { |
125 delete resultMetadata; | 125 delete resultMetadata; |
126 return NULL; | 126 return NULL; |
127 } | 127 } |
128 tempCd->setOther(resultMetadata); | 128 tempCd->setOther(resultMetadata); |
129 return tempCd; | 129 return tempCd; |
130 } | 130 } |
131 FX_INT32 CBC_DecodedBitStreamPaser::decodeMacroBlock(CFX_Int32Array &codewords,
FX_INT32 codeIndex, CBC_PDF417ResultMetadata* resultMetadata, FX_INT32 &e) | 131 int32_t CBC_DecodedBitStreamPaser::decodeMacroBlock(CFX_Int32Array &codewords, i
nt32_t codeIndex, CBC_PDF417ResultMetadata* resultMetadata, int32_t &e) |
132 { | 132 { |
133 if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) { | 133 if (codeIndex + NUMBER_OF_SEQUENCE_CODEWORDS > codewords[0]) { |
134 e = BCExceptionFormatInstance; | 134 e = BCExceptionFormatInstance; |
135 return -1; | 135 return -1; |
136 } | 136 } |
137 CFX_Int32Array segmentIndexArray; | 137 CFX_Int32Array segmentIndexArray; |
138 segmentIndexArray.SetSize(NUMBER_OF_SEQUENCE_CODEWORDS); | 138 segmentIndexArray.SetSize(NUMBER_OF_SEQUENCE_CODEWORDS); |
139 for (FX_INT32 i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) { | 139 for (int32_t i = 0; i < NUMBER_OF_SEQUENCE_CODEWORDS; i++, codeIndex++) { |
140 segmentIndexArray.SetAt(i, codewords[codeIndex]); | 140 segmentIndexArray.SetAt(i, codewords[codeIndex]); |
141 } | 141 } |
142 CFX_ByteString str = decodeBase900toBase10(segmentIndexArray, NUMBER_OF_SEQU
ENCE_CODEWORDS, e); | 142 CFX_ByteString str = decodeBase900toBase10(segmentIndexArray, NUMBER_OF_SEQU
ENCE_CODEWORDS, e); |
143 BC_EXCEPTION_CHECK_ReturnValue(e, -1); | 143 BC_EXCEPTION_CHECK_ReturnValue(e, -1); |
144 resultMetadata->setSegmentIndex(atoi(str.GetBuffer(str.GetLength()))); | 144 resultMetadata->setSegmentIndex(atoi(str.GetBuffer(str.GetLength()))); |
145 CFX_ByteString fileId; | 145 CFX_ByteString fileId; |
146 codeIndex = textCompaction(codewords, codeIndex, fileId); | 146 codeIndex = textCompaction(codewords, codeIndex, fileId); |
147 resultMetadata->setFileId(fileId); | 147 resultMetadata->setFileId(fileId); |
148 if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) { | 148 if (codewords[codeIndex] == BEGIN_MACRO_PDF417_OPTIONAL_FIELD) { |
149 codeIndex++; | 149 codeIndex++; |
150 CFX_Int32Array additionalOptionCodeWords; | 150 CFX_Int32Array additionalOptionCodeWords; |
151 additionalOptionCodeWords.SetSize(codewords[0] - codeIndex); | 151 additionalOptionCodeWords.SetSize(codewords[0] - codeIndex); |
152 FX_INT32 additionalOptionCodeWordsIndex = 0; | 152 int32_t additionalOptionCodeWordsIndex = 0; |
153 FX_BOOL end = FALSE; | 153 FX_BOOL end = FALSE; |
154 while ((codeIndex < codewords[0]) && !end) { | 154 while ((codeIndex < codewords[0]) && !end) { |
155 FX_INT32 code = codewords[codeIndex++]; | 155 int32_t code = codewords[codeIndex++]; |
156 if (code < TEXT_COMPACTION_MODE_LATCH) { | 156 if (code < TEXT_COMPACTION_MODE_LATCH) { |
157 additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = co
de; | 157 additionalOptionCodeWords[additionalOptionCodeWordsIndex++] = co
de; |
158 } else { | 158 } else { |
159 switch (code) { | 159 switch (code) { |
160 case MACRO_PDF417_TERMINATOR: | 160 case MACRO_PDF417_TERMINATOR: |
161 resultMetadata->setLastSegment(TRUE); | 161 resultMetadata->setLastSegment(TRUE); |
162 codeIndex++; | 162 codeIndex++; |
163 end = TRUE; | 163 end = TRUE; |
164 break; | 164 break; |
165 default: | 165 default: |
166 e = BCExceptionFormatInstance; | 166 e = BCExceptionFormatInstance; |
167 return -1; | 167 return -1; |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
171 CFX_Int32Array array; | 171 CFX_Int32Array array; |
172 array.SetSize(additionalOptionCodeWordsIndex); | 172 array.SetSize(additionalOptionCodeWordsIndex); |
173 array.Copy(additionalOptionCodeWords); | 173 array.Copy(additionalOptionCodeWords); |
174 resultMetadata->setOptionalData(array); | 174 resultMetadata->setOptionalData(array); |
175 } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) { | 175 } else if (codewords[codeIndex] == MACRO_PDF417_TERMINATOR) { |
176 resultMetadata->setLastSegment(TRUE); | 176 resultMetadata->setLastSegment(TRUE); |
177 codeIndex++; | 177 codeIndex++; |
178 } | 178 } |
179 return codeIndex; | 179 return codeIndex; |
180 } | 180 } |
181 FX_INT32 CBC_DecodedBitStreamPaser::textCompaction(CFX_Int32Array &codewords, FX
_INT32 codeIndex, CFX_ByteString &result) | 181 int32_t CBC_DecodedBitStreamPaser::textCompaction(CFX_Int32Array &codewords, int
32_t codeIndex, CFX_ByteString &result) |
182 { | 182 { |
183 CFX_Int32Array textCompactionData; | 183 CFX_Int32Array textCompactionData; |
184 textCompactionData.SetSize((codewords[0] - codeIndex) << 1); | 184 textCompactionData.SetSize((codewords[0] - codeIndex) << 1); |
185 CFX_Int32Array byteCompactionData; | 185 CFX_Int32Array byteCompactionData; |
186 byteCompactionData.SetSize((codewords[0] - codeIndex) << 1); | 186 byteCompactionData.SetSize((codewords[0] - codeIndex) << 1); |
187 FX_INT32 index = 0; | 187 int32_t index = 0; |
188 FX_BOOL end = FALSE; | 188 FX_BOOL end = FALSE; |
189 while ((codeIndex < codewords[0]) && !end) { | 189 while ((codeIndex < codewords[0]) && !end) { |
190 FX_INT32 code = codewords[codeIndex++]; | 190 int32_t code = codewords[codeIndex++]; |
191 if (code < TEXT_COMPACTION_MODE_LATCH) { | 191 if (code < TEXT_COMPACTION_MODE_LATCH) { |
192 textCompactionData[index] = code / 30; | 192 textCompactionData[index] = code / 30; |
193 textCompactionData[index + 1] = code % 30; | 193 textCompactionData[index + 1] = code % 30; |
194 index += 2; | 194 index += 2; |
195 } else { | 195 } else { |
196 switch (code) { | 196 switch (code) { |
197 case TEXT_COMPACTION_MODE_LATCH: | 197 case TEXT_COMPACTION_MODE_LATCH: |
198 textCompactionData[index++] = TEXT_COMPACTION_MODE_LATCH; | 198 textCompactionData[index++] = TEXT_COMPACTION_MODE_LATCH; |
199 break; | 199 break; |
200 case BYTE_COMPACTION_MODE_LATCH: | 200 case BYTE_COMPACTION_MODE_LATCH: |
(...skipping 25 matching lines...) Expand all Loading... |
226 case BYTE_COMPACTION_MODE_LATCH_6: | 226 case BYTE_COMPACTION_MODE_LATCH_6: |
227 codeIndex--; | 227 codeIndex--; |
228 end = TRUE; | 228 end = TRUE; |
229 break; | 229 break; |
230 } | 230 } |
231 } | 231 } |
232 } | 232 } |
233 decodeTextCompaction(textCompactionData, byteCompactionData, index, result); | 233 decodeTextCompaction(textCompactionData, byteCompactionData, index, result); |
234 return codeIndex; | 234 return codeIndex; |
235 } | 235 } |
236 void CBC_DecodedBitStreamPaser::decodeTextCompaction(CFX_Int32Array &textCompact
ionData, CFX_Int32Array &byteCompactionData, FX_INT32 length, CFX_ByteString &re
sult) | 236 void CBC_DecodedBitStreamPaser::decodeTextCompaction(CFX_Int32Array &textCompact
ionData, CFX_Int32Array &byteCompactionData, int32_t length, CFX_ByteString &res
ult) |
237 { | 237 { |
238 Mode subMode = ALPHA; | 238 Mode subMode = ALPHA; |
239 Mode priorToShiftMode = ALPHA; | 239 Mode priorToShiftMode = ALPHA; |
240 FX_INT32 i = 0; | 240 int32_t i = 0; |
241 while (i < length) { | 241 while (i < length) { |
242 FX_INT32 subModeCh = textCompactionData[i]; | 242 int32_t subModeCh = textCompactionData[i]; |
243 FX_CHAR ch = 0; | 243 FX_CHAR ch = 0; |
244 switch (subMode) { | 244 switch (subMode) { |
245 case ALPHA: | 245 case ALPHA: |
246 if (subModeCh < 26) { | 246 if (subModeCh < 26) { |
247 ch = (FX_CHAR) ('A' + subModeCh); | 247 ch = (FX_CHAR) ('A' + subModeCh); |
248 } else { | 248 } else { |
249 if (subModeCh == 26) { | 249 if (subModeCh == 26) { |
250 ch = ' '; | 250 ch = ' '; |
251 } else if (subModeCh == LL) { | 251 } else if (subModeCh == LL) { |
252 subMode = LOWER; | 252 subMode = LOWER; |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 } | 344 } |
345 } | 345 } |
346 break; | 346 break; |
347 } | 347 } |
348 if (ch != 0) { | 348 if (ch != 0) { |
349 result += ch; | 349 result += ch; |
350 } | 350 } |
351 i++; | 351 i++; |
352 } | 352 } |
353 } | 353 } |
354 FX_INT32 CBC_DecodedBitStreamPaser::byteCompaction(FX_INT32 mode, CFX_Int32Array
&codewords, FX_INT32 codeIndex, CFX_ByteString &result) | 354 int32_t CBC_DecodedBitStreamPaser::byteCompaction(int32_t mode, CFX_Int32Array &
codewords, int32_t codeIndex, CFX_ByteString &result) |
355 { | 355 { |
356 if (mode == BYTE_COMPACTION_MODE_LATCH) { | 356 if (mode == BYTE_COMPACTION_MODE_LATCH) { |
357 FX_INT32 count = 0; | 357 int32_t count = 0; |
358 FX_INT64 value = 0; | 358 int64_t value = 0; |
359 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD)); | 359 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD)); |
360 CFX_Int32Array byteCompactedCodewords; | 360 CFX_Int32Array byteCompactedCodewords; |
361 byteCompactedCodewords.SetSize(6); | 361 byteCompactedCodewords.SetSize(6); |
362 FX_BOOL end = FALSE; | 362 FX_BOOL end = FALSE; |
363 FX_INT32 nextCode = codewords[codeIndex++]; | 363 int32_t nextCode = codewords[codeIndex++]; |
364 while ((codeIndex < codewords[0]) && !end) { | 364 while ((codeIndex < codewords[0]) && !end) { |
365 byteCompactedCodewords[count++] = nextCode; | 365 byteCompactedCodewords[count++] = nextCode; |
366 value = 900 * value + nextCode; | 366 value = 900 * value + nextCode; |
367 nextCode = codewords[codeIndex++]; | 367 nextCode = codewords[codeIndex++]; |
368 if (nextCode == TEXT_COMPACTION_MODE_LATCH || | 368 if (nextCode == TEXT_COMPACTION_MODE_LATCH || |
369 nextCode == BYTE_COMPACTION_MODE_LATCH || | 369 nextCode == BYTE_COMPACTION_MODE_LATCH || |
370 nextCode == NUMERIC_COMPACTION_MODE_LATCH || | 370 nextCode == NUMERIC_COMPACTION_MODE_LATCH || |
371 nextCode == BYTE_COMPACTION_MODE_LATCH_6 || | 371 nextCode == BYTE_COMPACTION_MODE_LATCH_6 || |
372 nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || | 372 nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || |
373 nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || | 373 nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || |
374 nextCode == MACRO_PDF417_TERMINATOR) { | 374 nextCode == MACRO_PDF417_TERMINATOR) { |
375 codeIndex--; | 375 codeIndex--; |
376 end = TRUE; | 376 end = TRUE; |
377 } else { | 377 } else { |
378 if ((count % 5 == 0) && (count > 0)) { | 378 if ((count % 5 == 0) && (count > 0)) { |
379 FX_INT32 j = 0; | 379 int32_t j = 0; |
380 for (; j < 6; ++j) { | 380 for (; j < 6; ++j) { |
381 decodedData[5 - j] = (FX_WORD) (value % 256); | 381 decodedData[5 - j] = (FX_WORD) (value % 256); |
382 value >>= 8; | 382 value >>= 8; |
383 } | 383 } |
384 for (j = 0; j < 6; ++j) { | 384 for (j = 0; j < 6; ++j) { |
385 result += (FX_CHAR)decodedData[j]; | 385 result += (FX_CHAR)decodedData[j]; |
386 } | 386 } |
387 count = 0; | 387 count = 0; |
388 } | 388 } |
389 } | 389 } |
390 } | 390 } |
391 FX_Free(decodedData); | 391 FX_Free(decodedData); |
392 if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH)
{ | 392 if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH)
{ |
393 byteCompactedCodewords[count++] = nextCode; | 393 byteCompactedCodewords[count++] = nextCode; |
394 } | 394 } |
395 for (FX_INT32 i = 0; i < count; i++) { | 395 for (int32_t i = 0; i < count; i++) { |
396 result += (FX_CHAR)(FX_WORD) byteCompactedCodewords[i]; | 396 result += (FX_CHAR)(FX_WORD) byteCompactedCodewords[i]; |
397 } | 397 } |
398 } else if (mode == BYTE_COMPACTION_MODE_LATCH_6) { | 398 } else if (mode == BYTE_COMPACTION_MODE_LATCH_6) { |
399 FX_INT32 count = 0; | 399 int32_t count = 0; |
400 FX_INT64 value = 0; | 400 int64_t value = 0; |
401 FX_BOOL end = FALSE; | 401 FX_BOOL end = FALSE; |
402 while (codeIndex < codewords[0] && !end) { | 402 while (codeIndex < codewords[0] && !end) { |
403 FX_INT32 code = codewords[codeIndex++]; | 403 int32_t code = codewords[codeIndex++]; |
404 if (code < TEXT_COMPACTION_MODE_LATCH) { | 404 if (code < TEXT_COMPACTION_MODE_LATCH) { |
405 count++; | 405 count++; |
406 value = 900 * value + code; | 406 value = 900 * value + code; |
407 } else { | 407 } else { |
408 if (code == TEXT_COMPACTION_MODE_LATCH || | 408 if (code == TEXT_COMPACTION_MODE_LATCH || |
409 code == BYTE_COMPACTION_MODE_LATCH || | 409 code == BYTE_COMPACTION_MODE_LATCH || |
410 code == NUMERIC_COMPACTION_MODE_LATCH || | 410 code == NUMERIC_COMPACTION_MODE_LATCH || |
411 code == BYTE_COMPACTION_MODE_LATCH_6 || | 411 code == BYTE_COMPACTION_MODE_LATCH_6 || |
412 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || | 412 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || |
413 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || | 413 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || |
414 code == MACRO_PDF417_TERMINATOR) { | 414 code == MACRO_PDF417_TERMINATOR) { |
415 codeIndex--; | 415 codeIndex--; |
416 end = TRUE; | 416 end = TRUE; |
417 } | 417 } |
418 } | 418 } |
419 if ((count % 5 == 0) && (count > 0)) { | 419 if ((count % 5 == 0) && (count > 0)) { |
420 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD)); | 420 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6 * sizeof(FX_WORD)); |
421 FX_INT32 j = 0; | 421 int32_t j = 0; |
422 for (; j < 6; ++j) { | 422 for (; j < 6; ++j) { |
423 decodedData[5 - j] = (FX_WORD) (value & 0xFF); | 423 decodedData[5 - j] = (FX_WORD) (value & 0xFF); |
424 value >>= 8; | 424 value >>= 8; |
425 } | 425 } |
426 for (j = 0; j < 6; ++j) { | 426 for (j = 0; j < 6; ++j) { |
427 result += (FX_CHAR)decodedData[j]; | 427 result += (FX_CHAR)decodedData[j]; |
428 } | 428 } |
429 count = 0; | 429 count = 0; |
430 FX_Free(decodedData); | 430 FX_Free(decodedData); |
431 } | 431 } |
432 } | 432 } |
433 } | 433 } |
434 return codeIndex; | 434 return codeIndex; |
435 } | 435 } |
436 FX_INT32 CBC_DecodedBitStreamPaser::numericCompaction(CFX_Int32Array &codewords,
FX_INT32 codeIndex, CFX_ByteString &result, FX_INT32 &e) | 436 int32_t CBC_DecodedBitStreamPaser::numericCompaction(CFX_Int32Array &codewords,
int32_t codeIndex, CFX_ByteString &result, int32_t &e) |
437 { | 437 { |
438 FX_INT32 count = 0; | 438 int32_t count = 0; |
439 FX_BOOL end = FALSE; | 439 FX_BOOL end = FALSE; |
440 CFX_Int32Array numericCodewords; | 440 CFX_Int32Array numericCodewords; |
441 numericCodewords.SetSize(MAX_NUMERIC_CODEWORDS); | 441 numericCodewords.SetSize(MAX_NUMERIC_CODEWORDS); |
442 while (codeIndex < codewords[0] && !end) { | 442 while (codeIndex < codewords[0] && !end) { |
443 FX_INT32 code = codewords[codeIndex++]; | 443 int32_t code = codewords[codeIndex++]; |
444 if (codeIndex == codewords[0]) { | 444 if (codeIndex == codewords[0]) { |
445 end = TRUE; | 445 end = TRUE; |
446 } | 446 } |
447 if (code < TEXT_COMPACTION_MODE_LATCH) { | 447 if (code < TEXT_COMPACTION_MODE_LATCH) { |
448 numericCodewords[count] = code; | 448 numericCodewords[count] = code; |
449 count++; | 449 count++; |
450 } else { | 450 } else { |
451 if (code == TEXT_COMPACTION_MODE_LATCH || | 451 if (code == TEXT_COMPACTION_MODE_LATCH || |
452 code == BYTE_COMPACTION_MODE_LATCH || | 452 code == BYTE_COMPACTION_MODE_LATCH || |
453 code == BYTE_COMPACTION_MODE_LATCH_6 || | 453 code == BYTE_COMPACTION_MODE_LATCH_6 || |
454 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || | 454 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || |
455 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || | 455 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || |
456 code == MACRO_PDF417_TERMINATOR) { | 456 code == MACRO_PDF417_TERMINATOR) { |
457 codeIndex--; | 457 codeIndex--; |
458 end = TRUE; | 458 end = TRUE; |
459 } | 459 } |
460 } | 460 } |
461 if (count % MAX_NUMERIC_CODEWORDS == 0 || | 461 if (count % MAX_NUMERIC_CODEWORDS == 0 || |
462 code == NUMERIC_COMPACTION_MODE_LATCH || | 462 code == NUMERIC_COMPACTION_MODE_LATCH || |
463 end) { | 463 end) { |
464 CFX_ByteString s = decodeBase900toBase10(numericCodewords, count, e)
; | 464 CFX_ByteString s = decodeBase900toBase10(numericCodewords, count, e)
; |
465 BC_EXCEPTION_CHECK_ReturnValue(e, -1); | 465 BC_EXCEPTION_CHECK_ReturnValue(e, -1); |
466 result += s; | 466 result += s; |
467 count = 0; | 467 count = 0; |
468 } | 468 } |
469 } | 469 } |
470 return codeIndex; | 470 return codeIndex; |
471 } | 471 } |
472 CFX_ByteString CBC_DecodedBitStreamPaser::decodeBase900toBase10(CFX_Int32Array &
codewords, FX_INT32 count, FX_INT32 &e) | 472 CFX_ByteString CBC_DecodedBitStreamPaser::decodeBase900toBase10(CFX_Int32Array &
codewords, int32_t count, int32_t &e) |
473 { | 473 { |
474 BigInteger result = 0; | 474 BigInteger result = 0; |
475 BigInteger nineHundred(900); | 475 BigInteger nineHundred(900); |
476 for (FX_INT32 i = 0; i < count; i++) { | 476 for (int32_t i = 0; i < count; i++) { |
477 result = result * nineHundred + BigInteger(codewords[i]); | 477 result = result * nineHundred + BigInteger(codewords[i]); |
478 } | 478 } |
479 CFX_ByteString resultString(bigIntegerToString(result).c_str()); | 479 CFX_ByteString resultString(bigIntegerToString(result).c_str()); |
480 if (resultString.GetAt(0) != '1') { | 480 if (resultString.GetAt(0) != '1') { |
481 e = BCExceptionFormatInstance; | 481 e = BCExceptionFormatInstance; |
482 return ' '; | 482 return ' '; |
483 } | 483 } |
484 return resultString.Mid(1, resultString.GetLength() - 1); | 484 return resultString.Mid(1, resultString.GetLength() - 1); |
485 } | 485 } |
OLD | NEW |