#include "CameraImageWrapper.h" #include #include #include CameraImageWrapper::CameraImageWrapper() : LuminanceSource(0,0), isSmoothTransformationEnabled(false) { } CameraImageWrapper::CameraImageWrapper(QImage& image) : LuminanceSource(image.width(), image.height()) , isSmoothTransformationEnabled(false) { setImage(image); } CameraImageWrapper::CameraImageWrapper(CameraImageWrapper& otherInstance) : LuminanceSource(otherInstance.getWidth(), otherInstance.getHeight()) , isSmoothTransformationEnabled(false) { image = otherInstance.getOriginalImage().copy(); } CameraImageWrapper::~CameraImageWrapper() { } 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 QApplication::desktop()->width()) image = image.scaled(QApplication::desktop()->width(), image.height(), Qt::IgnoreAspectRatio); if(image.height() > QApplication::desktop()->height()) image = image.scaled(image.width(), QApplication::desktop()->height(), Qt::IgnoreAspectRatio); return true; } bool CameraImageWrapper::setImage(QImage newImage) { if(newImage.isNull()) return false; image = newImage.copy(); if(image.width() > 640) image = image.scaled(640, image.height(), Qt::KeepAspectRatio, isSmoothTransformationEnabled ? Qt::SmoothTransformation : Qt::FastTransformation); return true; } QImage CameraImageWrapper::grayScaleImage(QImage::Format f) { QImage tmp(image.width(), image.height(), f); for(int i=0; i