aboutsummaryrefslogtreecommitdiff
path: root/source/Bitmap.cpp
diff options
context:
space:
mode:
authorMatejaMaric <matejamaricz@gmail.com>2019-07-09 00:26:42 +0200
committerMatejaMaric <matejamaricz@gmail.com>2019-07-09 00:26:42 +0200
commita7c9aeee1e68235af406e30654e4b2e5f0f7fda2 (patch)
tree492e4860bf17d196b5a79a83004aec217e69cf1e /source/Bitmap.cpp
downloaderender-a7c9aeee1e68235af406e30654e4b2e5f0f7fda2.tar.gz
erender-a7c9aeee1e68235af406e30654e4b2e5f0f7fda2.zip
First commit
Diffstat (limited to 'source/Bitmap.cpp')
-rw-r--r--source/Bitmap.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/Bitmap.cpp b/source/Bitmap.cpp
new file mode 100644
index 0000000..363145f
--- /dev/null
+++ b/source/Bitmap.cpp
@@ -0,0 +1,34 @@
+#include "Bitmap.h"
+
+Bitmap::Bitmap(int width_, int height_) {
+ width = width_;
+ height = height_;
+ pixels = new unsigned char[width * height * 4];
+}
+
+Bitmap::~Bitmap() {
+ delete[] pixels;
+}
+
+void Bitmap::fill(int r, int g, int b) {
+ for (int i = 0; i < width * height * 4; i+=4)
+ {
+ pixels[i + 0] = r;
+ pixels[i + 1] = g;
+ pixels[i + 2] = b;
+ pixels[i + 3] = 255;
+ }
+}
+
+void Bitmap::setPixel(int x, int y, int r, int g, int b) {
+ int hlp = ((y * width) + x) * 4;
+ if (!(hlp < 0 || hlp >(width * height * 4) - 3)) {
+ pixels[hlp + 0] = r;
+ pixels[hlp + 1] = g;
+ pixels[hlp + 2] = b;
+ pixels[hlp + 3] = 255;
+ }
+ else {
+ std::cout << "Position of pixel:\t" << hlp << "\tX: " << x << "\tY: "<< y << "\n";
+ }
+}