added custom function for calculating the grayscale value of a pixel.

This commit is contained in:
favoritas37 2016-02-21 04:12:02 +02:00
parent 41ebf93087
commit dfde91a225
2 changed files with 10 additions and 27 deletions

View File

@ -50,8 +50,8 @@ QImage* CameraImageWrapper::grayScaleImage(const QImage *origin)
for(int j=0; j<origin->height(); j++)
{
QRgb pixel = origin->pixel(QPoint(i,j));
QRgb pix = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3;
//qGray(origin->pixel(QPoint(i,j)));
QRgb pix = gray(qRed(pixel),qGreen(pixel),qBlue(pixel));
//gray(origin->pixel(QPoint(i,j)));
tmp->setPixel(i,j, qRgb(pix ,pix,pix));
}
}
@ -157,31 +157,6 @@ ArrayRef<char> CameraImageWrapper::getMatrixP() const
return arr;
}
//bool CameraImageWrapper::isCropSupported() const
//{
// return true;
//}
//Ref<LuminanceSource> CameraImageWrapper::crop(int left, int top, int width, int height) const
//{
//}
//bool CameraImageWrapper::isRotateSupported() const
//{
// return true;
//}
//Ref<LuminanceSource> CameraImageWrapper::invert() const
//{
//}
//Ref<LuminanceSource> CameraImageWrapper::rotateCounterClockwise() const
//{
//}
QImage *CameraImageWrapper::sharpen(const QImage *origin)
{
QImage * newImage = new QImage(* origin);
@ -220,3 +195,9 @@ QImage *CameraImageWrapper::sharpen(const QImage *origin)
}
return newImage;
}
unsigned int CameraImageWrapper::gray(unsigned int r, unsigned int g, unsigned int b)
{
//values based on http://entropymine.com/imageworsener/grayscale/
return (r*7+g*23+b*2)/32;
}

View File

@ -36,6 +36,8 @@ private:
QImage* sharpen(const QImage *origin);
unsigned int gray(unsigned int r, unsigned int g, unsigned int b);
QImage* image;
Ref<GreyscaleLuminanceSource> delegate;
};