aboutsummaryrefslogtreecommitdiff
path: root/src/Bitmap.cpp
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-02-19 17:28:33 +0100
committerMateja <mail@matejamaric.com>2021-02-19 17:28:33 +0100
commit9e7016e23471b7ba67598b5558c7fc7c528f1f2a (patch)
tree693b9a7fe468e8df1f431b3b5c33971f1a996764 /src/Bitmap.cpp
parent3b89cf20f583a82a3cd5bdbe04c07630838af5c3 (diff)
downloaderender-9e7016e23471b7ba67598b5558c7fc7c528f1f2a.tar.gz
erender-9e7016e23471b7ba67598b5558c7fc7c528f1f2a.zip
Moved texture loading to `Bitmap` class.
Diffstat (limited to 'src/Bitmap.cpp')
-rw-r--r--src/Bitmap.cpp31
1 files changed, 30 insertions, 1 deletions
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<std::chrono::duration<double>>(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<std::chrono::duration<double>>(time2 - time1);
}
Bitmap::~Bitmap() {
- delete[] pixels;
+ if (image == nullptr)
+ delete[] pixels;
+ else
+ delete image;
}
void Bitmap::fill(int r, int g, int b) {