Search in sources :

Example 91 with SimpleImage

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

the class FlameRenderer method renderSlices.

public void renderSlices(SliceRenderInfo pSliceRenderInfo, String pFilenamePattern) {
    if (!flame.isRenderable())
        throw new RuntimeException("Slices can not be created of empty flames");
    int fileIdx = 1;
    int passes = pSliceRenderInfo.getSlices() / pSliceRenderInfo.getSlicesPerRender();
    if (pSliceRenderInfo.getSlices() % pSliceRenderInfo.getSlicesPerRender() != 0)
        passes++;
    progressDisplayPhaseCount = passes;
    double zmin = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmin() : pSliceRenderInfo.getZmax();
    double zmax = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmax() : pSliceRenderInfo.getZmin();
    double thickness = (zmax - zmin) / (double) pSliceRenderInfo.getSlices();
    double currZ = zmax;
    int currSlice = 0;
    for (int pass = 0; pass < passes; pass++) {
        if (forceAbort) {
            break;
        }
        System.gc();
        progressDisplayPhase = pass;
        Flame currFlame = flame.makeCopy();
        prepareFlameForSliceRendering(currFlame);
        initRasterSizes(pSliceRenderInfo.getImageWidth(), pSliceRenderInfo.getImageHeight());
        List<RenderSlice> slices = new ArrayList<RenderSlice>();
        for (int i = 0; i < pSliceRenderInfo.getSlicesPerRender() && currSlice < pSliceRenderInfo.getSlices(); i++) {
            RenderSlice slice = new RenderSlice(allocRaster(flame.getSpatialOversampling(), flame.getSampleDensity()), currZ - thickness, currZ);
            slices.add(slice);
            currZ -= thickness;
            currSlice++;
        }
        List<List<RenderPacket>> renderFlames = new ArrayList<List<RenderPacket>>();
        for (int t = 0; t < prefs.getTinaRenderThreads(); t++) {
            renderFlames.add(createRenderPackets(flame, flame.getFrame()));
        }
        iterate(0, 1, renderFlames, slices);
        if (!forceAbort) {
            LogDensityPoint logDensityPnt = new LogDensityPoint(flame.getActiveLightCount());
            while (slices.size() > 0) {
                if (forceAbort) {
                    break;
                }
                RenderSlice slice = slices.get(0);
                RenderedFlame renderedFlame = new RenderedFlame();
                renderedFlame.init(pSliceRenderInfo.createRenderInfo(), flame);
                SimpleImage img = renderedFlame.getImage();
                logDensityFilter.setRaster(slice.getRaster(), rasterWidth, rasterHeight, img.getImageWidth(), img.getImageHeight());
                GammaCorrectedRGBPoint rbgPoint = new GammaCorrectedRGBPoint();
                for (int i = 0; i < img.getImageHeight(); i++) {
                    for (int j = 0; j < img.getImageWidth(); j++) {
                        logDensityFilter.transformPoint(logDensityPnt, j, i);
                        gammaCorrectionFilter.transformPoint(logDensityPnt, rbgPoint, j, i);
                        img.setARGB(j, i, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
                    }
                }
                String filename = String.format(pFilenamePattern, fileIdx++);
                try {
                    new ImageWriter().saveImage(renderedFlame.getImage(), filename);
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
                slice = null;
                slices.remove(0);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ImageWriter(org.jwildfire.io.ImageWriter) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) List(java.util.List) Flame(org.jwildfire.create.tina.base.Flame)

Example 92 with SimpleImage

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

the class FlameRenderer method renderImageSimple.

private void renderImageSimple(SimpleImage pImage) {
    int threadCount = prefs.getTinaRenderThreads();
    if (threadCount < 1)
        threadCount = 1;
    logDensityFilter.setRaster(raster, rasterWidth, rasterHeight, pImage.getImageWidth(), pImage.getImageHeight());
    if (renderScale == 2) {
        SimpleImage newImg = new SimpleImage(pImage.getImageWidth() * renderScale, pImage.getImageHeight() * renderScale);
        int rowsPerThread = pImage.getImageHeight() / threadCount;
        List<RenderImageSimpleScaledThread> threads = new ArrayList<RenderImageSimpleScaledThread>();
        for (int i = 0; i < threadCount; i++) {
            int startRow = i * rowsPerThread;
            int endRow = i < threadCount - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
            RenderImageSimpleScaledThread thread = new RenderImageSimpleScaledThread(flame, logDensityFilter, gammaCorrectionFilter, renderScale, startRow, endRow, pImage, newImg);
            threads.add(thread);
            if (threadCount > 1) {
                new Thread(thread).start();
            } else {
                thread.run();
            }
        }
        ThreadTools.waitForThreads(threadCount, threads);
        pImage.setBufferedImage(newImg.getBufferedImg(), newImg.getImageWidth(), newImg.getImageHeight());
    } else if (renderScale == 1) {
        int rowsPerThread = pImage.getImageHeight() / threadCount;
        List<RenderImageSimpleThread> threads = new ArrayList<RenderImageSimpleThread>();
        for (int i = 0; i < threadCount; i++) {
            int startRow = i * rowsPerThread;
            int endRow = i < rowsPerThread - 1 ? startRow + rowsPerThread : pImage.getImageHeight();
            RenderImageSimpleThread thread = new RenderImageSimpleThread(flame, logDensityFilter, gammaCorrectionFilter, startRow, endRow, pImage);
            threads.add(thread);
            if (threadCount > 1) {
                new Thread(thread).start();
            } else {
                thread.run();
            }
        }
        ThreadTools.waitForThreads(threadCount, threads);
    } else {
        throw new IllegalArgumentException("renderScale " + renderScale);
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) RenderImageSimpleThread(org.jwildfire.create.tina.render.image.RenderImageSimpleThread) ArrayList(java.util.ArrayList) List(java.util.List) PCPoint(org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint) RenderImageSimpleScaledThread(org.jwildfire.create.tina.render.image.RenderImageSimpleScaledThread) RenderImageThread(org.jwildfire.create.tina.render.image.RenderImageThread) RenderHDRImageThread(org.jwildfire.create.tina.render.image.RenderHDRImageThread) RenderImageSimpleScaledThread(org.jwildfire.create.tina.render.image.RenderImageSimpleScaledThread) RenderImageSimpleThread(org.jwildfire.create.tina.render.image.RenderImageSimpleThread) PostFilterImageThread(org.jwildfire.create.tina.render.image.PostFilterImageThread) RenderZBufferThread(org.jwildfire.create.tina.render.image.RenderZBufferThread)

Example 93 with SimpleImage

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

the class RandomFlameGeneratorSampler method calculateDiffCoverage.

public static double calculateDiffCoverage(SimpleImage pImg, SimpleImage pSimplifiedRefImg) {
    SimpleImage img = createSimplifiedRefImage(pImg);
    long maxCoverage = img.getImageWidth() * img.getImageHeight();
    long coverage = 0;
    Pixel pixel = new Pixel();
    Pixel refPixel = new Pixel();
    for (int k = 0; k < img.getImageHeight(); k++) {
        for (int l = 0; l < img.getImageWidth(); l++) {
            pixel.setARGBValue(img.getARGBValue(l, k));
            refPixel.setARGBValue(pSimplifiedRefImg.getARGBValue(l, k));
            if (fabs(pixel.r - refPixel.r) > 29.0 || fabs(pixel.g - refPixel.g) > 15.0 || fabs(pixel.b - refPixel.b) > 78.0) {
                coverage++;
            }
        }
    }
    // System.out.println((double) coverage / (double) maxCoverage);
    return (double) coverage / (double) maxCoverage;
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Pixel(org.jwildfire.image.Pixel)

Example 94 with SimpleImage

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

the class RandomFlameGeneratorSampler method createSimplifiedRefImage.

public static SimpleImage createSimplifiedRefImage(SimpleImage pImg) {
    SimpleImage img = pImg.clone();
    PixelizeTransformer pT = new PixelizeTransformer();
    pT.setCentre(false);
    pT.setGridSize(5);
    pT.transformImage(img);
    return img;
}
Also used : PixelizeTransformer(org.jwildfire.transform.PixelizeTransformer) SimpleImage(org.jwildfire.image.SimpleImage)

Example 95 with SimpleImage

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

the class RandomFlameGeneratorSampler method calculateCoverage.

public static double calculateCoverage(SimpleImage pImg, int bgRed, int bgGreen, int bgBlue, boolean useFilter) {
    SimpleImage img;
    if (useFilter) {
        SimpleImage filteredImg = new SimpleImage(pImg.getBufferedImg(), pImg.getImageWidth(), pImg.getImageHeight());
        ConvolveTransformer transformer = new ConvolveTransformer();
        transformer.initDefaultParams(filteredImg);
        transformer.setKernelType(KernelType.SOBEL_3X3);
        transformer.transformImage(filteredImg);
        img = filteredImg;
    } else {
        img = pImg;
    }
    long maxCoverage = img.getImageWidth() * img.getImageHeight();
    long coverage = 0;
    Pixel pixel = new Pixel();
    if (bgRed == 0 && bgGreen == 0 && bgBlue == 0) {
        for (int k = 0; k < img.getImageHeight(); k++) {
            for (int l = 0; l < img.getImageWidth(); l++) {
                pixel.setARGBValue(img.getARGBValue(l, k));
                if (pixel.r > 29 || pixel.g > 15 || pixel.b > 78) {
                    coverage++;
                }
            }
        }
    } else {
        for (int k = 0; k < img.getImageHeight(); k++) {
            for (int l = 0; l < img.getImageWidth(); l++) {
                pixel.setARGBValue(img.getARGBValue(l, k));
                if (Math.abs(pixel.r - bgRed) > 29.0 && Math.abs(pixel.g - bgGreen) > 15.0 && Math.abs(pixel.b - bgBlue) > 78.0) {
                    coverage++;
                }
            }
        }
    }
    return (double) coverage / (double) maxCoverage;
}
Also used : ConvolveTransformer(org.jwildfire.transform.ConvolveTransformer) 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