From 64403633d5c35b39a5eb106aea1d7accd398ee34 Mon Sep 17 00:00:00 2001 From: Jeroen Vlek Date: Thu, 7 Mar 2013 18:56:52 +0100 Subject: [PATCH] Fixed pixel type and made it more flexible --- Image.cpp | 2 +- Image.h | 4 ++-- ImageCompare.cpp | 6 +++--- ImageImp.h | 4 ++-- Pixel.h | 19 +++++++++++++++++++ QtEvoPic.pro | 2 +- QtImageImp.cpp | 4 ++-- QtImageImp.h | 4 ++-- RGBA32.h | 17 ----------------- 9 files changed, 32 insertions(+), 30 deletions(-) create mode 100644 Pixel.h delete mode 100644 RGBA32.h diff --git a/Image.cpp b/Image.cpp index 7e54b3e..6e1b96e 100644 --- a/Image.cpp +++ b/Image.cpp @@ -47,7 +47,7 @@ void Image::loadFromFile(const std::string& filename) std::cout << "[ Image::loadFromFile() ] Only TargetImage can load file: " << filename << std::endl; } -const RGBA32* Image::get(unsigned int x, unsigned int y) +const PIXEL* Image::get(unsigned int x, unsigned int y) { return m_imp->get(x,y); } diff --git a/Image.h b/Image.h index 45f0b15..5de61dc 100644 --- a/Image.h +++ b/Image.h @@ -16,7 +16,7 @@ #include "Gene.h" #include "ImageImp.h" -#include "RGBA32.h" +#include "Pixel.h" #include @@ -53,7 +53,7 @@ class Image /** * @return The pixel at location (x,y) */ - const RGBA32* get(unsigned int x, unsigned int y); + const PIXEL* get(unsigned int x, unsigned int y); protected: /** diff --git a/ImageCompare.cpp b/ImageCompare.cpp index d0b645d..6a7d8ed 100644 --- a/ImageCompare.cpp +++ b/ImageCompare.cpp @@ -6,7 +6,7 @@ */ #include "ImageCompare.h" -#include "RGBA32.h" +#include "Pixel.h" #include #include @@ -31,8 +31,8 @@ double ImageCompare::compare(Image& a, Image& b) unsigned int totalPixels = 0; for(unsigned int x = 0; x < a.getWidth(); ++x) { for(unsigned int y = 0; y < a.getHeight(); ++y) { - const RGBA32* pixelA = a.get(x, y); - const RGBA32* pixelB = b.get(x, y); + const PIXEL* pixelA = a.get(x, y); + const PIXEL* pixelB = b.get(x, y); int diffR = (int) pixelA->r - (int) pixelB->r; diffR *= diffR; diff --git a/ImageImp.h b/ImageImp.h index b0c7ae7..123da45 100644 --- a/ImageImp.h +++ b/ImageImp.h @@ -15,7 +15,7 @@ #define IMAGEIMP_H_ #include "Gene.h" -#include "RGBA32.h" +#include "Pixel.h" #include @@ -57,7 +57,7 @@ class ImageImp /** * @return The pixel at location (x,y) */ - virtual const RGBA32* get(unsigned int x, unsigned int y) =0; + virtual const PIXEL* get(unsigned int x, unsigned int y) =0; protected: diff --git a/Pixel.h b/Pixel.h new file mode 100644 index 0000000..2f98c2e --- /dev/null +++ b/Pixel.h @@ -0,0 +1,19 @@ +/* + * Pixel.h + * + * Created on: Jan 22, 2012 + * Author: jvlek + */ + +#ifndef PIXEL_H_ +#define PIXEL_H_ + +struct ARGB32 +{ + unsigned char b, g, r, a; +}; + +#define PIXEL ARGB32 + + +#endif /* PIXEL_H_ */ diff --git a/QtEvoPic.pro b/QtEvoPic.pro index 0c3abc8..84609f9 100644 --- a/QtEvoPic.pro +++ b/QtEvoPic.pro @@ -5,7 +5,7 @@ TARGET = QtEvoPic QT += core \ gui HEADERS += PairGenerator.h \ - RGBA32.h \ + Pixel.h \ ImageCompare.h \ QtEvoPic.h \ GUI.h \ diff --git a/QtImageImp.cpp b/QtImageImp.cpp index 93ef211..8fefeca 100644 --- a/QtImageImp.cpp +++ b/QtImageImp.cpp @@ -68,10 +68,10 @@ unsigned int QtImageImp::getHeight() return height(); } -const RGBA32* QtImageImp::get(unsigned int x, unsigned int y) +const PIXEL* QtImageImp::get(unsigned int x, unsigned int y) { const unsigned char* pixel = scanLine(y) + (x * 4); - return (const RGBA32*) pixel; + return (const PIXEL*) pixel; } void QtImageImp::clear() diff --git a/QtImageImp.h b/QtImageImp.h index 61cd770..4acd7ab 100644 --- a/QtImageImp.h +++ b/QtImageImp.h @@ -16,7 +16,7 @@ #include "Gene.h" #include "ImageImp.h" -#include "RGBA32.h" +#include "Pixel.h" #include #include @@ -36,7 +36,7 @@ class QtImageImp: public ImageImp, public QImage void loadFromFile(const std::string& filename); - const RGBA32* get(unsigned int x, unsigned int y); + const PIXEL* get(unsigned int x, unsigned int y); unsigned int getWidth(); unsigned int getHeight(); diff --git a/RGBA32.h b/RGBA32.h deleted file mode 100644 index 2057d3d..0000000 --- a/RGBA32.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * RGBA32.h - * - * Created on: Jan 22, 2012 - * Author: jvlek - */ - -#ifndef RGBA32_H_ -#define RGBA32_H_ - -struct RGBA32 -{ - unsigned char r, g, b, a; -}; - - -#endif /* RGBA32_H_ */