Search in sources :

Example 81 with SimpleImage

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);
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 82 with SimpleImage

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;
        }
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) WFImage(org.jwildfire.image.WFImage) SimpleImage(org.jwildfire.image.SimpleImage)

Example 83 with SimpleImage

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();
}
Also used : JScrollPane(javax.swing.JScrollPane) SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension) ImagePanel(org.jwildfire.swing.ImagePanel)

Example 84 with SimpleImage

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();
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) TextTransformer(org.jwildfire.transform.TextTransformer) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 85 with SimpleImage

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();
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

SimpleImage (org.jwildfire.image.SimpleImage)174 Pixel (org.jwildfire.image.Pixel)37 ImagePanel (org.jwildfire.swing.ImagePanel)24 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)20 Dimension (java.awt.Dimension)18 Flame (org.jwildfire.create.tina.base.Flame)17 File (java.io.File)16 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)16 ArrayList (java.util.ArrayList)14 Rectangle (java.awt.Rectangle)12 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)12 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)12 Graphics (java.awt.Graphics)10 SimpleHDRImage (org.jwildfire.image.SimpleHDRImage)10 WFImage (org.jwildfire.image.WFImage)9 ImageReader (org.jwildfire.io.ImageReader)9 JPanel (javax.swing.JPanel)8 JScrollPane (javax.swing.JScrollPane)8 ResolutionProfile (org.jwildfire.base.ResolutionProfile)8 Color (java.awt.Color)7