@Property(category = PropertyCategory.SECONDARY, description = "Genlock color B")
protected Color colorB = new Color(0, 0, 0);
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage bImg = (SimpleImage) pImg;
SimpleImage fImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
if (fImg == bImg)
fImg = fImg.clone();
SimpleImage aImg = (alphaChannelImage != null) ? alphaChannelImage : alphaChannel.getImage();
if (aImg == bImg)
aImg = aImg.clone();
Pixel hPixel = new Pixel();
Pixel bPixel = new Pixel();
// calculate left and top edge
int left, top;
if (this.fgHAlign == HAlignment.CENTRE) {
left = (bImg.getImageWidth() - fImg.getImageWidth()) / 2;
}
else if (this.fgHAlign == HAlignment.LEFT) {
left = 0;
}
else if (this.fgHAlign == HAlignment.RIGHT) {
left = bImg.getImageWidth() - fImg.getImageWidth();
}
else {
left = this.fgLeft;
}
if (this.fgVAlign == VAlignment.CENTRE) {
top = (bImg.getImageHeight() - fImg.getImageHeight()) / 2;
}
else if (this.fgVAlign == VAlignment.TOP) {
top = 0;
}
else if (this.fgVAlign == VAlignment.BOTTOM) {
top = bImg.getImageHeight() - fImg.getImageHeight();
}
else {
top = this.fgTop;
}
//
// calculate alhpa left and top edge
int aleft, atop;
if (this.alphaHAlign == HAlignment.CENTRE) {
aleft = (bImg.getImageWidth() - aImg.getImageWidth()) / 2;
}
else if (this.alphaHAlign == HAlignment.LEFT) {
aleft = 0;
}
else if (this.alphaHAlign == HAlignment.RIGHT) {
aleft = bImg.getImageWidth() - aImg.getImageWidth();
}
else {
aleft = this.alphaLeft;
}
if (this.alphaVAlign == VAlignment.CENTRE) {
atop = (bImg.getImageHeight() - aImg.getImageHeight()) / 2;
}
else if (this.alphaVAlign == VAlignment.TOP) {
atop = 0;
}
else if (this.alphaVAlign == VAlignment.BOTTOM) {
atop = bImg.getImageHeight() - aImg.getImageHeight();
}
else {
atop = this.alphaTop;
}
// calculate affected region
int hsize = 0, vsize = 0;
int bgleft = 0, bgtop = 0;
int sleft = 0, stop = 0;
int swidth = fImg.getImageWidth();
int sheight = fImg.getImageHeight();
int bgwidth = bImg.getImageWidth();
int bgheight = bImg.getImageHeight();
/* case 1 */
if ((left >= 0) && (top >= 0)) {
if ((left >= bgwidth) || (top >= bgheight))
return;
hsize = bgwidth - left;
if (hsize > swidth)
hsize = swidth;
vsize = bgheight - top;
if (vsize > sheight)
vsize = sheight;
bgtop = top;
bgleft = left;
sleft = 0;
stop = 0;
}
/* case 2 */
else if ((left < 0) && (top >= 0)) {
if ((left <= (0 - swidth)) || (top >= bgheight))
return;
hsize = swidth + left;
if (hsize > bgwidth)
hsize = bgwidth;
vsize = bgheight - top;
if (vsize > sheight)
vsize = sheight;
bgtop = top;
bgleft = 0;
sleft = 0 - left;
stop = 0;
}
/* case 3 */
else if ((left >= 0) && (top < 0)) {
if ((left >= bgwidth) || (top <= (0 - sheight)))
return;
hsize = bgwidth - left;
if (hsize > swidth)
hsize = swidth;
vsize = sheight + top;
if (vsize > bgheight)
vsize = bgheight;
bgtop = 0;
bgleft = left;
stop = 0 - top;
sleft = 0;
}
/* case 4 */
else if ((left < 0) && (top < 0)) {
if ((left <= (0 - swidth)) || (top <= (0 - sheight)))
return;
hsize = swidth + left;
if (hsize > bgwidth)
hsize = bgwidth;
vsize = sheight + top;
if (vsize > bgheight)
vsize = bgheight;
bgtop = 0;
bgleft = 0;
stop = 0 - top;
sleft = 0 - left;
}
// Genlock colors
int credA = this.colorA.getRed();
int cgreenA = this.colorA.getGreen();
int cblueA = this.colorA.getBlue();
int credB = this.colorB.getRed();
int cgreenB = this.colorB.getGreen();
int cblueB = this.colorB.getBlue();
{
int tc;
if (credA > credB) {
tc = credA;
credA = credB;
credB = tc;
}
if (cgreenA > cgreenB) {
tc = cgreenA;
cgreenA = cgreenB;
cgreenB = tc;
}
if (cblueA > cblueB) {
tc = cblueA;
cblueA = cblueB;
cblueB = tc;
}
}
//
if (this.genlock == Genlock.NONE) {
for (int i = 0; i < vsize; i++) {
for (int j = 0; j < hsize; j++) {
hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
int bgX = bgleft + j;
int bgY = bgtop + i;
int aX = bgX - aleft;
int aY = bgY - atop;
int mix = aImg.getRValueIgnoreBounds(aX, aY);
int m1 = 255 - mix;
int m2 = mix;
bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
bImg.setRGB(bgX, bgY, r, g, b);
}
}
}
else if (this.genlock == Genlock.COLOR) {
for (int i = 0; i < vsize; i++) {
for (int j = 0; j < hsize; j++) {
hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
if ((hPixel.r != credA) || (hPixel.g != cgreenA) || (hPixel.b != cblueA)) {
int bgX = bgleft + j;
int bgY = bgtop + i;
int aX = bgX - aleft;
int aY = bgY - atop;
int mix = aImg.getRValueIgnoreBounds(aX, aY);
int m1 = 255 - mix;
int m2 = mix;
bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
bImg.setRGB(bgX, bgY, r, g, b);
}
}
}
}
else if (this.genlock == Genlock.IN_RANGE) {
for (int i = 0; i < vsize; i++) {
for (int j = 0; j < hsize; j++) {
hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
if (((hPixel.r < credA) || (hPixel.r > credB))
&& ((hPixel.g < cgreenA) || (hPixel.g > cgreenB))
&& ((hPixel.b < cblueA) || (hPixel.b > cblueB))) {
int bgX = bgleft + j;
int bgY = bgtop + i;
int aX = bgX - aleft;
int aY = bgY - atop;
int mix = aImg.getRValueIgnoreBounds(aX, aY);
int m1 = 255 - mix;
int m2 = mix;
bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 255;
bImg.setRGB(bgX, bgY, r, g, b);
}
}
}
}
else if (this.genlock == Genlock.OUT_RANGE) {
for (int i = 0; i < vsize; i++) {
for (int j = 0; j < hsize; j++) {
hPixel.setARGBValue(fImg.getARGBValue(sleft + j, stop + i));
if (((hPixel.r >= credA) && (hPixel.r <= credB))
&& ((hPixel.g >= cgreenA) && (hPixel.g <= cgreenB))
&& ((hPixel.b >= cblueA) && (hPixel.b <= cblueB))) {
int bgX = bgleft + j;
int bgY = bgtop + i;
int aX = bgX - aleft;
int aY = bgY - atop;
int mix = aImg.getRValueIgnoreBounds(aX, aY);
int m1 = 255 - mix;
int m2 = mix;
bPixel.setARGBValue(bImg.getARGBValue(bgX, bgY));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 255;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 255;