diff --git a/src/core/transformations/conversion_grayscale.cpp b/src/core/transformations/conversion_grayscale.cpp index 7cc66cb..bd15118 100644 --- a/src/core/transformations/conversion_grayscale.cpp +++ b/src/core/transformations/conversion_grayscale.cpp @@ -1,4 +1,6 @@ #include "conversion_grayscale.h" +#include + ConversionGrayscale::ConversionGrayscale(PNM* img) : Transformation(img) @@ -12,19 +14,53 @@ ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) : PNM* ConversionGrayscale::transform() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - int width = image->width(); int height = image->height(); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); + + if (image->format() == QImage::Format_Mono) { + for (int x=0; xpixel(x,y); + int v = qGray(pixel); + + if(v>128) + { + v=PIXEL_VAL_MAX; + } + else + { + v=PIXEL_VAL_MIN; + } + + newImage->setPixel(x,y, QColor(v,v,v).rgb()); + + } } else // if (image->format() == QImage::Format_RGB32) { + for (int x=0; xpixel(x,y); + + double r = (double) qRed(pixel); + double g =(double) qGreen(pixel); + double b =(double) qBlue(pixel); + + double p=((r*0.3)+(g*0.6)+(b*0.1)); + + + newImage->setPixel(x,y, QColor(p,p,p).rgb()); + + + } } diff --git a/src/core/transformations/correction.cpp b/src/core/transformations/correction.cpp index b78c7a1..9f78631 100644 --- a/src/core/transformations/correction.cpp +++ b/src/core/transformations/correction.cpp @@ -21,7 +21,60 @@ PNM* Correction::transform() PNM* newImage = new PNM(width, height, image->format()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for(int i=0; iformat() == QImage::Format_Mono) + { + for (int x=0; xpixel(x,y); + int v = qGray(pixel); + + if(LUT[v]==-1) + { + temp=pow(((v+shift)*factor),gamma); + + if(temp>255) temp=255; + if(temp<0) temp=0; + + LUT[v]=(int)temp; + } + + newImage->setPixel(x,y, QColor(LUT[v],LUT[v],LUT[v]).rgb()); + + } + + } + else // if (image->format() == QImage::Format_RGB32) + { + + for (int x=0; xpixel(x,y); + + rgb[0] = qRed(pixel); + rgb[1] = qGreen(pixel); + rgb[2] = qBlue(pixel); + + for(int i=0;i<3;i++) + { + if(LUT[rgb[i]]==-1) + { + temp=pow(((rgb[i]+shift)*factor),gamma); + + if(temp>255) temp=255; + if(temp<0) temp=0; + + LUT[rgb[i]]=(int)temp; + } + } + + newImage->setPixel(x,y, QColor(LUT[rgb[0]],LUT[rgb[1]],LUT[rgb[2]]).rgb()); + } + + } return newImage; } diff --git a/src/core/transformations/correction.h b/src/core/transformations/correction.h index 324be2e..1a06413 100644 --- a/src/core/transformations/correction.h +++ b/src/core/transformations/correction.h @@ -13,6 +13,8 @@ public: private: int LUT[PIXEL_VAL_MAX+1]; + int rgb[3]; + float temp; }; #endif // CORRECTION_H