Merge remote-tracking branch 'origin/master' into fix_image_datas_convert_to

This commit is contained in:
Flössie
2016-09-21 21:59:28 +02:00
2 changed files with 33 additions and 50 deletions

View File

@@ -77,9 +77,7 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
cmsDoTransform (monitorTransform, buffer, data + ix, W);
}
}
} // End of parallelization
} else {
int W = lab->W;
@@ -127,7 +125,6 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, RenderingIntent intent, bool standard_gamma)
{
//gamutmap(lab);
if (cx < 0) {
cx = 0;
@@ -242,8 +239,6 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, RenderingIntent intent, bool bw)
{
//gamutmap(lab);
if (cx < 0) {
cx = 0;
}
@@ -263,10 +258,10 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
Image16* image = new Image16 (cw, ch);
cmsHPROFILE oprof = iccStore->getProfile (profile);
if (oprof) {
#ifdef _OPENMP
#pragma omp parallel for if (multiThread)
#endif
for (int i = cy; i < cy + ch; i++) {
float* rL = lab->L[i];
@@ -277,26 +272,17 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
short* za = (short*)image->b(i - cy);
for (int j = cx; j < cx + cw; j++) {
float x_, y_, z_;
Color::Lab2XYZ(rL[j], ra[j], rb[j], x_, y_, z_);
float fy = (0.0086206897f * rL[j]) / 327.68f + 0.1379310345f; // (L+16)/116
float fx = (0.002 * ra[j]) / 327.68f + fy;
float fz = fy - (0.005f * rb[j]) / 327.68f;
float LL = rL[j] / 327.68f;
float x_ = 65535.0f * (float) Color::f2xyz(fx) * Color::D50x;
//float y_ = 65535.0 * Color::f2xyz(fy);
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_));
xa[j - cx] = float2uint16range(x_);
ya[j - cx] = float2uint16range(y_);
za[j - cx] = float2uint16range(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);
xa[j - cx] = float2uint16range(y_ * Color::D50x);
za[j - cx] = float2uint16range(y_ * Color::D50z);
}
}
}
@@ -309,7 +295,9 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
cmsDeleteTransform(hTransform);
} else {
#ifdef _OPENMP
#pragma omp parallel for if (multiThread)
#endif
for (int i = cy; i < cy + ch; i++) {
float R, G, B;
@@ -346,8 +334,6 @@ Image16* ImProcFunctions::lab2rgb16 (LabImage* lab, int cx, int cy, int cw, int
Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int ch, Glib::ustring profile, RenderingIntent intent, 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);
if (cx < 0) {
cx = 0;
}
@@ -506,13 +492,11 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int
Color::calcGamma(pwr, ts, mode, imax, g_a0, g_a1, g_a2, g_a3, g_a4, g_a5); // call to calcGamma with selected gamma and slope : return parameters for LCMS2
ga4 = g_a3 * ts;
//printf("g_a0=%f g_a1=%f g_a2=%f g_a3=%f g_a4=%f\n", g_a0,g_a1,g_a2,g_a3,g_a4);
ga0 = gampos;
ga1 = 1. / (1.0 + g_a4);
ga2 = g_a4 / (1.0 + g_a4);
ga3 = 1. / slpos;
ga5 = 0.0;
//printf("ga0=%f ga1=%f ga2=%f ga3=%f ga4=%f\n", ga0,ga1,ga2,ga3,ga4);
}
@@ -539,13 +523,14 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int
// 7 parameters for smoother curves
cmsWhitePointFromTemp(&xyD, t50);
GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, 5, Parameters);//5 = more smoother than 4
cmsHPROFILE oprofdef = cmsCreateRGBProfileTHR(NULL, &xyD, &Primaries, GammaTRC); //oprofdef become Outputprofile
cmsHPROFILE oprofdef = cmsCreateRGBProfileTHR(NULL, &xyD, &Primaries, GammaTRC); //oprofdef becomes Outputprofile
cmsFreeToneCurve(GammaTRC[0]);
if (oprofdef) {
#ifdef _OPENMP
#pragma omp parallel for if (multiThread)
#endif
for (int i = cy; i < cy + ch; i++) {
float* rL = lab->L[i];
@@ -556,39 +541,32 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int
short* za = (short*)image->b(i - cy);
for (int j = cx; j < cx + cw; j++) {
float x_, y_, z_;
Color::Lab2XYZ(rL[j], ra[j], rb[j], x_, y_, z_);
float fy = (0.0086206897f * rL[j]) / 327.68f + 0.1379310345f; // (L+16)/116
float fx = (0.002f * ra[j]) / 327.68f + fy;
float fz = fy - (0.005f * rb[j]) / 327.68f;
float LL = rL[j] / 327.68f;
float x_ = 65535.0f * (float)Color::f2xyz(fx) * Color::D50x;
// float y_ = 65535.0 * Color::f2xyz(fy);
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) round(x_)) ;
ya[j - cx] = CLIP((int) round(y_));
za[j - cx] = CLIP((int) round(z_));
xa[j - cx] = float2uint16range(x_);
ya[j - cx] = float2uint16range(y_);
za[j - cx] = float2uint16range(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);
xa[j - cx] = float2uint16range(y_ * Color::D50x);
za[j - cx] = float2uint16range(y_ * Color::D50z);
}
}
}
cmsHPROFILE iprof = iccStore->getXYZProfile ();
lcmsMutex->lock ();
cmsHTRANSFORM hTransform = cmsCreateTransform (iprof, TYPE_RGB_16, oprofdef, TYPE_RGB_16, intent, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE);
cmsHTRANSFORM hTransform = cmsCreateTransform (iprof, TYPE_RGB_16, oprofdef, TYPE_RGB_16, intent, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE);
lcmsMutex->unlock ();
image->ExecCMSTransform(hTransform);
cmsDeleteTransform(hTransform);
} else {
//
#ifdef _OPENMP
#pragma omp parallel for if (multiThread)
#endif
for (int i = cy; i < cy + ch; i++) {
float R, G, B;
float* rL = lab->L[i];
@@ -619,6 +597,4 @@ Image16* ImProcFunctions::lab2rgb16b (LabImage* lab, int cx, int cy, int cw, int
return image;
}
//#include "sRGBgamutbdy.cc"
}

View File

@@ -80,7 +80,7 @@ inline _Tp intp(_Tp a, _Tp b, _Tp c)
// following is valid:
// intp(a, b+x, c+x) = intp(a, b, c) + x
// intp(a, b*x, c*x) = intp(a, b, c) * x
return a * (b-c) + c;
return a * (b - c) + c;
}
template<typename T>
@@ -101,5 +101,12 @@ inline T norminf(const T& x, const T& y)
return std::max(std::abs(x), std::abs(y));
}
inline int float2uint16range(float d) // clips input to [0;65535] and rounds
{
d = CLIP(d); // clip to [0;65535]
return d + 0.5f;
}
}
#endif