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

📄 grayimageiter.h

📁 barcode readers [ from Image]
💻 H
字号:
//
// Class for easy indexing of an image.
// Using () gets current pixel.
// Using ++ advances to next pixel.
// End() tests for end.
//
// Copyright (C) 2003, 2006 by Jon A. Webb (Contact via GMail; username is jonawebb)
//
// 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 RGrayImageIter_h
#define RGrayImageIter_h

#include <fbs.h>

namespace Core
{
	class IGrayImageIter
	{
	public:
		// Lifecycle
		inline IGrayImageIter(const CImage& image) :
			inHeight(0),
		    inRowLength(0),
			inWidth(0),		
			ipBegin(NULL),
			ipCurrent(NULL),
			ipEnd(NULL),
			ipREnd(NULL)
		 {
			_LIT(LRGrayIterErr, "IGrayImageIter: Not a byte gray image");
			__ASSERT_ALWAYS(image.iBitmap.DisplayMode() == EGray256, User::Panic(LRGrayIterErr, KErrGeneral));
			inWidth =  image.iBitmap.SizeInPixels().iWidth;		
			inHeight = image.iBitmap.SizeInPixels().iHeight;
			ipBegin = (unsigned char*) image.iBitmap.DataAddress();
			inRowLength = image.iBitmap.ScanLineLength(inWidth, EGray256);
			ipCurrent = ipBegin;
			ipREnd = ipCurrent + inWidth; // just beyond last pixel in row
			ipEnd = ipCurrent + inRowLength * (inHeight - 1) + inWidth; // just beyond last pixel in image
		 }

		 inline IGrayImageIter(const IGrayImageIter& other)
		 {
			inHeight = other.inHeight;
			inRowLength = other.inRowLength;
			inWidth =  other.inWidth;		
			ipBegin = other.ipBegin;
			ipCurrent = other.ipCurrent;
			ipREnd = other.ipREnd;
			ipEnd = other.ipEnd;
		 }
	public:
		inline ~IGrayImageIter(void) 
		{
		};

		// Operations
	public:

		// Prefix ++
		inline IGrayImageIter& operator++() {
			ASSERT(!REnd());
			ipCurrent++;
			return *this;
		}
		// Postfix ++
		inline IGrayImageIter operator++(int) {
			ASSERT(!REnd());
			IGrayImageIter prev = *this;
			ipCurrent++;
			return prev;
		}
		// Start over
		inline void Reset() {
			ipCurrent = ipBegin;
			ipREnd = ipBegin + inWidth;
		}
		// Next row
		inline void NextRow() {
			if (ipREnd != ipEnd) {
				ipCurrent = ipREnd + inRowLength - inWidth; // start of next row
				ipREnd += inRowLength;
			} else {
				ipCurrent = ipEnd; // asserting End()
				ipREnd = ipCurrent; // asserting REnd()
			}
		}

		// Operators
		inline IGrayImageIter& operator=(const IGrayImageIter& other)
		{
			if (this != &other) {
				inHeight = other.inHeight;
				inRowLength = other.inRowLength;
				inWidth =  other.inWidth;		
				ipBegin = other.ipBegin;
				ipCurrent = other.ipCurrent;
				ipREnd = other.ipREnd;
				ipEnd = other.ipEnd;
			}
			return *this;
		}

		// Accessors
	public:
		inline unsigned char operator()() const {
			return *ipCurrent;
		}
		inline unsigned char& operator()() {
			return *ipCurrent;
		}
		inline bool End() const {
			return ipCurrent == ipEnd;
		}
		inline bool REnd() const {
			return ipCurrent == ipREnd;
		}

	private:
		// Attributes
		int inHeight;
		int inRowLength;
		int inWidth;
		unsigned char *ipBegin;
		unsigned char *ipCurrent;
		unsigned char *ipEnd;
		unsigned char *ipREnd;
	};

};

#endif // RImageIter_h

⌨️ 快捷键说明

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