diff --git a/02/README.md b/02/README.md index 723e5da..5a739ef 100644 --- a/02/README.md +++ b/02/README.md @@ -1,3 +1,4 @@ -# Rozwiązania laboratoria 03 +# Rozwiązania laboratoria 02 -# Znajdują się w katalogu ./02/do_sprawdzenia/cpp/mysimplegimp +Cały kod znajduje się w katalogu głównym ,,app/cpp/mysimplegimp'' +Zmienieone pliki projektu dla zadania lab02 znajdują się w katalogu ,,02/do_sprawdzenia'' diff --git a/02/do_sprawdzenia/conversion_grayscale.cpp b/02/do_sprawdzenia/conversion_grayscale.cpp new file mode 100644 index 0000000..f79b784 --- /dev/null +++ b/02/do_sprawdzenia/conversion_grayscale.cpp @@ -0,0 +1,53 @@ +#include "conversion_grayscale.h" +#include +#include +ConversionGrayscale::ConversionGrayscale(PNM* img) : + Transformation(img) +{ +} + +ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) : + Transformation(img, iv) +{ +} + +PNM* ConversionGrayscale::transform() +{ + 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)); // Getting the pixel(x,y) value + newImage->setPixel(x,y, color == Qt::white ? PIXEL_VAL_MAX : PIXEL_VAL_MIN); + } + } + + } + else // if (image->format() == QImage::Format_RGB32) + { + for (int x=0; xpixel(x,y); // Getting the pixel(x,y) value + //int r = qRed(pixel); // Get the 0-255 value of the R channel + //int g = qGreen(pixel); // Get the 0-255 value of the G channel + //int b = qBlue(pixel); + double r = qRed(pixel)*0.3; + double g = qGreen(pixel)*0.6; + double b = qBlue(pixel)*0.1; + QColor newPixel = QColor(r+g+b,r+g+b,r+g+b); + newImage->setPixel(x,y, newPixel.rgb()); + + } + } + } + + return newImage; +} diff --git a/02/do_sprawdzenia/correction.cpp b/02/do_sprawdzenia/correction.cpp new file mode 100644 index 0000000..4f6415f --- /dev/null +++ b/02/do_sprawdzenia/correction.cpp @@ -0,0 +1,60 @@ +#include "correction.h" + +Correction::Correction(PNM* img) : + Transformation(img) +{ +} + +Correction::Correction(PNM* img, ImageViewer* iv) : + Transformation(img, iv) +{ +} + +PNM* Correction::transform() +{ + float shift = getParameter("shift").toFloat(); + float factor = getParameter("factor").toFloat(); + float gamma = getParameter("gamma").toFloat(); + + int width = image->width(); + int height = image->height(); + + PNM* newImage = new PNM(width, height, image->format()); + + for(unsigned int i=0; i PIXEL_VAL_MAX) adjustedValue = PIXEL_VAL_MAX; + // if adjusted value is smaller than 0, will be set to 0 + if (adjustedValue < PIXEL_VAL_MIN) adjustedValue = PIXEL_VAL_MIN; + + //Fill LUT table + LUT[i] = adjustedValue; + } + + // Set new pixels + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + QRgb pixel = image->pixel(x,y); + int r = qRed(pixel); + int g = qGreen(pixel); + int b = qBlue(pixel); + QColor newPixel = QColor(LUT[r], LUT[g], LUT[b]); + newImage->setPixel(x, y, newPixel.rgb()); + } + } + + return newImage; +} diff --git a/02/do_sprawdzenia/pic1.png b/02/do_sprawdzenia/pic1.png new file mode 100644 index 0000000..52e93be Binary files /dev/null and b/02/do_sprawdzenia/pic1.png differ diff --git a/02/do_sprawdzenia/pic2.png b/02/do_sprawdzenia/pic2.png new file mode 100644 index 0000000..583018c Binary files /dev/null and b/02/do_sprawdzenia/pic2.png differ diff --git a/02/do_sprawdzenia/pic3.png b/02/do_sprawdzenia/pic3.png new file mode 100644 index 0000000..451f741 Binary files /dev/null and b/02/do_sprawdzenia/pic3.png differ diff --git a/02/do_sprawdzenia/pic4.png b/02/do_sprawdzenia/pic4.png new file mode 100644 index 0000000..51c4e18 Binary files /dev/null and b/02/do_sprawdzenia/pic4.png differ diff --git a/app/cpp/mysimplegimp/src/core/transformations/correction.cpp b/app/cpp/mysimplegimp/src/core/transformations/correction.cpp index b78c7a1..4f6415f 100644 --- a/app/cpp/mysimplegimp/src/core/transformations/correction.cpp +++ b/app/cpp/mysimplegimp/src/core/transformations/correction.cpp @@ -21,7 +21,40 @@ PNM* Correction::transform() PNM* newImage = new PNM(width, height, image->format()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for(unsigned int i=0; i PIXEL_VAL_MAX) adjustedValue = PIXEL_VAL_MAX; + // if adjusted value is smaller than 0, will be set to 0 + if (adjustedValue < PIXEL_VAL_MIN) adjustedValue = PIXEL_VAL_MIN; + + //Fill LUT table + LUT[i] = adjustedValue; + } + + // Set new pixels + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + QRgb pixel = image->pixel(x,y); + int r = qRed(pixel); + int g = qGreen(pixel); + int b = qBlue(pixel); + QColor newPixel = QColor(LUT[r], LUT[g], LUT[b]); + newImage->setPixel(x, y, newPixel.rgb()); + } + } return newImage; }