Added Read method

This commit is contained in:
Leonetienne
2022-03-05 22:00:57 +01:00
parent 33932906c4
commit 808738ac2e
9 changed files with 277 additions and 17 deletions

View File

@@ -1,8 +1,7 @@
#include "BMP.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include "BmpWriter.h"
#include "BmpReader.h"
#define CHECK_IF_INITIALIZED if (!isInitialized) throw std::runtime_error("Image not initialized!");
@@ -13,6 +12,14 @@ namespace Leonetienne::BmpPP {
return;
}
BMP::BMP(const std::string &filename) {
if(!Read(filename))
throw std::runtime_error("Unable to read bmp image!");
return;
}
BMP::BMP(const Eule::Vector2i &size, const Colormode& colormode)
:
size { size },
@@ -57,17 +64,7 @@ namespace Leonetienne::BmpPP {
}
bool BMP::Read(const std::string &filename) {
std::ifstream ifs(filename, std::ifstream::binary);
if (!ifs.good())
return false;
// When reading the image, we don't care about most of the header.
// All we want is the images resolutions, bits-per-pixel, and pixelbuffer address...
// This is because we do not support ALL of bmp, but just the most common formats...
return true;
return BmpReader::Read(*this, filename);
}
std::uint8_t *BMP::GetPixel(const Eule::Vector2i &position) {