diff --git a/rtengine/color.cc b/rtengine/color.cc index 4cc8dc63e..2c74c99e3 100644 --- a/rtengine/color.cc +++ b/rtengine/color.cc @@ -54,10 +54,10 @@ namespace rtengine { const double Color::sRGBGammaCurve = 2.4; const double Color::eps_max=580.40756; //(MAXVALF* 216.0f/24389.0); - const double Color::kappa=903.29630; //24389.0/27.0; + const double Color::kappa=24389.0/27.0;//903.29630; - const float Color::D50x=0.96422; - const float Color::D50z=0.82521; + const float Color::D50x=0.9642f; //0.96422; + const float Color::D50z=0.8249f; //0.82521; const double Color::u0=4.0*D50x/(D50x+15+3*D50z); const double Color::v0=9.0/(D50x+15+3*D50z); const double Color::epskap=8.0; @@ -703,7 +703,8 @@ namespace rtengine { const double epsilonExpInv3 = 6.0/29.0; const double kappaInv = 27.0/24389.0; // inverse of kappa - return (f > epsilonExpInv3) ? f*f*f : (116 * f - 16) * kappaInv; + return (f > epsilonExpInv3) ? f*f*f : (116. * f - 16.) * kappaInv; + } /* diff --git a/rtengine/improcfun.h b/rtengine/improcfun.h index 23e2603b0..e50bec30a 100644 --- a/rtengine/improcfun.h +++ b/rtengine/improcfun.h @@ -288,8 +288,8 @@ class ImProcFunctions { void BadpixelsLab(LabImage * src, LabImage * dst, double radius, int thresh, int mode, float b_l, float t_l, float t_r, float b_r, float skinprot, float chrom); Image8* lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, bool standard_gamma); - Image16* lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, Glib::ustring profi, Glib::ustring gam, bool freegamma, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6);// for gamma output - Image16* lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile);//without gamma ==>default + Image16* lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, Glib::ustring profi, Glib::ustring gam, bool freegamma, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6, bool bw);// for gamma output + Image16* lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, bool bw);//without gamma ==>default // CieImage *ciec; bool transCoord (int W, int H, int x, int y, int w, int h, int& xv, int& yv, int& wv, int& hv, double ascaleDef = -1, const LCPMapper *pLCPMap=NULL); diff --git a/rtengine/iplab2rgb.cc b/rtengine/iplab2rgb.cc index b42760782..4ec313dd2 100644 --- a/rtengine/iplab2rgb.cc +++ b/rtengine/iplab2rgb.cc @@ -263,7 +263,7 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, return image; } // for default (not gamma) -Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile) { +Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, bool bw) { //gamutmap(lab); @@ -288,19 +288,24 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int short* za = (short*)image->b(i-cy); for (int j=cx; jColor::epskap) ? 65535.0*fy*fy*fy : 65535.0*LL/Color::kappa; - - xa[j-cx] = CLIP((int)(x_+0.5)); - ya[j-cx] = CLIP((int)(y_+0.5)); - za[j-cx] = CLIP((int)(z_+0.5)); + float z_ = 65535.0f * (float) Color::f2xyz(fz)*Color::D50z; + float y_= (LL>Color::epskap) ? 65535.0f*fy*fy*fy : 65535.0f*LL/Color::kappa; + + xa[j-cx] = CLIP((int) round(x_)); + ya[j-cx] = CLIP((int) round(y_)); + za[j-cx] = CLIP((int) round(z_)); + if(bw && y_ < 65535.f ){//force Bw value and take highlight into account + xa[j-cx] =(int) round(y_* Color::D50x ); + za[j-cx] =(int) round(y_* Color::D50z); + } + } } @@ -321,15 +326,15 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int float* rb = lab->b[i]; for (int j=cx; jColor::epskap) ? 65535.0*fy*fy*fy : 65535.0*LL/Color::kappa; + float z_ = 65535.0f * (float) Color::f2xyz(fz)*Color::D50z; + float y_= (LL>Color::epskap) ? (float) 65535.0f*fy*fy*fy : 65535.0f*LL/Color::kappa; Color::xyz2srgb(x_,y_,z_,R,G,B); @@ -344,7 +349,7 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int // for gamma options (BT709...sRGB linear...) -Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, Glib::ustring profi, Glib::ustring gam, bool freegamma, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6) { +Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, Glib::ustring profi, Glib::ustring gam, bool freegamma, double gampos, double slpos, double &ga0, double &ga1, double &ga2, double &ga3, double &ga4, double &ga5, double &ga6, bool bw) { //gamutmap(lab); @@ -432,19 +437,24 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int short* za = (short*)image->b(i-cy); for (int j=cx; jColor::epskap) ? 65535.0*fy*fy*fy : 65535.0*LL/Color::kappa; + float z_ = 65535.0f * (float)Color::f2xyz(fz)*Color::D50z; + float y_= (LL>Color::epskap) ? (float) 65535.0*fy*fy*fy : 65535.0f*LL/Color::kappa; - xa[j-cx] = CLIP((int)x_); - ya[j-cx] = CLIP((int)y_); - za[j-cx] = CLIP((int)z_); + xa[j-cx] = CLIP((int) round(x_)) ; + ya[j-cx] = CLIP((int) round(y_)); + za[j-cx] = CLIP((int) round(z_)); + if(bw && y_ < 65535.f){//force Bw value and take highlight into account + xa[j-cx] =(int) round(y_ * Color::D50x); + za[j-cx] =(int) round(y_ * Color::D50z); + } + } } @@ -465,15 +475,15 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int float* rb = lab->b[i]; for (int j=cx; jColor::epskap) ? 65535.0*fy*fy*fy : 65535.0*LL/Color::kappa; + float z_ = 65535.0f * (float) Color::f2xyz(fz)*Color::D50z; + float y_= (LL>Color::epskap) ? (float) 65535.0*fy*fy*fy : 65535.0f*LL/Color::kappa; Color::xyz2srgb(x_,y_,z_,R,G,B); diff --git a/rtengine/simpleprocess.cc b/rtengine/simpleprocess.cc index 3690c0c69..06fe414d7 100644 --- a/rtengine/simpleprocess.cc +++ b/rtengine/simpleprocess.cc @@ -199,6 +199,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p ColorAppearance customColCurve1, customColCurve2,customColCurve3 ; ToneCurve customToneCurvebw1; ToneCurve customToneCurvebw2; + //if(params.blackwhite.enabled) params.toneCurve.hrenabled=false; ipf.g = imgsrc->getGamma(); ipf.iGamma = true; @@ -422,9 +423,8 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p else if (params.icm.working=="Beta RGB") ns=4; else if (params.icm.working=="BestRGB") ns=5; else if (params.icm.working=="BruceRGB") ns=6; - - - readyImg = ipf.lab2rgb16b (labView, cx, cy, cw, ch, params.icm.output, params.icm.working, params.icm.gamma, params.icm.freegamma, params.icm.gampos, params.icm.slpos, ga0,ga1,ga2,ga3,ga4,ga5,ga6 ); + // if(params.blackwhite.enabled) params.toneCurve.hrenabled=false; + readyImg = ipf.lab2rgb16b (labView, cx, cy, cw, ch, params.icm.output, params.icm.working, params.icm.gamma, params.icm.freegamma, params.icm.gampos, params.icm.slpos, ga0,ga1,ga2,ga3,ga4,ga5,ga6, params.blackwhite.enabled ); customGamma = true; //or selected Free gamma @@ -569,13 +569,22 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p else { // if Default gamma mode: we use the profile selected in the "Output profile" combobox; // gamma come from the selected profile, otherwise it comes from "Free gamma" tool - readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm.output); + + readyImg = ipf.lab2rgb16 (labView, cx, cy, cw, ch, params.icm.output, params.blackwhite.enabled); if (settings->verbose) printf("Output profile: \"%s\"\n", params.icm.output.c_str()); } delete labView; labView = NULL; - + + if(params.blackwhite.enabled) {//force BW r=g=b + for (int ccw=0;ccwr(cch,ccw)=readyImg->g(cch,ccw); + readyImg->b(cch,ccw)=readyImg->g(cch,ccw); + } + } + } if (pl) pl->setProgress (0.70); if (params.resize.enabled) {