1 // This file is part of OpenCV project. 2 // It is subject to the license terms in the LICENSE file found in the top-level directory 3 // of this distribution and at http://opencv.org/license.html. 4 // 5 // Tencent is pleased to support the open source community by making WeChat QRCode available. 6 // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 7 // 8 // Modified from ZXing. Copyright ZXing authors. 9 // Licensed under the Apache License, Version 2.0 (the "License"). 10 11 #ifndef __ZXING_QRCODE_DECODER_DECODER_HPP__ 12 #define __ZXING_QRCODE_DECODER_DECODER_HPP__ 13 14 #include "../../common/array.hpp" 15 #include "../../common/bitmatrix.hpp" 16 #include "../../common/counted.hpp" 17 #include "../../common/decoder_result.hpp" 18 #include "../../common/detector_result.hpp" 19 #include "../../common/reedsolomon/reed_solomon_decoder.hpp" 20 #include "../../errorhandler.hpp" 21 #include "../version.hpp" 22 #include "bitmatrixparser.hpp" 23 24 namespace zxing { 25 namespace qrcode { 26 27 class Decoder { 28 public: 29 enum DecoderState { 30 NOTSTART = 19, 31 START = 20, 32 READVERSION = 21, 33 READERRORCORRECTIONLEVEL = 22, 34 READCODEWORDSORRECTIONLEVEL = 23, 35 FINISH = 24 36 }; 37 38 private: 39 DecoderState decoderState_; 40 float possibleFix_; 41 ReedSolomonDecoder rsDecoder_; 42 void correctErrors(ArrayRef<char> bytes, int numDataCodewords, ErrorHandler& err_handler); 43 44 public: 45 Decoder(); 46 Ref<DecoderResult> decode(Ref<BitMatrix> bits, ErrorHandler& err_handler); 47 48 private: 49 Ref<DecoderResult> decode(Ref<BitMatrix> bits, bool isMirror, ErrorHandler& err_handler); 50 51 float estimateFixedPattern(Ref<BitMatrix> bits, Version* version, ErrorHandler& err_handler); 52 53 private: 54 unsigned int possibleVersion_; 55 56 public: 57 unsigned int getPossibleVersion(); getState()58 DecoderState getState() { return decoderState_; } getPossibleFix()59 float getPossibleFix() { return possibleFix_; } 60 }; 61 62 } // namespace qrcode 63 } // namespace zxing 64 65 #endif // __ZXING_QRCODE_DECODER_DECODER_HPP__ 66