diff options
| author | Comment <tim@gray.(none)> | 2013-07-26 22:46:17 +0100 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-07-26 22:46:17 +0100 |
| commit | f4170d6bfb763ad0af4002277a37dcd1692534d5 (patch) | |
| tree | db32d9753de780063e3afeb64764e13e5c4f5087 /rotord/src/Pixels.cpp | |
| parent | 3d7eea02aa7a155b84c8c74ecbfd55a1941a9297 (diff) | |
tidy files
Diffstat (limited to 'rotord/src/Pixels.cpp')
| -rw-r--r-- | rotord/src/Pixels.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/rotord/src/Pixels.cpp b/rotord/src/Pixels.cpp new file mode 100644 index 0000000..78f4bbb --- /dev/null +++ b/rotord/src/Pixels.cpp @@ -0,0 +1,90 @@ +#include "Pixels.h" +Pixels::Pixels(){ + pixels=nullptr; + pixelsOwner=false; +} +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 |
