aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2020-11-23 16:12:52 +0200
committerMirta <mirta@twine-s.com>2020-11-23 16:12:52 +0200
commit4e9af2b852eb3b9eecfa09e9bc76869558e183cb (patch)
tree67e0d997fea7a8153e3fb899705b6ebdc2703472 /Software/Visual_Studio
parentca9fb35bec0127af86ce06c3f1020ad15ea1874e (diff)
downloadTango-4e9af2b852eb3b9eecfa09e9bc76869558e183cb.tar.gz
Tango-4e9af2b852eb3b9eecfa09e9bc76869558e183cb.zip
Extend Calibration Tables to greater than 100%
Diffstat (limited to 'Software/Visual_Studio')
-rw-r--r--Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp127
-rw-r--r--Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h4
2 files changed, 107 insertions, 24 deletions
diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp
index 5eae7299c..37fd71dc1 100644
--- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp
+++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.cpp
@@ -435,7 +435,9 @@ void Tango::ColorLib::ColorCalibrator::Linearizaton(double *InkVals, double *&Li
if (CheckDuplicates(InkVals, error))
return;
- if (CheckLimits(InkVals, error))
+ int foundValInd = -1;
+ int NumIntervals = 1;
+ if (CheckLimits(InkVals, foundValInd, NumIntervals, error))
return;
//Values are sorted and unique
@@ -443,18 +445,69 @@ void Tango::ColorLib::ColorCalibrator::Linearizaton(double *InkVals, double *&Li
if (CheckMonotonicity(yVal, error))
return;
//Values are monotonic, therefore can be inverted
- int Kconst = 1;
- if (yVal[0] > yVal[m_nsize - 1])
- Kconst = -1;
- for (int i = 0; i < m_nsize; ++i)
+ if (NumIntervals == 1)
{
- yVal[i] *= Kconst;
+ int Kconst = 1;
+ if (yVal[0] > yVal[m_nsize - 1])
+ Kconst = -1;
+ for (int i = 0; i < m_nsize; ++i)
+ {
+ yVal[i] *= Kconst;
+ }
+
+ if (false == Linearize(yVal, LinearInkVal, 0, m_nsize, error))
+ {
+ return;
+ }
}
-
- if (false == Linearize(yVal, LinearInkVal, error))
+ else
{
- return;
- }
+ double *tmpyval1 = new double[foundValInd+1];
+ double *tmpLinearInkVal1 = new double[foundValInd + 1];
+ int Kconst = 1;
+ //[0 -100] data
+ if (yVal[0] > yVal[foundValInd])
+ Kconst = -1;
+ for (int i = 0; i < foundValInd+1; ++i)
+ tmpyval1[i] = Kconst*yVal[i];
+ if (false == Linearize(tmpyval1, tmpLinearInkVal1, 0, foundValInd + 1, error))
+ {
+ delete [] tmpyval1;
+ tmpyval1 = NULL;
+ delete[] tmpLinearInkVal1;
+ tmpLinearInkVal1 = NULL;
+ return;
+ }
+ int remPoints = m_nsize - foundValInd + 1;
+ double *tmpyval2= new double[foundValInd + 1];
+ double *tmpLinearInkVal2 = new double[foundValInd + 1];
+ if (yVal[foundValInd] > yVal[m_nsize-1])
+ Kconst = -1;
+ for (int i = foundValInd; i < m_nsize; ++i)
+ tmpyval2[i- foundValInd] = Kconst * yVal[i];
+ if (false == Linearize(tmpyval2, tmpLinearInkVal2, foundValInd, m_nsize, error))
+ {
+ delete[] tmpyval2;
+ tmpyval2 = NULL;
+ delete[] tmpLinearInkVal2;
+ tmpLinearInkVal2 = NULL;
+ return;
+ }
+ //arrange data
+ for (int i = 0; i < foundValInd + 1; ++i)
+ LinearInkVal[i] = tmpLinearInkVal1[i];
+ for (int i=1; i< remPoints; ++i)
+ LinearInkVal[i+ foundValInd] = tmpLinearInkVal2[i];
+
+ delete[] tmpyval1;
+ tmpyval1 = NULL;
+ delete[] tmpLinearInkVal1;
+ tmpLinearInkVal1 = NULL;
+ delete[] tmpyval2;
+ tmpyval2 = NULL;
+ delete[] tmpLinearInkVal2;
+ tmpLinearInkVal2 = NULL;
+ }
}
bool Tango::ColorLib::ColorCalibrator::SortValues(double *InkVals, double *yVal)
{
@@ -527,21 +580,36 @@ bool Tango::ColorLib::ColorCalibrator::CheckDuplicates(double *InkVals, std::str
return false;
}
-bool Tango::ColorLib::ColorCalibrator::CheckLimits(double *InkVals, std::string &error)
+bool Tango::ColorLib::ColorCalibrator::CheckLimits(double *InkVals, int &foundValInd, int &NumIntervals, std::string &error)
{
double maxVal = -1000.0;
double minVal = 1000.0;
+ double constVal = 100.0;
+ bool foundVal = false;
+
for (int i = 0; i < m_nsize; ++i)
{
+ if (InkVals[i] == constVal)
+ {
+ foundValInd = i;
+ foundVal = true;
+ }
maxVal = fmax(maxVal, InkVals[i]);
minVal = fmin(minVal, InkVals[i]);
}
- if (maxVal != 100.0)
+ if (maxVal < 100.0)
{
- error ="Maximal value has to be 100%";
+ error ="Maximal value has to be at least 100%";
return true;
}
-
+ if (foundVal == false)
+ {
+ error = "Inks List has to contain 100%";
+ return true;
+ }
+ if (foundValInd >= 0)
+ if (maxVal > InkVals[foundValInd])
+ NumIntervals = 2;
if (minVal != 0.0)
{
error = "Minimal value has to be 0";
@@ -633,20 +701,35 @@ bool Tango::ColorLib::ColorCalibrator::CheckMonotonicity(double *yVal, std::stri
}
return false;
}
-bool Tango::ColorLib::ColorCalibrator::Linearize(double *yVal, double*LinearInkVal, std::string &error)
+bool Tango::ColorLib::ColorCalibrator::Linearize(double *yVal, double*LinearInkVal, int FirstInkInd, int LasInkInd, std::string &error)
{
- double Gain = (yVal[m_nsize - 1] - yVal[0]) / (m_inkpercentage[m_nsize - 1] - m_inkpercentage[0]);
- double Offset = yVal[0] - Gain * m_inkpercentage[0];
- double *LabLinear = new double[m_nsize];
- for (int i = 0; i < m_nsize; i++)
- LabLinear[i] = Gain * m_inkpercentage[i] + Offset;
+ double Gain = (yVal[LasInkInd - FirstInkInd-1] - yVal[0]) / (m_inkpercentage[LasInkInd - 1] - m_inkpercentage[FirstInkInd]);
+ double Offset = yVal[0] - Gain * m_inkpercentage[FirstInkInd];
+ int nPoints = LasInkInd - FirstInkInd ;
+ double *LabLinear = new double[nPoints];
+ double *partialInkPercentage = new double[nPoints];
+ for (int i = 0; i < nPoints; i++)
+ {
+ LabLinear[i] = Gain * m_inkpercentage[FirstInkInd + i] + Offset;
+ partialInkPercentage[i] = m_inkpercentage[FirstInkInd + i];
+ }
double outVal = 0.0;
- for (int i = 0; i < m_nsize; i++)
+ for (int i = 0; i < nPoints; i++)
{
- if (false == Interp1D(LabLinear, m_inkpercentage, yVal[i], outVal, error))
+ if (false == Interp1D(LabLinear, partialInkPercentage, yVal[i], outVal, error))
+ {
+ delete[] LabLinear;
+ LabLinear = NULL;
+ delete[] partialInkPercentage;
+ partialInkPercentage = NULL;
return false;
+ }
LinearInkVal[i] = outVal;
}
+ delete[] LabLinear;
+ LabLinear = NULL;
+ delete[] partialInkPercentage;
+ partialInkPercentage = NULL;
return true;
}
bool Tango::ColorLib::ColorCalibrator::Interp1D(double* xx, double *yy, double InValue, double &OutValue, std::string &error)
diff --git a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h
index 8763397ca..637aaf8f1 100644
--- a/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h
+++ b/Software/Visual_Studio/ColorLib/Tango.ColorLib_v4/ColorCalibrator.h
@@ -29,11 +29,11 @@ namespace Tango
const size_t &nsize, const int &inkChannel, const double& targetl, const double& targeta, const double& targetb);
void Linearizaton(double *InkVals, double*& LinearInkVal, std::string &error);
bool SortValues(double *InkVals, double *yVal);
- bool CheckLimits(double *InkVals, std::string &error);
+ bool CheckLimits(double *InkVals, int &foundValInd, int &NumIntervals, std::string &error);
void SmoothCurveData(double *XVal, double *YVal, int FilterWidth);
bool CheckMonotonicity(double *yVal, std::string &error);
bool CheckDuplicates(double *InkVals, std::string &error);
- bool Linearize(double *yVal, double*LinearInkVal, std::string &error);
+ bool Linearize(double *yVal, double*LinearInkVal, int FirstInkInd, int LasInkInd, std::string &error);
bool Interp1D(double* xx, double *yy, double InValue, double &OutValue, std::string &error);
protected: