Мелкие исправления

This commit is contained in:
Евгений Титаренко 2024-04-01 18:55:57 +03:00
parent 4af1f2f4a0
commit 570986b499
2 changed files with 41 additions and 2 deletions

View file

@ -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;

View file

@ -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 &);
};