@Property(description = "Formula of the blue channel")
private String formula3Blue;
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage bgImg = (SimpleImage) pImg;
SimpleImage fgImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
if (fgImg == bgImg)
fgImg = fgImg.clone();
Pixel fgPixel = new Pixel();
Pixel bgPixel = new Pixel();
// calculate left and top edge
int fgLeft, fgTop;
int bgWidth = bgImg.getImageWidth();
int bgHeight = bgImg.getImageHeight();
int fgWidth = fgImg.getImageWidth();
int fgHeight = fgImg.getImageHeight();
if (hAlign == HAlignment.CENTRE) {
fgLeft = (bgWidth - fgWidth) / 2;
}
else if (hAlign == HAlignment.LEFT) {
fgLeft = 0;
}
else if (hAlign == HAlignment.RIGHT) {
fgLeft = bgWidth - fgWidth;
}
else {
fgLeft = this.left;
}
if (vAlign == VAlignment.CENTRE) {
fgTop = (bgHeight - fgHeight) / 2;
}
else if (vAlign == VAlignment.TOP) {
fgTop = 0;
}
else if (vAlign == VAlignment.BOTTOM) {
fgTop = bgHeight - fgHeight;
}
else {
fgTop = this.top;
}
// Initialize the parser
JEPWrapper parser = new JEPWrapper();
parser.addVariable("fgR", 0.0);
parser.addVariable("fgG", 0.0);
parser.addVariable("fgB", 0.0);
parser.addVariable("fgWidth", (double) fgWidth);
parser.addVariable("fgHeight", (double) fgHeight);
parser.addVariable("bgR", 0.0);
parser.addVariable("bgG", 0.0);
parser.addVariable("bgB", 0.0);
parser.addVariable("bgWidth", (double) bgWidth);
parser.addVariable("bgHeight", (double) bgHeight);
parser.addVariable("fgLeft", (double) fgLeft);
parser.addVariable("fgTop", (double) fgTop);
parser.addVariable("fgX", 0.0);
parser.addVariable("fgY", 0.0);
Node redNode = parser.parse(formula1Red);
Node greenNode = parser.parse(formula2Green);
Node blueNode = parser.parse(formula3Blue);
// compose the images
for (int i = 0; i < fgHeight; i++) {
int top = fgTop + i;
if (top >= 0 && top < bgHeight) {
parser.setVarValue("fgY", (double) i / 255.0);
for (int j = 0; j < fgWidth; j++) {
int left = fgLeft + j;
if (left >= 0 && left < bgWidth) {
parser.setVarValue("fgX", (double) j / 255.0);
bgPixel.setARGBValue(bgImg.getARGBValue(left, top));
fgPixel.setARGBValue(fgImg.getARGBValue(j, i));
parser.setVarValue("bgR", (double) bgPixel.r / 255.0);
parser.setVarValue("bgG", (double) bgPixel.g / 255.0);
parser.setVarValue("bgB", (double) bgPixel.b / 255.0);
parser.setVarValue("fgR", (double) fgPixel.r / 255.0);
parser.setVarValue("fgG", (double) fgPixel.g / 255.0);