use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class TurnTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
if ((this.angle == Angle._90) || (this.angle == Angle._270))
img.resetImage(height, width);
Pixel pixel = new Pixel();
if (((this.angle == Angle._90) && (this.direction == Direction.LEFT)) || ((this.angle == Angle._270) && (this.direction == Direction.RIGHT))) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(j, i));
img.setRGB(i, width - j - 1, pixel);
}
}
} else if (this.angle == Angle._180) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(j, i));
img.setRGB(width - j - 1, height - i - 1, pixel);
}
}
} else if (((angle == Angle._270) && (this.direction == Direction.LEFT)) || ((angle == Angle._90) && (this.direction == Direction.RIGHT))) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(j, i));
img.setRGB(height - i - 1, j, pixel);
}
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class TwirlTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
double w1 = (double) pImg.getImageWidth() - 1.0;
double h1 = (double) pImg.getImageHeight() - 1.0;
double alpha = (0.0 - (double) (this.amount) * Math.PI) / (double) 180.0;
double cx = this.centreX - 0.5;
double cy = this.centreY - 0.5;
double zoom = 1.0 / this.zoom;
double radius = this.radius;
radius *= radius;
double power = this.power;
double da = alpha / Math.pow(radius, power);
Pixel pPixel = new Pixel();
for (int pY = 0; pY < pImg.getImageHeight(); pY++) {
for (int pX = 0; pX < pImg.getImageWidth(); pX++) {
pPixel.setARGBValue(img.getARGBValue(pX, pY));
double dyq = (double) pY - cy;
double y0 = dyq * zoom;
dyq *= dyq;
double x0 = (double) pX - cx;
double rr = x0 * x0 + dyq;
x0 *= zoom;
if (rr <= radius) {
if (this.fallOff == FallOff.OUT)
rr = radius - rr;
double am = Math.pow(rr, power) * da;
double sina = Math.sin(am);
double cosa = Math.cos(am);
double x = cosa * x0 + sina * y0 + cx;
double y = -sina * x0 + cosa * y0 + cy;
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))));
}
} else {
readSrcPixels(pX, pY);
pPixel.r = srcP.r;
pPixel.g = srcP.g;
pPixel.b = srcP.b;
}
img.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
}
}
applySmoothing(img, 1);
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class WaveTransformer method waveX.
private void waveX(SimpleImage pImg) {
double cx = this.centreX - 0.5;
double cy = this.centreY - 0.5;
double zoom = 1.0 / this.zoom;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
double PI2 = 2.0 * Math.PI;
double shift = this.shift;
double wavelength = this.wavelength * this.zoom;
double amplitude = 0.0 - this.amplitude * this.zoom;
double phase = this.phase;
shift = 2.0 * shift / (double) (height - 1);
double amp = amplitude;
double t = this.frames != 0 ? (double) this.frame / (double) this.frames : 0.0;
double w1 = (double) width - 1.0;
double h1 = (double) height - 1.0;
Pixel pPixel = new Pixel();
for (int pY = 0; pY < height; pY++) {
for (int pX = 0; pX < width; pX++) {
pPixel.setARGBValue(pImg.getARGBValue(pX, pY));
/* transform the point */
double x0 = (double) pX - cx;
double y0 = (double) pY - cy;
double dl = (x0 - shift * pY) / wavelength;
double zz = amp * Math.sin((PI2 * (t - dl)) + phase);
y0 += zz;
double x = x0 * zoom + cx;
double y = y0 * zoom + cy;
/* color-wrapping */
if (this.wrap) {
while (x >= ((double) width - 0.5)) x -= (double) (width - 1);
while ((int) x < 0.5) x += (double) (width - 1);
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))));
}
pImg.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class WindTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
int contrast = 0;
short[][] smask = new short[height][width];
int rs = 2990;
int gs = 5880;
int bs = 1130;
rs = (rs * Tools.VPREC) / 10000;
gs = (gs * Tools.VPREC) / 10000;
bs = (bs * Tools.VPREC) / 10000;
Pixel p0 = new Pixel();
Pixel p1 = new Pixel();
Tools.srand123(this.seed);
/* flip the image */
if (direction == Direction.LEFT) {
srcImg = srcImg.clone();
FlipTransformer ft = new FlipTransformer();
ft.setAxis(FlipTransformer.Axis.X);
ft.transformImage(srcImg);
ft.setAxis(FlipTransformer.Axis.X);
ft.transformImage(img);
}
/**
* 1st line *
*/
for (int i = 0; i < width; i++) smask[0][i] = 1;
/**
* lines 2...(height-2) *
*/
for (int i = 1; i < (height - 1); i++) {
/* 1st pixel */
smask[i][0] = 1;
/* process pixels 2..width-1 */
for (int j = 1; j < (width - 1); j++) {
int dd = 0, int1;
p1.setARGBValue(srcImg.getARGBValue(j - 1, i - 1));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd += int1;
p1.setARGBValue(srcImg.getARGBValue(j + 1, i - 1));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd -= int1;
p1.setARGBValue(srcImg.getARGBValue(j - 1, i));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd += int1;
p1.setARGBValue(srcImg.getARGBValue(j + 1, i));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd -= int1;
p1.setARGBValue(srcImg.getARGBValue(j - 1, i + 1));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd += int1;
p1.setARGBValue(srcImg.getARGBValue(j + 1, i + 1));
int1 = (rs * p1.r + gs * p1.g + bs * p1.b) >> Tools.SPREC;
dd -= int1;
if (dd < contrast) {
smask[i][j] = 1;
}
}
/* last pixel */
smask[i][width - 1] = 1;
}
/**
* last line *
*/
for (int i = 0; i < width; i++) smask[height - 1][i] = 1;
/**
* accept only "thick" lines *
*/
for (int i = 1; i < (height - 1); i++) {
for (int j = 1; j < (width - 1); j++) {
if (smask[i][j] == 0) {
if (smask[i][j + 1] != 0)
smask[i][j] = 1;
}
}
}
/**
* create "thin" lines *
*/
for (int i = 1; i < (height - 1); i++) {
nextLine: for (int j = (width - 2); j >= 1; j--) {
if (smask[i][j] == 0) {
int k = j - 1;
while (smask[i][k] == 0) {
smask[i][k] = 1;
k--;
if (k < 1)
continue nextLine;
}
}
}
}
/**
* remove isolated pixels *
*/
for (int i = 1; i < (height - 1); i++) {
for (int j = 1; j < (width - 1); j++) {
if (smask[i][j] == 0) {
int dd = 0;
dd += smask[i][j - 1];
dd += smask[i][j + 1];
dd += smask[i - 1][j];
dd += smask[i + 1][j];
dd += smask[i + 1][j - 1];
dd += smask[i + 1][j + 1];
dd += smask[i - 1][j - 1];
dd += smask[i - 1][j + 1];
if (dd == 8)
smask[i][j] = 1;
}
}
}
/**
* apply the changes *
*/
int intensity0 = this.intensity;
int intensity1 = intensity0 / 2;
{
double rprob = (double) ((double) 1.0 - (double) this.probability / (double) 100.0);
for (int i = 0; i < height; i++) {
cont: for (int j = (width - 1); j >= 0; j--) {
if ((smask[i][j] == 0) && (Tools.drand() >= rprob)) {
if (j < 1) {
continue cont;
}
int intensity = intensity0 + (int) (Tools.drand() * intensity1 + 0.5);
double dm = 100.0 / (double) (intensity - 1);
int kmax = intensity;
if ((j + kmax) >= width)
kmax = width - j;
for (int k = 0; k < kmax; k++) {
int mix = (int) (100.0 - (double) k * dm + 0.5);
int m1 = 100 - mix;
int m2 = mix;
p0.setARGBValue(srcImg.getARGBValue(j, i));
p1.setARGBValue(srcImg.getARGBValue(j + k, i));
int rv = ((int) ((int) p1.r * m1) + (int) p0.r * m2) / (int) 100;
int gv = ((int) ((int) p1.g * m1) + (int) p0.g * m2) / (int) 100;
int bv = ((int) ((int) p1.b * m1) + (int) p0.b * m2) / (int) 100;
img.setRGB(j + k, i, rv, gv, bv);
}
}
}
}
}
/* flip the image */
if (direction == Direction.LEFT) {
FlipTransformer ft = new FlipTransformer();
ft.setAxis(FlipTransformer.Axis.X);
ft.transformImage(img);
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class Mesh3DTransformer method applySmoothing.
protected void applySmoothing(SimpleImage pImg, int pSmoothingAmount) {
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
Pixel pixel = new Pixel();
for (int k = 0; k < pSmoothingAmount; k++) {
for (int i = 1; i < (height - 1); i++) {
/* process pixels 2..width-1 */
for (int j = 1; j < (width - 1); j++) {
pixel.setARGBValue(pImg.getARGBValue(j, i - 1));
int r1 = pixel.r;
int g1 = pixel.g;
int b1 = pixel.b;
pixel.setARGBValue(pImg.getARGBValue(j + 1, i));
int r2 = pixel.r;
int g2 = pixel.g;
int b2 = pixel.b;
pixel.setARGBValue(pImg.getARGBValue(j, i + 1));
int r3 = pixel.r;
int g3 = pixel.g;
int b3 = pixel.b;
pixel.setARGBValue(pImg.getARGBValue(j, i));
int r = pixel.r;
int g = pixel.g;
int b = pixel.b;
int av1 = (r1 + g1 + b1);
int av2 = (r2 + g2 + b2);
int av3 = (r3 + g3 + b3);
int av = (r + g + b);
int d1 = av1 - av;
if (d1 < 0)
d1 = 0 - d1;
int d2 = av2 - av;
if (d2 < 0)
d2 = 0 - d2;
int d3 = av3 - av;
if (d3 < 0)
d3 = 0 - d3;
if ((d1 > 64) && (d2 > 64)) {
int rv = r1 * d1 + r2 * d2;
rv /= (d1 + d2);
rv += r;
rv /= 2;
int gv = g1 * d1 + g2 * d2;
gv /= (d1 + d2);
gv += g;
gv /= 2;
int bv = b1 * d1 + b2 * d2;
bv /= (d1 + d2);
bv += b;
bv /= 2;
pImg.setRGB(j, i, rv, gv, bv);
} else if ((d2 > 64) && (d3 > 64)) {
int rv = r2 * d2 + r3 * d3;
rv /= (d2 + d3);
rv += r;
rv /= 2;
int gv = g2 * d2 + g3 * d3;
gv /= (d2 + d3);
gv += g;
gv /= 2;
int bv = b2 * d2 + b3 * d3;
bv /= (d2 + d3);
bv += b;
bv /= 2;
pImg.setRGB(j, i, rv, gv, bv);
}
}
}
}
}
Aggregations