Search in sources :

Example 71 with SimpleImage

use of org.jwildfire.image.SimpleImage 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 72 with SimpleImage

use of org.jwildfire.image.SimpleImage 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)

Example 73 with SimpleImage

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

the class LineArtTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int cvAdd;
    if ((mode == Mode.GRAY) || (mode == Mode.COLOR))
        cvAdd = 255;
    else
        cvAdd = 0;
    int[][] matrix9 = new int[3][3];
    matrix9[0][0] = -1;
    matrix9[0][1] = -1;
    matrix9[0][2] = 1;
    matrix9[1][0] = 0;
    matrix9[1][1] = 2;
    matrix9[1][2] = 0;
    matrix9[2][0] = -1;
    matrix9[2][1] = -1;
    matrix9[2][2] = 1;
    srcImg = srcImg.clone();
    if ((mode == Mode.GRAY) || (mode == Mode.INVERSE_GREY)) {
        ColorToGrayTransformer cT = new ColorToGrayTransformer();
        cT.setWeights(ColorToGrayTransformer.Weights.LUMINANCE);
        cT.transformImage(srcImg);
    }
    if (this.contrast != 0) {
        BalancingTransformer bT = new BalancingTransformer();
        bT.setContrast(this.contrast);
        bT.transformImage(srcImg);
    }
    if ((mode == Mode.GRAY) || (mode == Mode.INVERSE_GREY))
        ConvolveTools.convolve_3x3_grey(srcImg, img, matrix9, cvAdd);
    else
        ConvolveTools.convolve_3x3_color(srcImg, img, matrix9, cvAdd);
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage)

Example 74 with SimpleImage

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

the class MagnetTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    double cx = centreX - 0.5;
    double cy = centreY - 0.5;
    double zoom = 1.0 / this.zoom;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    double famount = this.amount;
    double fdamping = this.damping;
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    Pixel pPixel = new Pixel();
    for (int i = 0; i < height; i++) {
        double dyq = (double) i - cy;
        double y0 = dyq * zoom;
        dyq *= dyq;
        for (int j = 0; j < width; j++) {
            pPixel.setARGBValue(img.getARGBValue(j, i));
            /* transform the point */
            double x0 = (double) j - cx;
            double rr = Math.sqrt(x0 * x0 + dyq);
            x0 *= zoom;
            double amount = famount * Math.exp(rr * fdamping);
            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(j, i, pPixel.r, pPixel.g, pPixel.b);
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 75 with SimpleImage

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

the class ScaleTransformer method performImageTransformation.

@Override
protected void performImageTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int srcWidth = pImg.getImageWidth();
    int srcHeight = pImg.getImageHeight();
    double width, height;
    if (unit == Unit.PIXELS) {
        width = (double) scaleWidth;
        height = (double) scaleHeight;
    } else {
        width = (double) scaleWidth / 100.0 * (double) srcWidth;
        height = (double) scaleHeight / 100.0 * (double) srcHeight;
    }
    if (aspect == ScaleAspect.KEEP_WIDTH) {
        double scl = width / (double) srcWidth;
        height = (double) srcHeight * scl;
    } else if (aspect == ScaleAspect.KEEP_HEIGHT) {
        double scl = height / (double) srcHeight;
        width = (double) srcWidth * scl;
    }
    int dstWidth = (int) (width + 0.5);
    if (dstWidth < 1)
        dstWidth = 1;
    int dstHeight = (int) (height + 0.5);
    if (dstHeight < 1)
        dstHeight = 1;
    SimpleImage srcImg = img.clone();
    img.resetImage(dstWidth, dstHeight);
    if ((dstWidth >= srcWidth) && (dstHeight >= srcHeight))
        scale_up_up(srcImg, img);
    else if ((dstWidth < srcWidth) && (dstHeight >= srcHeight))
        scale_down_up(srcImg, img);
    else if ((dstWidth >= srcWidth) && (dstHeight < srcHeight))
        scale_up_down(srcImg, img);
    else if ((dstWidth < srcWidth) && (dstHeight < srcHeight))
        scale_down_down(srcImg, img);
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage)

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