/* (non-Javadoc)
* @see ca.eandb.jmist.framework.tone.ToneMapperFactory#createToneMapper(java.lang.Iterable)
*/
@Override
public ToneMapper createToneMapper(Iterable<CIEXYZ> samples) {
CIExyY white;
if (autoCheckBox.isSelected()) {
double Yavg = 0.0;
double Ymax = 0.0;
int n = 0;
for (CIEXYZ sample : samples) {
if (sample != null) {
double Y = Math.abs(sample.Y());
if (Y > Ymax) {
Ymax = Y;
}
Yavg += Math.log(DELTA + Y);
n++;
}
}
Yavg /= (double) n;
Yavg = Math.exp(Yavg) - DELTA;
double Ymid = 1.03 - 2.0 / (2.0 + Math.log10(Yavg + 1.0));
white = new CIExyY(1.0 / 3.0, 1.0 / 3.0, Yavg / Ymid);
double ySliderValue = Math.log(white.Y()) / Math.log(2.0);
suspendChangeEvents = true;
whiteLuminanceSlider.setValue(ySliderValue);
whiteXChromaticitySlider.setValue(MAX_CHROMATICITY_SLIDER_VALUE / 3);
whiteYChromaticitySlider.setValue(MAX_CHROMATICITY_SLIDER_VALUE / 3);
suspendChangeEvents = false;
} else {
white = new CIExyY(
((double) whiteXChromaticitySlider.getValue()) / (double) MAX_CHROMATICITY_SLIDER_VALUE,
((double) whiteYChromaticitySlider.getValue()) / (double) MAX_CHROMATICITY_SLIDER_VALUE,
Math.pow(2.0, whiteLuminanceSlider.getValue()));
}
return new LinearToneMapper(white.toXYZ());
}