Newer
Older
Import / research / signals-slots / src / gui / image.cpp
@John John on 29 Dec 2020 880 bytes bulk import from macbookpro checkouts
#include <image.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


Image::Image()
    : w(0), h(0), stride(0), f(Format_Invalid), data(0), ownBits(true)
{
}


Image::Image(int _w, int _h, PixelFormat _fmt)
{
    init(_w, _h, _fmt);
}


Image::Image(int _w, int _h, unsigned char *b, PixelFormat fmt, int s)
    : w(_w), h(_h), f(fmt), data(b), stride(s), ownBits(false)
{
}


Image::~Image()
{
    if (ownBits)
        delete data;
}


void Image::init(int _w, int _h, PixelFormat _fmt)
{
    w = _w;
    h = _h;
    f = _fmt;
    ownBits = true;
    stride = w * FORMAT_BITS_PER_PIXEL(f) / 8;
    data = new unsigned char[h * stride];
}


void Image::fill(int col)
{
    unsigned char *dest = data;
    for (int j = 0; j < h; j++) {
        unsigned int *out = (unsigned int *)dest;
	for (int i = 0; i < w; i++) 
	    *out++ = col;
        dest += stride;
    }
}