38 #if !defined(_IMAGE_BASE_H_INCLUDED_)
39 # error do not include ImageBaseInline here.
47 #define CheckCoordinates(x,y,functionname) \
48 if (x < 0 || x > (int)GetWidth()-1) { \
49 BIASERR("x-coordinate out of range in "<<functionname<<" "<<x); \
51 if (y < 0 || y > (int)GetHeight()-1) { \
52 BIASERR("y-coordinate out of range in "<<functionname<<" "<<y); \
55 #define CheckCoordinates(x,y,functionname)
62 #define CheckChannel(channel,functionname) \
63 if (channel >= GetChannelCount()) { \
64 BIASERR("channel"<<channel<<" out of range in "<<functionname); \
67 #define CheckChannel(channel,functionname)
72 inline bool ImageBase::SamePixelAndChannelCount(
const ImageBase& Image)
const {
73 return ( (GetPixelCount() == Image.GetPixelCount()) &&
74 (GetChannelCount() == Image.GetChannelCount()) );
77 inline bool ImageBase::NotBiggerPixelAndSameChannelCount(
const ImageBase& Image)
const {
78 return ( (GetPixelCount() <= Image.GetPixelCount()) &&
79 (GetChannelCount() == Image.GetChannelCount()) );
82 inline void ImageBase::SetZero()
85 memset(GetImageData(), 0, GetWidthStep()*GetHeight());
89 inline void ImageBase::ReleaseImageDataPointer()
91 delete[] (
char**)ImageDataArray_;
92 delete[] (
char*)ImageData_;
98 ImageBase::GetPixelPosition(
unsigned int x,
unsigned int y,
99 unsigned short int channel)
const
101 CheckCoordinates((
int)x, (
int)y,
"GetPixelPosition");
104 return y*Width_+x+channel*GetPixelCount();
106 return y*Width_*ChannelCount_ +x*(ChannelCount_)+channel;
109 bool ImageBase::IsPositionInImage(
const int& x,
const int& y)
const{
110 return (x>=0 && x<(
int)Width_ && y>=0 && y<(
int)Height_);
113 int ImageBase::MoveToClosestPositionInImage(
int& x,
int& y)
const {
115 if (!((Width_>0)&&(Height_>0))) {
116 BIASERR(
"Image is not initialiozed correctly: "<<Width_<<
"x"<<Height_);
124 }
else if (x>=(
int)Width_) {
131 }
else if (y>=(
int)Height_) {
140 inline void ImageBase::BIASToTextureCoordinates(
const double& biasx,
143 double& gl_y)
const {
145 BIASASSERT(Width_>0 && Height_>0);
146 gl_x = (biasx + 0.5) / double(Width_);
148 gl_y = (biasy + 0.5) / double(Height_);
167 inline void ImageBase::TextureToBIASCoordinates(
const double& gl_x,
170 double& biasy)
const {
172 BIASASSERT(Width_>0 && Height_>0);
173 biasx = gl_x * double(Width_) - 0.5;
174 biasy = double(Height_) - (gl_y * double(Height_) + 0.5);
177 static bool recursion =
true;
178 recursion = !recursion;
184 BIASToTextureCoordinates(biasx, biasy, gl_x2, gl_y2);
192 template<
class castType>
194 const unsigned int x,
195 const unsigned int y,
196 const unsigned int channel)
203 case ImageBase::ST_unsignedchar: {
205 return static_cast<castType
>(p[y][x*C+channel]);
208 case ImageBase::ST_float: {
210 return static_cast<castType
>(p[y][x*C+channel]);
213 #ifdef BUILD_IMAGE_DOUBLE
214 case ImageBase::ST_double: {
216 return static_cast<castType
>(p[y][x*C+channel]);
221 #ifdef BUILD_IMAGE_INT
222 case ImageBase::ST_int: {
224 return static_cast<castType
>(p[y][x*C+channel]);
228 #ifdef BUILD_IMAGE_UINT
229 case ImageBase::ST_unsignedint: {
231 return static_cast<castType
>(p[y][x*C+channel]);
235 #ifdef BUILD_IMAGE_SHORT
236 case ImageBase::ST_shortint: {
238 return static_cast<castType
>(p[y][x*C+channel]);
242 #ifdef BUILD_IMAGE_USHORT
243 case ImageBase::ST_unsignedshortint: {
245 return static_cast<castType
>(p[y][x*C+channel]);
249 #ifdef BUILD_IMAGE_CHAR // signed!
250 case ImageBase::ST_char: {
252 return static_cast<castType
>(p[y][x*C+channel]);
264 template<
class inputType>
266 const unsigned int x,
267 const unsigned int y,
268 const unsigned int channel,
276 case ImageBase::ST_unsignedchar: {
278 p[y][x*C+channel] =
static_cast<unsigned char>(val);
281 case ImageBase::ST_float: {
283 p[y][x*C+channel] =
static_cast<float>(val);
286 #ifdef BUILD_IMAGE_DOUBLE
287 case ImageBase::ST_double: {
289 p[y][x*C+channel] =
static_cast<double>(val);
294 #ifdef BUILD_IMAGE_INT
295 case ImageBase::ST_int: {
297 p[y][x*C+channel] =
static_cast<int>(val);
301 #ifdef BUILD_IMAGE_UINT
302 case ImageBase::ST_unsignedint: {
304 p[y][x*C+channel] =
static_cast<unsigned int>(val);
308 #ifdef BUILD_IMAGE_SHORT
309 case ImageBase::ST_shortint: {
311 p[y][x*C+channel] =
static_cast<short>(val);
315 #ifdef BUILD_IMAGE_USHORT
316 case ImageBase::ST_unsignedshortint: {
318 p[y][x*C+channel] =
static_cast<unsigned short>(val);
322 #ifdef BUILD_IMAGE_CHAR // signed!
323 case ImageBase::ST_char: {
325 p[y][x*C+channel] =
static_cast<char>(val);
338 template<
class inputType>
340 const unsigned int channelId,
341 const inputType* channelIn)
353 for(
unsigned int y=0; y<height; y++) {
354 for(
unsigned int x=0; x<width; x++) {
355 p[y][x*C+channelId] =
static_cast<unsigned char>(channelIn[y*width+x]);
362 for(
unsigned int y=0; y<height; y++) {
363 for(
unsigned int x=0; x<width; x++) {
364 p[y][x*C+channelId] =
static_cast<float>(channelIn[y*width+x]);
369 #ifdef BUILD_IMAGE_DOUBLE
372 for(
unsigned int y=0; y<height; y++) {
373 for(
unsigned int x=0; x<width; x++) {
374 p[y][x*C+channelId] =
static_cast<double>(channelIn[y*width+x]);
381 #ifdef BUILD_IMAGE_INT
384 for(
unsigned int y=0; y<height; y++) {
385 for(
unsigned int x=0; x<width; x++) {
386 p[y][x*C+channelId] =
static_cast<int>(channelIn[y*width+x]);
392 #ifdef BUILD_IMAGE_UINT
395 for(
unsigned int y=0; y<height; y++) {
396 for(
unsigned int x=0; x<width; x++) {
397 p[y][x*C+channelId] =
static_cast<unsigned int>(channelIn[y*width+x]);
404 #ifdef BUILD_IMAGE_SHORT
407 for(
unsigned int y=0; y<height; y++) {
408 for(
unsigned int x=0; x<width; x++) {
409 p[y][x*C+channelId] =
static_cast<short>(channelIn[y*width+x]);
415 #ifdef BUILD_IMAGE_USHORT
418 for(
unsigned int y=0; y<height; y++) {
419 for(
unsigned int x=0; x<width; x++) {
420 p[y][x*C+channelId] =
static_cast<unsigned short>(channelIn[y*width+x]);
426 #ifdef BUILD_IMAGE_CHAR // signed!
429 for(
unsigned int y=0; y<height; y++) {
430 for(
unsigned int x=0; x<width; x++) {
431 p[y][x*C+channelId] =
static_cast<char>(channelIn[y*width+x]);
447 template<
class outputType>
449 const unsigned int channelId,
450 outputType* channelOut)
461 for(
unsigned int y=0; y<height; y++) {
462 for(
unsigned int x=0; x<width; x++) {
463 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
467 unsigned char const *data =
reinterpret_cast<unsigned char const *
>(im.
GetImageData());
468 unsigned char const *start = &data[channelId * width * height];
469 unsigned char const *end = &data[(channelId + 1) * width * height];
470 std::copy(start, end, channelOut);
477 for(
unsigned int y=0; y<height; y++) {
478 for(
unsigned int x=0; x<width; x++) {
479 channelOut[y*width+x] = p[y][x*C+channelId];
483 float const *data =
reinterpret_cast<float const *
>(im.
GetImageData());
484 float const *start = &data[channelId * width * height];
485 float const *end = &data[(channelId + 1) * width * height];
486 std::copy(start, end, channelOut);
490 #ifdef BUILD_IMAGE_DOUBLE
494 for(
unsigned int y=0; y<height; y++) {
495 for(
unsigned int x=0; x<width; x++) {
496 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
500 double const *data =
reinterpret_cast<double const *
>(im.
GetImageData());
501 double const *start = &data[channelId * width * height];
502 double const *end = &data[(channelId + 1) * width * height];
503 std::copy(start, end, channelOut);
509 #ifdef BUILD_IMAGE_INT
513 for(
unsigned int y=0; y<height; y++) {
514 for(
unsigned int x=0; x<width; x++) {
515 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
519 int const *data =
reinterpret_cast<int const *
>(im.
GetImageData());
520 int const *start = &data[channelId * width * height];
521 int const *end = &data[(channelId + 1) * width * height];
522 std::copy(start, end, channelOut);
527 #ifdef BUILD_IMAGE_UINT
531 for(
unsigned int y=0; y<height; y++) {
532 for(
unsigned int x=0; x<width; x++) {
533 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
537 unsigned int const *data =
reinterpret_cast<unsigned int const *
>(im.
GetImageData());
538 unsigned int const *start = &data[channelId * width * height];
539 unsigned int const *end = &data[(channelId + 1) * width * height];
540 std::copy(start, end, channelOut);
546 #ifdef BUILD_IMAGE_SHORT
550 for(
unsigned int y=0; y<height; y++) {
551 for(
unsigned int x=0; x<width; x++) {
552 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
556 short const *data =
reinterpret_cast<short const *
>(im.
GetImageData());
557 short const *start = &data[channelId * width * height];
558 short const *end = &data[(channelId + 1) * width * height];
559 std::copy(start, end, channelOut);
564 #ifdef BUILD_IMAGE_USHORT
568 for(
unsigned int y=0; y<height; y++) {
569 for(
unsigned int x=0; x<width; x++) {
570 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
574 unsigned short const *data =
reinterpret_cast<unsigned short const *
>(im.
GetImageData());
575 unsigned short const *start = &data[channelId * width * height];
576 unsigned short const *end = &data[(channelId + 1) * width * height];
577 std::copy(start, end, channelOut);
582 #ifdef BUILD_IMAGE_CHAR // signed!
586 for(
unsigned int y=0; y<height; y++) {
587 for(
unsigned int x=0; x<width; x++) {
588 channelOut[y*width+x] =
static_cast<float>(p[y][x*C+channelId]);
592 char const *data =
reinterpret_cast<char const *
>(im.
GetImageData());
593 char const *start = &data[channelId * width * height];
594 char const *end = &data[(channelId + 1) * width * height];
595 std::copy(start, end, channelOut);
(16bit) unsigned integer image storage type
bool IsInterleaved() const
(8bit) signed char image storage type
double image storage type
unsigned int GetWidth() const
(16bit) signed integer image storage type
const void * GetImageData() const
void ** GetImageDataArray() const
Get an array of pointers to image data.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
(32bit) signed integer image storage type
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
This is the base class for images in BIAS.
(32bit) unsigned integer image storage type