From 6ead23f87542763732be86674a367c135e6c81dd Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Fri, 11 Dec 2015 14:02:05 +0100 Subject: [PATCH] [TASK] Migrate histogramm adaption over to YUV. --- imageviewer-qt4.cpp | 46 +++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/imageviewer-qt4.cpp b/imageviewer-qt4.cpp index e0906cc..97459cc 100644 --- a/imageviewer-qt4.cpp +++ b/imageviewer-qt4.cpp @@ -229,8 +229,8 @@ void ImageViewer::analyzeImage() { * @brief ImageViewer::adjustBrightness */ void ImageViewer::adjustBrightness(int b) { - int h, s, old_l; - int new_l = 0; + //int h, s, old_l; + //int new_l = 0; int delta = b - 255; for(int x=0; xgetImage()->width(); x++) { for(int y=0; ygetImage()->height(); y++) { @@ -249,8 +249,8 @@ void ImageViewer::adjustBrightness(int b) { } } updateImageDisplay(); - logFile << "Brightness adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl; - renewLogging(); + //logFile << "Brightness adjusted to: " << old_l << " + " << delta << " -> (" << h << ", " << s << ", " << new_l << ")" << std::endl; + //renewLogging(); } /** @@ -349,17 +349,19 @@ void ImageViewer::robustAutomaticContrastAdaption(int c_param) { void ImageViewer::linearHistogrammAdaption(void) { logFile << "Doing linear histogramm adaption ..." << std::endl; renewLogging(); - int h, s, l; + //int h, s, l; int* ach = original->getAbsoluteCumulativeIntensityHistogramm(); int pixels = working_copy->getImage()->width()*working_copy->getImage()->height(); for(int x=0; xgetImage()->width(); x++) { for(int y=0; ygetImage()->height(); y++) { QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); - color.getHsl(&h, &s, &l); - - l = (int) qFloor(ach[l] * (255.0/pixels)); - - color.setHsl(h, s, l); + //color.getHsl(&h, &s, &l); + //l = (int) qFloor(ach[l] * (255.0/pixels)); + //color.setHsl(h, s, l); + struct yuv yuv = LazyImage::RGBToYUV(color.rgb()); + int l = qRound(yuv.y * 255.0); + yuv.y = qFloor(ach[l] * (255.0/pixels)) / 255.0; + color = LazyImage::YUVToRGB(yuv); working_copy->getImage()->setPixel(x, y, color.rgb()); } } @@ -426,13 +428,17 @@ void ImageViewer::partialLinearHistogrammAdaption() { renewLogging(); // Apply the brightness map - int h, s, l; + //int h, s, l; for(int x=0; xgetImage()->width(); x++) { for(int y=0; ygetImage()->height(); y++) { QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); - color.getHsl(&h, &s, &l); - l = brightness_map[l]; - color.setHsl(h, s, l); + //color.getHsl(&h, &s, &l); + //l = brightness_map[l]; + //color.setHsl(h, s, l); + struct yuv yuv = LazyImage::RGBToYUV(color.rgb()); + int l = qRound(yuv.y * 255.0); + yuv.y = qFloor(brightness_map[l]) / 255.0; + color = LazyImage::YUVToRGB(yuv); working_copy->getImage()->setPixel(x, y, color.rgb()); } } @@ -482,13 +488,17 @@ void ImageViewer::succeedingHistogrammAdaption() { } // Apply the map for each pixel. - int h, s, l; + //int h, s, l; for(int x=0; xgetImage()->width(); x++) { for(int y=0; ygetImage()->height(); y++) { QColor color = QColor::fromRgb(original->getImage()->pixel(x, y)); - color.getHsl(&h, &s, &l); - l = histogramm_map[l]; - color.setHsl(h, s, l); + //color.getHsl(&h, &s, &l); + //l = histogramm_map[l]; + //color.setHsl(h, s, l); + struct yuv yuv = LazyImage::RGBToYUV(color.rgb()); + int l = qRound(yuv.y * 255.0); + yuv.y = qFloor(histogramm_map[l]) / 255.0; + color = LazyImage::YUVToRGB(yuv); working_copy->getImage()->setPixel(x, y, color.rgb()); } }