From 3946c846abb34f9c0e58dc16708079f7bb399d23 Mon Sep 17 00:00:00 2001 From: Damian Kowalski Date: Sat, 6 Apr 2024 12:45:07 +0200 Subject: [PATCH] added greyscale --- .../transformations/conversion_grayscale.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/transformations/conversion_grayscale.cpp b/src/core/transformations/conversion_grayscale.cpp index 7cc66cb..28e5f50 100644 --- a/src/core/transformations/conversion_grayscale.cpp +++ b/src/core/transformations/conversion_grayscale.cpp @@ -21,11 +21,27 @@ PNM* ConversionGrayscale::transform() if (image->format() == QImage::Format_Mono) { - + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + QRgb pixel = image->pixel(x, y); + int gray = qGray(pixel); + newImage->setPixel(x, y, qRgb(gray, gray, gray)); + } + } } else // if (image->format() == QImage::Format_RGB32) { - + for (int y = 0; y < height; ++y) + { + for (int x = 0; x < width; ++x) + { + QRgb pixel = image->pixel(x, y); + int gray = qGray(pixel); + newImage->setPixel(x, y, qRgb(gray, gray, gray)); + } + } } return newImage;