use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class Cartesian2PolarTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
double zoom;
if (this.zoom != 0.0)
zoom = 1.0 / this.zoom;
else
zoom = 1.0;
zoom *= 2.0;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
boolean wrap = this.wrap;
double cx = (double) width / 2;
double cy = (double) height / 2;
double daScale = (double) (height - 2) / (Math.PI + Math.PI);
double drScale = (double) (width - 1) / Math.sqrt((double) width * (double) width + (double) height * (double) height);
double PI2 = Math.PI / 2.0;
double TWOPI = Math.PI + Math.PI;
double a0 = (this.phi0) * Math.PI / 180.0;
double r0 = this.r0;
Pixel pPixel = new Pixel();
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
for (int i = 0; i < height; i++) {
double y0 = zoom * ((double) i - cy);
for (int j = 0; j < width; j++) {
/* transform the point */
double x0 = zoom * ((double) j - cx);
double dr = Math.sqrt(x0 * x0 + y0 * y0);
double da;
if (x0 != 0)
da = Math.atan(Tools.fabs33(y0) / Tools.fabs33(x0));
else
da = PI2;
if (x0 < 0.0) {
if (y0 < 0.0)
da = Math.PI - da;
else
da += Math.PI;
} else {
if (y0 >= 0.0)
da = TWOPI - da;
}
double x = (dr + r0) * drScale;
if (wrap) {
while (x >= ((double) width - 0.5)) x -= (double) (width - 1);
while ((int) x < 0.5) x += (double) (width - 1);
}
double y = (da + a0) * daScale + 1.0;
while (y >= ((double) height - 0.5)) y -= (double) (height - 1);
while ((int) y < 0.5) y += (double) (height - 1);
/* 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);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class FormulaComposeTransformer method performPixelTransformation.
@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);
parser.setVarValue("fgB", (double) fgPixel.b / 255.0);
// TODO Genlock: z. B. Testen, ob Intensitat 0 oder grober 0
// genlockFormula, genlockOperator (gleich, grober), genlockRefValue
bgPixel.r = Tools.roundColor((Double) parser.evaluate(redNode) * 255.0);
bgPixel.g = Tools.roundColor((Double) parser.evaluate(greenNode) * 255.0);
bgPixel.b = Tools.roundColor((Double) parser.evaluate(blueNode) * 255.0);
bgImg.setRGB(left, top, bgPixel);
}
}
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ScaleTransformer method scale_up_up.
private void scale_up_up(SimpleImage srcImg, SimpleImage dstImg) {
int swidth = srcImg.getImageWidth();
int sheight = srcImg.getImageHeight();
int width = dstImg.getImageWidth();
int height = dstImg.getImageHeight();
double sclX, sclY;
if (width > 1) {
sclX = (double) (swidth - 1) / (double) (width - 1);
} else
sclX = 1.0;
if (height > 1) {
sclY = (double) (sheight - 1) / (double) (height - 1);
} else
sclY = 1.0;
double cxD = (double) (width - 1) * 0.5;
double cyD = (double) (height - 1) * 0.5;
double cxS = (double) (swidth - 1) * 0.5;
double cyS = (double) (sheight - 1) * 0.5;
Pixel pPixel = new Pixel();
for (int i = 0; i < height; i++) {
double y0 = (double) i - cyD;
double y = y0 * sclY + cyS;
for (int j = 0; j < width; j++) {
// transform the point
double x0 = (double) j - cxD;
double x = x0 * sclX + cxS;
// render it
if (((int) x < 0) || ((int) x >= swidth) || ((int) y < 0) || ((int) y >= sheight)) {
pPixel.r = pPixel.g = pPixel.b = 0;
} else {
double xi = Tools.fmod33(x);
double yi = Tools.fmod33(y);
readSrcPixels(srcImg, 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))));
}
dstImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ScaleTransformer method scale_down_up.
private void scale_down_up(SimpleImage srcImg, SimpleImage dstImg) {
int swidth = srcImg.getImageWidth();
int sheight = srcImg.getImageHeight();
int width = dstImg.getImageWidth();
int height = dstImg.getImageHeight();
double sclX, sclY;
if (width > 1) {
sclX = (double) (swidth - 1) / (double) (width - 1);
} else
sclX = 1.0;
if (height > 1) {
sclY = (double) (sheight - 1) / (double) (height - 1);
} else
sclY = 1.0;
double cxD = (double) (width - 1) * 0.5;
double cyD = (double) (height - 1) * 0.5;
double cxS = (double) (swidth - 1) * 0.5;
double cyS = (double) (sheight - 1) * 0.5;
Pixel pPixel = new Pixel();
for (int i = 0; i < height; i++) {
double y0 = (double) i - cyD;
double y = y0 * sclY + cyS;
for (int j = 0; j < width; j++) {
// transform the point
double x0 = (double) j - cxD;
double x = x0 * sclX + cxS;
double xn = (x0 + 1.0) * sclX + cxS;
if (xn >= (swidth - 0.5))
xn = swidth - 1.0;
if (((int) x < 0) || ((int) x >= swidth) || ((int) y < 0) || ((int) y >= sheight)) {
pPixel.r = pPixel.g = pPixel.b = 0;
} else {
double xi = Tools.fmod33(x);
double yi = Tools.fmod33(y);
readSrcPixels(srcImg, x, y);
int cvalR = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
int cvalG = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
int cvalB = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
x = x - xi + 1.0;
int cnt = 1;
while (x < xn) {
readSrcPixels(srcImg, x, y);
cvalR += (1.0 - yi) * srcP.r + yi * srcR.r;
cvalG += (1.0 - yi) * srcP.g + yi * srcR.g;
cvalB += (1.0 - yi) * srcP.b + yi * srcR.b;
x += 1.0;
cnt++;
}
pPixel.r = roundColor(cvalR / (double) cnt);
pPixel.g = roundColor(cvalG / (double) cnt);
pPixel.b = roundColor(cvalB / (double) cnt);
}
dstImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ShearTransformer method shearX.
private void shearX(SimpleImage pImg) {
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
Pixel pPixel = new Pixel();
double cx = (double) width / 2.0 - 0.5;
double cy = (double) height / 2.0 - 0.5;
double oy = this.centreY - cy;
double zoom = this.zoom;
if (zoom < 0.01)
zoom = 0.01;
zoom = 1.0 / zoom;
double fshift = this.amount / (100.0 - 1.0);
double shift = 0.0 - fshift;
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
for (int i = 0; i < height; i++) {
double y0 = (double) i - cy;
for (int j = 0; j < width; j++) {
/* transform the point */
double x0 = (double) j - cx;
double amp = (y0 - oy) * shift;
double x = (x0 + amp) * zoom + cx;
double y = y0 * zoom + cy;
/* 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))));
}
pImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
}
}
}
Aggregations