Search in sources :

Example 6 with Pixel

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

the class LogDensityFilter method calculateBGColor.

public void calculateBGColor(LogDensityPoint dest, int pX, int pY) {
    if (bgImage != null) {
        Pixel toolPixel = dest.toolPixel;
        if (destImageWidth == bgImage.getImageWidth() && destImageHeight == bgImage.getImageHeight()) {
            toolPixel.setARGBValue(bgImage.getARGBValue(pX, pY));
            dest.bgRed = toolPixel.r;
            dest.bgGreen = toolPixel.g;
            dest.bgBlue = toolPixel.b;
        } else {
            double xCoord = (double) pX * (double) (bgImage.getImageWidth() - 1) / (double) (destImageWidth - 1);
            double yCoord = (double) pY * (double) (bgImage.getImageHeight() - 1) / (double) (destImageHeight - 1);
            toolPixel.setARGBValue(bgImage.getARGBValueIgnoreBounds((int) xCoord, (int) yCoord));
            int luR = toolPixel.r;
            int luG = toolPixel.g;
            int luB = toolPixel.b;
            toolPixel.setARGBValue(bgImage.getARGBValueIgnoreBounds(((int) xCoord) + 1, (int) yCoord));
            int ruR = toolPixel.r;
            int ruG = toolPixel.g;
            int ruB = toolPixel.b;
            toolPixel.setARGBValue(bgImage.getARGBValueIgnoreBounds((int) xCoord, ((int) yCoord) + 1));
            int lbR = toolPixel.r;
            int lbG = toolPixel.g;
            int lbB = toolPixel.b;
            toolPixel.setARGBValue(bgImage.getARGBValueIgnoreBounds(((int) xCoord) + 1, ((int) yCoord) + 1));
            int rbR = toolPixel.r;
            int rbG = toolPixel.g;
            int rbB = toolPixel.b;
            double x = MathLib.frac(xCoord);
            double y = MathLib.frac(yCoord);
            dest.bgRed = Tools.roundColor(GfxMathLib.blerp(luR, ruR, lbR, rbR, x, y));
            dest.bgGreen = Tools.roundColor(GfxMathLib.blerp(luG, ruG, lbG, rbG, x, y));
            dest.bgBlue = Tools.roundColor(GfxMathLib.blerp(luB, ruB, lbB, rbB, x, y));
        }
    } else {
        switch(flame.getBgColorType()) {
            case GRADIENT_2X2:
                {
                    double x = (double) pX / (double) (destImageWidth - 1);
                    double y = (double) pY / (double) (destImageHeight - 1);
                    dest.bgRed = Tools.roundColor(GfxMathLib.blerp(flame.getBgColorULRed(), flame.getBgColorURRed(), flame.getBgColorLLRed(), flame.getBgColorLRRed(), x, y));
                    dest.bgGreen = Tools.roundColor(GfxMathLib.blerp(flame.getBgColorULGreen(), flame.getBgColorURGreen(), flame.getBgColorLLGreen(), flame.getBgColorLRGreen(), x, y));
                    dest.bgBlue = Tools.roundColor(GfxMathLib.blerp(flame.getBgColorULBlue(), flame.getBgColorURBlue(), flame.getBgColorLLBlue(), flame.getBgColorLRBlue(), x, y));
                }
                break;
            case GRADIENT_2X2_C:
                {
                    int w2 = destImageWidth / 2 - 1;
                    int h2 = destImageHeight / 2 - 1;
                    double x, y;
                    double ulRed, urRed, llRed, lrRed;
                    double ulGreen, urGreen, llGreen, lrGreen;
                    double ulBlue, urBlue, llBlue, lrBlue;
                    if (pX <= w2) {
                        x = (double) pX / (double) w2;
                        if (pY <= h2) {
                            y = (double) pY / (double) h2;
                            ulRed = flame.getBgColorULRed();
                            urRed = GfxMathLib.lerp(flame.getBgColorULRed(), flame.getBgColorURRed(), 0.5);
                            llRed = GfxMathLib.lerp(flame.getBgColorLLRed(), flame.getBgColorULRed(), 0.5);
                            lrRed = flame.getBgColorCCRed();
                            ulGreen = flame.getBgColorULGreen();
                            urGreen = GfxMathLib.lerp(flame.getBgColorULGreen(), flame.getBgColorURGreen(), 0.5);
                            llGreen = GfxMathLib.lerp(flame.getBgColorLLGreen(), flame.getBgColorULGreen(), 0.5);
                            lrGreen = flame.getBgColorCCGreen();
                            ulBlue = flame.getBgColorULBlue();
                            urBlue = GfxMathLib.lerp(flame.getBgColorULBlue(), flame.getBgColorURBlue(), 0.5);
                            llBlue = GfxMathLib.lerp(flame.getBgColorLLBlue(), flame.getBgColorULBlue(), 0.5);
                            lrBlue = flame.getBgColorCCBlue();
                        } else {
                            y = (double) (pY - h2) / (double) h2;
                            ulRed = GfxMathLib.lerp(flame.getBgColorULRed(), flame.getBgColorLLRed(), 0.5);
                            urRed = flame.getBgColorCCRed();
                            llRed = flame.getBgColorLLRed();
                            lrRed = GfxMathLib.lerp(flame.getBgColorLLRed(), flame.getBgColorLRRed(), 0.5);
                            ulGreen = GfxMathLib.lerp(flame.getBgColorULGreen(), flame.getBgColorLLGreen(), 0.5);
                            urGreen = flame.getBgColorCCGreen();
                            llGreen = flame.getBgColorLLGreen();
                            lrGreen = GfxMathLib.lerp(flame.getBgColorLLGreen(), flame.getBgColorLRGreen(), 0.5);
                            ulBlue = GfxMathLib.lerp(flame.getBgColorULBlue(), flame.getBgColorLLBlue(), 0.5);
                            urBlue = flame.getBgColorCCBlue();
                            llBlue = flame.getBgColorLLBlue();
                            lrBlue = GfxMathLib.lerp(flame.getBgColorLLBlue(), flame.getBgColorLRBlue(), 0.5);
                        }
                    } else {
                        x = (double) (pX - w2) / (double) w2;
                        if (pY <= h2) {
                            y = (double) pY / (double) h2;
                            ulRed = GfxMathLib.lerp(flame.getBgColorULRed(), flame.getBgColorURRed(), 0.5);
                            urRed = flame.getBgColorURRed();
                            llRed = flame.getBgColorCCRed();
                            lrRed = GfxMathLib.lerp(flame.getBgColorURRed(), flame.getBgColorLRRed(), 0.5);
                            ulGreen = GfxMathLib.lerp(flame.getBgColorULGreen(), flame.getBgColorURGreen(), 0.5);
                            urGreen = flame.getBgColorURGreen();
                            llGreen = flame.getBgColorCCGreen();
                            lrGreen = GfxMathLib.lerp(flame.getBgColorURGreen(), flame.getBgColorLRGreen(), 0.5);
                            ulBlue = GfxMathLib.lerp(flame.getBgColorULBlue(), flame.getBgColorURBlue(), 0.5);
                            urBlue = flame.getBgColorURBlue();
                            llBlue = flame.getBgColorCCBlue();
                            lrBlue = GfxMathLib.lerp(flame.getBgColorURBlue(), flame.getBgColorLRBlue(), 0.5);
                        } else {
                            y = (double) (pY - h2) / (double) h2;
                            ulRed = flame.getBgColorCCRed();
                            urRed = GfxMathLib.lerp(flame.getBgColorURRed(), flame.getBgColorLRRed(), 0.5);
                            llRed = GfxMathLib.lerp(flame.getBgColorLLRed(), flame.getBgColorLRRed(), 0.5);
                            lrRed = flame.getBgColorLRRed();
                            ulGreen = flame.getBgColorCCGreen();
                            urGreen = GfxMathLib.lerp(flame.getBgColorURGreen(), flame.getBgColorLRGreen(), 0.5);
                            llGreen = GfxMathLib.lerp(flame.getBgColorLLGreen(), flame.getBgColorLRGreen(), 0.5);
                            lrGreen = flame.getBgColorLRGreen();
                            ulBlue = flame.getBgColorCCBlue();
                            urBlue = GfxMathLib.lerp(flame.getBgColorURBlue(), flame.getBgColorLRBlue(), 0.5);
                            llBlue = GfxMathLib.lerp(flame.getBgColorLLBlue(), flame.getBgColorLRBlue(), 0.5);
                            lrBlue = flame.getBgColorLRBlue();
                        }
                    }
                    dest.bgRed = Tools.roundColor(GfxMathLib.blerp(ulRed, urRed, llRed, lrRed, x, y));
                    dest.bgGreen = Tools.roundColor(GfxMathLib.blerp(ulGreen, urGreen, llGreen, lrGreen, x, y));
                    dest.bgBlue = Tools.roundColor(GfxMathLib.blerp(ulBlue, urBlue, llBlue, lrBlue, x, y));
                }
                break;
            default:
                dest.bgRed = flame.getBgColorRed();
                dest.bgGreen = flame.getBgColorGreen();
                dest.bgBlue = flame.getBgColorBlue();
                break;
        }
    }
}
Also used : Pixel(org.jwildfire.image.Pixel) RasterPoint(org.jwildfire.create.tina.base.raster.RasterPoint)

Example 7 with Pixel

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

the class SWFAnimationRenderThread method fillBuffer.

private void fillBuffer(byte[] pBuffer, int pOffset, SimpleImage pImage, int pChannel) {
    Pixel p = new Pixel();
    int offset = pOffset;
    int lineWidth = pImage.getImageWidth() + 1;
    for (int i = 0; i < pImage.getImageHeight(); i++) {
        for (int j = 0; j < pImage.getImageWidth(); j++) {
            p.setARGBValue(pImage.getARGBValue(j, i));
            switch(pChannel) {
                case 0:
                    pBuffer[offset + j] = (byte) p.r;
                    break;
                case 1:
                    pBuffer[offset + j] = (byte) p.g;
                    break;
                case 2:
                    pBuffer[offset + j] = (byte) p.b;
                    break;
                default:
                    pBuffer[offset + j] = (byte) p.a;
                    break;
            }
        }
        offset += lineWidth;
    }
}
Also used : Pixel(org.jwildfire.image.Pixel)

Example 8 with Pixel

use of org.jwildfire.image.Pixel 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 9 with Pixel

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

the class GradientCreator method fillImage.

@Override
public void fillImage(SimpleImage res) {
    if ((gradientFilename == null) || (gradientFilename.length() == 0)) {
        boolean simpleImg = ulColor.equals(urColor) && urColor.equals(llColor) && llColor.equals(lrColor) && lrColor.equals(ulColor);
        if (simpleImg) {
            Graphics g = res.getBufferedImg().getGraphics();
            g.setColor(ulColor);
            g.fillRect(0, 0, res.getImageWidth(), res.getImageHeight());
        } else {
            // UL 0
            // UR 1
            // LL 2
            // LR 3
            final int SPREC = 10;
            int width = res.getImageWidth();
            int height = res.getImageHeight();
            /*left line */
            int lmr = ((int) (llColor.getRed() - ulColor.getRed()) << SPREC) / (int) (height - 1);
            int lmg = ((int) (llColor.getGreen() - ulColor.getGreen()) << SPREC) / (int) (height - 1);
            int lmb = ((int) (llColor.getBlue() - ulColor.getBlue()) << SPREC) / (int) (height - 1);
            int lnr = ulColor.getRed();
            int lng = ulColor.getGreen();
            int lnb = ulColor.getBlue();
            /* right line */
            int rmr = ((int) (lrColor.getRed() - urColor.getRed()) << SPREC) / (int) (height - 1);
            int rmg = ((int) (lrColor.getGreen() - urColor.getGreen()) << SPREC) / (int) (height - 1);
            int rmb = ((int) (lrColor.getBlue() - urColor.getBlue()) << SPREC) / (int) (height - 1);
            int rnr = urColor.getRed();
            int rng = urColor.getGreen();
            int rnb = urColor.getBlue();
            for (int i = 0; i < height; i++) {
                /* interpolate left and right border */
                int lr, lg, lb, rr, rg, rb;
                if (i == 0) {
                    lr = ulColor.getRed();
                    lg = ulColor.getGreen();
                    lb = ulColor.getBlue();
                    rr = urColor.getRed();
                    rg = urColor.getGreen();
                    rb = urColor.getBlue();
                } else if (i == (height - 1)) {
                    lr = llColor.getRed();
                    lg = llColor.getGreen();
                    lb = llColor.getBlue();
                    rr = lrColor.getRed();
                    rg = lrColor.getGreen();
                    rb = lrColor.getBlue();
                } else {
                    lr = (int) (((int) i * lmr) >> SPREC) + lnr;
                    lg = (int) (((int) i * lmg) >> SPREC) + lng;
                    lb = (int) (((int) i * lmb) >> SPREC) + lnb;
                    rr = (int) (((int) i * rmr) >> SPREC) + rnr;
                    rg = (int) (((int) i * rmg) >> SPREC) + rng;
                    rb = (int) (((int) i * rmb) >> SPREC) + rnb;
                }
                /* create the horizontal line */
                int hmr = ((int) (rr - lr) << SPREC) / (int) (width - 1);
                int hmg = ((int) (rg - lg) << SPREC) / (int) (width - 1);
                int hmb = ((int) (rb - lb) << SPREC) / (int) (width - 1);
                int hnr = lr;
                int hng = lg;
                int hnb = lb;
                /* 1st pixel of the line */
                res.setRGB(0, i, lr, lg, lb);
                int thr = 0, thg = 0, thb = 0;
                for (int j = 1; j < (width - 1); j++) {
                    thr += hmr;
                    thg += hmg;
                    thb += hmb;
                    int rval = (int) (thr >> SPREC) + hnr;
                    int gval = (int) (thg >> SPREC) + hng;
                    int bval = (int) (thb >> SPREC) + hnb;
                    res.setRGB(j, i, rval, gval, bval);
                }
                /* last pixel of the line */
                res.setRGB(width - 1, i, rr, rg, rb);
            }
        }
    } else {
        int width = res.getImageWidth();
        int height = res.getImageHeight();
        String content;
        try {
            content = Tools.readUTF8Textfile(gradientFilename);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new RuntimeException(ex);
        }
        String[] rows = content.split("[\\r\\n]+");
        // index=257 color=4273232
        Pattern pattern = Pattern.compile("(\\s*)(index=)([0-9]+)(\\s+)(color=)([0-9]+)(\\s*)");
        Map<Integer, Integer> colorMap = new HashMap<Integer, Integer>();
        int maxIdx = 0;
        for (String row : rows) {
            Matcher matcher = pattern.matcher(row);
            if (matcher.find()) {
                // System.out.println(matcher.group(3) + "/" + matcher.group(6));
                int idx = Integer.parseInt(matcher.group(3));
                if (idx > maxIdx)
                    maxIdx = idx;
                colorMap.put(idx, Integer.parseInt(matcher.group(6)));
            }
        }
        Integer lastColor = 0;
        Pixel toolPixel = new Pixel();
        for (int i = 0; i < maxIdx; i++) {
            if (i < width) {
                Integer color = colorMap.get(i);
                if (color == null) {
                    color = lastColor;
                } else {
                    lastColor = color;
                }
                toolPixel.setARGBValue(color);
                for (int j = 0; j < height; j++) {
                    // is bgr, not rgb
                    res.setRGB(i, j, toolPixel.b, toolPixel.g, toolPixel.r);
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) Graphics(java.awt.Graphics) Pixel(org.jwildfire.image.Pixel)

Example 10 with Pixel

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

the class ConvolveTools method convolve_3x3_color.

public static void convolve_3x3_color(SimpleImage pSrcImg, SimpleImage pImg, int[][] pMatrix, int pCVAdd) {
    int width = pSrcImg.getImageWidth();
    int height = pSrcImg.getImageHeight();
    int sizeM = pMatrix.length;
    int sizeMHalve = sizeM / 2;
    int sumM = 0;
    for (int i = 0; i < sizeM; i++) {
        for (int j = 0; j < sizeM; j++) {
            sumM += pMatrix[i][j];
        }
    }
    if (sumM == 0)
        sumM = 1;
    Pixel pixel = new Pixel();
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            int intSumR = 0;
            int intSumG = 0;
            int intSumB = 0;
            for (int k = 0; k < sizeM; k++) {
                int y = i - sizeMHalve + k;
                for (int l = 0; l < sizeM; l++) {
                    int x = j - sizeMHalve + l;
                    pixel.setARGBValue(pSrcImg.getARGBValueIgnoreBounds(x, y));
                    intSumR += pixel.r * pMatrix[k][l];
                    intSumG += pixel.g * pMatrix[k][l];
                    intSumB += pixel.b * pMatrix[k][l];
                }
            }
            intSumR = Tools.limitColor((intSumR / sumM) + pCVAdd);
            intSumG = Tools.limitColor((intSumG / sumM) + pCVAdd);
            intSumB = Tools.limitColor((intSumB / sumM) + pCVAdd);
            pImg.setRGB(j, i, intSumR, intSumG, intSumB);
        }
    }
}
Also used : Pixel(org.jwildfire.image.Pixel)

Aggregations

Pixel (org.jwildfire.image.Pixel)62 SimpleImage (org.jwildfire.image.SimpleImage)37 RGBColor (org.jwildfire.create.tina.palette.RGBColor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 HSLPixel (org.jwildfire.transform.HSLTransformer.HSLPixel)3 Color (java.awt.Color)2 Graphics2D (java.awt.Graphics2D)2 BufferedImage (java.awt.image.BufferedImage)2 JEPWrapper (org.jwildfire.base.mathparser.JEPWrapper)2 HSLTransformer (org.jwildfire.transform.HSLTransformer)2 Node (org.nfunk.jep.Node)2 SVGDiagram (com.kitfox.svg.SVGDiagram)1 SVGUniverse (com.kitfox.svg.SVGUniverse)1 Graphics (java.awt.Graphics)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1