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

Side by Side Diff: xfa/fxbarcode/qrcode/BC_QRDecodedBitStreamParser.cpp

Issue 2048983002: Get rid of NULLs in xfa/fxbarcode/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits 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
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRDetector.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2007 ZXing authors 8 * Copyright 2007 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 26 matching lines...) Expand all
37 CBC_QRDecodedBitStreamParser::CBC_QRDecodedBitStreamParser() {} 37 CBC_QRDecodedBitStreamParser::CBC_QRDecodedBitStreamParser() {}
38 CBC_QRDecodedBitStreamParser::~CBC_QRDecodedBitStreamParser() {} 38 CBC_QRDecodedBitStreamParser::~CBC_QRDecodedBitStreamParser() {}
39 CBC_CommonDecoderResult* CBC_QRDecodedBitStreamParser::Decode( 39 CBC_CommonDecoderResult* CBC_QRDecodedBitStreamParser::Decode(
40 CFX_ByteArray* bytes, 40 CFX_ByteArray* bytes,
41 CBC_QRCoderVersion* version, 41 CBC_QRCoderVersion* version,
42 CBC_QRCoderErrorCorrectionLevel* ecLevel, 42 CBC_QRCoderErrorCorrectionLevel* ecLevel,
43 int32_t byteModeDecode, 43 int32_t byteModeDecode,
44 int32_t& e) { 44 int32_t& e) {
45 CBC_CommonBitSource bits(bytes); 45 CBC_CommonBitSource bits(bytes);
46 CFX_ByteString result; 46 CFX_ByteString result;
47 CBC_CommonCharacterSetECI* currentCharacterSetECI = NULL; 47 CBC_CommonCharacterSetECI* currentCharacterSetECI = nullptr;
48 FX_BOOL fc1Infact = FALSE; 48 FX_BOOL fc1Infact = FALSE;
49 CFX_Int32Array byteSegments; 49 CFX_Int32Array byteSegments;
50 CBC_QRCoderMode* mode = NULL; 50 CBC_QRCoderMode* mode = nullptr;
51 do { 51 do {
52 if (bits.Available() < 4) { 52 if (bits.Available() < 4) {
53 mode = CBC_QRCoderMode::sTERMINATOR; 53 mode = CBC_QRCoderMode::sTERMINATOR;
54 } else { 54 } else {
55 int32_t iTemp1 = bits.ReadBits(4, e); 55 int32_t iTemp1 = bits.ReadBits(4, e);
56 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 56 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
57 mode = CBC_QRCoderMode::ForBits(iTemp1, e); 57 mode = CBC_QRCoderMode::ForBits(iTemp1, e);
58 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 58 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
59 if (mode == NULL) { 59 if (!mode) {
60 e = BCExceptionUnSupportMode; 60 e = BCExceptionUnSupportMode;
61 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 61 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
62 } 62 }
63 } 63 }
64 if (!(mode == CBC_QRCoderMode::sTERMINATOR)) { 64 if (!(mode == CBC_QRCoderMode::sTERMINATOR)) {
65 if (mode == CBC_QRCoderMode::sFNC1_FIRST_POSITION || 65 if (mode == CBC_QRCoderMode::sFNC1_FIRST_POSITION ||
66 mode == CBC_QRCoderMode::sFNC1_SECOND_POSITION) { 66 mode == CBC_QRCoderMode::sFNC1_SECOND_POSITION) {
67 fc1Infact = TRUE; 67 fc1Infact = TRUE;
68 } else if (mode == CBC_QRCoderMode::sSTRUCTURED_APPEND) { 68 } else if (mode == CBC_QRCoderMode::sSTRUCTURED_APPEND) {
69 bits.ReadBits(16, e); 69 bits.ReadBits(16, e);
70 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 70 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
71 } else if (mode == CBC_QRCoderMode::sECI) { 71 } else if (mode == CBC_QRCoderMode::sECI) {
72 int32_t value = ParseECIValue(&bits, e); 72 int32_t value = ParseECIValue(&bits, e);
73 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 73 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
74 currentCharacterSetECI = 74 currentCharacterSetECI =
75 CBC_CommonCharacterSetECI::GetCharacterSetECIByValue(value); 75 CBC_CommonCharacterSetECI::GetCharacterSetECIByValue(value);
76 } else { 76 } else {
77 if (mode == CBC_QRCoderMode::sGBK) { 77 if (mode == CBC_QRCoderMode::sGBK) {
78 bits.ReadBits(4, e); 78 bits.ReadBits(4, e);
79 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 79 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
80 } 80 }
81 int32_t numBits = mode->GetCharacterCountBits(version, e); 81 int32_t numBits = mode->GetCharacterCountBits(version, e);
82 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 82 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
83 int32_t count = bits.ReadBits(numBits, e); 83 int32_t count = bits.ReadBits(numBits, e);
84 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 84 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
85 if (mode == CBC_QRCoderMode::sNUMERIC) { 85 if (mode == CBC_QRCoderMode::sNUMERIC) {
86 DecodeNumericSegment(&bits, result, count, e); 86 DecodeNumericSegment(&bits, result, count, e);
87 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 87 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
88 } else if (mode == CBC_QRCoderMode::sALPHANUMERIC) { 88 } else if (mode == CBC_QRCoderMode::sALPHANUMERIC) {
89 DecodeAlphanumericSegment(&bits, result, count, fc1Infact, e); 89 DecodeAlphanumericSegment(&bits, result, count, fc1Infact, e);
90 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 90 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
91 } else if (mode == CBC_QRCoderMode::sBYTE) { 91 } else if (mode == CBC_QRCoderMode::sBYTE) {
92 DecodeByteSegment(&bits, result, count, currentCharacterSetECI, 92 DecodeByteSegment(&bits, result, count, currentCharacterSetECI,
93 &byteSegments, byteModeDecode, e); 93 &byteSegments, byteModeDecode, e);
94 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 94 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
95 } else if (mode == CBC_QRCoderMode::sGBK) { 95 } else if (mode == CBC_QRCoderMode::sGBK) {
96 DecodeGBKSegment(&bits, result, count, e); 96 DecodeGBKSegment(&bits, result, count, e);
97 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 97 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
98 } else if (mode == CBC_QRCoderMode::sKANJI) { 98 } else if (mode == CBC_QRCoderMode::sKANJI) {
99 DecodeKanjiSegment(&bits, result, count, e); 99 DecodeKanjiSegment(&bits, result, count, e);
100 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 100 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
101 } else { 101 } else {
102 e = BCExceptionUnSupportMode; 102 e = BCExceptionUnSupportMode;
103 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 103 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
104 } 104 }
105 } 105 }
106 } 106 }
107 } while (!(mode == CBC_QRCoderMode::sTERMINATOR)); 107 } while (!(mode == CBC_QRCoderMode::sTERMINATOR));
108 CBC_CommonDecoderResult* tempCd = new CBC_CommonDecoderResult(); 108 CBC_CommonDecoderResult* tempCd = new CBC_CommonDecoderResult();
109 tempCd->Init(*bytes, result, byteSegments, ecLevel, e); 109 tempCd->Init(*bytes, result, byteSegments, ecLevel, e);
110 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 110 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
111 return tempCd; 111 return tempCd;
112 } 112 }
113 void CBC_QRDecodedBitStreamParser::DecodeGBKSegment(CBC_CommonBitSource* bits, 113 void CBC_QRDecodedBitStreamParser::DecodeGBKSegment(CBC_CommonBitSource* bits,
114 CFX_ByteString& result, 114 CFX_ByteString& result,
115 int32_t count, 115 int32_t count,
116 int32_t& e) { 116 int32_t& e) {
117 CFX_ByteString buffer; 117 CFX_ByteString buffer;
118 while (count > 0) { 118 while (count > 0) {
119 int32_t twoBytes = bits->ReadBits(13, e); 119 int32_t twoBytes = bits->ReadBits(13, e);
120 BC_EXCEPTION_CHECK_ReturnVoid(e); 120 BC_EXCEPTION_CHECK_ReturnVoid(e);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 return ((firstByte & 0x3f) << 8) | secondByte; 264 return ((firstByte & 0x3f) << 8) | secondByte;
265 } else if ((firstByte & 0xe0) == 0xc0) { 265 } else if ((firstByte & 0xe0) == 0xc0) {
266 int32_t secondThirdByte = bits->ReadBits(16, e); 266 int32_t secondThirdByte = bits->ReadBits(16, e);
267 BC_EXCEPTION_CHECK_ReturnValue(e, 0); 267 BC_EXCEPTION_CHECK_ReturnValue(e, 0);
268 return ((firstByte & 0x1f) << 16) | secondThirdByte; 268 return ((firstByte & 0x1f) << 16) | secondThirdByte;
269 } 269 }
270 e = BCExceptionBadECI; 270 e = BCExceptionBadECI;
271 BC_EXCEPTION_CHECK_ReturnValue(e, 0); 271 BC_EXCEPTION_CHECK_ReturnValue(e, 0);
272 return 0; 272 return 0;
273 } 273 }
OLDNEW
« no previous file with comments | « xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp ('k') | xfa/fxbarcode/qrcode/BC_QRDetector.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698