📄 rgbimageiter.h
字号:
//
// Class for easy indexing of an image.
// Using ()[R,G,B] 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 RgbImageIter_h
#define RgbImageIter_h
#include "RgbIndex.h" // for enum TRgbVal
namespace Core
{
class IRgbImageIter
{
public:
// Lifecycle
inline IRgbImageIter(CImage& image) :
inHeight(0),
inRowBytes(0),
inWidth(0),
ipBegin(NULL),
ipCurrent(NULL),
ipEnd(NULL),
ipREnd(NULL)
{
_LIT(LRgbIterErr, "IRgbImageIter: Not a color 24-bit image");
__ASSERT_ALWAYS(image.iBitmap.DisplayMode() == EColor16M, User::Panic(LRgbIterErr, KErrGeneral));
inWidth = image.iBitmap.SizeInPixels().iWidth;
inHeight = image.iBitmap.SizeInPixels().iHeight;
inRowBytes = CFbsBitmap::ScanLineLength(image.iBitmap.SizeInPixels().iWidth, EColor16M);
ipBegin = (unsigned char*) image.iBitmap.DataAddress();
ipCurrent = ipBegin;
ipREnd = ipCurrent + inWidth * 3;
ipEnd = ipCurrent + inRowBytes * (inHeight-1) + inWidth* 3;
}
inline IRgbImageIter(const IRgbImageIter& other)
{
inWidth = other.inWidth;
inHeight = other.inHeight;
inRowBytes = other.inRowBytes;
ipBegin = other.ipBegin;
ipCurrent = other.ipCurrent;
ipREnd = other.ipREnd;
ipEnd = other.ipEnd;
}
inline ~IRgbImageIter(void)
{
};
// Operations
public:
// Prefix ++
inline IRgbImageIter& operator++() {
ASSERT(!REnd());
ipCurrent += 3;
return *this;
}
// Postfix ++
inline IRgbImageIter operator++(int) {
ASSERT(!REnd());
IRgbImageIter prev = *this;
ipCurrent += 3;
return prev;
}
// Start over
inline void Reset() {
ipCurrent = ipBegin;
ipREnd = ipBegin + inWidth * 3;
}
// 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 - inWidth * 3;
} else {
ipCurrent = ipEnd; // asserting End()
ipREnd = ipCurrent; // asserting REnd
}
}
// Operators
public:
inline IRgbImageIter& operator=(const IRgbImageIter& other) {
if (this != &other) {
inWidth = other.inWidth;
inHeight = other.inHeight;
inRowBytes = other.inRowBytes;
ipBegin = other.ipBegin;
ipCurrent = other.ipCurrent;
ipREnd = other.ipREnd;
ipEnd = other.ipEnd;
}
return *this;
}
// Accessors
public:
inline const unsigned char operator[](int color) const {
return ipCurrent[color];
}
inline unsigned char& operator[](int color) {
return ipCurrent[color];
}
inline bool End() const {
return ipCurrent == ipEnd;
}
inline bool REnd() const {
return ipCurrent == ipREnd;
}
private:
// Attributes
int inHeight;
int inRowBytes;
int inWidth;
unsigned char *ipBegin;
unsigned char *ipCurrent;
unsigned char *ipEnd;
unsigned char *ipREnd;
};
};
#endif // RgbImageIter_h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -