Fixed blend matrix does not work correctly/causes crashes, new V2

see issue 1010
This commit is contained in:
Oliver Duis
2011-09-20 19:22:53 +02:00
parent a744c9de6e
commit de602fa391
3 changed files with 35 additions and 20 deletions

View File

@@ -36,13 +36,6 @@ Imagefloat::Imagefloat (int w, int h)
allocate (w, h); allocate (w, h);
} }
// Copy other image
Imagefloat::Imagefloat (Imagefloat& other) {
unaligned=NULL; data=NULL;
allocate (other.width, other.height);
memcpy(data, other.data, width*height*3);
}
Imagefloat::~Imagefloat () { Imagefloat::~Imagefloat () {
if (data!=NULL) { if (data!=NULL) {

View File

@@ -53,7 +53,6 @@ class Imagefloat : public ImageIO, public IImagefloat {
Imagefloat (); Imagefloat ();
Imagefloat (int width, int height); Imagefloat (int width, int height);
Imagefloat (Imagefloat& other);
~Imagefloat (); ~Imagefloat ();
Imagefloat* copy (); Imagefloat* copy ();

View File

@@ -1627,7 +1627,7 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams
} }
} else { } else {
Imagefloat* imgPreLCMS=NULL; Imagefloat* imgPreLCMS=NULL;
if (cmp.blendCMSMatrix) imgPreLCMS=new Imagefloat(*im); if (cmp.blendCMSMatrix) imgPreLCMS=im->copy();
// use supplied input profile // use supplied input profile
// color space transform is expecting data in the range (0,1) // color space transform is expecting data in the range (0,1)
@@ -1661,6 +1661,7 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams
cmsDeleteTransform(hTransform); cmsDeleteTransform(hTransform);
// restore normalization to the range (0,65535) and blend matrix colors if LCMS is clipping // restore normalization to the range (0,65535) and blend matrix colors if LCMS is clipping
const float RecoverTresh = 65535.0 * 0.98; // just the last few percent highlights are merged
#pragma omp parallel for #pragma omp parallel for
for ( int h = 0; h < im->height; ++h ) for ( int h = 0; h < im->height; ++h )
for ( int w = 0; w < im->width; ++w ) { for ( int w = 0; w < im->width; ++w ) {
@@ -1670,21 +1671,43 @@ void RawImageSource::colorSpaceConversion (Imagefloat* im, ColorManagementParams
if (cmp.blendCMSMatrix) { if (cmp.blendCMSMatrix) {
// Red // Red
if (im->r[h][w]>65534.9) { float red=im->r[h][w];
float f = mat[0][0]*imgPreLCMS->r[h][w] + mat[0][1]*imgPreLCMS->g[h][w] + mat[0][2]*imgPreLCMS->b[h][w]; if (red>RecoverTresh) {
if (f>im->r[h][w]) im->r[h][w]=f; float matrixRed = mat[0][0]*imgPreLCMS->r[h][w] + mat[0][1]*imgPreLCMS->g[h][w] + mat[0][2]*imgPreLCMS->b[h][w];
}
// Green if (red>=65535.0)
if (im->g[h][w]>65534.9) { im->r[h][w] = matrixRed;
float f = mat[1][0]*imgPreLCMS->r[h][w] + mat[1][1]*imgPreLCMS->g[h][w] + mat[1][2]*imgPreLCMS->b[h][w]; else {
if (f>im->g[h][w]) im->g[h][w]=f; float fac = (red - RecoverTresh) / (65535.0 - RecoverTresh);
im->r[h][w] = (1.0-fac) * red + fac * matrixRed;
}
} }
// Green
float green=im->g[h][w];
if (green>RecoverTresh) {
float matrixGreen = mat[1][0]*imgPreLCMS->r[h][w] + mat[1][1]*imgPreLCMS->g[h][w] + mat[1][2]*imgPreLCMS->b[h][w];
if (green>=65535.0)
im->g[h][w] = matrixGreen;
else {
float fac = (green - RecoverTresh) / (65535.0 - RecoverTresh);
im->g[h][w] = (1.0-fac) * green + fac * matrixGreen;
}
}
// Blue // Blue
if (im->b[h][w]>65534.9) { float blue=im->b[h][w];
float f = mat[2][0]*imgPreLCMS->r[h][w] + mat[2][1]*imgPreLCMS->g[h][w] + mat[2][2]*imgPreLCMS->b[h][w]; if (blue>RecoverTresh) {
if (f>im->b[h][w]) im->b[h][w]=f; float matrixBlue = mat[2][0]*imgPreLCMS->r[h][w] + mat[2][1]*imgPreLCMS->g[h][w] + mat[2][2]*imgPreLCMS->b[h][w];
if (blue>=65535.0)
im->b[h][w] = matrixBlue;
else {
float fac = (blue - RecoverTresh) / (65535.0 - RecoverTresh);
im->b[h][w] = (1.0-fac) * blue + fac * matrixBlue;
}
} }
} }
} }