vlen = this.radius - this.baseRadius;
if (vlen < 0.0001)
vlen = 0.0001;
double vlenq = vlen * vlen;
Pixel pixel = new Pixel();
final double brMAX = 256.0;
switch (this.mode) {
case RED:
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.r += tt;
if (pixel.r < 0)
pixel.r = 0;
else if (pixel.r > 255)
pixel.r = 255;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.r += tt;
if (pixel.r < 0)
pixel.r = 0;
else if (pixel.r > 255)
pixel.r = 255;
img.setRGB(j, i, pixel);
}
}
}
break;
case GREEN:
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.g += tt;
if (pixel.g < 0)
pixel.g = 0;
else if (pixel.g > 255)
pixel.g = 255;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.g += tt;
if (pixel.g < 0)
pixel.g = 0;
else if (pixel.g > 255)
pixel.g = 255;
img.setRGB(j, i, pixel);
}
}
}
break;
case BLUE:
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.b += tt;
if (pixel.b < 0)
pixel.b = 0;
else if (pixel.b > 255)
pixel.b = 255;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.b += tt;
if (pixel.b < 0)
pixel.b = 0;
else if (pixel.b > 255)
pixel.b = 255;
img.setRGB(j, i, pixel);
}
}
}
break;
case BRIGHTNESS:
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.r += tt;
if (pixel.r < 0)
pixel.r = 0;
else if (pixel.r > 255)
pixel.r = 255;
pixel.g += tt;
if (pixel.g < 0)
pixel.g = 0;
else if (pixel.g > 255)
pixel.g = 255;
pixel.b += tt;
if (pixel.b < 0)
pixel.b = 0;
else if (pixel.b > 255)
pixel.b = 255;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
int tt = (int) ((double) ival / (double) brMAX * (double) 255.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
pixel.r += tt;
if (pixel.r < 0)
pixel.r = 0;
else if (pixel.r > 255)
pixel.r = 255;
pixel.g += tt;
if (pixel.g < 0)
pixel.g = 0;
else if (pixel.g > 255)
pixel.g = 255;
pixel.b += tt;
if (pixel.b < 0)
pixel.b = 0;
else if (pixel.b > 255)
pixel.b = 255;
img.setRGB(j, i, pixel);
}
}
}
break;
case CONTRAST:
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;
int ival = v1 + (int) (dv * prj + 0.5);
double scale = (double) (ival) / brMAX;
int sc = (int) (scale * (double) Tools.VPREC + 0.5);
int dc;
pixel.setARGBValue(img.getARGBValue(j, i));
if (ival > 0) {
dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.r + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.r = dc;
dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.g + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.g = dc;
dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.b + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.b = dc;
}
else {
int val;
dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.r + dc;
if (pixel.r < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.r = val;
dc = (int) ((int) ((pixel.g - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.g + dc;
if (pixel.g < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.g = val;
dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.b + dc;
if (pixel.b < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.b = val;
}
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
double scale = (double) (ival) / brMAX;
int sc = (int) (scale * (double) Tools.VPREC + 0.5);
int dc;
pixel.setARGBValue(img.getARGBValue(j, i));
if (ival > 0) {
dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.r + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.r = dc;
dc = (int) (((int) (pixel.g - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.g + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.g = dc;
dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
dc = pixel.b + dc;
if (dc < 0)
dc = 0;
else if (dc > 255)
dc = 255;
pixel.b = dc;
}
else {
int val;
dc = (int) (((int) (pixel.r - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.r + dc;
if (pixel.r < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.r = val;
dc = (int) ((int) ((pixel.g - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.g + dc;
if (pixel.g < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.g = val;
dc = (int) ((int) ((pixel.b - (int) 127) * sc) >> Tools.SPREC);
if (dc < (-255))
dc = (-255);
else if (dc > 255)
dc = 255;
val = pixel.b + dc;
if (pixel.b < 127) {
if (val > 127)
val = 127;
}
else {
if (val < 127)
val = 127;
}
pixel.b = val;
}
img.setRGB(j, i, pixel);
}
}
}
break;
case GAMMA: {
final double max = 255.0;
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;
int ival = v1 + (int) (dv * prj + 0.5);
double g = (double) 512.0 / (512.0 + (double) ival);
pixel.setARGBValue(img.getARGBValue(j, i));
int val;
val = pixel.r;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.r = val;
val = pixel.g;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.g = val;
val = pixel.b;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.b = val;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
double g = (double) 512.0 / (512.0 + (double) ival);
pixel.setARGBValue(img.getARGBValue(j, i));
int val;
val = pixel.r;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.r = val;
val = pixel.g;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.g = val;
val = pixel.b;
if (val == 0)
val = 0;
else
val = (int) (max * Math.pow((double) val / 255.0, g) + 0.5);
pixel.b = val;
img.setRGB(j, i, pixel);
}
}
}
}
break;
case SATURATION: {
int rs = 2990;
int gs = 5880;
int bs = 1130;
rs = (rs * Tools.VPREC) / 10000;
gs = (gs * Tools.VPREC) / 10000;
bs = (bs * Tools.VPREC) / 10000;
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;
int ival = v1 + (int) (dv * prj + 0.5);
int scl = (int) ((double) ival / 255.0 * 1024.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
int rv = pixel.r;
int gv = pixel.g;
int bv = pixel.b;
int avg = (rs * rv + gs * gv + bs * bv) >> Tools.SPREC;
rv += ((rv - avg) * scl) >> Tools.SPREC;
if (rv < 0)
rv = 0;
else if (rv > 255)
rv = 255;
pixel.r = rv;
gv += ((gv - avg) * scl) >> Tools.SPREC;
if (gv < 0)
gv = 0;
else if (gv > 255)
gv = 255;
pixel.g = gv;
bv += ((bv - avg) * scl) >> Tools.SPREC;
if (bv < 0)
bv = 0;
else if (bv > 255)
bv = 255;
pixel.b = bv;
img.setRGB(j, i, pixel);
}
}
}
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;
int ival = v1 + (int) (dv * prj + 0.5);
int scl = (int) ((double) ival / 255.0 * 1024.0 + 0.5);
pixel.setARGBValue(img.getARGBValue(j, i));
int rv = pixel.r;
int gv = pixel.g;
int bv = pixel.b;
int avg = (rs * rv + gs * gv + bs * bv) >> Tools.SPREC;
rv += ((rv - avg) * scl) >> Tools.SPREC;