use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class RotateBlurTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
if (this.radius < 1)
return;
SimpleImage img = (SimpleImage) pImg;
int amount = this.amount;
if (amount < 0)
amount = 0 - amount;
else if (amount == 0)
return;
for (int i = 1; i <= amount; i++) {
SimpleImage tmpImg;
for (int pass = 0; pass <= 1; pass++) {
tmpImg = img.clone();
{
RotateTransformer rT = new RotateTransformer();
rT.setZoom(1.0);
rT.setCentreX(this.centreX);
rT.setCentreY(this.centreY);
rT.setRadius(this.radius);
rT.setSmoothing(0);
rT.setAmount((pass == 0) ? (double) i : (double) 0 - i);
rT.transformImage(tmpImg);
}
{
ComposeTransformer cT = new ComposeTransformer();
cT.setTransparency(25);
cT.setGenlock(ComposeTransformer.Genlock.NONE);
cT.setForegroundImage(tmpImg);
cT.transformImage(img);
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class RotateTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
Pixel pPixel = new Pixel();
double alpha = (0.0 - this.amount) * Math.PI / 180.0;
double cosa = Math.cos(alpha);
double sina = Math.sin(alpha);
double cx = this.centreX - 0.5;
double cy = this.centreY - 0.5;
double zoom = this.zoom;
if (zoom < 0.01)
zoom = 0.01;
zoom = 1.0 / zoom;
double radius = this.radius * this.radius;
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
for (int i = 0; i < height; i++) {
double dyq = (double) i - cy;
double y0 = dyq * zoom;
dyq *= dyq;
for (int j = 0; j < width; j++) {
/* transform the point */
double x0 = (double) j - cx;
double rr = x0 * x0 + dyq;
if (rr <= radius) {
x0 *= zoom;
double x = cosa * x0 + sina * y0 + cx;
double y = -sina * x0 + cosa * y0 + cy;
/* render it */
/* render it */
double xi = Tools.fmod33(x);
double yi = Tools.fmod33(y);
if ((x < 0.0) || (x > w1) || (y < 0.0) || (y > h1)) {
pPixel.r = pPixel.g = pPixel.b = 0;
} else {
readSrcPixels(x, y);
pPixel.r = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
pPixel.g = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
pPixel.b = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
}
img.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
}
}
}
applySmoothing(img, smoothing);
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class ComposeTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage bImg = (SimpleImage) pImg;
SimpleImage fImg = (foregroundImage != null) ? foregroundImage : foreground.getImage();
if (fImg == bImg)
fImg = fImg.clone();
Pixel hPixel = new Pixel();
Pixel bPixel = new Pixel();
// calculate left and top edge
int left, top;
if (hAlign == HAlignment.CENTRE) {
left = (bImg.getImageWidth() - fImg.getImageWidth()) / 2;
} else if (hAlign == HAlignment.LEFT) {
left = 0;
} else if (hAlign == HAlignment.RIGHT) {
left = bImg.getImageWidth() - fImg.getImageWidth();
} else {
left = this.left;
}
if (vAlign == VAlignment.CENTRE) {
top = (bImg.getImageHeight() - fImg.getImageHeight()) / 2;
} else if (vAlign == VAlignment.TOP) {
top = 0;
} else if (vAlign == VAlignment.BOTTOM) {
top = bImg.getImageHeight() - fImg.getImageHeight();
} else {
top = this.top;
}
// 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;
} else /* case 2 */
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;
} else /* case 3 */
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;
} else /* case 4 */
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;
}
}
//
int mix = 100 - this.transparency;
if (mix == 100) {
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));
bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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)) {
bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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))) {
bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.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))) {
bImg.setRGB(bgleft + j, bgtop + i, hPixel.r, hPixel.g, hPixel.b);
}
}
}
}
}
} else {
int m1 = 100 - mix;
int m2 = mix;
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));
bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
bImg.setRGB(bgleft + j, bgtop + i, 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)) {
bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
bImg.setRGB(bgleft + j, bgtop + i, 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))) {
bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
bImg.setRGB(bgleft + j, bgtop + i, 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))) {
bPixel.setARGBValue(bImg.getARGBValue(bgleft + j, bgtop + i));
int r = ((int) ((int) bPixel.r * m1) + (int) ((int) hPixel.r) * m2) / (int) 100;
int g = ((int) ((int) bPixel.g * m1) + (int) ((int) hPixel.g) * m2) / (int) 100;
int b = ((int) ((int) bPixel.b * m1) + (int) ((int) hPixel.b) * m2) / (int) 100;
bImg.setRGB(bgleft + j, bgtop + i, r, g, b);
}
}
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class ConvolveTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int[][] kernel = getKernel();
int width = srcImg.getImageWidth();
int height = srcImg.getImageHeight();
int m1 = this.transparency;
int m2 = (100 - this.transparency);
int kernelSize = kernel.length;
int halveKernelSize = kernelSize / 2;
int kernelSum = 0;
for (int i = 0; i < kernelSize; i++) {
for (int j = 0; j < kernelSize; j++) {
kernelSum += kernel[i][j];
}
}
if (kernelSum == 0)
kernelSum = 1;
Pixel pixel = new Pixel();
if (colorMode == ColorMode.GREY) {
srcImg = srcImg.clone();
new ColorToGrayTransformer().transformImage(srcImg);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int intSumR = 0;
for (int k = 0; k < kernelSize; k++) {
int y = i - halveKernelSize + k;
addPixels: for (int l = 0; l < kernelSize; l++) {
int x = j - halveKernelSize + l;
if (x < 0) {
switch(this.edgeMode) {
case MIRROR:
x = -x;
break;
case WRAP:
x += width;
break;
case BLACK:
continue addPixels;
}
} else if (x >= width) {
switch(this.edgeMode) {
case MIRROR:
x = 2 * width - x - 1;
break;
case WRAP:
x -= width;
break;
case BLACK:
continue addPixels;
}
}
if (y < 0) {
switch(this.edgeMode) {
case MIRROR:
y = -y;
break;
case WRAP:
y += height;
break;
case BLACK:
continue addPixels;
}
} else if (y >= height) {
switch(this.edgeMode) {
case MIRROR:
y = 2 * height - y - 1;
break;
case WRAP:
y -= height;
break;
case BLACK:
continue addPixels;
}
}
intSumR += srcImg.getRValue(x, y) * kernel[k][l];
}
}
intSumR = Tools.limitColor((intSumR / kernelSum) + this.bias);
if (this.transparency == 0) {
img.setRGB(j, i, intSumR, intSumR, intSumR);
} else {
pixel.setARGBValue(srcImg.getARGBValue(j, i));
int rval = Tools.limitColor(((pixel.r * m1 + intSumR * m2) / 100));
img.setRGB(j, i, rval, rval, rval);
}
}
}
} else {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int intSumR = 0;
int intSumG = 0;
int intSumB = 0;
for (int k = 0; k < kernelSize; k++) {
int y = i - halveKernelSize + k;
addPixels: for (int l = 0; l < kernelSize; l++) {
int x = j - halveKernelSize + l;
if (x < 0) {
switch(this.edgeMode) {
case MIRROR:
x = -x;
break;
case WRAP:
x += width;
break;
case BLACK:
continue addPixels;
}
} else if (x >= width) {
switch(this.edgeMode) {
case MIRROR:
x = 2 * width - x - 1;
break;
case WRAP:
x -= width;
break;
case BLACK:
continue addPixels;
}
}
if (y < 0) {
switch(this.edgeMode) {
case MIRROR:
y = -y;
break;
case WRAP:
y += height;
break;
case BLACK:
continue addPixels;
}
} else if (y >= height) {
switch(this.edgeMode) {
case MIRROR:
y = 2 * height - y - 1;
break;
case WRAP:
y -= height;
break;
case BLACK:
continue addPixels;
}
}
pixel.setARGBValue(srcImg.getARGBValue(x, y));
intSumR += pixel.r * kernel[k][l];
intSumG += pixel.g * kernel[k][l];
intSumB += pixel.b * kernel[k][l];
}
}
intSumR = Tools.limitColor((intSumR / kernelSum) + this.bias);
intSumG = Tools.limitColor((intSumG / kernelSum) + this.bias);
intSumB = Tools.limitColor((intSumB / kernelSum) + this.bias);
if (this.transparency == 0) {
img.setRGB(j, i, intSumR, intSumG, intSumB);
} else {
pixel.setARGBValue(srcImg.getARGBValue(j, i));
int rval = Tools.limitColor(((pixel.r * m1 + intSumR * m2) / 100));
int gval = Tools.limitColor(((pixel.g * m1 + intSumG * m2) / 100));
int bval = Tools.limitColor(((pixel.b * m1 + intSumB * m2) / 100));
img.setRGB(j, i, rval, gval, bval);
}
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DisplaceMapTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
if ((Math.abs(this.amount) < MathLib.EPSILON) || ((displaceXMap == null) && (displaceYMap == null)))
return;
SimpleImage img = (SimpleImage) pImg;
double nAmount = this.amount / 127.5;
double rZoom = 1.0 / this.zoom;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
SimpleImage xMap = (displaceXMap != null) ? displaceXMap.getImage() : null;
SimpleImage yMap = (displaceYMap != null) ? displaceYMap.getImage() : null;
Pixel pPixel = new Pixel();
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
double cx = (double) width / 2.0;
double cy = (double) height / 2.0;
for (int pY = 0; pY < height; pY++) {
for (int pX = 0; pX < width; pX++) {
double x0 = pX - cx;
double y0 = pY - cy;
double dX, dY;
if (xMap == null)
dX = 0.0;
else
dX = (double) (xMap.getRValueIgnoreBounds(pX, pY) - 127.5) * nAmount;
if (yMap == null)
dY = 0.0;
else
dY = (double) (yMap.getGValueIgnoreBounds(pX, pY) - 127.5) * nAmount;
double x = cx + (x0 + dX) * rZoom;
double y = cy + (y0 + dY) * rZoom;
/* render it */
double xi = Tools.fmod33(x);
double yi = Tools.fmod33(y);
if ((x < 0.0) || (x > w1) || (y < 0.0) || (y > h1)) {
pPixel.r = pPixel.g = pPixel.b = 0;
} else {
readSrcPixels(x, y);
pPixel.r = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
pPixel.g = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
pPixel.b = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
}
img.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
}
}
applySmoothing(img, 3);
}
Aggregations