Fixed bad quality ICCv2 for RT output profile
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
#include "curves.h"
|
||||
#include "alignedbuffer.h"
|
||||
#include "color.h"
|
||||
|
||||
namespace rtengine
|
||||
{
|
||||
|
||||
@@ -314,6 +313,71 @@ Imagefloat* ImProcFunctions::lab2rgbOut(LabImage* lab, int cx, int cy, int cw, i
|
||||
lcmsMutex->unlock();
|
||||
} else {
|
||||
oprof = ICCStore::getInstance()->getProfile(icm.output);
|
||||
Glib::ustring outtest = icm.output;
|
||||
std::string fileis_RTv2 = outtest.substr(0, 4);
|
||||
//printf("IsRTv2=%s\n", fileis_RTv2.c_str());
|
||||
if(fileis_RTv2 == "RTv2") {//Only fot ICC v2 : read tag from desc to retrieve gamma and slope save before in generate ICC v2
|
||||
//due to bug in LCMS in CmsToneCurve
|
||||
//printf("icmout=%s \n",icm.output.c_str());
|
||||
GammaValues g_b; //gamma parameters
|
||||
GammaValues gb; //gamma parameters
|
||||
const double eps = 0.000000001; // not divide by zero
|
||||
double gammatag = 2.4;
|
||||
double slopetag = 12.92;
|
||||
cmsMLU *modelDescMLU = (cmsMLU*) (cmsReadTag(oprof, cmsSigDeviceModelDescTag));
|
||||
if (modelDescMLU) {
|
||||
cmsUInt32Number count = cmsMLUgetWide(modelDescMLU, "eng", "USA", nullptr, 0); // get buffer length first
|
||||
if (count) {
|
||||
wchar_t *buffer = new wchar_t[count];
|
||||
count = cmsMLUgetWide(modelDescMLU, "eng", "USA", buffer, count); // now put the string in the buffer
|
||||
char* cModelDesc = g_utf16_to_utf8((unsigned short int*)buffer, -1, nullptr, nullptr, nullptr); // convert to utf-8 in a buffer allocated by glib
|
||||
delete [] buffer;
|
||||
if (cModelDesc) {
|
||||
Glib::ustring modelDesc(cModelDesc);
|
||||
g_free(cModelDesc);
|
||||
// printf("dmdd=%s\n", modelDesc.c_str());
|
||||
|
||||
std::size_t pos = modelDesc.find("g");
|
||||
std::size_t posmid = modelDesc.find("s");
|
||||
std::size_t posend = modelDesc.find("!");
|
||||
std::string strgamma = modelDesc.substr(pos + 1, (posmid - pos));
|
||||
gammatag = std::stod(strgamma.c_str());
|
||||
std::string strslope = modelDesc.substr(posmid + 1, (posend - posmid));
|
||||
slopetag = std::stod(strslope.c_str());
|
||||
// printf("gam=%f slo=%f\n", gammatag, slopetag);
|
||||
}
|
||||
} else {
|
||||
printf("Error: lab2rgbOut / String length is null!\n");
|
||||
}
|
||||
} else {
|
||||
printf("Error: lab2rgbOut / cmsReadTag/cmsSigDeviceModelDescTag failed!\n");
|
||||
}
|
||||
|
||||
double pwr = 1.0 / gammatag;
|
||||
double ts = slopetag;
|
||||
double slope = slopetag == 0 ? eps : slopetag;
|
||||
|
||||
int mode = 0;
|
||||
Color::calcGamma(pwr, ts, mode, g_b); // call to calcGamma with selected gamma and slope : return parameters for LCMS2
|
||||
gb[4] = g_b[3] * ts;
|
||||
gb[0] = gammatag;
|
||||
gb[1] = 1. / (1.0 + g_b[4]);
|
||||
gb[2] = g_b[4] / (1.0 + g_b[4]);
|
||||
gb[3] = 1. / slope;
|
||||
gb[5] = 0.0;
|
||||
gb[6] = 0.0;
|
||||
|
||||
cmsToneCurve* GammaTRC[3];
|
||||
cmsFloat64Number Parameters[7] = { gb[0], gb[1], gb[2], gb[3], gb[4], gb[5], gb[6] } ;
|
||||
|
||||
GammaTRC[0] = GammaTRC[1] = GammaTRC[2] = cmsBuildParametricToneCurve(nullptr, 5, Parameters); //5 = smoother than 4
|
||||
cmsWriteTag(oprof, cmsSigRedTRCTag, GammaTRC[0]);
|
||||
cmsWriteTag(oprof, cmsSigGreenTRCTag, GammaTRC[1]);
|
||||
cmsWriteTag(oprof, cmsSigBlueTRCTag, GammaTRC[2]);
|
||||
cmsFreeToneCurve(GammaTRC[0]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (oprof) {
|
||||
|
||||
Reference in New Issue
Block a user