| 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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 i++; | 354 i++; |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 int32_t CBC_DecodedBitStreamPaser::byteCompaction(int32_t mode, | 357 int32_t CBC_DecodedBitStreamPaser::byteCompaction(int32_t mode, |
| 358 CFX_Int32Array& codewords, | 358 CFX_Int32Array& codewords, |
| 359 int32_t codeIndex, | 359 int32_t codeIndex, |
| 360 CFX_ByteString& result) { | 360 CFX_ByteString& result) { |
| 361 if (mode == BYTE_COMPACTION_MODE_LATCH) { | 361 if (mode == BYTE_COMPACTION_MODE_LATCH) { |
| 362 int32_t count = 0; | 362 int32_t count = 0; |
| 363 int64_t value = 0; | 363 int64_t value = 0; |
| 364 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6); | 364 uint16_t* decodedData = FX_Alloc(uint16_t, 6); |
| 365 CFX_Int32Array byteCompactedCodewords; | 365 CFX_Int32Array byteCompactedCodewords; |
| 366 byteCompactedCodewords.SetSize(6); | 366 byteCompactedCodewords.SetSize(6); |
| 367 FX_BOOL end = FALSE; | 367 FX_BOOL end = FALSE; |
| 368 int32_t nextCode = codewords[codeIndex++]; | 368 int32_t nextCode = codewords[codeIndex++]; |
| 369 while ((codeIndex < codewords[0]) && !end) { | 369 while ((codeIndex < codewords[0]) && !end) { |
| 370 byteCompactedCodewords[count++] = nextCode; | 370 byteCompactedCodewords[count++] = nextCode; |
| 371 value = 900 * value + nextCode; | 371 value = 900 * value + nextCode; |
| 372 nextCode = codewords[codeIndex++]; | 372 nextCode = codewords[codeIndex++]; |
| 373 if (nextCode == TEXT_COMPACTION_MODE_LATCH || | 373 if (nextCode == TEXT_COMPACTION_MODE_LATCH || |
| 374 nextCode == BYTE_COMPACTION_MODE_LATCH || | 374 nextCode == BYTE_COMPACTION_MODE_LATCH || |
| 375 nextCode == NUMERIC_COMPACTION_MODE_LATCH || | 375 nextCode == NUMERIC_COMPACTION_MODE_LATCH || |
| 376 nextCode == BYTE_COMPACTION_MODE_LATCH_6 || | 376 nextCode == BYTE_COMPACTION_MODE_LATCH_6 || |
| 377 nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || | 377 nextCode == BEGIN_MACRO_PDF417_CONTROL_BLOCK || |
| 378 nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || | 378 nextCode == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || |
| 379 nextCode == MACRO_PDF417_TERMINATOR) { | 379 nextCode == MACRO_PDF417_TERMINATOR) { |
| 380 codeIndex--; | 380 codeIndex--; |
| 381 end = TRUE; | 381 end = TRUE; |
| 382 } else { | 382 } else { |
| 383 if ((count % 5 == 0) && (count > 0)) { | 383 if ((count % 5 == 0) && (count > 0)) { |
| 384 int32_t j = 0; | 384 int32_t j = 0; |
| 385 for (; j < 6; ++j) { | 385 for (; j < 6; ++j) { |
| 386 decodedData[5 - j] = (FX_WORD)(value % 256); | 386 decodedData[5 - j] = (uint16_t)(value % 256); |
| 387 value >>= 8; | 387 value >>= 8; |
| 388 } | 388 } |
| 389 for (j = 0; j < 6; ++j) { | 389 for (j = 0; j < 6; ++j) { |
| 390 result += (FX_CHAR)decodedData[j]; | 390 result += (FX_CHAR)decodedData[j]; |
| 391 } | 391 } |
| 392 count = 0; | 392 count = 0; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 FX_Free(decodedData); | 396 FX_Free(decodedData); |
| 397 if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) { | 397 if (codeIndex == codewords[0] && nextCode < TEXT_COMPACTION_MODE_LATCH) { |
| 398 byteCompactedCodewords[count++] = nextCode; | 398 byteCompactedCodewords[count++] = nextCode; |
| 399 } | 399 } |
| 400 for (int32_t i = 0; i < count; i++) { | 400 for (int32_t i = 0; i < count; i++) { |
| 401 result += (FX_CHAR)(FX_WORD)byteCompactedCodewords[i]; | 401 result += (FX_CHAR)(uint16_t)byteCompactedCodewords[i]; |
| 402 } | 402 } |
| 403 } else if (mode == BYTE_COMPACTION_MODE_LATCH_6) { | 403 } else if (mode == BYTE_COMPACTION_MODE_LATCH_6) { |
| 404 int32_t count = 0; | 404 int32_t count = 0; |
| 405 int64_t value = 0; | 405 int64_t value = 0; |
| 406 FX_BOOL end = FALSE; | 406 FX_BOOL end = FALSE; |
| 407 while (codeIndex < codewords[0] && !end) { | 407 while (codeIndex < codewords[0] && !end) { |
| 408 int32_t code = codewords[codeIndex++]; | 408 int32_t code = codewords[codeIndex++]; |
| 409 if (code < TEXT_COMPACTION_MODE_LATCH) { | 409 if (code < TEXT_COMPACTION_MODE_LATCH) { |
| 410 count++; | 410 count++; |
| 411 value = 900 * value + code; | 411 value = 900 * value + code; |
| 412 } else { | 412 } else { |
| 413 if (code == TEXT_COMPACTION_MODE_LATCH || | 413 if (code == TEXT_COMPACTION_MODE_LATCH || |
| 414 code == BYTE_COMPACTION_MODE_LATCH || | 414 code == BYTE_COMPACTION_MODE_LATCH || |
| 415 code == NUMERIC_COMPACTION_MODE_LATCH || | 415 code == NUMERIC_COMPACTION_MODE_LATCH || |
| 416 code == BYTE_COMPACTION_MODE_LATCH_6 || | 416 code == BYTE_COMPACTION_MODE_LATCH_6 || |
| 417 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || | 417 code == BEGIN_MACRO_PDF417_CONTROL_BLOCK || |
| 418 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || | 418 code == BEGIN_MACRO_PDF417_OPTIONAL_FIELD || |
| 419 code == MACRO_PDF417_TERMINATOR) { | 419 code == MACRO_PDF417_TERMINATOR) { |
| 420 codeIndex--; | 420 codeIndex--; |
| 421 end = TRUE; | 421 end = TRUE; |
| 422 } | 422 } |
| 423 } | 423 } |
| 424 if ((count % 5 == 0) && (count > 0)) { | 424 if ((count % 5 == 0) && (count > 0)) { |
| 425 FX_WORD* decodedData = FX_Alloc(FX_WORD, 6); | 425 uint16_t* decodedData = FX_Alloc(uint16_t, 6); |
| 426 int32_t j = 0; | 426 int32_t j = 0; |
| 427 for (; j < 6; ++j) { | 427 for (; j < 6; ++j) { |
| 428 decodedData[5 - j] = (FX_WORD)(value & 0xFF); | 428 decodedData[5 - j] = (uint16_t)(value & 0xFF); |
| 429 value >>= 8; | 429 value >>= 8; |
| 430 } | 430 } |
| 431 for (j = 0; j < 6; ++j) { | 431 for (j = 0; j < 6; ++j) { |
| 432 result += (FX_CHAR)decodedData[j]; | 432 result += (FX_CHAR)decodedData[j]; |
| 433 } | 433 } |
| 434 count = 0; | 434 count = 0; |
| 435 FX_Free(decodedData); | 435 FX_Free(decodedData); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 } | 438 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 for (int32_t i = 0; i < count; i++) { | 484 for (int32_t i = 0; i < count; i++) { |
| 485 result = result * nineHundred + BigInteger(codewords[i]); | 485 result = result * nineHundred + BigInteger(codewords[i]); |
| 486 } | 486 } |
| 487 CFX_ByteString resultString(bigIntegerToString(result).c_str()); | 487 CFX_ByteString resultString(bigIntegerToString(result).c_str()); |
| 488 if (resultString.GetAt(0) != '1') { | 488 if (resultString.GetAt(0) != '1') { |
| 489 e = BCExceptionFormatInstance; | 489 e = BCExceptionFormatInstance; |
| 490 return ' '; | 490 return ' '; |
| 491 } | 491 } |
| 492 return resultString.Mid(1, resultString.GetLength() - 1); | 492 return resultString.Mid(1, resultString.GetLength() - 1); |
| 493 } | 493 } |
| OLD | NEW |