2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstring>
|
2013-08-03 23:24:22 +02:00
|
|
|
#include <vector>
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
// Local includes
|
|
|
|
#include "RgbColor.h"
|
|
|
|
|
|
|
|
class RgbImage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
RgbImage(const unsigned width, const unsigned height, const RgbColor background = RgbColor::BLACK);
|
|
|
|
|
|
|
|
~RgbImage();
|
|
|
|
|
|
|
|
inline unsigned width() const
|
|
|
|
{
|
|
|
|
return mWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned height() const
|
|
|
|
{
|
|
|
|
return mHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPixel(const unsigned x, const unsigned y, const RgbColor color);
|
|
|
|
|
|
|
|
const RgbColor& operator()(const unsigned x, const unsigned y) const;
|
|
|
|
|
|
|
|
RgbColor& operator()(const unsigned x, const unsigned y);
|
|
|
|
|
|
|
|
inline void copy(const RgbImage& other)
|
|
|
|
{
|
|
|
|
assert(other.mWidth == mWidth);
|
|
|
|
assert(other.mHeight == mHeight);
|
|
|
|
|
|
|
|
memcpy(mColors, other.mColors, mWidth*mHeight*sizeof(RgbColor));
|
|
|
|
}
|
|
|
|
|
2013-08-03 23:24:22 +02:00
|
|
|
RgbColor* memptr()
|
2013-07-26 22:38:34 +02:00
|
|
|
{
|
2013-08-03 23:24:22 +02:00
|
|
|
return mColors;
|
2013-07-26 22:38:34 +02:00
|
|
|
}
|
|
|
|
|
2013-08-14 17:02:09 +02:00
|
|
|
const RgbColor* memptr() const
|
|
|
|
{
|
|
|
|
return mColors;
|
|
|
|
}
|
2013-08-03 23:24:22 +02:00
|
|
|
private:
|
2013-08-02 11:54:09 +02:00
|
|
|
|
2013-08-03 23:24:22 +02:00
|
|
|
inline unsigned toIndex(const unsigned x, const unsigned y) const
|
2013-08-02 11:54:09 +02:00
|
|
|
{
|
2013-08-03 23:24:22 +02:00
|
|
|
return y*mWidth + x;
|
2013-08-02 11:54:09 +02:00
|
|
|
}
|
|
|
|
|
2013-07-26 22:38:34 +02:00
|
|
|
private:
|
2013-08-03 23:24:22 +02:00
|
|
|
const unsigned mWidth;
|
|
|
|
const unsigned mHeight;
|
2013-07-26 22:38:34 +02:00
|
|
|
|
|
|
|
/** The colors of the image */
|
|
|
|
RgbColor* mColors;
|
|
|
|
};
|