Search in sources :

Example 26 with Pixel

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

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

the class Mesh2DTransformer method applySmoothing.

protected void applySmoothing(SimpleImage pImg, int pSmoothingAmount) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pixel = new Pixel();
    for (int k = 0; k < pSmoothingAmount; k++) {
        for (int i = 1; i < (height - 1); i++) {
            /* process pixels 2..width-1 */
            for (int j = 1; j < (width - 1); j++) {
                pixel.setARGBValue(pImg.getARGBValue(j, i - 1));
                int r1 = pixel.r;
                int g1 = pixel.g;
                int b1 = pixel.b;
                pixel.setARGBValue(pImg.getARGBValue(j + 1, i));
                int r2 = pixel.r;
                int g2 = pixel.g;
                int b2 = pixel.b;
                pixel.setARGBValue(pImg.getARGBValue(j, i + 1));
                int r3 = pixel.r;
                int g3 = pixel.g;
                int b3 = pixel.b;
                pixel.setARGBValue(pImg.getARGBValue(j, i));
                int r = pixel.r;
                int g = pixel.g;
                int b = pixel.b;
                int av1 = (r1 + g1 + b1);
                int av2 = (r2 + g2 + b2);
                int av3 = (r3 + g3 + b3);
                int av = (r + g + b);
                int d1 = av1 - av;
                if (d1 < 0)
                    d1 = 0 - d1;
                int d2 = av2 - av;
                if (d2 < 0)
                    d2 = 0 - d2;
                int d3 = av3 - av;
                if (d3 < 0)
                    d3 = 0 - d3;
                if ((d1 > 64) && (d2 > 64)) {
                    int rv = r1 * d1 + r2 * d2;
                    rv /= (d1 + d2);
                    rv += r;
                    rv /= 2;
                    int gv = g1 * d1 + g2 * d2;
                    gv /= (d1 + d2);
                    gv += g;
                    gv /= 2;
                    int bv = b1 * d1 + b2 * d2;
                    bv /= (d1 + d2);
                    bv += b;
                    bv /= 2;
                    pImg.setRGB(j, i, rv, gv, bv);
                } else if ((d2 > 64) && (d3 > 64)) {
                    int rv = r2 * d2 + r3 * d3;
                    rv /= (d2 + d3);
                    rv += r;
                    rv /= 2;
                    int gv = g2 * d2 + g3 * d3;
                    gv /= (d2 + d3);
                    gv += g;
                    gv /= 2;
                    int bv = b2 * d2 + b3 * d3;
                    bv /= (d2 + d3);
                    bv += b;
                    bv /= 2;
                    pImg.setRGB(j, i, rv, gv, bv);
                }
            }
        }
    }
}
Also used : Pixel(org.jwildfire.image.Pixel)

Example 28 with Pixel

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

the class ScaleTransformer method scale_up_down.

private void scale_up_down(SimpleImage srcImg, SimpleImage dstImg) {
    int swidth = srcImg.getImageWidth();
    int sheight = srcImg.getImageHeight();
    int width = dstImg.getImageWidth();
    int height = dstImg.getImageHeight();
    double sclX, sclY;
    if (width > 1) {
        sclX = (double) (swidth - 1) / (double) (width - 1);
    } else
        sclX = 1.0;
    if (height > 1) {
        sclY = (double) (sheight - 1) / (double) (height - 1);
    } else
        sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();
    for (int i = 0; i < height; i++) {
        double y0 = (double) i - cyD;
        double yn = (y0 + 1.0) * sclY + cyS;
        if (yn >= (sheight - 0.5))
            yn = sheight - 1.0;
        for (int j = 0; j < width; j++) {
            // transform the point
            double x0 = (double) j - cxD;
            double x = x0 * sclX + cxS;
            double y = y0 * sclY + cyS;
            if (((int) x < 0) || ((int) x >= swidth) || ((int) y < 0) || ((int) y >= sheight)) {
                pPixel.r = pPixel.g = pPixel.b = 0;
            } else {
                double xi = Tools.fmod33(x);
                double yi = Tools.fmod33(y);
                readSrcPixels(srcImg, x, y);
                int cvalR = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
                int cvalG = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
                int cvalB = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
                y = y - yi + 1.0;
                int cnt = 1;
                while (y < yn) {
                    readSrcPixels(srcImg, x, y);
                    cvalR += (1.0 - xi) * srcP.r + xi * srcQ.r;
                    cvalG += (1.0 - xi) * srcP.g + xi * srcQ.g;
                    cvalB += (1.0 - xi) * srcP.b + xi * srcQ.b;
                    y += 1.0;
                    cnt++;
                }
                pPixel.r = roundColor(cvalR / (double) cnt);
                pPixel.g = roundColor(cvalG / (double) cnt);
                pPixel.b = roundColor(cvalB / (double) cnt);
            }
            dstImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
        }
    }
}
Also used : Pixel(org.jwildfire.image.Pixel)

Example 29 with Pixel

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

the class ScaleTransformer method scale_down_down.

private void scale_down_down(SimpleImage srcImg, SimpleImage dstImg) {
    int swidth = srcImg.getImageWidth();
    int sheight = srcImg.getImageHeight();
    int width = dstImg.getImageWidth();
    int height = dstImg.getImageHeight();
    double sclX, sclY;
    if (width > 1) {
        sclX = (double) (swidth - 1) / (double) (width - 1);
    } else
        sclX = 1.0;
    if (height > 1) {
        sclY = (double) (sheight - 1) / (double) (height - 1);
    } else
        sclY = 1.0;
    double cxD = (double) (width - 1) * 0.5;
    double cyD = (double) (height - 1) * 0.5;
    double cxS = (double) (swidth - 1) * 0.5;
    double cyS = (double) (sheight - 1) * 0.5;
    Pixel pPixel = new Pixel();
    for (int i = 0; i < height; i++) {
        double y0 = (double) i - cyD;
        for (int j = 0; j < width; j++) {
            // transform the point
            double x0 = (double) j - cxD;
            double x = x0 * sclX + cxS;
            double xn = (x0 + 1.0) * sclX + cxS;
            if (xn >= (swidth - 0.5))
                xn = swidth - 1.0;
            double y = y0 * sclY + cyS;
            double yn = (y0 + 1.0) * sclY + cyS;
            if (yn >= (sheight - 0.5))
                yn = sheight - 1.0;
            // render it
            if (((int) x < 0) || ((int) x >= swidth) || ((int) y < 0) || ((int) y >= sheight)) {
                pPixel.r = pPixel.g = pPixel.b = 0;
            } else {
                double xi = Tools.fmod33(x);
                double yi = Tools.fmod33(y);
                readSrcPixels(srcImg, x, y);
                // 1st line
                readSrcPixels(srcImg, x, y);
                int cvalR = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.r) + xi * (srcQ.r)) + yi * ((1.0 - xi) * (srcR.r) + xi * (srcS.r))));
                int cvalG = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.g) + xi * (srcQ.g)) + yi * ((1.0 - xi) * (srcR.g) + xi * (srcS.g))));
                int cvalB = roundColor(((1.0 - yi) * ((1.0 - xi) * (srcP.b) + xi * (srcQ.b)) + yi * ((1.0 - xi) * (srcR.b) + xi * (srcS.b))));
                double xc = x - xi + 1.0;
                int cnt = 1;
                while (xc < xn) {
                    readSrcPixels(srcImg, x, y);
                    cvalR += (1.0 - yi) * srcP.r + yi * srcR.r;
                    cvalG += (1.0 - yi) * srcP.g + yi * srcR.g;
                    cvalB += (1.0 - yi) * srcP.b + yi * srcR.b;
                    xc += 1.0;
                    cnt++;
                }
                // remaining lines
                y = y - yi + 1.0;
                while (y < yn) {
                    // 1st point
                    readSrcPixels(srcImg, x, y);
                    cvalR += (1.0 - xi) * srcP.r + xi * srcQ.r;
                    cvalG += (1.0 - xi) * srcP.g + xi * srcQ.g;
                    cvalB += (1.0 - xi) * srcP.b + xi * srcQ.b;
                    // remaining points
                    xc = x - xi + 1.0;
                    cnt++;
                    while (xc < xn) {
                        readSrcPixels(srcImg, x, y);
                        cvalR += srcP.r;
                        cvalG += srcP.g;
                        cvalB += srcP.b;
                        xc += 1.0;
                        cnt++;
                    }
                    y += 1.0;
                }
                pPixel.r = roundColor(cvalR / (double) cnt);
                pPixel.g = roundColor(cvalG / (double) cnt);
                pPixel.b = roundColor(cvalB / (double) cnt);
            }
            dstImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
        }
    }
}
Also used : Pixel(org.jwildfire.image.Pixel)

Example 30 with Pixel

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

the class ShearTransformer method shearX_Damp.

private void shearX_Damp(SimpleImage pImg) {
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    Pixel pPixel = new Pixel();
    double cx = (double) width / 2.0 - 0.5;
    double cy = (double) height / 2.0 - 0.5;
    double ox = this.centreX - cx;
    double oy = this.centreY - cy;
    double zoom = this.zoom;
    if (zoom < 0.01)
        zoom = 0.01;
    zoom = 1.0 / zoom;
    double fshift = this.amount / (100.0 - 1.0);
    double shift = 0.0 - fshift;
    double damping = this.damping;
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    for (int i = 0; i < height; i++) {
        double y0 = (double) i - cy;
        for (int j = 0; j < width; j++) {
            /* transform the point */
            double x0 = (double) j - cx;
            double amp = (y0 - oy) * shift;
            double dl2 = x0 - ox;
            if (dl2 < 0.0)
                dl2 = 0.0 - dl2;
            amp = amp * Math.exp(dl2 * damping);
            double x = (x0 + amp) * zoom + cx;
            double y = y0 * zoom + 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))));
            }
            pImg.setRGB(j, i, pPixel.r, pPixel.g, pPixel.b);
        }
    }
}
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