diff options
| author | Dylan <boss@tehbox.org> | 2025-08-08 15:22:35 +1200 |
|---|---|---|
| committer | Dylan <boss@tehbox.org> | 2025-08-08 15:38:59 +1200 |
| commit | 41ddbec10d11b01ccc10bf7e1dc862a9f3e4c85f (patch) | |
| tree | c4775a629588419803320818fc1458f6d35e8ae8 /src/image.h | |
| parent | 5823a8dff5c6c565c9b253b122d2baeb767b72e2 (diff) | |
| download | tehimage-41ddbec10d11b01ccc10bf7e1dc862a9f3e4c85f.tar.gz tehimage-41ddbec10d11b01ccc10bf7e1dc862a9f3e4c85f.zip | |
feat: Simplified APIv0.0.1
Had to restrict images to 8 bit depth sadly
This could potentially be changed in the future by setting bit depth
with templates and changing the data to be the specified bit depth
Diffstat (limited to 'src/image.h')
| -rw-r--r-- | src/image.h | 44 |
1 files changed, 3 insertions, 41 deletions
diff --git a/src/image.h b/src/image.h index be26437..7a7ba31 100644 --- a/src/image.h +++ b/src/image.h @@ -5,17 +5,15 @@ #include <memory> #include <string> -template <typename T> struct Pixel { - T r, g, b, a; + uint8_t r, g, b, a; }; - class Image { protected: - std::unique_ptr<uint8_t[]> imageData; + std::unique_ptr<Pixel[]> pixels; // uint8_t* imageData; uint8_t colorValues; uint8_t bpp; @@ -28,8 +26,7 @@ public: virtual int readFromFile(std::string filename) = 0; virtual int writeToFile(std::string filename) = 0; - template <typename T = uint8_t> - Pixel<T> getPixel(unsigned int x, unsigned int y); + Pixel& operator[](int x, int y); uint32_t width = 0; uint32_t height = 0; @@ -39,38 +36,3 @@ public: uint8_t filterMethod; uint8_t interlaceMethod; }; - - -template <typename T> -Pixel<T> Image::getPixel(unsigned int x, unsigned int y) -{ - Pixel<T> pixel; - - if(sizeof(T)*8 == bitDepth) - { - unsigned long rIndex = y * width * colorValues + x * colorValues; - pixel.r = ((T*)imageData.get())[rIndex]; - pixel.g = ((T*)imageData.get())[rIndex + 1]; - pixel.b = ((T*)imageData.get())[rIndex + 2]; - - if(colorValues == 4) - pixel.a = ((T*)imageData.get())[rIndex + 3]; - else - pixel.a = 0; - } - else - { - unsigned long startIndex = y * width * colorValues * bitDepth/8 + x * colorValues * bitDepth/8; - - uint32_t pixelData[4]; - int tsize = sizeof(T); - int bytesToTake = std::min(tsize, bitDepth/8); - for(int i = 0; i < colorValues; i++) - { - for(int j = 0; j < bytesToTake; j++) - pixelData[i] += imageData[startIndex++] << (bitDepth - j*8 - 8); - startIndex += bitDepth/8 - bytesToTake; - } - } - return pixel; -} |
