2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
// hyperion Utils includes
|
|
|
|
#include <utils/RgbImage.h>
|
|
|
|
|
|
|
|
|
|
|
|
RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) :
|
2013-09-09 04:54:13 +02:00
|
|
|
_width(width),
|
|
|
|
_height(height),
|
2013-08-03 23:24:22 +02:00
|
|
|
mColors(new RgbColor[width*height])
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-03 23:24:22 +02:00
|
|
|
for (unsigned i=0; i<width*height; ++i)
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-03 23:24:22 +02:00
|
|
|
mColors[i] = background;
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbImage::~RgbImage()
|
|
|
|
{
|
|
|
|
delete[] mColors;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RgbImage::setPixel(const unsigned x, const unsigned y, const RgbColor color)
|
|
|
|
{
|
|
|
|
// Debug-mode sanity check on given index
|
|
|
|
(*this)(x,y) = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RgbColor& RgbImage::operator()(const unsigned x, const unsigned y) const
|
|
|
|
{
|
|
|
|
// Debug-mode sanity check on given index
|
2013-09-09 04:54:13 +02:00
|
|
|
assert(x < _width);
|
|
|
|
assert(y < _height);
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
const unsigned index = toIndex(x, y);
|
|
|
|
return mColors[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbColor& RgbImage::operator()(const unsigned x, const unsigned y)
|
|
|
|
{
|
|
|
|
// Debug-mode sanity check on given index
|
2013-09-09 04:54:13 +02:00
|
|
|
assert(x < _width);
|
|
|
|
assert(y < _height);
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
const unsigned index = toIndex(x, y);
|
|
|
|
return mColors[index];
|
|
|
|
}
|