RawAdjustments(PlanarImage source) {
super(source);
}
public PlanarImage setFront() {
PlanarImage front = back;
/*** WHITE BALANCE and EXPOSURE ***/
float lightness = 0.18f;
if (autoWB) {
float wb[] = autoWhiteBalance(back);
System.out.println("Auto WB: " + wb[0] + ", " + wb[1] + ", " + wb[2]);
temperature = neutralTemperature(wb, daylightTemperature);
tint = 0;
System.out.println("Correlated Temperature: " + temperature);
} else if (p != null) {
int pixel[] = pointToPixel(p);
if (pixel != null) {
float oldTemperature = 0;
for (int k = 0; k < 10 && Math.abs(oldTemperature - temperature) > 0.01 * temperature; k++) {
oldTemperature = temperature;
int newPixel[] = new int[3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
newPixel[j] += (int) (pixel[i] * cameraRGB(temperature)[j][i]);
float n[] = WhiteBalanceV2.neutralize(newPixel, caMethod, temperature, daylightTemperature);
lightness = newPixel[1]/255.0f;
temperature = n[0];
tint = Math.min(Math.max(n[1], -20), 20);
}
}
}
// Chromatic adaptation matrix
Matrix B = new Matrix(ColorScience.chromaticAdaptation(daylightTemperature, temperature, caMethod));
Matrix CA = XYZtoRGB.times(B.times(RGBtoZYX));
// Normalize the CA matrix to keep exposure constant
Matrix m = CA.times(new Matrix(new double[][]{{1},{1},{1}}));
double max = m.get(1, 0);
if (max != 1)
CA = CA.times(new Matrix(new double[][]{{1/max, 0, 0},{0, 1/max, 0},{0, 0, 1/max}}));
float actualExposure = exposure;
String thisCamera = metadata.getCameraMake(true);
for (String camera : fakeISO100Cameras)
if (thisCamera.equals(camera)) {
if (metadata.getISO() == 100) {
actualExposure -= 1;
}
break;
}
// The matrix taking into account the camera color space and its basic white balance and exposure
float camMatrix[][] = new Matrix(cameraRGB(temperature)).times(Math.pow(2, actualExposure)).getArrayFloat();
front = new HighlightRecoveryOpImage(front, preMul, camMatrix, CA.getArrayFloat(), null);
if (tint != 0)
front = WhiteBalanceV2.tintCast(front, tint, lightness);
front.setProperty(JAIContext.PERSISTENT_CACHE_TAG, Boolean.TRUE);
/*** NOISE REDUCTION ***/
RenderingHints mfHints = new RenderingHints(JAI.KEY_BORDER_EXTENDER, BorderExtender.createInstance(BorderExtender.BORDER_COPY));
if (color_noise != 0) {
ColorScience.LinearTransform transform = new ColorScience.YST();
double[][] rgb2llab = transform.fromRGB(back.getSampleModel().getDataType());
double[][] llab2rgb = transform.toRGB(back.getSampleModel().getDataType());
ParameterBlock pb = new ParameterBlock();
pb.addSource( front );
pb.add( rgb2llab );
PlanarImage ystImage = JAI.create("BandCombine", pb, null);
pb = new ParameterBlock();
pb.addSource(ystImage);
pb.add(color_noise * scale);
pb.add(0.02f + 0.001f * color_noise);