61 lines
1.1 KiB
C++
61 lines
1.1 KiB
C++
#include "Image.hpp"
|
|
|
|
#include "Color.hpp"
|
|
|
|
#include <cstring>
|
|
#include <stdint.h>
|
|
|
|
|
|
namespace frame
|
|
{
|
|
|
|
Image::Image(uint32_t pWidth, uint32_t pHeight)
|
|
: mWidth(pWidth)
|
|
, mHeight(pHeight)
|
|
, mBuffer(mWidth * mHeight, 0)
|
|
{
|
|
}
|
|
|
|
Image::Image(Size size)
|
|
: Image(size.width, size.height)
|
|
{
|
|
}
|
|
|
|
void Image::Create(uint32_t pWidth, uint32_t pHeight)
|
|
{
|
|
mWidth = pWidth;
|
|
mHeight = pHeight;
|
|
|
|
mBuffer.clear();
|
|
mBuffer.resize(mWidth * mHeight);
|
|
}
|
|
|
|
uint8_t& Image::at(uint32_t x, uint32_t y)
|
|
{
|
|
return mBuffer.at(toInternal(x, y));
|
|
}
|
|
|
|
uint8_t const& Image::at(uint32_t x, uint32_t y) const
|
|
{
|
|
return mBuffer.at(toInternal(x, y));
|
|
}
|
|
|
|
void Image::Clear(Color color)
|
|
{
|
|
memset(mBuffer.data(), color, mBuffer.size());
|
|
}
|
|
|
|
void Image::operator=(Image const& image)
|
|
{
|
|
mHeight = image.mHeight;
|
|
mWidth = image.mWidth;
|
|
mBuffer = image.mBuffer;
|
|
}
|
|
|
|
size_t Image::toInternal(uint32_t x, uint32_t y) const
|
|
{
|
|
return x + mWidth * y;
|
|
}
|
|
|
|
} // namespace frame
|