aboutsummaryrefslogtreecommitdiff
path: root/src/image.h
diff options
context:
space:
mode:
authorBossCode45 <boss@tehbox.org>2025-06-27 14:54:46 +1200
committerBossCode45 <boss@tehbox.org>2025-07-24 12:48:21 +1200
commitf953c730af2b90db99f709258c5d5e50fdcaadf7 (patch)
treeadbc79f0d48a74a42fd0eb22d85f03696a99dc42 /src/image.h
parent06a2928d96b3d9aeaffb19013ba71a5cb6d96381 (diff)
downloadtehimage-f953c730af2b90db99f709258c5d5e50fdcaadf7.tar.gz
tehimage-f953c730af2b90db99f709258c5d5e50fdcaadf7.zip
Initial commit
Bringing a lot of stuff over from my maze-reader project in an attempt to split the image reading code off into a library.
Diffstat (limited to 'src/image.h')
-rw-r--r--src/image.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/image.h b/src/image.h
new file mode 100644
index 0000000..f4071ea
--- /dev/null
+++ b/src/image.h
@@ -0,0 +1,51 @@
+#pragma once
+
+#include <cstddef>
+#include <cstdint>
+
+template <typename T>
+struct Pixel
+{
+ T r, g, b, a;
+};
+
+
+class Image
+{
+protected:
+ uint8_t* imageData;
+ uint8_t colorValues;
+ uint8_t bpp;
+public:
+ Image() = default;
+ ~Image();
+
+ uint32_t width = 0;
+ uint32_t height = 0;
+ uint8_t bitDepth;
+ uint8_t colorType;
+ uint8_t compressionMethod;
+ uint8_t filterMethod;
+ uint8_t interlaceMethod;
+
+ template <typename T>
+ Pixel<T> getPixel(unsigned int x, unsigned int y);
+};
+
+
+template <typename T>
+Pixel<T> Image::getPixel(unsigned int x, unsigned int y)
+{
+ Pixel<T> pixel;
+
+ pixel.r = (T)imageData[y * width * colorValues * bitDepth/8 + x * colorValues * bitDepth/8];
+ pixel.g = (T)imageData[y * width * colorValues * bitDepth/8 + x * colorValues * bitDepth/8 + 1];
+ pixel.b = (T)imageData[y * width * colorValues * bitDepth/8 + x * colorValues * bitDepth/8 + 2];
+
+ if(colorValues == 4)
+ pixel.a = imageData[y * width * colorValues * bitDepth/8 + x * colorValues * bitDepth/8 + 3];
+ else
+ pixel.a = 0;
+
+ return pixel;
+}