2011-11-16 13:40:46 +00:00
|
|
|
#include "CameraImageWrapper.h"
|
|
|
|
#include <QColor>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
|
2014-01-21 15:29:44 +00:00
|
|
|
CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0)
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-21 15:29:44 +00:00
|
|
|
CameraImageWrapper::CameraImageWrapper(const QImage &sourceImage) : LuminanceSource(sourceImage.width(), sourceImage.height())
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
2014-01-21 15:29:44 +00:00
|
|
|
image = sourceImage.copy();
|
2011-11-16 13:40:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-21 15:29:44 +00:00
|
|
|
CameraImageWrapper::CameraImageWrapper(CameraImageWrapper& otherInstance) : LuminanceSource(otherInstance.getWidth(), otherInstance.getHeight())
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
|
|
|
image = otherInstance.getOriginalImage().copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraImageWrapper::~CameraImageWrapper()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-21 15:29:44 +00:00
|
|
|
CameraImageWrapper *CameraImageWrapper::Factory(const QImage &sourceImage, int maxWidth, int maxHeight, bool smoothTransformation)
|
|
|
|
{
|
|
|
|
QImage image;
|
|
|
|
if((maxWidth != 1 || maxHeight != 1) && (sourceImage.width() > maxWidth || sourceImage.height() > maxHeight))
|
|
|
|
image = sourceImage.scaled(
|
|
|
|
maxWidth != -1 ? maxWidth : sourceImage.width(),
|
|
|
|
maxHeight != -1 ? maxHeight : sourceImage.height(),
|
|
|
|
Qt::KeepAspectRatio,
|
|
|
|
smoothTransformation ? Qt::SmoothTransformation : Qt::FastTransformation);
|
|
|
|
else
|
|
|
|
image = sourceImage;
|
|
|
|
|
|
|
|
return new CameraImageWrapper(image);
|
|
|
|
}
|
|
|
|
|
2011-11-16 13:40:46 +00:00
|
|
|
int CameraImageWrapper::getWidth() const
|
|
|
|
{
|
|
|
|
return image.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CameraImageWrapper::getHeight() const
|
|
|
|
{
|
|
|
|
return image.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char CameraImageWrapper::getPixel(int x, int y) const
|
|
|
|
{
|
|
|
|
QRgb pixel = image.pixel(x,y);
|
|
|
|
|
|
|
|
return qGray(pixel);//((qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char* CameraImageWrapper::copyMatrix() const
|
|
|
|
{
|
|
|
|
unsigned char* newMatrix = (unsigned char*)malloc(image.width()*image.height()*sizeof(unsigned char));
|
|
|
|
|
|
|
|
int cnt = 0;
|
|
|
|
for(int i=0; i<image.width(); i++)
|
|
|
|
{
|
|
|
|
for(int j=0; j<image.height(); j++)
|
|
|
|
{
|
|
|
|
newMatrix[cnt++] = getPixel(i,j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newMatrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage CameraImageWrapper::getOriginalImage()
|
|
|
|
{
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2013-07-27 17:01:25 +00:00
|
|
|
ArrayRef<char> CameraImageWrapper::getRow(int y, ArrayRef<char> row) const
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
|
|
|
int width = getWidth();
|
|
|
|
|
2013-07-27 17:01:25 +00:00
|
|
|
if (row->size() != width)
|
|
|
|
row.reset(ArrayRef<char>(width));
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
row[x] = getPixel(x,y);
|
|
|
|
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
2013-07-27 17:01:25 +00:00
|
|
|
ArrayRef<char> CameraImageWrapper::getMatrix() const
|
2011-11-16 13:40:46 +00:00
|
|
|
{
|
|
|
|
int width = getWidth();
|
|
|
|
int height = getHeight();
|
2013-07-27 17:01:25 +00:00
|
|
|
char* matrix = new char[width*height];
|
|
|
|
char* m = matrix;
|
2011-11-16 13:40:46 +00:00
|
|
|
|
|
|
|
for(int y=0; y<height; y++)
|
|
|
|
{
|
2013-07-27 17:01:25 +00:00
|
|
|
ArrayRef<char> tmpRow;
|
|
|
|
tmpRow = getRow(y, ArrayRef<char>(width));
|
2013-07-28 17:29:54 +00:00
|
|
|
#if __cplusplus > 199711L
|
|
|
|
memcpy(m, tmpRow->values()..data(), width);
|
|
|
|
#else
|
|
|
|
memcpy(m, &tmpRow->values()[0], width);
|
|
|
|
#endif
|
2011-11-16 13:40:46 +00:00
|
|
|
m += width * sizeof(unsigned char);
|
|
|
|
}
|
|
|
|
|
2013-08-02 16:52:30 +00:00
|
|
|
ArrayRef<char> arr = ArrayRef<char>(matrix, width*height);
|
|
|
|
|
2015-05-16 14:14:14 +00:00
|
|
|
if (matrix) {
|
|
|
|
delete matrix;
|
|
|
|
}
|
2013-08-02 16:52:30 +00:00
|
|
|
|
|
|
|
return arr;
|
2011-11-16 13:40:46 +00:00
|
|
|
}
|