From: Enblend <enb...@li...> - 2017-02-12 16:13:21
|
branch: details: http://enblend.hg.sourceforge.net/hgweb/enblend/enblend/hg/p/enblend/code/rev/15c4d05b015a changeset: 1496:15c4d05b015a user: Chris <cs...@us...> date: Sun Feb 12 17:00:19 2017 +0100 description: Take care of NaNs when working in Luv colorspace. Therebe we can gently mop up some more magenta artifact pixels in deep shadows. diffstat: VERSION | 2 +- src/fixmath.h | 45 +++++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-) diffs (67 lines): diff -r b55f76af4d3e -r 15c4d05b015a VERSION --- a/VERSION Sun Feb 12 16:59:51 2017 +0100 +++ b/VERSION Sun Feb 12 17:00:19 2017 +0100 @@ -1,1 +1,1 @@ -4.3-f0304648cc0f +4.3-b55f76af4d3e diff -r b55f76af4d3e -r 15c4d05b015a src/fixmath.h --- a/src/fixmath.h Sun Feb 12 16:59:51 2017 +0100 +++ b/src/fixmath.h Sun Feb 12 17:00:19 2017 +0100 @@ -1270,20 +1270,49 @@ #endif // LOG_COLORSPACE_CONVERSION assert(!std::isnan(luv[0]) && luv[0] >= 0.0); - const Luv2XYZFunctor::result_type xyz {luv2xyz(luv)}; + Luv2XYZFunctor::result_type xyz {luv2xyz(luv)}; double rgb[3]; cmsDoTransform(XYZToInputTransform, &xyz[0], rgb, 1U); if (EXPECT_RESULT(is_below_threshold(rgb), false)) { - // Optimization Possibility: If XYZ2LabFunctor is instantiated with `double': - // union { - // XYZ2LabFunctor::result_type lab_array; - // cmsCIELab lab_struct; - // }; - const XYZ2LabFunctor::result_type lab_vector {xyz2lab(xyz)}; - const cmsCIELab lab {lab_vector[0], lab_vector[1], lab_vector[2]}; + XYZ2LabFunctor::result_type lab_vector {xyz2lab(xyz)}; + cmsCIELab lab {lab_vector[0], lab_vector[1], lab_vector[2]}; + + if (EXPECT_RESULT(std::isnan(lab.a) || std::isnan(lab.b), false)) + { +#ifdef LOG_COLORSPACE_OPTIMIZATION +#ifdef OPENMP +#pragma omp critical +#endif // LOG_COLORSPACE_CONVERSION + std::cout << + "+ ConvertLuvPyramidToVectorFunctor::operator(): initial XYZ = " << xyz << "\n" + " Lab = (" << lab.L << ", " << lab.a << ", " << lab.b << "), " + "RGB = (" << rgb[0] << ", " << rgb[1] << ", " << rgb[2] << ")\n"; +#endif + xyz[0] = std::max(xyz[0], 0.0); + xyz[1] = std::max(xyz[1], 0.0); + xyz[2] = std::max(xyz[2], 0.0); + + cmsDoTransform(XYZToInputTransform, &xyz[0], rgb, 1U); + lab_vector = xyz2lab(xyz); + + lab.L = lab_vector[0]; + lab.a = lab_vector[1]; + lab.b = lab_vector[2]; + +#ifdef LOG_COLORSPACE_OPTIMIZATION +#ifdef OPENMP +#pragma omp critical +#endif + std::cout << + "+ ConvertLuvPyramidToVectorFunctor::operator(): fixed XYZ = " << xyz << "\n" + " Lab = (" << lab.L << ", " << lab.a << ", " << lab.b << "), " + "RGB = (" << rgb[0] << ", " << rgb[1] << ", " << rgb[2] << ")\n"; +#endif // LOG_COLORSPACE_CONVERSION + } + polish_rgb(&lab, rgb); } |