| 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 2008 ZXing authors | 8 * Copyright 2008 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 30 matching lines...) Expand all Loading... |
| 41 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (FX_CHAR)127}; | 41 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (FX_CHAR)127}; |
| 42 const int32_t CBC_DataMatrixDecodedBitStreamParser::PAD_ENCODE = 0; | 42 const int32_t CBC_DataMatrixDecodedBitStreamParser::PAD_ENCODE = 0; |
| 43 const int32_t CBC_DataMatrixDecodedBitStreamParser::ASCII_ENCODE = 1; | 43 const int32_t CBC_DataMatrixDecodedBitStreamParser::ASCII_ENCODE = 1; |
| 44 const int32_t CBC_DataMatrixDecodedBitStreamParser::C40_ENCODE = 2; | 44 const int32_t CBC_DataMatrixDecodedBitStreamParser::C40_ENCODE = 2; |
| 45 const int32_t CBC_DataMatrixDecodedBitStreamParser::TEXT_ENCODE = 3; | 45 const int32_t CBC_DataMatrixDecodedBitStreamParser::TEXT_ENCODE = 3; |
| 46 const int32_t CBC_DataMatrixDecodedBitStreamParser::ANSIX12_ENCODE = 4; | 46 const int32_t CBC_DataMatrixDecodedBitStreamParser::ANSIX12_ENCODE = 4; |
| 47 const int32_t CBC_DataMatrixDecodedBitStreamParser::EDIFACT_ENCODE = 5; | 47 const int32_t CBC_DataMatrixDecodedBitStreamParser::EDIFACT_ENCODE = 5; |
| 48 const int32_t CBC_DataMatrixDecodedBitStreamParser::BASE256_ENCODE = 6; | 48 const int32_t CBC_DataMatrixDecodedBitStreamParser::BASE256_ENCODE = 6; |
| 49 CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser() {} | 49 CBC_DataMatrixDecodedBitStreamParser::CBC_DataMatrixDecodedBitStreamParser() {} |
| 50 CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser() {} | 50 CBC_DataMatrixDecodedBitStreamParser::~CBC_DataMatrixDecodedBitStreamParser() {} |
| 51 |
| 51 CBC_CommonDecoderResult* CBC_DataMatrixDecodedBitStreamParser::Decode( | 52 CBC_CommonDecoderResult* CBC_DataMatrixDecodedBitStreamParser::Decode( |
| 52 CFX_ByteArray& bytes, | 53 CFX_ByteArray& bytes, |
| 53 int32_t& e) { | 54 int32_t& e) { |
| 54 CBC_CommonBitSource bits(&bytes); | 55 CBC_CommonBitSource bits(&bytes); |
| 55 CFX_ByteString result; | 56 CFX_ByteString result; |
| 56 CFX_ByteString resultTrailer; | 57 CFX_ByteString resultTrailer; |
| 57 CFX_Int32Array byteSegments; | 58 CFX_Int32Array byteSegments; |
| 58 int32_t mode = ASCII_ENCODE; | 59 int32_t mode = ASCII_ENCODE; |
| 59 do { | 60 do { |
| 60 if (mode == 1) { | 61 if (mode == 1) { |
| 61 mode = DecodeAsciiSegment(&bits, result, resultTrailer, e); | 62 mode = DecodeAsciiSegment(&bits, result, resultTrailer, e); |
| 62 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 63 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 63 } else { | 64 } else { |
| 64 switch (mode) { | 65 switch (mode) { |
| 65 case 2: | 66 case 2: |
| 66 DecodeC40Segment(&bits, result, e); | 67 DecodeC40Segment(&bits, result, e); |
| 67 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 68 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 68 break; | 69 break; |
| 69 case 3: | 70 case 3: |
| 70 DecodeTextSegment(&bits, result, e); | 71 DecodeTextSegment(&bits, result, e); |
| 71 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 72 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 72 break; | 73 break; |
| 73 case 4: | 74 case 4: |
| 74 DecodeAnsiX12Segment(&bits, result, e); | 75 DecodeAnsiX12Segment(&bits, result, e); |
| 75 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 76 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 76 break; | 77 break; |
| 77 case 5: | 78 case 5: |
| 78 DecodeEdifactSegment(&bits, result, e); | 79 DecodeEdifactSegment(&bits, result, e); |
| 79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 80 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 80 break; | 81 break; |
| 81 case 6: | 82 case 6: |
| 82 DecodeBase256Segment(&bits, result, byteSegments, e); | 83 DecodeBase256Segment(&bits, result, byteSegments, e); |
| 83 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | 84 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 84 break; | 85 break; |
| 85 default: | 86 default: |
| 86 e = BCExceptionFormatException; | 87 e = BCExceptionFormatException; |
| 87 return NULL; | 88 return nullptr; |
| 88 } | 89 } |
| 89 mode = ASCII_ENCODE; | 90 mode = ASCII_ENCODE; |
| 90 } | 91 } |
| 91 } while (mode != PAD_ENCODE && bits.Available() > 0); | 92 } while (mode != PAD_ENCODE && bits.Available() > 0); |
| 92 if (resultTrailer.GetLength() > 0) { | 93 if (resultTrailer.GetLength() > 0) { |
| 93 result += resultTrailer; | 94 result += resultTrailer; |
| 94 } | 95 } |
| 95 CBC_CommonDecoderResult* tempCp = new CBC_CommonDecoderResult(); | 96 CBC_CommonDecoderResult* tempCp = new CBC_CommonDecoderResult(); |
| 96 tempCp->Init(bytes, result, | 97 tempCp->Init(bytes, result, byteSegments, nullptr, e); |
| 97 (byteSegments.GetSize() <= 0) ? CFX_Int32Array() : byteSegments, | 98 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
| 98 NULL, e); | |
| 99 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); | |
| 100 return tempCp; | 99 return tempCp; |
| 101 } | 100 } |
| 101 |
| 102 int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment( | 102 int32_t CBC_DataMatrixDecodedBitStreamParser::DecodeAsciiSegment( |
| 103 CBC_CommonBitSource* bits, | 103 CBC_CommonBitSource* bits, |
| 104 CFX_ByteString& result, | 104 CFX_ByteString& result, |
| 105 CFX_ByteString& resultTrailer, | 105 CFX_ByteString& resultTrailer, |
| 106 int32_t& e) { | 106 int32_t& e) { |
| 107 FX_CHAR buffer[128]; | 107 FX_CHAR buffer[128]; |
| 108 FX_BOOL upperShift = FALSE; | 108 FX_BOOL upperShift = FALSE; |
| 109 do { | 109 do { |
| 110 int32_t oneByte = bits->ReadBits(8, e); | 110 int32_t oneByte = bits->ReadBits(8, e); |
| 111 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 111 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 BC_FX_ByteString_Append(result, *bytes); | 464 BC_FX_ByteString_Append(result, *bytes); |
| 465 delete bytes; | 465 delete bytes; |
| 466 } | 466 } |
| 467 uint8_t CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State( | 467 uint8_t CBC_DataMatrixDecodedBitStreamParser::Unrandomize255State( |
| 468 int32_t randomizedBase256Codeword, | 468 int32_t randomizedBase256Codeword, |
| 469 int32_t base256CodewordPosition) { | 469 int32_t base256CodewordPosition) { |
| 470 int32_t pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; | 470 int32_t pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1; |
| 471 int32_t tempVariable = randomizedBase256Codeword - pseudoRandomNumber; | 471 int32_t tempVariable = randomizedBase256Codeword - pseudoRandomNumber; |
| 472 return (uint8_t)(tempVariable >= 0 ? tempVariable : tempVariable + 256); | 472 return (uint8_t)(tempVariable >= 0 ? tempVariable : tempVariable + 256); |
| 473 } | 473 } |
| OLD | NEW |