From 9e7016e23471b7ba67598b5558c7fc7c528f1f2a Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 19 Feb 2021 17:28:33 +0100 Subject: Moved texture loading to `Bitmap` class. --- src/Bitmap.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/Bitmap.cpp') diff --git a/src/Bitmap.cpp b/src/Bitmap.cpp index 363145f..733eefe 100644 --- a/src/Bitmap.cpp +++ b/src/Bitmap.cpp @@ -1,13 +1,42 @@ #include "Bitmap.h" Bitmap::Bitmap(int width_, int height_) { + std::chrono::high_resolution_clock::time_point time1 = std::chrono::high_resolution_clock::now(); + width = width_; height = height_; pixels = new unsigned char[width * height * 4]; + image = nullptr; + + std::chrono::high_resolution_clock::time_point time2 = std::chrono::high_resolution_clock::now(); + loadingTime = std::chrono::duration_cast>(time2 - time1); +} + +Bitmap::Bitmap(std::string fileName) { + std::chrono::high_resolution_clock::time_point time1 = std::chrono::high_resolution_clock::now(); + + image = new sf::Image(); + isLoaded = image->loadFromFile(fileName); + if (isLoaded) { + width = image->getSize().x; + height = image->getSize().y; + pixels = (unsigned char*)image->getPixelsPtr(); + } + else { + width = 0; + height = 0; + pixels = nullptr; + } + + std::chrono::high_resolution_clock::time_point time2 = std::chrono::high_resolution_clock::now(); + loadingTime = std::chrono::duration_cast>(time2 - time1); } Bitmap::~Bitmap() { - delete[] pixels; + if (image == nullptr) + delete[] pixels; + else + delete image; } void Bitmap::fill(int r, int g, int b) { -- cgit v1.2.3