From f146826ff9c107053f82fc4981da17639763231b Mon Sep 17 00:00:00 2001 From: Leonetienne Date: Sat, 5 Mar 2022 19:51:57 +0100 Subject: [PATCH] Added a re-initialize method --- Src/BMP.cpp | 21 +++++++++++++++++++++ Src/BMP.h | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/Src/BMP.cpp b/Src/BMP.cpp index 340b9f3..35ca8f9 100644 --- a/Src/BMP.cpp +++ b/Src/BMP.cpp @@ -11,7 +11,28 @@ namespace Leonetienne::BmpPP { size { size }, colormode { colormode } { + ReInitialize(size, colormode); + return; + } + + void BMP::ReInitialize(const Eule::Vector2i &size) { + // Carry over new attributes + this->size = size; + + // Re-initialize the pixelbuffer + pixelBuffer.clear(); + pixelBuffer.resize(size.x * size.y * GetNumColorChannels()); + + return; + } + + void BMP::ReInitialize(const Eule::Vector2i &size, const Colormode &colormode) { + // Carry over new attributes + this->size = size; + this->colormode = colormode; + + // Re-initialize the pixelbuffer pixelBuffer.clear(); pixelBuffer.resize(size.x * size.y * GetNumColorChannels()); diff --git a/Src/BMP.h b/Src/BMP.h index e9f47ab..c7318df 100644 --- a/Src/BMP.h +++ b/Src/BMP.h @@ -24,6 +24,12 @@ namespace Leonetienne::BmpPP { //! Will set the color of a pixel at a given position void SetPixel(const Eule::Vector2i& position, const std::uint8_t r, const std::uint8_t g, const std::uint8_t b, const std::uint8_t a = 0xFF); + //! Will basically reconstruct this image, to fit a new resolution + void ReInitialize(const Eule::Vector2i& size); + + //! Will basically reconstruct this image, to fit a new resolution and new format + void ReInitialize(const Eule::Vector2i& size, const Colormode& colormode); + //! Will return a pointer to the raw pixel data std::uint8_t* data();