From 41ddbec10d11b01ccc10bf7e1dc862a9f3e4c85f Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 8 Aug 2025 15:22:35 +1200 Subject: feat: Simplified API 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 --- src/image.h | 44 +++----------------------------------------- 1 file changed, 3 insertions(+), 41 deletions(-) (limited to 'src/image.h') 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 #include -template struct Pixel { - T r, g, b, a; + uint8_t r, g, b, a; }; - class Image { protected: - std::unique_ptr imageData; + std::unique_ptr 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 - Pixel 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 -Pixel Image::getPixel(unsigned int x, unsigned int y) -{ - Pixel 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; -} -- cgit v1.2.3