diff --git a/rtengine/dcp.cc b/rtengine/dcp.cc index a6ffa4e63..60acca23f 100644 --- a/rtengine/dcp.cc +++ b/rtengine/dcp.cc @@ -205,7 +205,7 @@ DCPLightType DCPProfile::GetLightType(short iLightSource) const { return Daylight; } -void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::ustring workingSpace) const { +void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::ustring workingSpace, float rawWhiteFac) const { TMatrix mWork = iccStore->workingSpaceInverseMatrix (workingSpace); double mXYZCAM[3][3]; @@ -258,10 +258,12 @@ void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::us int hueStep = iSatDivisions; int valStep = iHueDivisions * hueStep; + bool useRawWhite=fabs(rawWhiteFac)>0.001; + // Convert to prophoto and apply LUT #pragma omp parallel for for (int y=0; yheight; y++) { - float newr, newg, newb, h,s,v; + float newr, newg, newb, h,s,v,hs,ss,vs; for (int x=0; xwidth; x++) { newr = m2ProPhoto[0][0]*pImg->r[y][x] + m2ProPhoto[0][1]*pImg->g[y][x] + m2ProPhoto[0][2]*pImg->b[y][x]; newg = m2ProPhoto[1][0]*pImg->r[y][x] + m2ProPhoto[1][1]*pImg->g[y][x] + m2ProPhoto[1][2]*pImg->b[y][x]; @@ -272,13 +274,21 @@ void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::us ImProcFunctions::rgb2hsv(newr, newg, newb, h , s, v); h*=6.f; // RT calculates in [0,1] + if (useRawWhite) { + // Retro-calculate what the point was like before RAW white came in + ImProcFunctions::rgb2hsv(newr/rawWhiteFac, newg/rawWhiteFac, newb/rawWhiteFac, hs, ss, vs); + hs*=6.f; // RT calculates in [0,1] + } else { + hs=h; ss=s; vs=v; + } + // Apply the HueSatMap. Ported from Adobes reference implementation float hueShift, satScale, valScale; if (iValDivisions < 2) // Optimize most common case of "2.5D" table. { - float hScaled = h * hScale; - float sScaled = s * sScale; + float hScaled = hs * hScale; + float sScaled = ss * sScale; int hIndex0 = max((int)hScaled, 0); int sIndex0 = max(min((int)sScaled,maxSatIndex0),0); @@ -329,9 +339,9 @@ void DCPProfile::Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::us } else { - float hScaled = h * hScale; - float sScaled = s * sScale; - float vScaled = v * vScale; + float hScaled = hs * hScale; + float sScaled = ss * sScale; + float vScaled = vs * vScale; int hIndex0 = (int) hScaled; int sIndex0 = max(min((int)sScaled,maxSatIndex0),0); diff --git a/rtengine/dcp.h b/rtengine/dcp.h index ea90e4344..bb3ed2c88 100644 --- a/rtengine/dcp.h +++ b/rtengine/dcp.h @@ -57,7 +57,7 @@ namespace rtengine { DCPProfile(Glib::ustring fname); ~DCPProfile(); - void Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::ustring workingSpace) const; + void Apply(Imagefloat *pImg, DCPLightType preferredProfile, Glib::ustring workingSpace, float rawWhiteFac=1) const; void Apply(Image16 *pImg, DCPLightType preferredProfile, Glib::ustring workingSpace) const; }; diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc index 16e35d0a0..08651efaf 100644 --- a/rtengine/rawimagesource.cc +++ b/rtengine/rawimagesource.cc @@ -427,7 +427,7 @@ void RawImageSource::getImage (ColorTemp ctemp, int tran, Imagefloat* image, Pre // Color correction (only when running on full resolution) if (ri->isBayer() && pp.skip==1) processFalseColorCorrection (image, raw.ccSteps); - colorSpaceConversion (image, cmp, embProfile, camProfile, xyz_cam, (static_cast(getMetaData()))->getCamera(), defGain); + colorSpaceConversion (image, cmp, raw, embProfile, camProfile, xyz_cam, (static_cast(getMetaData()))->getCamera()); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1690,7 +1690,7 @@ void RawImageSource::getProfilePreprocParams(cmsHPROFILE in, float& gammaFac, fl //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Converts raw image including ICC input profile to working space - floating point version -void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double camMatrix[3][3], std::string camName, double& defgain) { +void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams cmp, RAWParams raw, cmsHPROFILE embedded, cmsHPROFILE camprofile, double camMatrix[3][3], std::string camName) { //MyTime t1, t2, t3; //t1.set (); @@ -1700,7 +1700,7 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams if (!findInputProfile(cmp.input, embedded, camName, &dcpProf, in)) return; if (dcpProf!=NULL) { - dcpProf->Apply(im, (DCPLightType)cmp.preferredProfile, cmp.working); + dcpProf->Apply(im, (DCPLightType)cmp.preferredProfile, cmp.working, (float)raw.expos); } else { // Calculate matrix for direct conversion raw>working space TMatrix work = iccStore->workingSpaceInverseMatrix (cmp.working); @@ -1916,7 +1916,7 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Converts raw image including ICC input profile to working space - 16bit int version -void RawImageSource::colorSpaceConversion16 (Image16* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double camMatrix[3][3], std::string camName, double& defgain) { +void RawImageSource::colorSpaceConversion16 (Image16* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double camMatrix[3][3], std::string camName) { cmsHPROFILE in; DCPProfile *dcpProf; diff --git a/rtengine/rawimagesource.h b/rtengine/rawimagesource.h index 031253316..4a0a7d0a1 100644 --- a/rtengine/rawimagesource.h +++ b/rtengine/rawimagesource.h @@ -167,8 +167,8 @@ class RawImageSource : public ImageSource { void getAutoExpHistogram (LUTu & histogram, int& histcompr); void getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LUTu & histBlueRaw); - static void colorSpaceConversion16 (Image16* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], std::string camName, double& defgain); - static void colorSpaceConversion (Imagefloat* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], std::string camName, double& defgain); + static void colorSpaceConversion16 (Image16* im, ColorManagementParams cmp, cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], std::string camName); + static void colorSpaceConversion (Imagefloat* im, ColorManagementParams cmp, RAWParams raw, cmsHPROFILE embedded, cmsHPROFILE camprofile, double cam[3][3], std::string camName); static void inverse33 (const double (*coeff)[3], double (*icoeff)[3]); void boxblur2(float** src, float** dst, int H, int W, int box ); diff --git a/rtengine/rtthumbnail.cc b/rtengine/rtthumbnail.cc index 55599041c..8f1d46962 100644 --- a/rtengine/rtthumbnail.cc +++ b/rtengine/rtthumbnail.cc @@ -680,7 +680,7 @@ IImage8* Thumbnail::processImage (const procparams::ProcParams& params, int rhei */ // perform color space transformation if (isRaw) - RawImageSource::colorSpaceConversion16 (resImg, params.icm, embProfile, camProfile, cam2xyz, camName, logDefGain ); + RawImageSource::colorSpaceConversion16 (resImg, params.icm, embProfile, camProfile, cam2xyz, camName ); else StdImageSource::colorSpaceConversion16 (resImg, params.icm, embProfile);