pathanimator/c++/image.cpp

54 lines
1.2 KiB
C++
Raw Normal View History

2022-01-17 15:53:17 +01:00
/// \file image.cpp
/// \copyright 2022 Sascha Nitsch
/// Licenced under MIT
/// \brief definition of the main class of the application
// system includes
#include <stdlib.h>
#include <string.h>
// own includes
#include "image.h"
Image::Image(uint16_t width, uint16_t height, uint8_t channels, uint8_t bits, void* pixels) {
m_width = width;
m_height = height;
m_channels = channels;
m_pixels = pixels;
m_ownPixel = false;
m_bitsPerChannel = bits;
}
Image::~Image() {
if (m_ownPixel && m_pixels) {
free(m_pixels);
}
}
bool Image::allocateMemory() {
if (m_ownPixel && m_pixels) {
free(m_pixels);
}
m_pixels = reinterpret_cast<uint8_t*>(malloc(m_width * m_height * m_channels * m_bitsPerChannel / 8));
bzero(m_pixels, m_width * m_height * m_channels * m_bitsPerChannel / 8);
if (m_pixels) {
m_ownPixel = true;
return true;
}
return false;
}
uint8_t* Image::getPixels8() const {
return reinterpret_cast<uint8_t*>(m_pixels);
}
uint16_t* Image::getPixels16() const {
return reinterpret_cast<uint16_t*>(m_pixels);
}
uint16_t Image::getHeight() const {
return m_height;
}
uint16_t Image::getWidth() const {
return m_width;
}