2010-05-06 04:18:01 -07:00
|
|
|
#include "CameraImageWrapper.h"
|
|
|
|
#include <QColor>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
|
|
|
CameraImageWrapper::CameraImageWrapper() : LuminanceSource()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraImageWrapper::CameraImageWrapper(CameraImageWrapper& otherInstance) : LuminanceSource()
|
2011-09-19 03:32:17 -07:00
|
|
|
{
|
2010-05-06 04:18:01 -07:00
|
|
|
image = otherInstance.getOriginalImage().copy();
|
2011-09-19 03:32:17 -07:00
|
|
|
}
|
2010-05-06 04:18:01 -07:00
|
|
|
|
|
|
|
CameraImageWrapper::~CameraImageWrapper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-06 13:19:38 -07:00
|
|
|
int CameraImageWrapper::getWidth() const
|
2011-09-19 03:32:17 -07:00
|
|
|
{
|
2010-05-06 13:19:38 -07:00
|
|
|
return image.width();
|
2011-09-19 03:32:17 -07:00
|
|
|
}
|
2010-05-06 04:18:01 -07:00
|
|
|
|
2010-05-06 13:19:38 -07:00
|
|
|
int CameraImageWrapper::getHeight() const
|
2011-09-19 03:32:17 -07:00
|
|
|
{
|
2010-05-06 13:19:38 -07:00
|
|
|
return image.height();
|
2011-09-19 03:32:17 -07:00
|
|
|
}
|
2010-05-06 04:18:01 -07:00
|
|
|
|
2010-05-06 13:19:38 -07:00
|
|
|
unsigned char CameraImageWrapper::getPixel(int x, int y) const
|
2011-09-19 03:32:17 -07:00
|
|
|
{
|
2010-05-06 04:18:01 -07:00
|
|
|
QRgb pixel = image.pixel(x,y);
|
2010-05-06 13:19:38 -07:00
|
|
|
|
2010-05-06 04:18:01 -07:00
|
|
|
return qGray(pixel);//((qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3);
|
2011-09-19 03:32:17 -07:00
|
|
|
}
|
2010-05-06 04:18:01 -07:00
|
|
|
|
2010-05-06 13:19:38 -07:00
|
|
|
unsigned char* CameraImageWrapper::copyMatrix() const
|
2011-09-19 03:32:17 -07:00
|
|
|
{
|
|
|
|
unsigned char* newMatrix = (unsigned char*)malloc(image.width()*image.height()*sizeof(unsigned char));
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
for(int i=0; i<image.width(); i++)
|
2010-05-06 13:19:38 -07:00
|
|
|
{
|
2011-09-19 03:32:17 -07:00
|
|
|
for(int j=0; j<image.height(); j++)
|
2010-05-06 13:19:38 -07:00
|
|
|
{
|
2011-09-19 03:32:17 -07:00
|
|
|
newMatrix[cnt++] = getPixel(i,j);
|
2010-05-06 13:19:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 03:32:17 -07:00
|
|
|
return newMatrix;
|
|
|
|
}
|
|
|
|
|
2010-05-06 13:19:38 -07:00
|
|
|
void CameraImageWrapper::setImage(QString fileName)
|
2010-05-06 04:18:01 -07:00
|
|
|
{
|
|
|
|
image.load(fileName);
|
|
|
|
|
|
|
|
if(image.width() > QApplication::desktop()->width())
|
2010-05-06 13:19:38 -07:00
|
|
|
image = image.scaled(QApplication::desktop()->width(), image.height(), Qt::IgnoreAspectRatio);
|
|
|
|
|
2010-05-06 04:18:01 -07:00
|
|
|
if(image.height() > QApplication::desktop()->height())
|
2010-05-06 13:19:38 -07:00
|
|
|
image = image.scaled(image.width(), QApplication::desktop()->height(), Qt::IgnoreAspectRatio);
|
2010-05-06 04:18:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void CameraImageWrapper::setImage(QImage newImage)
|
|
|
|
{
|
|
|
|
image = newImage.copy();
|
2010-05-06 13:19:38 -07:00
|
|
|
|
2010-05-06 04:18:01 -07:00
|
|
|
if(image.width() > 640)
|
2010-05-06 13:19:38 -07:00
|
|
|
image = image.scaled(640, image.height(), Qt::KeepAspectRatio);
|
2010-05-06 04:18:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage CameraImageWrapper::grayScaleImage(QImage::Format f)
|
|
|
|
{
|
|
|
|
QImage tmp(image.width(), image.height(), f);
|
|
|
|
for(int i=0; i<image.width(); i++)
|
|
|
|
{
|
|
|
|
for(int j=0; j<image.height(); j++)
|
|
|
|
{
|
|
|
|
int pix = (int)getPixel(i,j);
|
|
|
|
tmp.setPixel(i,j, qRgb(pix ,pix,pix));
|
|
|
|
}
|
|
|
|
}
|
2010-05-06 13:19:38 -07:00
|
|
|
|
2010-05-06 04:18:01 -07:00
|
|
|
return tmp;
|
2010-05-06 13:19:38 -07:00
|
|
|
|
|
|
|
//return image.convertToFormat(f);
|
2010-05-06 04:18:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage CameraImageWrapper::getOriginalImage()
|
|
|
|
{
|
2010-05-06 13:19:38 -07:00
|
|
|
return image;
|
2010-05-06 04:18:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 03:32:17 -07:00
|
|
|
unsigned char* CameraImageWrapper::getRow(int y, unsigned char* row)
|
|
|
|
{
|
|
|
|
int width = getWidth();
|
|
|
|
|
|
|
|
if (row == NULL)
|
|
|
|
{
|
|
|
|
row = new unsigned char[width];
|
|
|
|
pRow = row;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
row[x] = getPixel(x,y);
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char* CameraImageWrapper::getMatrix()
|
|
|
|
{
|
|
|
|
int width = getWidth();
|
|
|
|
int height = getHeight();
|
|
|
|
unsigned char* matrix = new unsigned char[width*height];
|
|
|
|
unsigned char* m = matrix;
|
|
|
|
|
|
|
|
for(int y=0; y<height; y++)
|
|
|
|
{
|
|
|
|
unsigned char* tmpRow;
|
|
|
|
memcpy(m, tmpRow = getRow(y, NULL), width);
|
|
|
|
m += width * sizeof(unsigned char);
|
|
|
|
|
|
|
|
delete tmpRow;
|
|
|
|
}
|
|
|
|
|
|
|
|
pMatrix = matrix;
|
|
|
|
return matrix;
|
|
|
|
}
|