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

📄 rgb12bppimageiter.h

📁 barcode readers [ from Image]
💻 H
字号:
//
// Class for indexing of a 12-bpp RGB image.
// Using [R,G,B] gets red, green, blue values.
// Using ++ advances to next pixel.
// End() tests for end.
// Note that this class does not provide a way to assign values to the
// image. This is because the 4-bit pixels cannot be directly addressed.
//
// Copyright (C) 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 Rgb12bppImageIter_h
#define Rgb12bppImageIter_h

#include "RgbIndex.h" // for enum TRgbVal

namespace Core
{
	class IRgb12bppImageIter
	{
	public:
		// Lifecycle
		inline IRgb12bppImageIter(CImage& image) :
			inHeight(0),
			inRowBytes(0),
			ipBegin(NULL),
			ipCurrent(NULL),
			ipEnd(NULL),
			ipREnd(NULL)
			 {
				_LIT(LRgbIterErr, "IRgb12bppImageIter: Not a color 12-bit image");
				__ASSERT_ALWAYS(image.iBitmap.DisplayMode() == EColor4K, User::Panic(LRgbIterErr, KErrGeneral));
				TInt nWidth = image.iBitmap.SizeInPixels().iWidth; // the number of pixels since we take pairs
				inHeight = image.iBitmap.SizeInPixels().iHeight;
				inRowBytes = nWidth * 2; // number of bytes in a row
				ipBegin = (unsigned char*) image.iBitmap.DataAddress();
				ipCurrent = ipBegin;
				ipREnd = ipCurrent + inRowBytes; // actual width of the row
				ipEnd = ipCurrent + inRowBytes * (inHeight-1);
			 }
		inline IRgb12bppImageIter(const IRgb12bppImageIter& other)
			 {
				inHeight = other.inHeight;
				inRowBytes = other.inRowBytes;
				ipBegin = other.ipBegin;
				ipCurrent = other.ipCurrent;
				ipREnd = other.ipREnd;
				ipEnd = other.ipEnd;
			 }
		inline ~IRgb12bppImageIter(void) 
		{
		};

		// Operations
	public:

		// Prefix ++
		inline IRgb12bppImageIter& operator++() {
			ASSERT(!REnd());
			ipCurrent += 2; // next pixel
			return *this;
		}
		// Postfix ++
		inline IRgb12bppImageIter operator++(int) {
			ASSERT(!REnd());
			IRgb12bppImageIter prev = *this;
			ipCurrent += 2;
			return prev;
		}
		// Start over
		inline void Reset() {
			ipCurrent = ipBegin;
			ipREnd = ipBegin + inRowBytes;
		}
		// Next row
		// if we are at the last row we make sure End() and REnd() are asserted
		inline void NextRow() {
			if (ipREnd != ipEnd) {
				ipREnd += inRowBytes;
				ipCurrent = ipREnd - inRowBytes;
			} else {
				ipCurrent = ipEnd; // asserting End()
				ipREnd = ipCurrent; // asserting REnd
			}
		}

		// Operators
	public:
		inline IRgb12bppImageIter& operator=(const IRgb12bppImageIter& other) {
			if (this != &other) {
				inHeight = other.inHeight;
				inRowBytes = other.inRowBytes;
				ipBegin = other.ipBegin;
				ipCurrent = other.ipCurrent;
				ipREnd = other.ipREnd;
				ipEnd = other.ipEnd;
			}
			return *this;
		}


		// Accessors
	public:
		// The pixel layout is GB0R
		inline const unsigned char operator[](int color) const {
			switch (color) {
				case R:
					return (unsigned char) ((ipCurrent[1] & 0x0f) << 4);
				case G:
					return (unsigned char) (ipCurrent[0] & 0xf0);
				case B:
					return (unsigned char) ((ipCurrent[0] & 0x0f) << 4);
				default:
					{
						_LIT(LParamErr, "Color must be R, G, or B");
						User::Panic(LParamErr, KErrGeneral);
						return 0;
					}
			}
		}
		inline bool End() const {
			return ipCurrent == ipEnd;
		}
		inline bool REnd() const {
			return ipCurrent == ipREnd;
		}

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

};

#endif // Rgb12bppImageIter_h

⌨️ 快捷键说明

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