Skip to content

Commit

Permalink
Fixed pixel type and made it more flexible
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvlek committed Mar 7, 2013
1 parent 7ace891 commit 6440363
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "Gene.h"
#include "ImageImp.h"
#include "RGBA32.h"
#include "Pixel.h"

#include <string>

Expand Down Expand Up @@ -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:
/**
Expand Down
6 changes: 3 additions & 3 deletions ImageCompare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "ImageCompare.h"
#include "RGBA32.h"
#include "Pixel.h"

#include <cassert>
#include <cmath>
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ImageImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define IMAGEIMP_H_

#include "Gene.h"
#include "RGBA32.h"
#include "Pixel.h"

#include <string>

Expand Down Expand Up @@ -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:
Expand Down
19 changes: 19 additions & 0 deletions Pixel.h
Original file line number Diff line number Diff line change
@@ -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_ */
2 changes: 1 addition & 1 deletion QtEvoPic.pro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ TARGET = QtEvoPic
QT += core \
gui
HEADERS += PairGenerator.h \
RGBA32.h \
Pixel.h \
ImageCompare.h \
QtEvoPic.h \
GUI.h \
Expand Down
4 changes: 2 additions & 2 deletions QtImageImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions QtImageImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "Gene.h"
#include "ImageImp.h"
#include "RGBA32.h"
#include "Pixel.h"

#include <QImage>
#include <QPainter>
Expand All @@ -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();
Expand Down
17 changes: 0 additions & 17 deletions RGBA32.h

This file was deleted.

0 comments on commit 6440363

Please sign in to comment.