From c4edc9359dd6cfb0836d0d370fe008f308bc0156 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 24 Apr 2013 16:50:02 +0100 Subject: uuencode functionality in place --- rotord/Pixels.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 rotord/Pixels.cpp (limited to 'rotord/Pixels.cpp') diff --git a/rotord/Pixels.cpp b/rotord/Pixels.cpp new file mode 100644 index 0000000..eef86c9 --- /dev/null +++ b/rotord/Pixels.cpp @@ -0,0 +1,87 @@ +#include "Pixels.h" + +Pixels::~Pixels(){ + clear(); +} +void Pixels::allocate(int w, int h, int _channels){ + if (w < 0 || h < 0) { + return; + } + + //we check if we are already allocated at the right size + if(bAllocated && w == width && h == height && channels ==_channels){ + return; //we don't need to allocate + } + + //we do need to allocate, clear the data + clear(); + + channels = _channels; + width= w; + height = h; + + pixels = new uint8_t[w * h * channels]; + bAllocated = true; + pixelsOwner = true; +} +void Pixels::clear(){ + if(pixels){ + if(pixelsOwner) delete[] pixels; + pixels = nullptr; + } + + width = 0; + height = 0; + channels = 0; + bAllocated = false; +} +bool Pixels::isAllocated() const{ + return bAllocated; +} + +void Pixels::setFromExternalPixels(uint8_t * newPixels,int w, int h, int _channels){ + clear(); + channels = _channels; + width= w; + height = h; + + pixels = newPixels; + pixelsOwner = false; + bAllocated = true; +} + +uint8_t * Pixels::getPixels(){ + return &pixels[0]; +} + +int Pixels::getWidth() const{ + return width; +} + +int Pixels::getHeight() const{ + return height; +} + +int Pixels::getBytesPerPixel() const{ + return channels; +} + +int Pixels::getNumChannels() const{ + return channels; +} + +void Pixels::swap(Pixels & pix){ + std::swap(pixels,pix.pixels); + std::swap(width, pix.width); + std::swap(height,pix.height); + std::swap(channels,pix.channels); + std::swap(pixelsOwner, pix.pixelsOwner); + std::swap(bAllocated, pix.bAllocated); +} + +void Pixels::set(uint8_t val){ + int size = width * height * channels; + for(int i = 0; i < size; i++){ + pixels[i] = val; + } +} \ No newline at end of file -- cgit v1.2.3