custom trc: another small speedup, #5025
This commit is contained in:
@@ -443,29 +443,26 @@ void ImProcFunctions::workingtrc(Imagefloat* src, Imagefloat* dst, int cw, int c
|
|||||||
{
|
{
|
||||||
dx = dz = 1.0;
|
dx = dz = 1.0;
|
||||||
}
|
}
|
||||||
double toxyz[3][3] = {
|
const float toxyz[3][3] = {
|
||||||
{
|
{
|
||||||
(wprof[0][0] / (dx * (normalizeIn ? 65535.0 : 1.0))), //I have suppressed / Color::D50x
|
static_cast<float>(wprof[0][0] / (dx * (normalizeIn ? 65535.0 : 1.0))), //I have suppressed / Color::D50x
|
||||||
(wprof[0][1] / (dx * (normalizeIn ? 65535.0 : 1.0))),
|
static_cast<float>(wprof[0][1] / (dx * (normalizeIn ? 65535.0 : 1.0))),
|
||||||
(wprof[0][2] / (dx * (normalizeIn ? 65535.0 : 1.0)))
|
static_cast<float>(wprof[0][2] / (dx * (normalizeIn ? 65535.0 : 1.0)))
|
||||||
}, {
|
}, {
|
||||||
(wprof[1][0] / (normalizeIn ? 65535.0 : 1.0)),
|
static_cast<float>(wprof[1][0] / (normalizeIn ? 65535.0 : 1.0)),
|
||||||
(wprof[1][1] / (normalizeIn ? 65535.0 : 1.0)),
|
static_cast<float>(wprof[1][1] / (normalizeIn ? 65535.0 : 1.0)),
|
||||||
(wprof[1][2] / (normalizeIn ? 65535.0 : 1.0))
|
static_cast<float>(wprof[1][2] / (normalizeIn ? 65535.0 : 1.0))
|
||||||
}, {
|
}, {
|
||||||
(wprof[2][0] / (dz * (normalizeIn ? 65535.0 : 1.0))), //I have suppressed / Color::D50z
|
static_cast<float>(wprof[2][0] / (dz * (normalizeIn ? 65535.0 : 1.0))), //I have suppressed / Color::D50z
|
||||||
(wprof[2][1] / (dz * (normalizeIn ? 65535.0 : 1.0))),
|
static_cast<float>(wprof[2][1] / (dz * (normalizeIn ? 65535.0 : 1.0))),
|
||||||
(wprof[2][2] / (dz * (normalizeIn ? 65535.0 : 1.0)))
|
static_cast<float>(wprof[2][2] / (dz * (normalizeIn ? 65535.0 : 1.0)))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
double pwr;
|
double pwr = 1.0 / gampos;
|
||||||
double ts;
|
double ts = slpos;
|
||||||
ts = slpos;
|
|
||||||
|
|
||||||
int five = mul;
|
int five = mul;
|
||||||
|
|
||||||
pwr = 1.0 / gampos;
|
|
||||||
|
|
||||||
if (gampos < 1.0) {
|
if (gampos < 1.0) {
|
||||||
pwr = gampos;
|
pwr = gampos;
|
||||||
@@ -474,7 +471,7 @@ void ImProcFunctions::workingtrc(Imagefloat* src, Imagefloat* dst, int cw, int c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// int select_temp = 1; //5003K
|
// int select_temp = 1; //5003K
|
||||||
const double eps = 0.000000001; // not divide by zero
|
constexpr double eps = 0.000000001; // not divide by zero
|
||||||
|
|
||||||
enum class ColorTemp {
|
enum class ColorTemp {
|
||||||
D50 = 5003, // for Widegamut, ProPhoto Best, Beta -> D50
|
D50 = 5003, // for Widegamut, ProPhoto Best, Beta -> D50
|
||||||
@@ -484,10 +481,8 @@ void ImProcFunctions::workingtrc(Imagefloat* src, Imagefloat* dst, int cw, int c
|
|||||||
};
|
};
|
||||||
ColorTemp temp = ColorTemp::D50;
|
ColorTemp temp = ColorTemp::D50;
|
||||||
|
|
||||||
cmsHPROFILE oprofdef;
|
|
||||||
float p[6]; //primaries
|
float p[6]; //primaries
|
||||||
|
|
||||||
if (true) {
|
|
||||||
//primaries for 10 working profiles ==> output profiles
|
//primaries for 10 working profiles ==> output profiles
|
||||||
if (profile == "WideGamut") {
|
if (profile == "WideGamut") {
|
||||||
p[0] = 0.7350; //Widegamut primaries
|
p[0] = 0.7350; //Widegamut primaries
|
||||||
@@ -608,14 +603,28 @@ void ImProcFunctions::workingtrc(Imagefloat* src, Imagefloat* dst, int cw, int c
|
|||||||
}
|
}
|
||||||
|
|
||||||
GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, five, gammaParams);//5 = more smoother than 4
|
GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(NULL, five, gammaParams);//5 = more smoother than 4
|
||||||
oprofdef = cmsCreateRGBProfile(&xyD, &Primaries, GammaTRC);
|
const cmsHPROFILE oprofdef = cmsCreateRGBProfile(&xyD, &Primaries, GammaTRC);
|
||||||
cmsFreeToneCurve(GammaTRC[0]);
|
cmsFreeToneCurve(GammaTRC[0]);
|
||||||
}
|
|
||||||
|
|
||||||
if (oprofdef) {
|
if (oprofdef) {
|
||||||
#pragma omp parallel for if (multiThread)
|
cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE;
|
||||||
|
cmsHPROFILE iprof = ICCStore::getInstance()->getXYZProfile();
|
||||||
|
lcmsMutex->lock();
|
||||||
|
// cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_16, oprofdef, TYPE_RGB_16, params->icm.outputIntent, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE);
|
||||||
|
cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_FLT, oprofdef, TYPE_RGB_FLT, params->icm.outputIntent, flags);
|
||||||
|
lcmsMutex->unlock();
|
||||||
|
#ifdef _OPENMP
|
||||||
|
#pragma omp parallel if (multiThread)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
AlignedBuffer<float> pBuf(cw * 3);
|
||||||
|
|
||||||
|
#ifdef _OPENMP
|
||||||
|
#pragma omp for schedule(dynamic, 16)
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < ch; i++) {
|
for (int i = 0; i < ch; i++) {
|
||||||
|
float *p = pBuf.data;
|
||||||
float* rr = src->r(i);
|
float* rr = src->r(i);
|
||||||
float* rg = src->g(i);
|
float* rg = src->g(i);
|
||||||
float* rb = src->b(i);
|
float* rb = src->b(i);
|
||||||
@@ -629,28 +638,24 @@ void ImProcFunctions::workingtrc(Imagefloat* src, Imagefloat* dst, int cw, int c
|
|||||||
float g1 = rg[j];
|
float g1 = rg[j];
|
||||||
float b1 = rb[j];
|
float b1 = rb[j];
|
||||||
|
|
||||||
xa[j] = toxyz[0][0] * r1 + toxyz[0][1] * g1 + toxyz[0][2] * b1;
|
*(p++) = toxyz[0][0] * r1 + toxyz[0][1] * g1 + toxyz[0][2] * b1;
|
||||||
ya[j] = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1;
|
*(p++) = toxyz[1][0] * r1 + toxyz[1][1] * g1 + toxyz[1][2] * b1;
|
||||||
za[j] = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1;
|
*(p++) = toxyz[2][0] * r1 + toxyz[2][1] * g1 + toxyz[2][2] * b1;
|
||||||
|
}
|
||||||
|
cmsDoTransform (hTransform, pBuf.data, pBuf.data, cw);
|
||||||
|
p = pBuf.data;
|
||||||
|
for (int x = 0; x < cw; x++) {
|
||||||
|
*(xa++) = *(p++);
|
||||||
|
*(ya++) = *(p++);
|
||||||
|
*(za++) = *(p++);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmsUInt32Number flags = cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE;
|
|
||||||
|
|
||||||
|
|
||||||
lcmsMutex->lock();
|
|
||||||
cmsHPROFILE iprof = ICCStore::getInstance()->getXYZProfile();
|
|
||||||
// cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_16, oprofdef, TYPE_RGB_16, params->icm.outputIntent, cmsFLAGS_NOOPTIMIZE | cmsFLAGS_NOCACHE);
|
|
||||||
cmsHTRANSFORM hTransform = cmsCreateTransform(iprof, TYPE_RGB_FLT, oprofdef, TYPE_RGB_FLT, params->icm.outputIntent, flags);
|
|
||||||
lcmsMutex->unlock();
|
|
||||||
|
|
||||||
dst->ExecCMSTransform(hTransform);
|
|
||||||
|
|
||||||
cmsDeleteTransform(hTransform);
|
cmsDeleteTransform(hTransform);
|
||||||
if (normalizeOut) {
|
if (normalizeOut) {
|
||||||
dst->normalizeFloatTo65535();
|
dst->normalizeFloatTo65535();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user