Search in sources :

Example 21 with Pixel

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

the class FlipTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pixel = new Pixel();
    if (axis == Axis.X) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(srcImg.getARGBValue(width - j - 1, i));
                img.setRGB(j, i, pixel);
            }
        }
    } else if (axis == Axis.Y) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(srcImg.getARGBValue(j, height - i - 1));
                img.setRGB(j, i, pixel);
            }
        }
    } else if (axis == Axis.XY) {
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                pixel.setARGBValue(srcImg.getARGBValue(width - j - 1, height - i - 1));
                img.setRGB(j, i, pixel);
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 22 with Pixel

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

the class FormulaColorTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    JEPWrapper parser = new JEPWrapper();
    parser.addVariable("r", 0.0);
    parser.addVariable("g", 0.0);
    parser.addVariable("b", 0.0);
    parser.addVariable("x", 0.0);
    parser.addVariable("y", 0.0);
    parser.addVariable("width", (double) width);
    parser.addVariable("height", (double) height);
    Node redNode = parser.parse(formula1Red);
    Node greenNode = parser.parse(formula2Green);
    Node blueNode = parser.parse(formula3Blue);
    Pixel pixel = new Pixel();
    for (int i = 0; i < height; i++) {
        parser.setVarValue("y", i);
        for (int j = 0; j < width; j++) {
            parser.setVarValue("x", j);
            pixel.setARGBValue(srcImg.getARGBValue(j, i));
            if (useOriginalRGBValues) {
                parser.setVarValue("r", (double) pixel.r);
                parser.setVarValue("g", (double) pixel.g);
                parser.setVarValue("b", (double) pixel.b);
                pixel.r = Tools.roundColor((Double) parser.evaluate(redNode));
                pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode));
                pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode));
            } else {
                parser.setVarValue("r", (double) pixel.r / 255.0);
                parser.setVarValue("g", (double) pixel.g / 255.0);
                parser.setVarValue("b", (double) pixel.b / 255.0);
                pixel.r = Tools.roundColor((Double) parser.evaluate(redNode) * 255.0);
                pixel.g = Tools.roundColor((Double) parser.evaluate(greenNode) * 255.0);
                pixel.b = Tools.roundColor((Double) parser.evaluate(blueNode) * 255.0);
            }
            img.setRGB(j, i, pixel);
        }
    }
}
Also used : JEPWrapper(org.jwildfire.base.mathparser.JEPWrapper) SimpleImage(org.jwildfire.image.SimpleImage) Node(org.nfunk.jep.Node) Pixel(org.jwildfire.image.Pixel)

Example 23 with Pixel

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

the class Genlock3DTransformer method transformMesh.

@Override
protected void transformMesh(Mesh3D pMesh3D, int pImageWidth, int pImageHeight) {
    int fCount = pMesh3D.getFCount();
    /* 3-point-polygons */
    if (fCount > 0) {
        Pixel pixel = new Pixel();
        int[] fLst = new int[fCount];
        int[] color = pMesh3D.getColor();
        double[] u = pMesh3D.getU();
        double[] v = pMesh3D.getV();
        int[] p1 = pMesh3D.getPP1();
        SimpleImage texture = pMesh3D.getTexture();
        int valid = 0;
        int r1 = this.colorA.getRed();
        int g1 = this.colorA.getGreen();
        int b1 = this.colorA.getBlue();
        int r2 = this.colorB.getRed();
        int g2 = this.colorB.getGreen();
        int b2 = this.colorB.getBlue();
        if (this.genlock == Genlock.COLOR) {
            for (int i = 0; i < fCount; i++) {
                if (color != null) {
                    pixel.setARGBValue(color[i]);
                } else {
                    int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
                    int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
                    pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
                }
                if ((pixel.r != r1) || (pixel.g != g1) || (pixel.b != b1)) {
                    fLst[i] = 1;
                    valid++;
                }
            }
        } else if (this.genlock == Genlock.IN_RANGE) {
            for (int i = 0; i < fCount; i++) {
                if (color != null) {
                    pixel.setARGBValue(color[i]);
                } else {
                    int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
                    int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
                    pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
                }
                if ((((pixel.r >= r1) && (pixel.r <= r2)) || ((pixel.r >= r2) && (pixel.r <= r1))) || (((pixel.g >= g1) && (pixel.g <= g2)) || ((pixel.g >= g2) && (pixel.g <= g1))) || (((pixel.b >= b1) && (pixel.b <= b2)) || ((pixel.b >= b2) && (pixel.b <= b1)))) {
                } else {
                    fLst[i] = 1;
                    valid++;
                }
            }
        } else if (this.genlock == Genlock.OUT_RANGE) {
            for (int i = 0; i < fCount; i++) {
                if (color != null) {
                    pixel.setARGBValue(color[i]);
                } else {
                    int px = (int) (u[p1[i]] * texture.getImageWidth() + 0.5);
                    int py = (int) (v[p1[i]] * texture.getImageHeight() + 0.5);
                    pixel.setARGBValue(texture.getARGBValueIgnoreBounds(px, py));
                }
                if ((((pixel.r >= r1) && (pixel.r <= r2)) || ((pixel.r >= r2) && (pixel.r <= r1))) || (((pixel.g >= g1) && (pixel.g <= g2)) || ((pixel.g >= g2) && (pixel.g <= g1))) || (((pixel.b >= b1) && (pixel.b <= b2)) || ((pixel.b >= b2) && (pixel.b <= b1)))) {
                    fLst[i] = 1;
                    valid++;
                }
            }
        }
        if (valid < fCount) {
            if (valid > 0) {
                pMesh3D.setFCount(valid);
                {
                    int[] pp = new int[valid];
                    int curr = 0;
                    int[] ps = pMesh3D.getPP1();
                    for (int i = 0; i < fCount; i++) {
                        if (fLst[i] != 0)
                            pp[curr++] = ps[i];
                    }
                    pMesh3D.setPP1(pp);
                }
                {
                    int[] pp = new int[valid];
                    int curr = 0;
                    int[] ps = pMesh3D.getPP2();
                    for (int i = 0; i < fCount; i++) {
                        if (fLst[i] != 0)
                            pp[curr++] = ps[i];
                    }
                    pMesh3D.setPP2(pp);
                }
                {
                    int[] pp = new int[valid];
                    int curr = 0;
                    int[] ps = pMesh3D.getPP3();
                    for (int i = 0; i < fCount; i++) {
                        if (fLst[i] != 0)
                            pp[curr++] = ps[i];
                    }
                    pMesh3D.setPP3(pp);
                }
                if (pMesh3D.getColor() != null) {
                    int[] rr = new int[valid];
                    int curr = 0;
                    int[] rs = pMesh3D.getColor();
                    for (int i = 0; i < fCount; i++) {
                        if (fLst[i] != 0)
                            rr[curr++] = rs[i];
                    }
                    pMesh3D.setColor(rr);
                }
            } else {
                pMesh3D.setFCount(0);
                pMesh3D.setPP1(null);
                pMesh3D.setPP2(null);
                pMesh3D.setPP3(null);
                pMesh3D.setColor(null);
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 24 with Pixel

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

the class HSLGradientTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    int x1 = this.x1;
    int y1 = this.y1;
    int v1 = this.value1;
    int x2 = this.x2;
    int y2 = this.y2;
    int v2 = this.value2;
    double rx = (double) (x2 - x1);
    double ry = (double) (y2 - y1);
    double dv = (double) (v2 - v1);
    double vlen;
    if (this.transition == Transition.PARALLEL)
        vlen = Math.sqrt(rx * rx + ry * ry);
    else
        vlen = this.radius - this.baseRadius;
    if (vlen < 0.0001)
        vlen = 0.0001;
    double vlenq = vlen * vlen;
    Pixel rgbPixel = new Pixel();
    HSLTransformer.HSLPixel hslPixel = new HSLTransformer.HSLPixel();
    switch(this.mode) {
        case HUE:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double phue = (v1 + dv * prj) / 255.0;
                        if (phue < (-1.0))
                            phue = -1;
                        else if (phue > 1.0)
                            phue = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        if (hslPixel.hue != (-1.0)) {
                            hslPixel.hue += phue;
                            if (hslPixel.hue < 0.0)
                                hslPixel.hue += 1.0;
                            else if (hslPixel.hue > 1.0)
                                hslPixel.hue -= 1.0;
                        }
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double phue = (v1 + dv * prj) / 255.0;
                        if (phue < (-1.0))
                            phue = -1;
                        else if (phue > 1.0)
                            phue = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        if (hslPixel.hue != (-1.0)) {
                            hslPixel.hue += phue;
                            if (hslPixel.hue < 0.0)
                                hslPixel.hue += 1.0;
                            else if (hslPixel.hue > 1.0)
                                hslPixel.hue -= 1.0;
                        }
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            }
            break;
        case SATURATION:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double psaturation = (v1 + dv * prj) / 255.0;
                        if (psaturation < (-1.0))
                            psaturation = -1.0;
                        else if (psaturation > 1.0)
                            psaturation = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        hslPixel.saturation += psaturation;
                        if (hslPixel.saturation < 0.0)
                            hslPixel.saturation = 0.0;
                        else if (hslPixel.saturation > 1.0)
                            hslPixel.saturation = 1.0;
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double psaturation = (v1 + dv * prj) / 255.0;
                        if (psaturation < (-1.0))
                            psaturation = -1.0;
                        else if (psaturation > 1.0)
                            psaturation = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        hslPixel.saturation += psaturation;
                        if (hslPixel.saturation < 0.0)
                            hslPixel.saturation = 0.0;
                        else if (hslPixel.saturation > 1.0)
                            hslPixel.saturation = 1.0;
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            }
            break;
        case LUMINOSITY:
            if (this.transition == Transition.PARALLEL) {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (ax * rx + ay * ry) / vlenq;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double pluminosity = (v1 + dv * prj) / 255.0;
                        if (pluminosity < (-1.0))
                            pluminosity = -1;
                        else if (pluminosity > 1.0)
                            pluminosity = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        hslPixel.luminosity += pluminosity;
                        if (hslPixel.luminosity < 0.0)
                            hslPixel.luminosity = 0.0;
                        else if (hslPixel.luminosity > 1.0)
                            hslPixel.luminosity = 1.0;
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            } else {
                for (int i = 0; i < height; i++) {
                    double ay = (double) (i - y1);
                    for (int j = 0; j < width; j++) {
                        double ax = (double) (j - x1);
                        double prj = (Math.sqrt(ax * ax + ay * ay) - baseRadius) / vlen;
                        if (prj < 0.0)
                            prj = 0.0;
                        else if (prj > 1.0)
                            prj = 1.0;
                        double pluminosity = (v1 + dv * prj) / 255.0;
                        if (pluminosity < (-1.0))
                            pluminosity = -1;
                        else if (pluminosity > 1.0)
                            pluminosity = 1.0;
                        rgbPixel.setARGBValue(img.getARGBValue(j, i));
                        HSLTransformer.rgb2hsl(rgbPixel, hslPixel);
                        hslPixel.luminosity += pluminosity;
                        if (hslPixel.luminosity < 0.0)
                            hslPixel.luminosity = 0.0;
                        else if (hslPixel.luminosity > 1.0)
                            hslPixel.luminosity = 1.0;
                        HSLTransformer.hsl2rgb(hslPixel, rgbPixel);
                        img.setRGB(j, i, rgbPixel);
                    }
                }
            }
            break;
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 25 with Pixel

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

the class HSLTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel rgbPixel = new Pixel();
    HSLPixel hslPixel = new HSLPixel();
    double phue = (double) (this.hue) / 255.0;
    if (phue < (-1.0))
        phue = -1;
    else if (phue > 1.0)
        phue = 1.0;
    double psaturation = (double) (this.saturation) / 255.0;
    if (psaturation < (-1.0))
        psaturation = -1.0;
    else if (psaturation > 1.0)
        psaturation = 1.0;
    double pluminosity = (double) (this.luminosity) / 255.0;
    if (pluminosity < (-1.0))
        pluminosity = -1;
    else if (pluminosity > 1.0)
        pluminosity = 1.0;
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            rgbPixel.setARGBValue(img.getARGBValue(j, i));
            rgb2hsl(rgbPixel, hslPixel);
            hslPixel.luminosity += pluminosity;
            if (hslPixel.luminosity < 0.0)
                hslPixel.luminosity = 0.0;
            else if (hslPixel.luminosity > 1.0)
                hslPixel.luminosity = 1.0;
            hslPixel.saturation += psaturation;
            if (hslPixel.saturation < 0.0)
                hslPixel.saturation = 0.0;
            else if (hslPixel.saturation > 1.0)
                hslPixel.saturation = 1.0;
            if (hslPixel.hue != (-1.0)) {
                hslPixel.hue += phue;
                if (hslPixel.hue < 0.0)
                    hslPixel.hue += 1.0;
                else if (hslPixel.hue > 1.0)
                    hslPixel.hue -= 1.0;
            }
            hsl2rgb(hslPixel, rgbPixel);
            img.setRGB(j, i, rgbPixel);
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) 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