@Property(description = "Base radius keeping the initial value (radial transition)")
private int baseRadius;
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
int x1 = this.x1;
int y1 = this.y1;
int v1 = this.value1;
int x2 = this.x2;
int y2 = this.y2;
int v2 = this.value2;
double rx = (double) (x2 - x1);
double ry = (double) (y2 - y1);
double dv = (double) (v2 - v1);
double vlen;
if (this.transition == Transition.PARALLEL)
vlen = Math.sqrt(rx * rx + ry * ry);
else
vlen = this.radius - this.baseRadius;
if (vlen < 0.0001)
vlen = 0.0001;
double vlenq = vlen * vlen;
Pixel rgbPixel = new Pixel();
HSLTransformer.HSLPixel hslPixel = new HSLTransformer.HSLPixel();
switch (this.mode) {
case HUE:
if (this.transition == Transition.PARALLEL) {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (ax * rx + ay * ry) / vlenq;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double phue = (v1 + dv * prj) / 255.0;
if (phue < (-1.0))
phue = -1;
else if (phue > 1.0)
phue = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
if (hslPixel.hue != (-1.0)) {
hslPixel.hue += phue;
if (hslPixel.hue < 0.0)
hslPixel.hue += 1.0;
else if (hslPixel.hue > 1.0)
hslPixel.hue -= 1.0;
}
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
else {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double phue = (v1 + dv * prj) / 255.0;
if (phue < (-1.0))
phue = -1;
else if (phue > 1.0)
phue = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
if (hslPixel.hue != (-1.0)) {
hslPixel.hue += phue;
if (hslPixel.hue < 0.0)
hslPixel.hue += 1.0;
else if (hslPixel.hue > 1.0)
hslPixel.hue -= 1.0;
}
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
break;
case SATURATION:
if (this.transition == Transition.PARALLEL) {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (ax * rx + ay * ry) / vlenq;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double psaturation = (v1 + dv * prj) / 255.0;
if (psaturation < (-1.0))
psaturation = -1.0;
else if (psaturation > 1.0)
psaturation = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
hslPixel.saturation += psaturation;
if (hslPixel.saturation < 0.0)
hslPixel.saturation = 0.0;
else if (hslPixel.saturation > 1.0)
hslPixel.saturation = 1.0;
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
else {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double psaturation = (v1 + dv * prj) / 255.0;
if (psaturation < (-1.0))
psaturation = -1.0;
else if (psaturation > 1.0)
psaturation = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
hslPixel.saturation += psaturation;
if (hslPixel.saturation < 0.0)
hslPixel.saturation = 0.0;
else if (hslPixel.saturation > 1.0)
hslPixel.saturation = 1.0;
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
break;
case LUMINOSITY:
if (this.transition == Transition.PARALLEL) {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (ax * rx + ay * ry) / vlenq;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double pluminosity = (v1 + dv * prj) / 255.0;
if (pluminosity < (-1.0))
pluminosity = -1;
else if (pluminosity > 1.0)
pluminosity = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
hslPixel.luminosity += pluminosity;
if (hslPixel.luminosity < 0.0)
hslPixel.luminosity = 0.0;
else if (hslPixel.luminosity > 1.0)
hslPixel.luminosity = 1.0;
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
else {
for (int i = 0; i < height; i++) {
double ay = (double) (i - y1);
for (int j = 0; j < width; j++) {
double ax = (double) (j - x1);
double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
if (prj < 0.0)
prj = 0.0;
else if (prj > 1.0)
prj = 1.0;
double pluminosity = (v1 + dv * prj) / 255.0;
if (pluminosity < (-1.0))
pluminosity = -1;
else if (pluminosity > 1.0)
pluminosity = 1.0;
rgbPixel.setARGBValue(img.getARGBValue(j, i));
HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
hslPixel.luminosity += pluminosity;
if (hslPixel.luminosity < 0.0)
hslPixel.luminosity = 0.0;
else if (hslPixel.luminosity > 1.0)
hslPixel.luminosity = 1.0;
HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
img.setRGB(j, i, rgbPixel);
}
}
}
break;
}