diff --git a/bmpimage.cpp b/bmpimage.cpp index 87e9565..fe29d54 100644 --- a/bmpimage.cpp +++ b/bmpimage.cpp @@ -1,6 +1,6 @@ #include "bmpimage.h" -BMPImage::BMPImage(BitmapFileHeader &fileHeader, BITMAPINFOHEADER &infoHeader, Pixel **pixelArray) { +BMPImage::BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, Pixel **pixelArray) { this->fileHeader = fileHeader; this->infoHeader = infoHeader; this->pixelArray = pixelArray; @@ -24,6 +24,35 @@ void BMPImage::write(const std::string &filename) { } } + Pixel **BMPImage::pixels(){ + return this->pixelArray; +} + +Pixel **BMPImage::pixels_copy() { + Pixel **newPixelArray; + newPixelArray = new Pixel *[this->infoHeader.BitmapHeight]; + for (int i = 0; i < this->infoHeader.BitmapHeight; ++i) { + newPixelArray[i] = new Pixel[this->infoHeader.BitmapWidth]; + std::copy(this->pixelArray[i], this->pixelArray[i] + this->infoHeader.BitmapWidth, newPixelArray[i]); + } + return newPixelArray; +} + +BitmapFileHeader BMPImage::fileHeader_copy() { + return this->fileHeader; +} + +BITMAPINFOHEADER BMPImage::infoHeader_copy() { + return this->infoHeader; +} + +BMPImage::~BMPImage() { + for (int i = 0; i < this->infoHeader.BitmapHeight; ++i) { + delete[] this->pixelArray[i]; + } + delete[] this->pixelArray; +} + BMPImage readBMPImage(const std::string &filename) { BitmapFileHeader bitmapFileHeader; BITMAPINFOHEADER bitmapInfoHeader; diff --git a/bmpimage.h b/bmpimage.h index 468cf98..fa3bf76 100644 --- a/bmpimage.h +++ b/bmpimage.h @@ -45,12 +45,22 @@ class BMPImage { BITMAPINFOHEADER infoHeader; Pixel **pixelArray; public: - BMPImage(BitmapFileHeader &fileHeader, BITMAPINFOHEADER &infoHeader, Pixel **pixelArray); + BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, Pixel **pixelArray); + + ~BMPImage(); [[nodiscard]] const uint32_t &width() const; [[nodiscard]] const uint32_t &height() const; + [[nodiscard]] Pixel **pixels(); + + [[nodiscard]] Pixel **pixels_copy(); + + [[nodiscard]] BitmapFileHeader fileHeader_copy(); + + [[nodiscard]] BITMAPINFOHEADER infoHeader_copy(); + void write(const std::string &); };