r22430 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Sun Mar 11 10:59:27 UTC 2018
Author: jghali
Date: Sun Mar 11 10:59:27 2018
New Revision: 22430
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22430
Log:
modify spectral values convertor so as to make it usable with E308 conversion tables
Modified:
trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.cpp
trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.h
Modified: trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22430&path=/trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.cpp
==============================================================================
--- trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.cpp (original)
+++ trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.cpp Sun Mar 11 10:59:27 2018
@@ -11,27 +11,36 @@
#include "scciedata.h"
ScSpectralValuesConvertor::ScSpectralValuesConvertor(eIlluminant illuminant, eObserver observer)
- : m_illuminant(ScCIEData::instance().cieIlluminant(illuminant)),
- m_observer(ScCIEData::instance().cieObserver(observer))
-{
- m_illuminantWhite = computeIlluminantWhite();
-}
-
-ScXYZ ScSpectralValuesConvertor::computeIlluminantWhite()
+{
+ const ScCIEIlluminant& cieIlluminant = ScCIEData::instance().cieIlluminant(illuminant);
+ const ScCIEObserver& cieObserver = ScCIEData::instance().cieObserver(observer);
+ m_illuminantWhite = computeIlluminantWhite(cieIlluminant, cieObserver);
+ computeWeights(cieIlluminant, cieObserver);
+}
+
+ScSpectralValuesConvertor::ScSpectralValuesConvertor(const ScE308Table& e308table)
+{
+ m_illuminantWhite = computeIlluminantWhite(e308table);
+ m_weightsX = e308table.weightsX();
+ m_weightsY = e308table.weightsY();
+ m_weightsZ = e308table.weightsZ();
+}
+
+ScXYZ ScSpectralValuesConvertor::computeIlluminantWhite(const ScCIEIlluminant& illuminant, const ScCIEObserver& observer)
{
int wl;
double illPower;
ScXYZ illWhite = { 0.0, 0.0, 0.0 };
- const QVector<int> wavelengths = m_illuminant.wavelengths();
- for (int i = 0; i < wavelengths.count(); ++i)
- {
- wl = wavelengths.at(i);
- illPower = m_illuminant.power(wl);
-
- illWhite.X += illPower * m_observer.xVal(wl);
- illWhite.Y += illPower * m_observer.yVal(wl);
- illWhite.Z += illPower * m_observer.zVal(wl);
+ const QVector<int> wavelengths = illuminant.wavelengths();
+ for (int i = 0; i < wavelengths.count(); ++i)
+ {
+ wl = wavelengths.at(i);
+ illPower = illuminant.power(wl);
+
+ illWhite.X += illPower * observer.xVal(wl);
+ illWhite.Y += illPower * observer.yVal(wl);
+ illWhite.Z += illPower * observer.zVal(wl);
}
double norm = 1.0 / illWhite.Y;
@@ -40,6 +49,50 @@
illWhite.Z *= norm;
return illWhite;
+}
+
+ScXYZ ScSpectralValuesConvertor::computeIlluminantWhite(const ScE308Table& e380table)
+{
+ int wl;
+ ScXYZ illWhite = { 0.0, 0.0, 0.0 };
+
+ const QVector<int> wavelengths = e380table.wavelengths();
+ for (int i = 0; i < wavelengths.count(); ++i)
+ {
+ wl = wavelengths.at(i);
+
+ illWhite.X += e380table.wX(wl);
+ illWhite.Y += e380table.wY(wl);
+ illWhite.Z += e380table.wZ(wl);
+ }
+
+ double norm = 1.0 / illWhite.Y;
+ illWhite.X *= norm;
+ illWhite.Y = 1.0;
+ illWhite.Z *= norm;
+
+ return illWhite;
+}
+
+void ScSpectralValuesConvertor::computeWeights(const ScCIEIlluminant& illuminant, const ScCIEObserver& observer)
+{
+ int wl;
+ double illPower;
+
+ m_weightsX.clear();
+ m_weightsY.clear();
+ m_weightsZ.clear();
+
+ const QVector<int> wavelengths = illuminant.wavelengths();
+ for (int i = 0; i < wavelengths.count(); ++i)
+ {
+ wl = wavelengths.at(i);
+ illPower = illuminant.power(wl);
+
+ m_weightsX[wl] = illPower * observer.xVal(wl);
+ m_weightsY[wl] = illPower * observer.yVal(wl);
+ m_weightsZ[wl] = illPower * observer.zVal(wl);
+ }
}
ScLab ScSpectralValuesConvertor::toLab(const QMap<int, double>& spectrum) const
@@ -73,7 +126,7 @@
ScXYZ ScSpectralValuesConvertor::toXYZ(const QMap<int, double>& spectrum) const
{
int wl;
- double illPower, reflectance;
+ double reflectance;
ScXYZ cieXYZ = { 0.0, 0.0, 0.0 };
ScXYZ illXYZ = { 0.0, 0.0, 0.0 };
@@ -84,11 +137,10 @@
for (iter = spectrum.begin(); iter != spectrum.end(); iter++)
{
wl = iter.key();
- illPower = m_illuminant.power(wl);
-
- illXYZ.X += illPower * m_observer.xVal(wl);
- illXYZ.Y += illPower * m_observer.yVal(wl);
- illXYZ.Z += illPower * m_observer.zVal(wl);
+
+ illXYZ.X += m_weightsX[wl];
+ illXYZ.Y += m_weightsY[wl];
+ illXYZ.Z += m_weightsZ[wl];
}
double normX = m_illuminantWhite.X / illXYZ.X;
@@ -100,14 +152,13 @@
{
wl = iter.key();
reflectance = iter.value();
- illPower = m_illuminant.power(wl);
// Fix possible measurement artifacts
reflectance = qMax(0.0, reflectance);
- cieXYZ.X += reflectance * illPower * m_observer.xVal(wl);
- cieXYZ.Y += reflectance * illPower * m_observer.yVal(wl);
- cieXYZ.Z += reflectance * illPower * m_observer.zVal(wl);
+ cieXYZ.X += reflectance * m_weightsX.value(wl, 0.0);
+ cieXYZ.Y += reflectance * m_weightsY.value(wl, 0.0);
+ cieXYZ.Z += reflectance * m_weightsZ.value(wl, 0.0);
}
cieXYZ.X *= normX;
@@ -125,7 +176,7 @@
ScXYZ ScSpectralValuesConvertor::toXYZ(const QVector<int>& wavelengths, const QVector<double>& reflectances) const
{
int wl;
- double illPower, reflectance;
+ double reflectance;
ScXYZ cieXYZ = { 0.0, 0.0, 0.0 };
ScXYZ illXYZ = { 0.0, 0.0, 0.0 };
@@ -137,11 +188,10 @@
for (int i = 0; i < wavelengths.count(); ++i)
{
wl = wavelengths.at(i);
- illPower = m_illuminant.power(wl);
-
- illXYZ.X += illPower * m_observer.xVal(wl);
- illXYZ.Y += illPower * m_observer.yVal(wl);
- illXYZ.Z += illPower * m_observer.zVal(wl);
+
+ illXYZ.X += m_weightsX[wl];
+ illXYZ.Y += m_weightsY[wl];
+ illXYZ.Z += m_weightsZ[wl];
}
double normX = m_illuminantWhite.X / illXYZ.X;
@@ -153,14 +203,13 @@
{
wl = wavelengths.at(i);
reflectance = reflectances.at(i);
- illPower = m_illuminant.power(wl);
// Fix possible measurement artifacts
reflectance = qMax(0.0, reflectance);
- cieXYZ.X += reflectance * illPower * m_observer.xVal(wl);
- cieXYZ.Y += reflectance * illPower * m_observer.yVal(wl);
- cieXYZ.Z += reflectance * illPower * m_observer.zVal(wl);
+ cieXYZ.X += reflectance * m_weightsX.value(wl, 0.0);
+ cieXYZ.Y += reflectance * m_weightsY.value(wl, 0.0);
+ cieXYZ.Z += reflectance * m_weightsZ.value(wl, 0.0);
}
cieXYZ.X *= normX;
Modified: trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22430&path=/trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.h
==============================================================================
--- trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.h (original)
+++ trunk/Scribus/scribus/colormgmt/scspectralvaluesconvertor.h Sun Mar 11 10:59:27 2018
@@ -14,6 +14,7 @@
#include "sccieilluminants.h"
#include "sccieobservers.h"
#include "sccolormgmtstructs.h"
+#include "sce308tables.h"
class ScSpectralValuesConvertor
{
@@ -23,6 +24,11 @@
* illuminant and observer
*/
ScSpectralValuesConvertor(eIlluminant illuminant, eObserver observer);
+
+ /**
+ * Construct spectral values to CIEXYZ convertor with specified E308 table
+ */
+ ScSpectralValuesConvertor(const ScE308Table& e380table);
/**
* Retrieve CIE XYZ values of illuminant white
@@ -50,11 +56,15 @@
ScXYZ toXYZ(const QVector<int>& wavelengths, const QVector<double>& reflectances) const;
protected:
- const ScCIEIlluminant& m_illuminant;
- const ScCIEObserver& m_observer;
ScXYZ m_illuminantWhite;
- ScXYZ computeIlluminantWhite();
+ QMap<int, double> m_weightsX;
+ QMap<int, double> m_weightsY;
+ QMap<int, double> m_weightsZ;
+
+ ScXYZ computeIlluminantWhite(const ScCIEIlluminant& illuminant, const ScCIEObserver& observer);
+ ScXYZ computeIlluminantWhite(const ScE308Table& e380table);
+ void computeWeights(const ScCIEIlluminant& illuminant, const ScCIEObserver& observer);
};
#endif
More information about the scribus-commit
mailing list