#include <PixelMap/PixelMap.hpp>
#include <Utilities/Extern.hpp>

PixelMap::PixelMap(int width, int height, Pixel background) :
    width(width),
    height(height),
    pixels(width * height, background)
{}

PixelMap::Pixel& PixelMap::at(int x, int y)
{
    return pixels[y * width + x];
}

void PixelMap::fillRect(int x, int y, int width, int height, Pixel pixel)
{
    for (int plotY=y; plotY<y+height; plotY++)
    {
        Pixel *plotter = &at(x, plotY);
        for (int i=0; i<width; i++)
        {
            *plotter++ = pixel;
        }
    }
}

void PixelMap::writePNG(std::string path)
{
    stbi_write_png(path.c_str(), width, height, 4, pixels.data(), 4 * width);
}