Search in sources :

Example 1 with BalancingTransformer

use of org.jwildfire.transform.BalancingTransformer 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 2 with BalancingTransformer

use of org.jwildfire.transform.BalancingTransformer in project JWildfire by thargor6.

the class JWildfire method createMainDesktopPane.

@SuppressWarnings("serial")
private JDesktopPane createMainDesktopPane() {
    if (prefs.getDesktopBackgroundImagePath() != null && !prefs.getDesktopBackgroundImagePath().isEmpty()) {
        try {
            SimpleImage img = new ImageReader(this).loadImage(prefs.getDesktopBackgroundImagePath());
            if (prefs.getDesktopBackgroundDarkenAmount() > 0.1) {
                double scale = prefs.getDesktopBackgroundDarkenAmount();
                {
                    BalancingTransformer bT = new BalancingTransformer();
                    bT.setContrast(Tools.limitValue(Tools.FTOI(-160.0 * scale), -200, 200));
                    bT.setGamma(Tools.limitValue(Tools.FTOI(-180.0 * scale), -200, 200));
                    bT.transformImage(img);
                }
                {
                    BalancingTransformer bT = new BalancingTransformer();
                    bT.setBrightness(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
                    bT.setContrast(Tools.limitValue(Tools.FTOI(-20.0 * scale), -200, 200));
                    bT.setGamma(Tools.limitValue(Tools.FTOI(-220.0 * scale), -200, 200));
                    bT.transformImage(img);
                }
                backgroundImage = img.getBufferedImg();
            }
        } catch (Exception ex) {
            backgroundImage = null;
            ex.printStackTrace();
        }
    }
    if (backgroundImage == null) {
        try {
            backgroundImage = ImageIO.read(this.getClass().getResource("/org/jwildfire/swing/backgrounds/wallpaper_pearls2.png"));
        } catch (Exception ex) {
            backgroundImage = null;
            ex.printStackTrace();
        }
    }
    if (backgroundImage != null) {
        return new JDesktopPane() {

            @Override
            protected void paintComponent(Graphics grphcs) {
                super.paintComponent(grphcs);
                grphcs.drawImage(backgroundImage, 0, 0, null);
            }

            @Override
            public Dimension getPreferredSize() {
                return new Dimension(backgroundImage.getWidth(), backgroundImage.getHeight());
            }
        };
    } else {
        return new JDesktopPane();
    }
}
Also used : Graphics(java.awt.Graphics) BalancingTransformer(org.jwildfire.transform.BalancingTransformer) JDesktopPane(javax.swing.JDesktopPane) SimpleImage(org.jwildfire.image.SimpleImage) Dimension(java.awt.Dimension) ImageReader(org.jwildfire.io.ImageReader) PropertyVetoException(java.beans.PropertyVetoException)

Example 3 with BalancingTransformer

use of org.jwildfire.transform.BalancingTransformer in project JWildfire by thargor6.

the class RGBPalette method transformColors.

private void transformColors() {
    int startIdx = selectionProvider.getFrom();
    int endIdx = selectionProvider.getTo();
    if (modified) {
        for (int i = 0; i < transformedColors.length; i++) {
            transformedColors[i] = null;
        }
        for (int i = 0; i < PALETTE_SIZE; i++) {
            RGBColor color = getRawColor(i);
            int idx = i + modShift;
            if (idx < 0) {
                idx += PALETTE_SIZE;
            } else if (idx >= PALETTE_SIZE) {
                idx -= PALETTE_SIZE;
            }
            transformedColors[idx] = new RGBColor(color.getRed(), color.getGreen(), color.getBlue());
        }
        if (modFrequency > 1) {
            RGBColor[] newTransformedColors = new RGBColor[PALETTE_SIZE];
            System.arraycopy(transformedColors, 0, newTransformedColors, 0, PALETTE_SIZE);
            int n = PALETTE_SIZE / modFrequency;
            for (int j = 0; j < modFrequency; j++) {
                for (int i = 0; i < n; i++) {
                    int idx = i + j * n;
                    if (idx < PALETTE_SIZE) {
                        newTransformedColors[idx] = transformedColors[i * modFrequency];
                    }
                }
            }
            System.arraycopy(newTransformedColors, 0, transformedColors, 0, PALETTE_SIZE);
            newTransformedColors = null;
        }
        if (modBlur > 0) {
            RGBColor[] newTransformedColors = new RGBColor[PALETTE_SIZE];
            System.arraycopy(transformedColors, 0, newTransformedColors, 0, PALETTE_SIZE);
            for (int i = 0; i < PALETTE_SIZE; i++) {
                int r = 0;
                int g = 0;
                int b = 0;
                int n = -1;
                for (int j = i - modBlur; j <= i + modBlur; j++) {
                    n++;
                    int k = (PALETTE_SIZE + j) % PALETTE_SIZE;
                    if (k != i) {
                        RGBColor color = transformedColors[k];
                        r += color.getRed();
                        g += color.getGreen();
                        b += color.getBlue();
                    }
                }
                if (n != 0) {
                    RGBColor color = new RGBColor(Tools.limitColor(r / n), Tools.limitColor(g / n), Tools.limitColor(b / n));
                    newTransformedColors[i] = color;
                }
            }
            System.arraycopy(newTransformedColors, 0, transformedColors, 0, PALETTE_SIZE);
            newTransformedColors = null;
        }
        SimpleImage img = new RGBPaletteRenderer().renderHorizPalette(transformedColors, PALETTE_SIZE, 1);
        if (modRed != 0 || modGreen != 0 || modBlue != 0 || modContrast != 0 || modGamma != 0 || modBrightness != 0 || modSaturation != 0) {
            BalancingTransformer bT = new BalancingTransformer();
            bT.setRed(modRed);
            bT.setGreen(modGreen);
            bT.setBlue(modBlue);
            bT.setContrast(modContrast);
            bT.setGamma(modGamma);
            bT.setBrightness(modBrightness);
            bT.setSaturation(modSaturation);
            bT.transformImage(img);
        }
        if (modHue != 0) {
            HSLTransformer hT = new HSLTransformer();
            hT.setHue(modHue);
            hT.transformImage(img);
        }
        if (modSwapRGB != 0) {
            SwapRGBTransformer sT = new SwapRGBTransformer();
            int maxValues = Mode.values().length;
            int idx = (int) ((double) Math.abs(modSwapRGB) / (double) 255.0 * (double) (maxValues - 1));
            sT.setMode(Mode.values()[idx]);
            sT.transformImage(img);
        }
        Pixel pixel = new Pixel();
        for (int i = startIdx; i <= endIdx; i++) {
            RGBColor color = transformedColors[i];
            pixel.setARGBValue(img.getARGBValue(i, 0));
            color.setRed(pixel.r);
            color.setGreen(pixel.g);
            color.setBlue(pixel.b);
        }
        modified = false;
    }
}
Also used : SwapRGBTransformer(org.jwildfire.transform.SwapRGBTransformer) BalancingTransformer(org.jwildfire.transform.BalancingTransformer) SimpleImage(org.jwildfire.image.SimpleImage) HSLTransformer(org.jwildfire.transform.HSLTransformer) Pixel(org.jwildfire.image.Pixel)

Example 4 with BalancingTransformer

use of org.jwildfire.transform.BalancingTransformer in project JWildfire by thargor6.

the class FlamePanel method preProcessImage.

@Override
protected SimpleImage preProcessImage(SimpleImage pSimpleImage) {
    SimpleImage img = super.preProcessImage(pSimpleImage);
    if (imageBrightness < 100 && imageBrightness >= 0) {
        BalancingTransformer bT = new BalancingTransformer();
        bT.setBrightness((int) (-(100 - imageBrightness) * 2.55));
        bT.transformImage(img);
    }
    return img;
}
Also used : BalancingTransformer(org.jwildfire.transform.BalancingTransformer) SimpleImage(org.jwildfire.image.SimpleImage)

Aggregations

SimpleImage (org.jwildfire.image.SimpleImage)4 BalancingTransformer (org.jwildfire.transform.BalancingTransformer)4 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 PropertyVetoException (java.beans.PropertyVetoException)1 JDesktopPane (javax.swing.JDesktopPane)1 Pixel (org.jwildfire.image.Pixel)1 ImageReader (org.jwildfire.io.ImageReader)1 ComposeTransformer (org.jwildfire.transform.ComposeTransformer)1 HSLTransformer (org.jwildfire.transform.HSLTransformer)1 ScaleTransformer (org.jwildfire.transform.ScaleTransformer)1 SwapRGBTransformer (org.jwildfire.transform.SwapRGBTransformer)1