merged branch 'unbounded-processing' into 'dev'
This commit is contained in:
@@ -30,8 +30,66 @@
|
||||
namespace rtengine
|
||||
{
|
||||
|
||||
extern void filmlike_clip(float *r, float *g, float *b);
|
||||
|
||||
namespace {
|
||||
|
||||
inline void clipLAB(float iL, float ia, float ib, float &oL, float &oa, float &ob, const float scale, const float wp[3][3], const float wip[3][3])
|
||||
{
|
||||
if (iL < 0.f) {
|
||||
oL = oa = ob = 0.f;
|
||||
} else if (iL > 32768.f) {
|
||||
|
||||
float X, Y, Z;
|
||||
float r, g, b;
|
||||
Color::Lab2XYZ(iL, ia, ib, X, Y, Z);
|
||||
Color::xyz2rgb(X, Y, Z, r, g, b, wip);
|
||||
filmlike_clip(&r, &g, &b);
|
||||
Color::rgbxyz(r, g, b, X, Y, Z, wp);
|
||||
Color::XYZ2Lab(X, Y, Z, oL, oa, ob);
|
||||
oL /= scale;
|
||||
oa /= scale;
|
||||
ob /= scale;
|
||||
|
||||
// oL = 32768.f / scale;
|
||||
// oa = ob = 0.f;
|
||||
} else {
|
||||
oL = iL / scale;
|
||||
oa = ia / scale;
|
||||
ob = ib / scale;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void clipLAB(float iL, float ia, float ib, double &oL, double &oa, double &ob, const float scale, const float wp[3][3], const float wip[3][3])
|
||||
{
|
||||
float tL, ta, tb;
|
||||
clipLAB(iL, ia, ib, tL, ta, tb, scale, wp, wip);
|
||||
oL = tL;
|
||||
oa = ta;
|
||||
ob = tb;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern const Settings* settings;
|
||||
|
||||
#define DECLARE_WORKING_MATRICES_(space) \
|
||||
TMatrix wprof = ICCStore::getInstance()->workingSpaceMatrix ( space ); \
|
||||
const float wp[3][3] = { \
|
||||
{static_cast<float> (wprof[0][0]), static_cast<float> (wprof[0][1]), static_cast<float> (wprof[0][2])}, \
|
||||
{static_cast<float> (wprof[1][0]), static_cast<float> (wprof[1][1]), static_cast<float> (wprof[1][2])}, \
|
||||
{static_cast<float> (wprof[2][0]), static_cast<float> (wprof[2][1]), static_cast<float> (wprof[2][2])} \
|
||||
}; \
|
||||
\
|
||||
TMatrix wiprof = ICCStore::getInstance()->workingSpaceInverseMatrix ( space ); \
|
||||
const float wip[3][3] = { \
|
||||
{static_cast<float> (wiprof[0][0]), static_cast<float> (wiprof[0][1]), static_cast<float> (wiprof[0][2])}, \
|
||||
{static_cast<float> (wiprof[1][0]), static_cast<float> (wiprof[1][1]), static_cast<float> (wiprof[1][2])}, \
|
||||
{static_cast<float> (wiprof[2][0]), static_cast<float> (wiprof[2][1]), static_cast<float> (wiprof[2][2])} \
|
||||
}
|
||||
|
||||
|
||||
// Used in ImProcCoordinator::updatePreviewImage (rtengine/improccoordinator.cc)
|
||||
// Crop::update (rtengine/dcrop.cc)
|
||||
// Thumbnail::processImage (rtengine/rtthumbnail.cc)
|
||||
@@ -40,6 +98,8 @@ extern const Settings* settings;
|
||||
// otherwise divide by 327.68, convert to xyz and apply the sRGB transform, before converting with gamma2curve
|
||||
void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
|
||||
{
|
||||
DECLARE_WORKING_MATRICES_(params->icm.working);
|
||||
|
||||
if (monitorTransform) {
|
||||
|
||||
int W = lab->W;
|
||||
@@ -76,9 +136,8 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
|
||||
float* rb = lab->b[i];
|
||||
|
||||
for (int j = 0; j < W; j++) {
|
||||
buffer[iy++] = rL[j] / 327.68f;
|
||||
buffer[iy++] = ra[j] / 327.68f;
|
||||
buffer[iy++] = rb[j] / 327.68f;
|
||||
clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy+1], buffer[iy+2], 327.68f, wp, wip);
|
||||
iy += 3;
|
||||
}
|
||||
|
||||
cmsDoTransform (monitorTransform, buffer, data + ix, W);
|
||||
@@ -106,12 +165,14 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
|
||||
|
||||
float R, G, B;
|
||||
float x_, y_, z_;
|
||||
float L, a, b;
|
||||
|
||||
for (int j = 0; j < W; ++j) {
|
||||
|
||||
//float L1=rL[j],a1=ra[j],b1=rb[j];//for testing
|
||||
clipLAB(rL[j], ra[j], rb[j], L, a, b, 1.f, wp, wip);
|
||||
|
||||
Color::Lab2XYZ(rL[j], ra[j], rb[j], x_, y_, z_ );
|
||||
Color::Lab2XYZ(L, a, b, x_, y_, z_ );
|
||||
|
||||
Color::xyz2srgb(x_, y_, z_, R, G, B);
|
||||
|
||||
@@ -136,6 +197,8 @@ void ImProcFunctions::lab2monitorRgb (LabImage* lab, Image8* image)
|
||||
// otherwise divide by 327.68, convert to xyz and apply the RGB transform, before converting with gamma2curve
|
||||
Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch, const procparams::ColorManagementParams &icm, bool consider_histogram_settings)
|
||||
{
|
||||
DECLARE_WORKING_MATRICES_(icm.working);
|
||||
|
||||
//gamutmap(lab);
|
||||
|
||||
if (cx < 0) {
|
||||
@@ -212,9 +275,8 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
|
||||
float* rb = lab->b[i];
|
||||
|
||||
for (int j = cx; j < cx + cw; j++) {
|
||||
buffer[iy++] = rL[j] / 327.68f;
|
||||
buffer[iy++] = ra[j] / 327.68f;
|
||||
buffer[iy++] = rb[j] / 327.68f;
|
||||
clipLAB(rL[j], ra[j], rb[j], buffer[iy], buffer[iy+1], buffer[iy+2], 327.68f, wp, wip);
|
||||
iy += 3;
|
||||
}
|
||||
|
||||
cmsDoTransform (hTransform, buffer, data + ix, cw);
|
||||
@@ -242,8 +304,10 @@ Image8* ImProcFunctions::lab2rgb (LabImage* lab, int cx, int cy, int cw, int ch,
|
||||
|
||||
float R, G, B;
|
||||
float x_, y_, z_;
|
||||
float L, a, b;
|
||||
|
||||
for (int j = cx; j < cx + cw; ++j) {
|
||||
clipLAB(rL[j], ra[j], rb[j], L, a, b, 1.f, wp, wip);
|
||||
Color::Lab2XYZ(rL[j], ra[j], rb[j], x_, y_, z_);
|
||||
|
||||
Color::xyz2rgb(x_, y_, z_, R, G, B, xyz_rgb);
|
||||
|
Reference in New Issue
Block a user