#include <cimg_fb.hpp>

gb::cimg_framebuffer::cimg_framebuffer(const char* filename, unsigned int x, unsigned int y)
    : m_filename(filename),
      m_image(x, y, 1, 3),
      m_dimx(x),
      m_dimy(y)
{
}

gb::cimg_framebuffer::~cimg_framebuffer(void)
{
    save_image();
}

unsigned int gb::cimg_framebuffer::dimx(void) const
{
    return m_dimx;
}

unsigned int gb::cimg_framebuffer::dimy(void) const
{
    return m_dimy;
}

void gb::cimg_framebuffer::save_image(void) const
{
    m_image.save_bmp(m_filename.c_str());
}

void gb::cimg_framebuffer::set_pixel(const glm::vec<4, int>& pos, const glm::vec<3, unsigned char>& color)
{
    m_image(pos.x, pos.y, 0, 0) = color.r;
    m_image(pos.x, pos.y, 0, 1) = color.g;
    m_image(pos.x, pos.y, 0, 2) = color.b;
}
