From ef21ae5e8dfc15eaaa7b54c1fad668fa47b57e13 Mon Sep 17 00:00:00 2001 From: Oliver Duis Date: Sun, 10 Jun 2012 21:01:17 +0200 Subject: [PATCH] Fixed random color dots in dark areas using some Canon DCP profiles see issue 1406 --- rtengine/dcp.cc | 3 ++ rtengine/improcfun.cc | 2 +- rtengine/utils.cc | 71 ------------------------------------------- rtengine/utils.h | 3 -- rtgui/hsvequalizer.cc | 8 ++--- 5 files changed, 8 insertions(+), 79 deletions(-) diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index 17350126e..a6ffa4e63 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -267,6 +267,8 @@ void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::us newg = m2ProPhoto[1][0]*pImg->r[y][x] + m2ProPhoto[1][1]*pImg->g[y][x] + m2ProPhoto[1][2]*pImg->b[y][x]; newb = m2ProPhoto[2][0]*pImg->r[y][x] + m2ProPhoto[2][1]*pImg->g[y][x] + m2ProPhoto[2][2]*pImg->b[y][x]; + // if point is in negative area, just the matrix, but not the LUT + if (newr>=0 && newg>=0 && newb>=0) { ImProcFunctions::rgb2hsv(newr, newg, newb, h , s, v); h*=6.f; // RT calculates in [0,1] @@ -411,6 +413,7 @@ void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::us if (h >= 6.0f) h -= 6.0f; h/=6.f; ImProcFunctions::hsv2rgb( h, s, v, newr, newg, newb); + } pImg->r[y][x] = m2Work[0][0]*newr + m2Work[0][1]*newg + m2Work[0][2]*newb; pImg->g[y][x] = m2Work[1][0]*newr + m2Work[1][1]*newg + m2Work[1][2]*newb; diff --git a/rtengine/improcfun.cc b/rtengine/improcfun.cc index 2d93a79b1..22fdcfc33 100644 --- a/rtengine/improcfun.cc +++ b/rtengine/improcfun.cc @@ -934,7 +934,7 @@ fclose(f);*/ double var_Max = max(var_R,var_G,var_B); double del_Max = var_Max - var_Min; v = var_Max; - if (fabs(del_Max)<0.00001) { + if (del_Max<0.00001 && del_Max>-0.00001) { // no fabs, slow! h = 0; s = 0; } diff --git a/rtengine/utils.cc b/rtengine/utils.cc index 3f368873f..9cfcd2d80 100644 --- a/rtengine/utils.cc +++ b/rtengine/utils.cc @@ -145,77 +145,6 @@ void vflip (unsigned char* img, int w, int h) { delete [] flipped; } -void rgb2hsv (int r, int g, int b, float &h, float &s, float &v) { - - double var_R = r / 65535.0; - double var_G = g / 65535.0; - double var_B = b / 65535.0; - - double var_Min = min(var_R,var_G,var_B); - double var_Max = max(var_R,var_G,var_B); - double del_Max = var_Max - var_Min; - v = var_Max; - if (fabs(del_Max)<0.00001) { - h = 0; - s = 0; - } - else { - s = del_Max/var_Max; - - if ( var_R == var_Max ) h = (var_G - var_B)/del_Max; - else if ( var_G == var_Max ) h = 2.0 + (var_B - var_R)/del_Max; - else if ( var_B == var_Max ) h = 4.0 + (var_R - var_G)/del_Max; - h /= 6.0; - - if ( h < 0 ) h += 1; - if ( h > 1 ) h -= 1; - } -} - -void hsv2rgb (float h, float s, float v, int &r, int &g, int &b) { - - float h1 = h*6; // sector 0 to 5 - int i = floor( h1 ); - float f = h1 - i; // fractional part of h - - float p = v * ( 1 - s ); - float q = v * ( 1 - s * f ); - float t = v * ( 1 - s * ( 1 - f ) ); - - float r1,g1,b1; - - if (i==0) {r1 = v; g1 = t; b1 = p;} - else if (i==1) {r1 = q; g1 = v; b1 = p;} - else if (i==2) {r1 = p; g1 = v; b1 = t;} - else if (i==3) {r1 = p; g1 = q; b1 = v;} - else if (i==4) {r1 = t; g1 = p; b1 = v;} - else if (i==5) {r1 = v; g1 = p; b1 = q;} - - r = (int)( r1 * 65535); - g = (int)( g1 * 65535); - b = (int)( b1 * 65535); -} - -// The same function but set float values instead if int -// Function copied for speed concerns -void hsv2rgb (float h, float s, float v, float &r, float &g, float &b) { - - float h1 = h*6; // sector 0 to 5 - int i = floor( h1 ); - float f = h1 - i; // fractional part of h - - float p = v * ( 1 - s ); - float q = v * ( 1 - s * f ); - float t = v * ( 1 - s * ( 1 - f ) ); - - if (i==0) {r = v; g = t; b = p;} - else if (i==1) {r = q; g = v; b = p;} - else if (i==2) {r = p; g = v; b = t;} - else if (i==3) {r = p; g = q; b = v;} - else if (i==4) {r = t; g = p; b = v;} - else if (i==5) {r = v; g = p; b = q;} -} - } diff --git a/rtengine/utils.h b/rtengine/utils.h index 58c633591..d33c8dc76 100644 --- a/rtengine/utils.h +++ b/rtengine/utils.h @@ -26,9 +26,6 @@ void nearestInterp (const unsigned char* src, int sw, int sh, unsigned char* dst void rotate (unsigned char* img, int& w, int& h, int deg); void hflip (unsigned char* img, int w, int h); void vflip (unsigned char* img, int w, int h); -void rgb2hsv (int r, int g, int b, float &h, float &s, float &v); -void hsv2rgb (float h, float s, float v, int &r, int &g, int &b); -void hsv2rgb (float h, float s, float v, float &r, float &g, float &b); } #endif diff --git a/rtgui/hsvequalizer.cc b/rtgui/hsvequalizer.cc index e2dbea66d..5b61d0217 100644 --- a/rtgui/hsvequalizer.cc +++ b/rtgui/hsvequalizer.cc @@ -18,7 +18,7 @@ */ #include "hsvequalizer.h" -#include "../rtengine/utils.h" +#include "../rtengine/improcfun.h" using namespace rtengine; using namespace rtengine::procparams; @@ -195,19 +195,19 @@ void HSVEqualizer::colorForValue (double valX, double valY) { h -= 1.0; else if (h < 0.0) h += 1.0; - hsv2rgb(h, (float)0.5, (float)0.5, r, g, b); + ImProcFunctions::hsv2rgb(h, (float)0.5, (float)0.5, r, g, b); red = (double)r; green = (double)g; blue = (double)b; } else if (ce == sshape) { // Saturation = f(Hue) - hsv2rgb((float)valX, (float)valY, (float)0.5, r, g, b); + ImProcFunctions::hsv2rgb((float)valX, (float)valY, (float)0.5, r, g, b); red = (double)r; green = (double)g; blue = (double)b; } else if (ce == vshape) { // Value = f(Hue) - hsv2rgb((float)valX, (float)0.5, (float)valY, r, g, b); + ImProcFunctions::hsv2rgb((float)valX, (float)0.5, (float)valY, r, g, b); red = (double)r; green = (double)g; blue = (double)b;