/// \file image.cpp /// \copyright 2022 Sascha Nitsch /// Licenced under MIT /// \brief definition of the main class of the application // system includes #include #include // 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(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(m_pixels); } uint16_t* Image::getPixels16() const { return reinterpret_cast(m_pixels); } uint16_t Image::getHeight() const { return m_height; } uint16_t Image::getWidth() const { return m_width; }