use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class BlackholeTransformer method performPixelTransformation.
@Override
protected void performPixelTransformation(WFImage pImg) {
SimpleImage img = (SimpleImage) pImg;
double cx = centreX - 0.5;
double cy = centreY - 0.5;
double rZoom = 1.0 / zoom;
int width = pImg.getImageWidth();
int height = pImg.getImageHeight();
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++) {
/* transform the point */
double x0 = pX - cx;
double y0 = pY - cy;
double rr = Math.sqrt(x0 * x0 + y0 * y0);
x0 *= rZoom;
y0 *= rZoom;
double scl;
if (rr != 0.0)
scl = (rr + amount) / rr;
else
scl = 0.0;
double x = x0 * scl + cx;
double y = y0 * scl + 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))));
}
img.setRGB(pX, pY, pPixel.r, pPixel.g, pPixel.b);
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class Bump3DTransformer method transformMesh.
@Override
protected void transformMesh(Mesh3D pMesh3D, int pImageWidth, int pImageHeight) {
int pCount = pMesh3D.getPCount();
int width = pImageWidth;
int height = pImageHeight;
double[] x = pMesh3D.getX();
double[] y = pMesh3D.getY();
double[] z = pMesh3D.getZ();
WFImage heightMap = this.heightMap.getHDRImage();
if (heightMap != null) {
int hwidth = heightMap.getImageWidth();
int hheight = heightMap.getImageHeight();
if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
throw new IllegalArgumentException("Heightmap has the wrong size (scaling of HDR images currently not supported)");
}
float[] lum = new float[2];
((SimpleHDRImage) heightMap).getMinMaxLum(lum);
lumMin = lum[0];
lumMax = lum[1];
lumRange = lumMax - lumMin;
} else {
heightMap = this.heightMap.getImage();
int hwidth = heightMap.getImageWidth();
int hheight = heightMap.getImageHeight();
if ((hwidth != this.hWidth) || (hheight != this.hHeight)) {
SimpleImage scaledHeightMap = ((SimpleImage) heightMap).clone();
ScaleTransformer scaleT = new ScaleTransformer();
scaleT.setAspect(this.aspect);
scaleT.setUnit(ScaleTransformer.Unit.PIXELS);
scaleT.setScaleWidth(this.hWidth);
scaleT.setScaleHeight(this.hHeight);
scaleT.performImageTransformation(scaledHeightMap);
heightMap = scaledHeightMap;
}
}
double amount = 0.0 - this.amount;
int dx = hLeft - width / 2;
int dy = hTop - height / 2;
if (hCentre) {
dx += (width - this.hWidth) / 2;
dy += (height - this.hHeight) / 2;
}
double[][] weights, intArray;
if (this.smoothingMatrix == SmoothingMatrix.MATRIX_3x3) {
int smoothSize = 3;
weights = weights_3x3;
intArray = new double[smoothSize][smoothSize];
} else {
int smoothSize = 5;
weights = weights_5x5;
intArray = new double[smoothSize][smoothSize];
}
double zmin = 0.0, zmax = 0.0;
for (int i = 0; i < pCount; i++) {
int xx = (int) (x[i] - (double) dx + 0.5);
int yy = (int) (y[i] - (double) dy + 0.5);
if ((xx >= 0) && (xx < this.hWidth) && (yy >= 0) && (yy < this.hHeight)) {
readPixels(heightMap, xx, yy, intArray);
double intensity = getWeightedIntensity(intArray, weights) * amount;
if (intensity < zmin)
zmin = intensity;
else if (intensity > zmax)
zmax = intensity;
z[i] += intensity;
}
}
// Subtract ground
double fam = (zmax - zmin) / 2.0 + zmin;
if ((fam != 0.0) && (noGround)) {
for (int i = 0; i < pCount; i++) {
z[i] -= fam;
}
}
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class JWildfireApplet method refreshImagePanel.
private void refreshImagePanel() {
if (imageScrollPane != null) {
getImgMainPnl().remove(imageScrollPane);
imageScrollPane = null;
}
ImgSize size = getImgSize();
image = new SimpleImage(size.getWidth(), size.getHeight());
image.fillBackground(prefs.getTinaRandomBatchBGColorRed(), prefs.getTinaRandomBatchBGColorGreen(), prefs.getTinaRandomBatchBGColorBlue());
ImagePanel imagePanel = new ImagePanel(image, 0, 0, image.getImageWidth());
imagePanel.setSize(image.getImageWidth(), image.getImageHeight());
imagePanel.setPreferredSize(new Dimension(image.getImageWidth(), image.getImageHeight()));
imageScrollPane = new JScrollPane(imagePanel);
imageScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
imageScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
getImgMainPnl().add(imageScrollPane, BorderLayout.CENTER);
getImgMainPnl().getParent().validate();
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DancingFractalsController method refreshFlameImage.
public void refreshFlameImage(Flame flame, boolean pDrawTriangles, double pFPS, long pFrame, boolean pDrawFPS) {
FlamePanel imgPanel = getFlamePanel();
if (imgPanel == null)
return;
Rectangle bounds = imgPanel.getImageBounds();
int width = bounds.width;
int height = bounds.height;
if (width >= 16 && height >= 16) {
RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
if (flame != null) {
double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
double oldSampleDensity = flame.getSampleDensity();
imgPanel.setDrawTriangles(pDrawTriangles);
try {
double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
flame.setWidth(info.getImageWidth());
flame.setHeight(info.getImageHeight());
Flame renderFlame = new FlamePreparer(prefs).createRenderFlame(flame);
FlameRenderer renderer = new FlameRenderer(renderFlame, prefs, false, false);
renderer.setProgressUpdater(null);
RenderedFlame res = renderer.renderFlame(info);
SimpleImage img = res.getImage();
if (pDrawFPS) {
TextTransformer txt = new TextTransformer();
txt.setText1("fps: " + Tools.doubleToString(pFPS) + ", time: " + Tools.doubleToString(pFrame / 1000.0) + "s");
txt.setAntialiasing(false);
txt.setColor(Color.LIGHT_GRAY);
txt.setMode(Mode.NORMAL);
txt.setFontStyle(FontStyle.PLAIN);
txt.setFontName("Arial");
txt.setFontSize(10);
txt.setHAlign(HAlignment.LEFT);
txt.setVAlign(VAlignment.BOTTOM);
txt.transformImage(img);
}
imgPanel.setImage(img);
} finally {
flame.setSpatialFilterRadius(oldSpatialFilterRadius);
flame.setSampleDensity(oldSampleDensity);
}
}
} else {
try {
imgPanel.setImage(new SimpleImage(width, height));
} catch (Exception ex) {
ex.printStackTrace();
}
}
flameRootPanel.repaint();
}
use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.
the class DancingFractalsController method refreshPoolPreviewFlameImage.
public void refreshPoolPreviewFlameImage(Flame flame) {
FlamePanel imgPanel = getPoolPreviewFlamePanel();
if (imgPanel == null)
return;
Rectangle bounds = imgPanel.getImageBounds();
int width = bounds.width;
int height = bounds.height;
if (width >= 16 && height >= 16) {
RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
if (flame != null) {
imgPanel.setDrawTriangles(false);
double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
flame.setWidth(info.getImageWidth());
flame.setHeight(info.getImageHeight());
Flame renderFlame = new FlamePreparer(prefs).createRenderFlame(flame);
FlameRenderer renderer = new FlameRenderer(renderFlame, prefs, false, false);
renderer.setProgressUpdater(null);
RenderedFlame res = renderer.renderFlame(info);
imgPanel.setImage(res.getImage());
} else {
imgPanel.setImage(new SimpleImage(width, height));
}
} else {
imgPanel.setImage(new SimpleImage(width, height));
}
poolFlamePreviewPnl.repaint();
}
Aggregations