📄 shortimageiter.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 RShortImageIter_h
#define RShortImageIter_h
#include <fbs.h>
namespace Core
{
class IShortImageIter
{
public:
// Lifecycle
inline IShortImageIter(const CImage& image) :
inHeight(0),
inRowShorts(0),
inWidth(0),
ipBegin(NULL),
ipCurrent(NULL),
ipEnd(NULL),
ipREnd(NULL)
{
_LIT(LRShortIterErr, "IShortImageIter: Not a short image");
__ASSERT_ALWAYS(image.iBitmap.DisplayMode() == EColor64K, User::Panic(LRShortIterErr, KErrGeneral));
inWidth = image.iBitmap.SizeInPixels().iWidth;
inHeight = image.iBitmap.SizeInPixels().iHeight;
inRowShorts = CFbsBitmap::ScanLineLength(image.iBitmap.SizeInPixels().iWidth, EColor64K) / 2;
ipBegin = (unsigned short*) image.iBitmap.DataAddress();
ipCurrent = ipBegin;
ipREnd = ipCurrent + inWidth;
ipEnd = ipCurrent + inWidth * inHeight;
}
inline IShortImageIter(const IShortImageIter& other)
{
inWidth = other.inWidth;
inHeight = other.inHeight;
inRowShorts = other.inRowShorts;
ipBegin = other.ipBegin;
ipCurrent = other.ipCurrent;
ipREnd = other.ipREnd;
ipEnd = other.ipEnd;
}
public:
inline ~IShortImageIter(void)
{
};
// Operations
public:
// called after bitmaps have been unlocked and locked --
// adjust image base address if necessary and keep same
// relative current position
void Adjust(const CImage& image) {
unsigned short* newBegin = (unsigned short*) image.iBitmap.DataAddress();
if (ipBegin != newBegin) {
ipCurrent = newBegin + (ipCurrent - ipBegin);
ipREnd = newBegin + (ipREnd - ipBegin);
ipEnd = newBegin + (ipEnd - ipBegin);
ipBegin = newBegin;
}
}
// Prefix ++
inline IShortImageIter& operator++() {
ASSERT(!REnd());
ipCurrent++;
return *this;
}
// Postfix ++
inline IShortImageIter operator++(int) {
ASSERT(!REnd());
IShortImageIter prev = *this;
ipCurrent++;
return prev;
}
// Start over
inline void Reset() {
ipCurrent = ipBegin;
ipREnd = ipBegin + inRowShorts;
}
// Next row
inline void NextRow() {
if (ipREnd != ipEnd) {
ipREnd += inRowShorts;
ipCurrent = ipREnd - inRowShorts;
} else {
ipCurrent = ipEnd; // asserting End()
ipREnd = ipCurrent; // asserting REnd()
}
}
// Operators
inline IShortImageIter& operator=(const IShortImageIter& other)
{
if (this != &other) {
inWidth = other.inWidth;
inHeight = other.inHeight;
inRowShorts = other.inRowShorts;
ipBegin = other.ipBegin;
ipCurrent = other.ipCurrent;
ipREnd = other.ipREnd;
ipEnd = other.ipEnd;
}
return *this;
}
// Accessors
public:
inline unsigned short operator()() const {
return *ipCurrent;
}
inline unsigned short& operator()() {
return *ipCurrent;
}
inline bool End() const {
return ipCurrent == ipEnd;
}
inline bool REnd() const {
return ipCurrent == ipREnd;
}
private:
// Attributes
int inHeight;
int inRowShorts;
int inWidth;
unsigned short *ipBegin;
unsigned short *ipCurrent;
unsigned short *ipEnd;
unsigned short *ipREnd;
};
};
#endif // RImageIter_h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -