Search in sources :

Example 56 with SimpleImage

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

the class PostBumpMapWFFunc method transform.

@Override
public void transform(FlameTransformationContext pContext, XForm pXForm, XYZPoint pAffineTP, XYZPoint pVarTP, double pAmount) {
    double x = (pAffineTP.x - offsetX + 1.0) / scaleX * 0.5 * (double) (imgWidth - 1);
    double y = (pAffineTP.y - offsetY + 1.0) / scaleY * 0.5 * (double) (imgHeight - 1);
    double dz = offsetZ;
    int ix = Tools.FTOI(x);
    int iy = Tools.FTOI(y);
    if (ix >= 0 && ix < imgWidth && iy >= 0 && iy < imgHeight) {
        double intensity;
        if (bumpMap instanceof SimpleImage) {
            toolPixel.setARGBValue(((SimpleImage) bumpMap).getARGBValue(ix, iy));
            double r = toolPixel.r;
            double g = toolPixel.g;
            double b = toolPixel.b;
            intensity = (0.299 * r + 0.588 * g + 0.113 * b) / 255.0;
        } else {
            ((SimpleHDRImage) bumpMap).getRGBValues(rgbArray, ix, iy);
            double r = rgbArray[0];
            double g = rgbArray[0];
            double b = rgbArray[0];
            intensity = (0.299 * r + 0.588 * g + 0.113 * b);
        }
        dz += scaleZ * intensity;
        if (resetZ != 0) {
            pVarTP.z = dz;
        } else {
            pVarTP.z += dz;
        }
    }
}
Also used : SimpleHDRImage(org.jwildfire.image.SimpleHDRImage) SimpleImage(org.jwildfire.image.SimpleImage) XYZPoint(org.jwildfire.create.tina.base.XYZPoint)

Example 57 with SimpleImage

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

the class LoaderTest method testImageLoader.

@Test
public void testImageLoader() throws Exception {
    // use an image we have available already in classpath
    FileInputStream fs = new FileInputStream("Delphi/jwildfire_icon.png");
    FileOutputStream fo = new FileOutputStream(new File("/dev/shm/test007"));
    IOUtils.copyLarge(fs, fo);
    fs.close();
    fo.close();
    String fn = "/dev/shm/test001";
    String name = "ImageSequenceLoader";
    JDesktopPane desk = new JDesktopPane();
    ImageSequenceLoader imageloader = (ImageSequenceLoader) LoadersList.getLoaderInstance(null, name);
    imageloader.setFilename(fn);
    imageloader.setFrame(7);
    Assert.assertEquals(fn, imageloader.getFilename());
    Assert.assertEquals(7, imageloader.getFrame());
    imageloader.setDesktop(desk);
    Assert.assertEquals(desk, imageloader.getDesktop());
    Assert.assertEquals(name, imageloader.getName());
    Assert.assertEquals(name, imageloader.getBeanInfo().getBeanDescriptor().getName());
    SimpleImage si = imageloader.loadImage();
    Assert.assertEquals(48, si.getImageHeight());
    Assert.assertEquals(48, si.getImageWidth());
    Assert.assertEquals(1.0, si.getAspect(), .000001);
    imageloader.execute();
    new File("/dev/shm/test007").delete();
}
Also used : JDesktopPane(javax.swing.JDesktopPane) FileOutputStream(java.io.FileOutputStream) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 58 with SimpleImage

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

the class PixelizeTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    // Init
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    int gridSize = this.gridSize;
    Grid grid = (gridSize < 1) ? Grid.OFF : this.grid;
    Pixel pixel = new Pixel();
    int pw = this.width;
    int ph = this.height;
    if (pw < 1)
        pw = 1;
    else if (pw > width)
        pw = width;
    if (ph < 1)
        ph = 1;
    else if (ph > height)
        ph = height;
    if ((pw == 1) && (ph == 1))
        return;
    int pwo = pw;
    int pho = ph;
    int hc = width / pw;
    if ((width % pw) != 0)
        hc += 2;
    int vc = height / ph;
    if ((height % ph) != 0)
        vc += 2;
    int[] pwa = new int[hc];
    int[] pha = new int[vc];
    int gSize = 0;
    if (grid != Grid.OFF) {
        gSize = gridSize;
        if ((gSize > pwo) || (gSize > pho)) {
            if (pwo > pho)
                gSize = pho;
            else
                gSize = pwo;
        }
    }
    int[] grUp = null, ggUp = null, gbUp = null;
    int[] grDown = null, ggDown = null, gbDown = null;
    int[] grLeft = null, ggLeft = null, gbLeft = null;
    int[] grRight = null, ggRight = null, gbRight = null;
    if (((grid) != Grid.OFF) && (gSize >= 1)) {
        if ((gSize % 2) == 0)
            gSize++;
        int s = (gSize / 2 + 1);
        if (gSize > 1) {
            grUp = new int[s];
            ggUp = new int[s];
            gbUp = new int[s];
            grDown = new int[s];
            ggDown = new int[s];
            gbDown = new int[s];
            grLeft = new int[s];
            ggLeft = new int[s];
            gbLeft = new int[s];
            grRight = new int[s];
            ggRight = new int[s];
            gbRight = new int[s];
        }
    }
    // 
    if ((width % pw) == 0) {
        for (int i = 0; i < hc; i++) pwa[i] = pw;
    } else {
        if (this.centre) {
            pwa[0] = (width % pw) / 2;
            if (pwa[0] == 0)
                pwa[0] = 1;
            for (int i = 1; i < (hc - 1); i++) pwa[i] = pw;
            pwa[hc - 1] = width - pwa[0] - (hc - 2) * pw;
            if (pwa[hc - 1] == 0)
                hc--;
        } else {
            hc--;
            for (int i = 0; i < (hc - 1); i++) pwa[i] = pw;
            pwa[hc - 1] = width - (hc - 1) * pw;
        }
    }
    if ((height % ph) == 0) {
        for (int i = 0; i < vc; i++) pha[i] = ph;
    } else {
        if (this.centre) {
            pha[0] = (height % ph) / 2;
            if (pha[0] == 0)
                pha[0] = 1;
            for (int i = 1; i < (vc - 1); i++) pha[i] = ph;
            pha[vc - 1] = height - pha[0] - (vc - 2) * ph;
            if (pha[vc - 1] == 0)
                vc--;
        } else {
            vc--;
            for (int i = 0; i < (vc - 1); i++) pha[i] = ph;
            pha[vc - 1] = height - (vc - 1) * ph;
        }
    }
    {
        int topOffset = 0;
        for (int i = 0; i < vc; i++) {
            ph = pha[i];
            int leftOffset = 0;
            for (int j = 0; j < hc; j++) {
                pw = pwa[j];
                int pc = pw * ph;
                /* compute the average-color */
                int ra = 0, ga = 0, ba = 0;
                for (int k = 0; k < ph; k++) {
                    for (int l = 0; l < pw; l++) {
                        int x = leftOffset + l;
                        int y = topOffset + k;
                        pixel.setARGBValue(srcImg.getARGBValue(x, y));
                        ra += pixel.r;
                        ga += pixel.g;
                        ba += pixel.b;
                    }
                }
                ra = Tools.limitColor(ra / pc);
                ga = Tools.limitColor(ga / pc);
                ba = Tools.limitColor(ba / pc);
                // set this color in the current box
                for (int k = 0; k < ph; k++) {
                    for (int l = 0; l < pw; l++) {
                        int x = leftOffset + l;
                        int y = topOffset + k;
                        img.setRGB(x, y, pixel);
                    }
                }
                leftOffset += pw;
            }
            topOffset += ph;
        }
    }
    if ((grid != Grid.OFF) && (gSize >= 1)) {
        double gFallOffUp = this.gridFallOffTop;
        double gFallOffDown = this.gridFallOffBottom;
        double gFallOffLeft = this.gridFallOffLeft;
        double gFallOffRight = this.gridFallOffRight;
        if (gFallOffUp < 0.0)
            gFallOffUp = 0.0;
        if (gFallOffDown < 0.0)
            gFallOffDown = 0.0;
        if (gFallOffLeft < 0.0)
            gFallOffLeft = 0.0;
        if (gFallOffRight < 0.0)
            gFallOffRight = 0.0;
        int s = (gSize / 2 + 1);
        int n = s - 1;
        if (gSize > 1) {
            if ((gFallOffUp < 0.0001) && (gFallOffDown < 0.0001) && (gFallOffLeft < 0.0001) && (gFallOffRight < 0.0001)) {
                for (int k = 0; k < s; k++) {
                    grUp[k] = grDown[k] = grLeft[k] = grRight[k] = this.gridColor.getRed();
                    ggUp[k] = ggDown[k] = ggLeft[k] = ggRight[k] = this.gridColor.getGreen();
                    gbUp[k] = gbDown[k] = gbLeft[k] = gbRight[k] = this.gridColor.getBlue();
                }
            } else {
                calcCArray(grUp, s, gFallOffUp, this.gridColor.getRed());
                calcCArray(ggUp, s, gFallOffUp, this.gridColor.getGreen());
                calcCArray(gbUp, s, gFallOffUp, this.gridColor.getBlue());
                calcCArray(grDown, s, gFallOffDown, this.gridColor.getRed());
                calcCArray(ggDown, s, gFallOffDown, this.gridColor.getGreen());
                calcCArray(gbDown, s, gFallOffDown, this.gridColor.getBlue());
                calcCArray(grLeft, s, gFallOffLeft, this.gridColor.getRed());
                calcCArray(ggLeft, s, gFallOffLeft, this.gridColor.getGreen());
                calcCArray(gbLeft, s, gFallOffLeft, this.gridColor.getBlue());
                calcCArray(grRight, s, gFallOffRight, this.gridColor.getRed());
                calcCArray(ggRight, s, gFallOffRight, this.gridColor.getGreen());
                calcCArray(gbRight, s, gFallOffRight, this.gridColor.getBlue());
            }
        } else
            n = 0;
        // horizontal grid
        if ((grid == Grid.XY) || (grid == Grid.X)) {
            int topOffset = 0;
            int r, g, b;
            for (int i = 0; i < (vc - 1); i++) {
                ph = pha[i];
                topOffset += ph;
                // base grid
                r = this.gridColor.getRed();
                g = this.gridColor.getGreen();
                b = this.gridColor.getBlue();
                for (int j = 0; j < width; j++) {
                    img.setRGB(j, topOffset, r, g, b);
                }
                // up
                for (int kk = 1; kk <= n; kk++) {
                    r = grUp[kk];
                    g = ggUp[kk];
                    b = gbUp[kk];
                    for (int j = 0; j < width; j++) {
                        int y = topOffset - kk;
                        if (y >= 0)
                            img.setRGB(j, y, r, g, b);
                    }
                }
                // down
                for (int kk = 1; kk <= n; kk++) {
                    r = grDown[kk];
                    g = ggDown[kk];
                    b = gbDown[kk];
                    for (int j = 0; j < width; j++) {
                        int y = topOffset + kk;
                        if (y < height)
                            img.setRGB(j, y, r, g, b);
                    }
                }
            }
        }
        // vertical grid
        if ((grid == Grid.XY) || (grid == Grid.Y)) {
            int r, g, b;
            int leftOffset = 0;
            for (int i = 0; i < (hc - 1); i++) {
                pw = pwa[i];
                leftOffset += pw;
                // base grid
                r = this.gridColor.getRed();
                g = this.gridColor.getGreen();
                b = this.gridColor.getBlue();
                for (int j = 0; j < height; j++) {
                    img.setRGB(leftOffset, j, r, g, b);
                }
                // left
                for (int kk = 1; kk <= n; kk++) {
                    r = grLeft[kk];
                    g = ggLeft[kk];
                    b = gbLeft[kk];
                    for (int j = 0; j < height; j++) {
                        int x = leftOffset - kk;
                        if (x >= 0)
                            img.setRGB(x, j, r, g, b);
                    }
                }
                // right
                for (int kk = 1; kk <= n; kk++) {
                    r = grRight[kk];
                    g = ggRight[kk];
                    b = gbRight[kk];
                    for (int j = 0; j < height; j++) {
                        int x = leftOffset + kk;
                        if (x < width)
                            img.setRGB(x, j, r, g, b);
                    }
                }
            }
        }
        // connections
        if (grid == Grid.XY) {
            int topOffset = 0;
            for (int i = 0; i < (vc - 1); i++) {
                ph = pha[i];
                topOffset += ph;
                int leftOffset = 0;
                for (int j = 0; j < (hc - 1); j++) {
                    pw = pwa[j];
                    leftOffset += pw;
                    int r, g, b;
                    // base grid
                    r = this.gridColor.getRed();
                    g = this.gridColor.getGreen();
                    b = this.gridColor.getBlue();
                    for (int kk = -n; kk <= +n; kk++) {
                        int x = leftOffset + kk;
                        int y = topOffset;
                        if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
                            img.setRGB(x, y, r, g, b);
                    }
                    // up
                    for (int kk = 1; kk <= n; kk++) {
                        r = grUp[kk];
                        g = ggUp[kk];
                        b = gbUp[kk];
                        for (int ll = kk; ll <= n; ll++) {
                            int x = leftOffset - ll;
                            int y = topOffset - kk;
                            if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
                                img.setRGB(x, y, r, g, b);
                            x = leftOffset + ll;
                            if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
                                img.setRGB(x, y, r, g, b);
                        }
                    }
                    // down
                    for (int kk = 1; kk <= n; kk++) {
                        r = grDown[kk];
                        g = ggDown[kk];
                        b = gbDown[kk];
                        for (int ll = kk; ll <= n; ll++) {
                            int x = leftOffset - ll;
                            int y = topOffset + kk;
                            if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
                                img.setRGB(x, y, r, g, b);
                            x = leftOffset + ll;
                            if ((x >= 0) && (x < width) && (y >= 0) && (y < height))
                                img.setRGB(x, y, r, g, b);
                        }
                    }
                }
            }
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 59 with SimpleImage

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

the class RectangleTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    Graphics g = img.getGraphics();
    g.setColor(color);
    if (thickness == 1) {
        g.drawRect(left, top, width, height);
    } else if (thickness > 1) {
        // p1                          p2
        // p5                      p6
        // p7                      p8
        // p3                          p4
        final int x1 = left;
        final int y1 = top;
        final int x2 = left + width - 1;
        final int y2 = top;
        final int x3 = left;
        final int y3 = top + height - 1;
        final int x4 = left + width - 1;
        final int y4 = top + height - 1;
        final int x5 = x1 + thickness;
        final int y5 = y1 + thickness;
        final int x6 = x2 - thickness;
        final int y6 = y2 + thickness;
        final int x7 = x3 + thickness;
        final int y7 = y3 - thickness;
        final int x8 = x4 - thickness;
        final int y8 = y4 - thickness;
        g.fillPolygon(new int[] { x1, x2, x6, x5 }, new int[] { y1, y2, y6, y5 }, 4);
        g.fillPolygon(new int[] { x7, x8, x4, x3 }, new int[] { y7, y8, y4, y3 }, 4);
        g.fillPolygon(new int[] { x1, x5, x7, x3 }, new int[] { y1, y5, y7, y3 }, 4);
        g.fillPolygon(new int[] { x2, x4, x8, x6 }, new int[] { y2, y4, y8, y6 }, 4);
    }
}
Also used : Graphics(java.awt.Graphics) SimpleImage(org.jwildfire.image.SimpleImage)

Example 60 with SimpleImage

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

the class RefractTransformer method performPixelTransformation.

@Override
protected void performPixelTransformation(WFImage pImg) {
    SimpleImage img = (SimpleImage) pImg;
    int width = pImg.getImageWidth();
    int height = pImg.getImageHeight();
    double xscl = this.scaleX;
    double yscl = this.scaleY;
    double w1 = (double) width - 1.0;
    double h1 = (double) height - 1.0;
    Pixel pPixel = new Pixel();
    for (int pY = 0; pY < height; pY++) {
        for (int pX = 0; pX < width; pX++) {
            pPixel.setARGBValue(img.getARGBValue(pX, pY));
            int argb = srcImg.getARGBValue(pX, pY);
            toolPixel.setARGBValue(argb);
            double gint = (double) (toolPixel.r - avg);
            double x = (double) pX - xscl * gint;
            double y = (double) pY - yscl * gint;
            /* color-wrapping */
            if (this.wrap) {
                while (x >= ((double) width - 0.5)) x -= (double) (width - 1);
                while ((int) x < 0.5) x += (double) (width - 1);
                while (y >= ((double) height - 0.5)) y -= (double) (height - 1);
                while ((int) y < 0.5) y += (double) (height - 1);
            }
            /* 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(pX, pY, pPixel.r, pPixel.g, pPixel.b);
        }
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

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