use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ShearTransformer method shearY.
private void shearY(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 ox = this.centreX - cx;
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 = (x0 - ox) * shift;
double x = x0 * zoom + cx;
double y = (y0 + amp) * 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);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class ShearTransformer method shearY_Damp.
private void shearY_Damp(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 ox = this.centreX - cx;
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 damping = this.damping;
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 = (x0 - ox) * shift;
double dl2 = y0 - oy;
if (dl2 < 0.0)
dl2 = 0.0 - dl2;
amp = amp * Math.exp(dl2 * damping);
double x = x0 * zoom + cx;
double y = (y0 + amp) * 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);
}
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class PixelTransformer method performImageTransformation.
protected void performImageTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
final int BLOCK_SIZE = 64;
final int imageWidth = pImg.getImageWidth();
final int imageHeight = pImg.getImageHeight();
final BufferedImage bufferedImg = img.getBufferedImg();
final int[] pixels = new int[imageWidth * BLOCK_SIZE];
final Pixel p = new Pixel();
for (int b = 0; b < imageHeight; b += BLOCK_SIZE) {
int blockSize = BLOCK_SIZE;
int currHeight = b + BLOCK_SIZE;
if (currHeight > imageHeight) {
blockSize -= (currHeight - imageHeight);
}
bufferedImg.getRGB(0, b, imageWidth, blockSize, pixels, 0, imageWidth);
for (int y = 0; y < blockSize; y++) {
for (int x = 0; x < imageWidth; x++) {
p.setARGBValue(pixels[y * imageWidth + x]);
transformPixel(p, x, y + b, imageWidth, imageHeight);
pixels[y * imageWidth + x] = p.getARGBValue();
}
}
bufferedImg.setRGB(0, b, imageWidth, blockSize, pixels, 0, imageWidth);
}
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class Pixelize3DTransformer method createMeshFromImage.
@Override
protected void createMeshFromImage(Mesh3D pMesh3D, SimpleImage pImg, double pQuant3D) {
Tools.srand123(seed);
int imgWidth = pImg.getImageWidth();
int imgHeight = pImg.getImageHeight();
double xMin = -(double) imgWidth * 0.5;
double yMin = -(double) imgHeight * 0.5;
double zsize2 = blockThickness * 0.5;
// allocate structure
Block block;
switch(blockType) {
case SIMPLE:
block = new SimpleBlock(blockWidth, blockHeight);
break;
case DETAILED:
block = new DetailedBlock(blockWidth, blockHeight);
break;
default:
throw new IllegalStateException();
}
int rectXCount = imgWidth / blockWidth + (imgWidth % blockWidth > 0 ? 1 : 0);
int rectYCount = imgHeight / blockHeight + (imgHeight % blockHeight > 0 ? 1 : 0);
int rectCount = rectXCount * rectYCount;
int rectPCount = block.estimatePCount();
int rectFCount = block.estimateFCount();
int pCount = rectCount * rectPCount;
int currP = 0;
int fCount = rectCount * rectFCount;
int currF = 0;
double[] x = new double[pCount];
double[] y = new double[pCount];
double[] z = new double[pCount];
int[] pp1 = new int[fCount];
int[] pp2 = new int[fCount];
int[] pp3 = new int[fCount];
int[] color = new int[fCount];
// create structure
int dx = centre ? (imgWidth % blockWidth) / 2 : 0;
int dy = centre ? (imgHeight % blockHeight) / 2 : 0;
for (int row = 0; row < imgHeight; ) {
int y1 = row - dy;
if (y1 < 0)
y1 = 0;
int y2 = row - dy + blockHeight;
if (y2 > imgHeight - dy)
y2 = imgHeight - dy;
for (int col = 0; col < imgWidth; ) {
int x1 = col - dx;
if (x1 < 0)
x1 = 0;
int x2 = col - dx + blockWidth;
if (x2 > imgWidth - dx)
x2 = imgWidth - dx;
Pixel p = block.computeAVGColor(pImg, x1, x2, y1, y2);
if (!filteredByGenlock(p)) {
block.prepareTransformation(blockScale, blockScaleVariance, blockAngleAlpha, blockAngleBeta, blockAngleVariance);
block.createBlock(pImg, x1, x2, y1, y2, zsize2, p.getARGBValue());
block.transformBlock(x1, x2, y1, y2, xMin, yMin);
block.addToMainStructure(x, y, z, pp1, pp2, pp3, color, currP, currF);
currF += block.getFCount();
currP += block.getPCount();
} else
System.out.println("GENLOCK");
col += blockWidth;
}
row += blockHeight;
}
//
System.out.println("FACES: " + currF + " (" + fCount + ")");
System.out.println("POINTS: " + currP + " (" + pCount + ")");
pMesh3D.setFCount(currF);
pMesh3D.setPCount(currP);
pMesh3D.setX(x);
pMesh3D.setY(y);
pMesh3D.setZ(z);
pMesh3D.setPP1(pp1);
pMesh3D.setPP2(pp2);
pMesh3D.setPP3(pp3);
pMesh3D.setColor(color);
pMesh3D.setImageWidth(imgWidth);
pMesh3D.setImageHeight(imgHeight);
}
use of org.jwildfire.image.Pixel in project JWildfire by thargor6.
the class Polar2CartesianTransformer 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 *= 0.8;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
boolean wrap = this.wrap;
double cx = (double) width / 2 - 0.5;
double cy = (double) height / 2 - 0.5;
double daScale = (double) (width - 1) / (Math.PI + Math.PI);
double a0 = this.phi0;
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 dr = zoom * ((double) i + r0);
if (dr < 0)
dr = 0 - dr;
for (int j = 0; j < width; j++) {
/* transform the point */
double da = ((double) j + a0) / daScale;
double x = dr * Math.sin(da) + cx;
double y = dr * Math.cos(da) + cy;
if (wrap) {
while (x > ((double) width - 0.1)) x -= (double) width - 1.2;
while ((int) x < 0.1) x += (double) width - 1.2;
}
if (wrap) {
while (y > ((double) height - 0.1)) y -= (double) height - 1.2;
while ((int) y < 0.1) y += (double) height - 1.2;
}
/* 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, height - i - 1, pPixel.r, pPixel.g, pPixel.b);
}
}
}
Aggregations