use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DisplaceTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
int probability = this.probability;
int rrad = this.radius;
srand123(seed);
Pixel sPixel = new Pixel();
if (probability == 100) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
sPixel.setARGBValue(img.getARGBValue(j, i));
int sr = sPixel.r;
int sg = sPixel.g;
int sb = sPixel.b;
int dx = (int) (rrad * drand() + 0.5);
int dy = (int) (rrad * drand() + 0.5);
int px = j + dx;
int py = i + dy;
if (px < 0)
px = 0;
else if (px >= width)
px = width - 1;
if (py < 0)
py = 0;
else if (py >= height)
py = height - 1;
sPixel.setARGBValue(img.getARGBValue(px, py));
int rp = sPixel.r;
int gp = sPixel.g;
int bp = sPixel.b;
img.setRGB(j, i, rp, gp, bp);
img.setRGB(px, py, sr, sg, sb);
}
}
} else {
double rprob = (double) ((double) 1.0 - (double) probability / (double) 100.0);
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
sPixel.setARGBValue(img.getARGBValue(j, i));
int sr = sPixel.r;
int sg = sPixel.g;
int sb = sPixel.b;
if (drand() >= rprob) {
int dx = (int) (rrad * drand() + 0.5);
int dy = (int) (rrad * drand() + 0.5);
int px = j + dx;
int py = i + dy;
if (px < 0)
px = 0;
else if (px >= width)
px = width - 1;
if (py < 0)
py = 0;
else if (py >= height)
py = height - 1;
sPixel.setARGBValue(img.getARGBValue(px, py));
int rp = sPixel.r;
int gp = sPixel.g;
int bp = sPixel.b;
img.setRGB(j, i, rp, gp, bp);
img.setRGB(px, py, sr, sg, sb);
}
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class ErodeTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
if (this.size <= 1)
return;
SimpleImage img = (SimpleImage) pImg;
Tools.srand123(this.seed);
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
short[][] shape;
switch(this.shape) {
case DIAMOND:
shape = generateDiamond(this.size);
break;
case DISK:
shape = generateDisk(this.size);
break;
case SQUARE:
shape = generateSquare(this.size);
break;
case PLUS:
shape = generatePlus(this.size);
break;
case X:
shape = generateX(this.size);
break;
default:
shape = generateRandom(this.size);
break;
}
SimpleImage srcGreyImg = null;
if ((this.mode == Mode.DILATE) || (this.mode == Mode.ERODE) || (this.mode == Mode.NEON)) {
srcGreyImg = srcImg.clone();
ColorToGrayTransformer cT = new ColorToGrayTransformer();
cT.setWeights(ColorToGrayTransformer.Weights.LUMINANCE);
cT.transformImage(srcGreyImg);
}
switch(mode) {
case ERODE:
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int lumMin = srcGreyImg.getRValue(j, i);
int xLumMin = j;
int yLumMin = i;
for (int s = 0; s < shape.length; s++) {
int x = j + shape[s][0];
int y = i + shape[s][1];
if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
int lum = srcGreyImg.getRValue(x, y);
if (lum < lumMin) {
lumMin = lum;
xLumMin = x;
yLumMin = y;
}
}
}
img.setARGB(j, i, srcImg.getARGBValue(xLumMin, yLumMin));
}
}
break;
case DILATE:
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int lumMax = srcGreyImg.getRValue(j, i);
int xLumMax = j;
int yLumMax = i;
for (int s = 0; s < shape.length; s++) {
int x = j + shape[s][0];
int y = i + shape[s][1];
if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
int lum = srcGreyImg.getRValue(x, y);
if (lum > lumMax) {
lumMax = lum;
xLumMax = x;
yLumMax = y;
}
}
}
img.setARGB(j, i, srcImg.getARGBValue(xLumMax, yLumMax));
}
}
break;
case NEON:
Pixel srcPixel = new Pixel();
Pixel currPixel = new Pixel();
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int lumMax = srcGreyImg.getRValue(j, i);
int lum0 = lumMax;
int xLumMax = j;
int yLumMax = i;
for (int s = 0; s < shape.length; s++) {
int x = j + shape[s][0];
int y = i + shape[s][1];
if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
int lum = srcGreyImg.getRValue(x, y);
if (lum > lumMax) {
lumMax = lum;
xLumMax = x;
yLumMax = y;
}
}
}
int m1 = 30;
int m2 = 100 - m1;
srcPixel.setARGBValue(srcImg.getARGBValue(xLumMax, yLumMax));
currPixel.setARGBValue(srcImg.getARGBValue(j, i));
currPixel.r = (srcPixel.r * m1 + currPixel.r * m2) / 100;
currPixel.g = (srcPixel.g * m1 + currPixel.g * m2) / 100;
currPixel.b = (srcPixel.b * m1 + currPixel.b * m2) / 100;
if (Math.abs(lum0 - lumMax) > 50)
img.setRGB(j, i, 0, 128, 0);
// pImg.setARGB(j, i, srcImg.getARGBValue(xLumMax, yLumMax));
}
}
break;
case OILTRANSFER:
int[] colorValues = new int[shape.length];
short[] colorUsed = new short[shape.length];
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
int cCount = 0;
for (int s = 0; s < colorUsed.length; s++) colorUsed[s] = 0;
for (int s = 0; s < shape.length; s++) {
int x = j + shape[s][0];
int y = i + shape[s][1];
if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) {
int color = srcImg.getARGBValue(x, y);
boolean found = false;
for (short t = 0; t < cCount; t++) {
if (colorValues[t] == color) {
colorUsed[t]++;
found = true;
break;
}
}
if (!found) {
colorValues[cCount] = color;
colorUsed[cCount++] = 1;
}
}
}
int color = srcImg.getARGBValue(j, i);
int usedMax = 1;
for (int t = 0; t < cCount; t++) {
if (colorUsed[t] > usedMax) {
usedMax = colorUsed[t];
color = colorValues[t];
}
}
img.setARGB(j, i, color);
}
}
break;
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FlipTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
Pixel pixel = new Pixel();
if (axis == Axis.X) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(width - j - 1, i));
img.setRGB(j, i, pixel);
}
}
} else if (axis == Axis.Y) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(j, height - i - 1));
img.setRGB(j, i, pixel);
}
}
} else if (axis == Axis.XY) {
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
pixel.setARGBValue(srcImg.getARGBValue(width - j - 1, height - i - 1));
img.setRGB(j, i, pixel);
}
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class FormulaColorTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
JEPWrapper parser = new JEPWrapper();
parser.addVariable("r", 0.0);
parser.addVariable("g", 0.0);
parser.addVariable("b", 0.0);
parser.addVariable("x", 0.0);
parser.addVariable("y", 0.0);
parser.addVariable("width", (double) width);
parser.addVariable("height", (double) height);
Node redNode = parser.parse(formula1Red);
Node greenNode = parser.parse(formula2Green);
Node blueNode = parser.parse(formula3Blue);
Pixel pixel = new Pixel();
for (int i = 0; i < height; i++) {
parser.setVarValue("y", i);
for (int j = 0; j < width; j++) {
parser.setVarValue("x", j);
pixel.setARGBValue(srcImg.getARGBValue(j, i));
if (useOriginalRGBValues) {
parser.setVarValue("r", (double) pixel.r);
parser.setVarValue("g", (double) pixel.g);
parser.setVarValue("b", (double) pixel.b);
pixel.r = Tools.roundColor((Double) parser.evaluate(redNode));
pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode));
pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode));
} else {
parser.setVarValue("r", (double) pixel.r / 255.0);
parser.setVarValue("g", (double) pixel.g / 255.0);
parser.setVarValue("b", (double) pixel.b / 255.0);
pixel.r = Tools.roundColor((Double) parser.evaluate(redNode) * 255.0);
pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode) * 255.0);
pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode) * 255.0);
}
img.setRGB(j, i, pixel);
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class Genlock3DTransformer method transformMesh.
@Override
protected void transformMesh(Mesh3D pMesh3D, int pImageWidth, int pImageHeight) {
int fCount = pMesh3D.getFCount();
/* 3-point-polygons */
if (fCount > 0) {
Pixel pixel = new Pixel();
int[] fLst = new int[fCount];
int[] color = pMesh3D.getColor();
double[] u = pMesh3D.getU();
double[] v = pMesh3D.getV();
int[] p1 = pMesh3D.getPP1();
SimpleImage texture = pMesh3D.getTexture();
int valid = 0;
int r1 = this.colorA.getRed();
int g1 = this.colorA.getGreen();
int b1 = this.colorA.getBlue();
int r2 = this.colorB.getRed();
int g2 = this.colorB.getGreen();
int b2 = this.colorB.getBlue();
if (this.genlock == Genlock.COLOR) {
for (int i = 0; i < fCount; i++) {
if (color != null) {
pixel.setARGBValue(color[i]);
} else {
int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
}
if ((pixel.r != r1) || (pixel.g != g1) || (pixel.b != b1)) {
fLst[i] = 1;
valid++;
}
}
} else if (this.genlock == Genlock.IN_RANGE) {
for (int i = 0; i < fCount; i++) {
if (color != null) {
pixel.setARGBValue(color[i]);
} else {
int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
}
if ((((pixel.r >= r1) && (pixel.r <= r2)) || ((pixel.r >= r2) && (pixel.r <= r1))) || (((pixel.g >= g1) && (pixel.g <= g2)) || ((pixel.g >= g2) && (pixel.g <= g1))) || (((pixel.b >= b1) && (pixel.b <= b2)) || ((pixel.b >= b2) && (pixel.b <= b1)))) {
} else {
fLst[i] = 1;
valid++;
}
}
} else if (this.genlock == Genlock.OUT_RANGE) {
for (int i = 0; i < fCount; i++) {
if (color != null) {
pixel.setARGBValue(color[i]);
} else {
int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
}
if ((((pixel.r >= r1) && (pixel.r <= r2)) || ((pixel.r >= r2) && (pixel.r <= r1))) || (((pixel.g >= g1) && (pixel.g <= g2)) || ((pixel.g >= g2) && (pixel.g <= g1))) || (((pixel.b >= b1) && (pixel.b <= b2)) || ((pixel.b >= b2) && (pixel.b <= b1)))) {
fLst[i] = 1;
valid++;
}
}
}
if (valid < fCount) {
if (valid > 0) {
pMesh3D.setFCount(valid);
{
int[] pp = new int[valid];
int curr = 0;
int[] ps = pMesh3D.getPP1();
for (int i = 0; i < fCount; i++) {
if (fLst[i] != 0)
pp[curr++] = ps[i];
}
pMesh3D.setPP1(pp);
}
{
int[] pp = new int[valid];
int curr = 0;
int[] ps = pMesh3D.getPP2();
for (int i = 0; i < fCount; i++) {
if (fLst[i] != 0)
pp[curr++] = ps[i];
}
pMesh3D.setPP2(pp);
}
{
int[] pp = new int[valid];
int curr = 0;
int[] ps = pMesh3D.getPP3();
for (int i = 0; i < fCount; i++) {
if (fLst[i] != 0)
pp[curr++] = ps[i];
}
pMesh3D.setPP3(pp);
}
if (pMesh3D.getColor() != null) {
int[] rr = new int[valid];
int curr = 0;
int[] rs = pMesh3D.getColor();
for (int i = 0; i < fCount; i++) {
if (fLst[i] != 0)
rr[curr++] = rs[i];
}
pMesh3D.setColor(rr);
}
} else {
pMesh3D.setFCount(0);
pMesh3D.setPP1(null);
pMesh3D.setPP2(null);
pMesh3D.setPP3(null);
pMesh3D.setColor(null);
}
}
}
}
Aggregations