1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file tcShadowFreeChromaticities.cpp
22 * @brief Remove the shadows from a set of chromaticities.
25 #include "tcShadowFreeChromaticities.h"
26 #include "tcChannel.h"
33 * Constructors + destructor
36 /// Primary constructor.
37 tcShadowFreeChromaticities::tcShadowFreeChromaticities(const QList
<tcChannel
*>& chromaticities
)
38 : tcIlluminantDirection(chromaticities
, chromaticities
.size(), tr("Shadow free chromaticities"), tr("Re-chromatised illuminant invariant"))
40 for (int i
= 0; i
< chromaticities
.size(); ++i
)
42 channels()[i
]->setName(tr("sfc(%1)").arg(chromaticities
[i
]->name()));
43 channels()[i
]->setDescription(tr("Shadow-free chromaticity of %1").arg(chromaticities
[i
]->name()));
48 tcShadowFreeChromaticities::~tcShadowFreeChromaticities()
53 * Interface for derived class to implement
56 void tcShadowFreeChromaticities::loadPortions(const QList
< Reference
< tcPixelData
<float> > >& chromaticities
, int width
, int height
)
58 QList
< Reference
< tcPixelData
<float> > > newChromaticityData
;
59 for (int i
= 0; i
< numChromaticities(); ++i
)
61 Reference
< tcPixelData
<GLfloat
> > newPixelData
= new tcPixelData
<GLfloat
>(width
, height
);
62 newChromaticityData
+= newPixelData
;
63 m_portions
+= newPixelData
;
66 // Go through the pixels
67 maths::VarVector
<float> logChromaticity(numChromaticities());
68 maths::VarVector
<float> temp(numChromaticities());
69 for (int i
= 0; i
< width
*height
; ++i
)
71 // Fill log chromaticity vector
72 for (int channel
= 0; channel
< numChromaticities(); ++channel
)
74 logChromaticity
[channel
] = logf(chromaticities
[channel
]->buffer()[i
]);
77 // Find the dot of the chromaticity values with the illuminant direction vector
78 float illuminant
= logChromaticity
* illuminantDirection();
80 // Subtract this * illuminant direction vector from original value to cancel out
81 temp
= illuminantDirection();
83 logChromaticity
-= temp
;
85 // Copy the data for now
86 for (int channel
= 0; channel
< numChromaticities(); ++channel
)
88 newChromaticityData
[channel
]->buffer()[i
] = expf(logChromaticity
[channel
]);