#include "CameraImageWrapper.h" #include #include #include CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0) { } CameraImageWrapper::CameraImageWrapper(const QImage &sourceImage) : LuminanceSource(sourceImage.width(), sourceImage.height()) { image = sourceImage.copy(); } CameraImageWrapper::CameraImageWrapper(CameraImageWrapper& otherInstance) : LuminanceSource(otherInstance.getWidth(), otherInstance.getHeight()) { image = otherInstance.getOriginalImage().copy(); } CameraImageWrapper::~CameraImageWrapper() { } 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); } 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 CameraImageWrapper::getRow(int y, ArrayRef row) const { int width = getWidth(); if (row->size() != width) row.reset(ArrayRef(width)); for (int x = 0; x < width; x++) row[x] = getPixel(x,y); return row; } ArrayRef CameraImageWrapper::getMatrix() const { int width = getWidth(); int height = getHeight(); char* matrix = new char[width*height]; char* m = matrix; for(int y=0; y tmpRow; tmpRow = getRow(y, ArrayRef(width)); #if __cplusplus > 199711L memcpy(m, tmpRow->values().data(), width); #else memcpy(m, &tmpRow->values()[0], width); #endif m += width * sizeof(unsigned char); } ArrayRef arr = ArrayRef(matrix, width*height); if (matrix) { delete matrix; } return arr; }