Search in sources :

Example 16 with SimpleImage

use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.

the class CloudCreator method fillImage.

@Override
protected void fillImage(SimpleImage res) {
    int width = res.getImageWidth();
    int height = res.getImageHeight();
    Random rnd = new Random();
    rnd.setSeed(this.seed);
    double cover = 1.0 - this.cover;
    double aspect = (double) width / (double) height;
    int frequency = this.initialFrequency;
    int frequencyX = (int) (frequency * aspect + 0.5);
    int frequencyY = (int) (frequency * aspect + 0.5);
    double alphaInt = 1.0f;
    BufferedImage mainImage = res.getBufferedImg();
    Graphics2D mainGr = mainImage.createGraphics();
    for (int i = 0; i < this.octaves; i++) {
        // create a small random image
        BufferedImage rndMap = new BufferedImage(frequencyX, frequencyY, BufferedImage.TYPE_INT_ARGB);
        {
            Graphics2D g = rndMap.createGraphics();
            try {
                switch(colorMode) {
                    case COLOR:
                        for (int x = 0; x < frequencyX; x++) {
                            for (int y = 0; y < frequencyY; y++) {
                                int rVal = rnd.nextInt(255);
                                int gVal = rnd.nextInt(255);
                                int bVal = rnd.nextInt(255);
                                g.setColor(new Color(rVal, gVal, bVal, (int) (255.0 * alphaInt + 0.5)));
                                g.fillRect(x, y, 1, 1);
                            }
                        }
                        break;
                    case GREY:
                        for (int x = 0; x < frequencyX; x++) {
                            for (int y = 0; y < frequencyY; y++) {
                                int val = rnd.nextInt(255);
                                g.setColor(new Color(val, val, val, (int) (255.0 * alphaInt + 0.5)));
                                g.fillRect(x, y, 1, 1);
                            }
                        }
                        break;
                    case BASE_COLOR:
                        int rBase = this.cloudColor.getRed();
                        int gBase = this.cloudColor.getGreen();
                        int bBase = this.cloudColor.getBlue();
                        for (int x = 0; x < frequencyX; x++) {
                            for (int y = 0; y < frequencyY; y++) {
                                int val = rnd.nextInt(255);
                                int rVal = (rBase * val) / 255;
                                int gVal = (gBase * val) / 255;
                                int bVal = (bBase * val) / 255;
                                g.setColor(new Color(rVal, gVal, bVal, (int) (255.0 * alphaInt + 0.5)));
                                g.fillRect(x, y, 1, 1);
                            }
                        }
                        break;
                }
            } finally {
                g.dispose();
            }
        }
        // scale up the image using Java-built-in interpolation
        {
            BufferedImage scaledRndMap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = scaledRndMap.createGraphics();
            try {
                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                g.drawImage(rndMap, 0, 0, width, height, 0, 0, frequencyX, frequencyY, null);
            } finally {
                g.dispose();
            }
            mainGr.drawImage(scaledRndMap, null, 0, 0);
        }
        alphaInt *= this.persistence;
        frequency += frequency;
        frequencyX = (int) (frequency * aspect + 0.5);
        frequencyY = (int) (frequency * aspect + 0.5);
    }
    // apply an exponential filter to let the noise more look like clouds
    if (mode == Mode.CLOUDS) {
        final double rWeight = 0.2990;
        final double gWeight = 0.5880;
        final double bWeight = 0.1130;
        SimpleImage bgImg = (this.backgroundImg != null) ? backgroundImg.getImage() : null;
        Pixel pixel = new Pixel();
        Pixel bgPixel = new Pixel();
        for (int i = 0; i < mainImage.getWidth(); i++) {
            for (int j = 0; j < mainImage.getHeight(); j++) {
                pixel.setARGBValue(res.getARGBValue(i, j));
                double lum = pixel.r * rWeight + pixel.g * gWeight + pixel.b * bWeight;
                double c = lum - (cover * 255);
                if (c < 0)
                    c = 0;
                int iVal = Tools.roundColor(255.0 - (Math.pow(this.sharpness, c) * 255.0));
                int bgRed = 0, bgGreen = 0, bgBlue = 0;
                switch(bgMode) {
                    case IMAGE:
                        if (bgImg != null) {
                            bgPixel.setARGBValue(bgImg.getARGBValueIgnoreBounds(i, j));
                            bgRed = bgPixel.r;
                            bgGreen = bgPixel.g;
                            bgBlue = bgPixel.b;
                        }
                        break;
                    case COLOR:
                        bgRed = this.bgColor.getRed();
                        bgGreen = this.bgColor.getGreen();
                        bgBlue = this.bgColor.getBlue();
                        break;
                }
                switch(colorMode) {
                    case GREY:
                        pixel.r = expose(iVal + 1.5 * bgRed);
                        pixel.g = expose(iVal + 1.5 * bgGreen);
                        pixel.b = expose(iVal + 1.5 * bgBlue);
                        break;
                    default:
                        pixel.r = expose((iVal * pixel.r) / 255 + 1.5 * bgRed);
                        pixel.g = expose((iVal * pixel.g) / 255 + 1.5 * bgGreen);
                        pixel.b = expose((iVal * pixel.b) / 255 + 1.5 * bgBlue);
                        break;
                }
                res.setRGB(i, j, pixel);
            }
        }
    }
}
Also used : Random(java.util.Random) Color(java.awt.Color) SimpleImage(org.jwildfire.image.SimpleImage) BufferedImage(java.awt.image.BufferedImage) Pixel(org.jwildfire.image.Pixel) Graphics2D(java.awt.Graphics2D)

Example 17 with SimpleImage

use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.

the class ImageCreator method createImage.

public SimpleImage createImage(int pWidth, int pHeight) {
    long t0 = initTime();
    BufferedImage bufferedImg = new BufferedImage(pWidth, pHeight, BufferedImage.TYPE_INT_RGB);
    SimpleImage res = new SimpleImage(bufferedImg, pWidth, pHeight);
    fillImage(res);
    showElapsedTime(t0);
    return res;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) BufferedImage(java.awt.image.BufferedImage)

Example 18 with SimpleImage

use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.

the class TileBrickCreator method fillImage.

@Override
protected void fillImage(SimpleImage res) {
    Tools.srand123(this.seed);
    double rprob = (double) ((double) 1.0 - (double) probability / (double) 100.0);
    SimpleImage brickImg = this.brickImage.getImage().clone();
    {
        ScaleTransformer scaleT = new ScaleTransformer();
        scaleT.setScaleWidth(brickSize);
        scaleT.setAspect(ScaleAspect.KEEP_WIDTH);
        scaleT.transformImage(brickImg);
    }
    int width = res.getImageWidth();
    int height = res.getImageHeight();
    int brickWidth = brickImg.getImageWidth();
    int brickHeight = brickImg.getImageHeight();
    int colCount = width / brickWidth;
    if (colCount * brickWidth < width)
        colCount++;
    int rowCount = height / brickHeight;
    if (rowCount * brickHeight < height)
        rowCount++;
    for (int i = 0; i < rowCount; i++) {
        int off = i * this.brickShift;
        while (off > 0) off -= brickWidth;
        for (int j = 0; j < (off == 0 ? colCount : colCount + 1); j++) {
            SimpleImage compImg = brickImg;
            if (Tools.drand() >= rprob) {
                int bRed = (int) (redVariance - Tools.drand() * 2 * redVariance + 0.5);
                int bGreen = (int) (greenVariance - Tools.drand() * 2 * greenVariance + 0.5);
                int bBlue = (int) (blueVariance - Tools.drand() * 2 * blueVariance + 0.5);
                compImg = compImg.clone();
                BalancingTransformer bT = new BalancingTransformer();
                bT.setRed(bRed);
                bT.setGreen(bGreen);
                bT.setBlue(bBlue);
                bT.transformImage(compImg);
            }
            ComposeTransformer cT = new ComposeTransformer();
            cT.setHAlign(ComposeTransformer.HAlignment.OFF);
            cT.setVAlign(ComposeTransformer.VAlignment.OFF);
            cT.setTop(i * brickHeight);
            int left = j * brickWidth + off;
            cT.setLeft(left);
            cT.setForegroundImage(compImg);
            cT.transformImage(res);
        }
    }
}
Also used : BalancingTransformer(org.jwildfire.transform.BalancingTransformer) ComposeTransformer(org.jwildfire.transform.ComposeTransformer) SimpleImage(org.jwildfire.image.SimpleImage) ScaleTransformer(org.jwildfire.transform.ScaleTransformer)

Example 19 with SimpleImage

use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.

the class DancingFractalsController method getFlamePanel.

private FlamePanel getFlamePanel() {
    if (flamePanel == null) {
        // flameRootPanel can't be null !?
        int borderWidth = flameRootPanel.getBorder().getBorderInsets(flameRootPanel).left;
        int width = flameRootPanel.getWidth() - borderWidth;
        int height = flameRootPanel.getHeight() - borderWidth;
        if (width < 16 || height < 16)
            return null;
        SimpleImage img = new SimpleImage(width, height);
        img.fillBackground(0, 0, 0);
        flamePanel = new FlamePanel(prefs, img, 0, 0, flameRootPanel.getWidth() - borderWidth, null, null);
        flamePanel.setRenderWidth(640);
        flamePanel.setRenderHeight(480);
        flameRootPanel.add(flamePanel, BorderLayout.CENTER);
        flameRootPanel.getParent().validate();
        flameRootPanel.repaint();
    }
    flamePanel.setFlameHolder(renderThread);
    return flamePanel;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel)

Example 20 with SimpleImage

use of org.jwildfire.image.SimpleImage in project JWildfire by thargor6.

the class DancingFractalsController method getGraph1Panel.

private ImagePanel getGraph1Panel() {
    if (graph1Panel == null && graph1RootPanel != null) {
        int width = graph1RootPanel.getWidth();
        int height = graph1RootPanel.getHeight();
        SimpleImage img = new SimpleImage(width, height);
        img.fillBackground(0, 0, 0);
        graph1Panel = new ImagePanel(img, 0, 0, graph1RootPanel.getWidth());
        graph1RootPanel.add(graph1Panel, BorderLayout.CENTER);
        graph1RootPanel.getParent().validate();
        graph1RootPanel.repaint();
    }
    return graph1Panel;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImagePanel(org.jwildfire.swing.ImagePanel)

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