⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bars2symupcx2.h

📁 barcode readers [ from Image]
💻 H
字号:
//
// Given an array of edge positions and strengths compute a string
// representing the bar code widths corresponding to those edge
// positions.
//
// Copyright (C) 2006 by Jon A. Webb
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

#ifndef Bars2SymUpc_h
#define Bars2SymUpc_h

#include "Array.h"
#include "Bars2Sym.h"
#include "HashTable.h"

#include <e32cons.h>
#include <e32math.h>

namespace Barcode
{
	class CBars2SymUpc: public CBars2Sym
    {
		static const int Digits = 6; // number of digits in a barcode
		static const int LeftWidth = 3;
		static const int RightWidth = 3;
		static const int MidWidth = 5;
		static const int DigitWidth = 7;
		static const int MidOffset = LeftWidth + Digits*DigitWidth;
		static const int RightOffset = LeftWidth + Digits*DigitWidth*2 + MidWidth;
		static const int TotalWidth = 
			LeftWidth + DigitWidth * Digits + MidWidth + DigitWidth * Digits + RightWidth;
        // Lifecycle
    public:
        IMPORT_C static CBars2SymUpc* NewL();
        ~CBars2SymUpc(void);

    private:
		// First-phase constructor
        CBars2SymUpc();
		// Second-phase constructor
		void ConstructL();

        // Operations
    public:
		// ClearHash clears the hash table
		void ClearHash();

        // FindBarsL
		//   Given an array of bar widths (one byte per bar) produce an array
		//   representing the string encoded, or return false if nothing was found.
        //
		// Input
		//  pPositions is an array of bar widths
		// Output
		//  pCode is the decoded string
        IMPORT_C bool DecodeL(
			Core::CImage image, 
			TRect rectangle,
			CodeType*& pCode);
	private:
		// BlurPatternL
		//    Given a vector of length nLength blur the coefficients
		//    using the Gaussian coefficients stored in ipfCoeff
		void BlurPatternL(TReal* vector, TInt nLength) const;

		// ComputeCoefficientsL
		//    Computes Gaussian coefficients with sigma = ifSigma
		//    and stores them in the created array ipfCoeff
		void ComputeCoefficientsL();

		// EstimateLeftEdge
		//    Finds the left edge of the barcode pattern at row nRow
		int EstimateLeftEdge(Core::CImage image, TInt nRow);

		// NormalizePattern
		//   Scales the floating point vector of weights in pfCoeff
		//   (length nLength) so that the sum is 0.0 (if bNormZero)
		//   and the sum of absolute values is 1.0. Also scales
		//   by 256.0 and assigns to pnCoeff if bConvInt.
		static void NormalizePattern(
			TReal* pfCoeff, 
			TInt nLength, 
			TInt16 *pnCoeff, 
			bool bNormZero,
			bool bConvInt);

		// TurnDigitsToText
		//   Translates decoded barcode into a string.
		static CBars2Sym::CodeType* CBars2SymUpc::TurnDigitsToText(TBuf8<Digits*2>& code);

		// VerifyCheckDigit
		//    Returns true if the check digit matches what it is supposed to be.
		//
		static bool VerifyCheckDigit(TBuf8<Digits*2>& digits);

	private:
		// Accessors
	public:
		int BarcodeWidth() const;
		const TDesC& Name() const;
    private:
		// Attributes
        // This is the convoluion table
		TInt16 iLeftConv[10][10][LeftWidth+DigitWidth*2];
		TInt16 iMidConv[10][10][MidWidth+DigitWidth*2];
		TInt16 iPairConv[10][10][DigitWidth*2];
		Core::CHashTable* iHash;
		CArrayFixFlat<TBuf8<Digits*2>*>* iCodes;
		CArrayFixFlat<TReal> *ipfCoeff;
		TReal ifSigma;
    };

};
#endif // Bars2SymUpc_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -