aboutsummaryrefslogtreecommitdiff
path: root/src/image.h
diff options
context:
space:
mode:
authorBossCode45 <boss@tehbox.org>2025-06-27 17:58:36 +1200
committerBossCode45 <boss@tehbox.org>2025-07-24 12:48:21 +1200
commit078b4e08fe3bccb7424dac76e158bf8bf48a182d (patch)
treea4f84f3fc346053c1c41990be4cc0867ab206cf5 /src/image.h
parenteed164fa72297efb69b624f3c58cb5deb339a974 (diff)
downloadtehimage-078b4e08fe3bccb7424dac76e158bf8bf48a182d.tar.gz
tehimage-078b4e08fe3bccb7424dac76e158bf8bf48a182d.zip
feat: Made it so that you can now convert between image subclasses
Also added the bitmap image subclass note: this is pretty hacky in how it works
Diffstat (limited to 'src/image.h')
-rw-r--r--src/image.h43
1 files changed, 39 insertions, 4 deletions
diff --git a/src/image.h b/src/image.h
index f4071ea..52f4279 100644
--- a/src/image.h
+++ b/src/image.h
@@ -1,7 +1,8 @@
#pragma once
-#include <cstddef>
#include <cstdint>
+#include <cstring>
+#include <string>
template <typename T>
struct Pixel
@@ -9,6 +10,14 @@ struct Pixel
T r, g, b, a;
};
+struct ImageData
+{
+
+
+
+
+ //unsigned long imageDataSize = 0;
+};
class Image
{
@@ -19,7 +28,16 @@ protected:
public:
Image() = default;
~Image();
+
+ template<std::derived_from<Image> T>
+ Image(const T& other);
+
+ virtual int readFromFile(std::string filename) = 0;
+ virtual int writeToFile(std::string filename) = 0;
+ template <typename T>
+ Pixel<T> getPixel(unsigned int x, unsigned int y);
+
uint32_t width = 0;
uint32_t height = 0;
uint8_t bitDepth;
@@ -27,12 +45,29 @@ public:
uint8_t compressionMethod;
uint8_t filterMethod;
uint8_t interlaceMethod;
-
- template <typename T>
- Pixel<T> getPixel(unsigned int x, unsigned int y);
};
+
+template<std::derived_from<Image> T> Image::Image(const T& other)
+{
+ this->colorValues = other.colorValues;
+ this->bpp = other.bpp;
+
+ this->width = other.width;
+ this->height = other.height;
+ this->bitDepth = other.bitDepth;
+ this->colorType = other.colorType;
+ this->compressionMethod = other.compressionMethod;
+ this->filterMethod = other.filterMethod;
+ this->interlaceMethod = other.interlaceMethod;
+
+ unsigned long imageDataSize = width * height * bpp;
+ imageData = new uint8_t[imageDataSize];
+ mempcpy(imageData, other.imageData, imageDataSize);
+}
+
+
template <typename T>
Pixel<T> Image::getPixel(unsigned int x, unsigned int y)
{