aboutsummaryrefslogtreecommitdiff
path: root/src/image.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/image.h')
-rw-r--r--src/image.h44
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;
-}