Search in sources :

Example 6 with ImageWriter

use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.

the class RenderMainFlameThread method run.

@Override
public void run() {
    finished = forceAbort = false;
    try {
        int width = resProfile.getWidth();
        int height = resProfile.getHeight();
        RenderInfo info = new RenderInfo(width, height, RenderMode.PRODUCTION);
        double wScl = (double) info.getImageWidth() / (double) flame.getWidth();
        double hScl = (double) info.getImageHeight() / (double) flame.getHeight();
        flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
        flame.setWidth(info.getImageWidth());
        flame.setHeight(info.getImageHeight());
        boolean renderHDR = qualProfile.isWithHDR();
        info.setRenderHDR(renderHDR);
        boolean renderZBuffer = qualProfile.isWithZBuffer();
        info.setRenderZBuffer(renderZBuffer);
        flame.setSampleDensity(qualProfile.getQuality());
        long t0, t1;
        renderer = new FlameRenderer(flame, prefs, flame.isBGTransparency(), false);
        renderer.setProgressUpdater(progressUpdater);
        t0 = Calendar.getInstance().getTimeInMillis();
        RenderedFlame res = renderer.renderFlame(info);
        if (forceAbort) {
            finished = true;
            return;
        }
        t1 = Calendar.getInstance().getTimeInMillis();
        new ImageWriter().saveImage(res.getImage(), outFile.getAbsolutePath());
        if (res.getHDRImage() != null) {
            new ImageWriter().saveImage(res.getHDRImage(), Tools.makeHDRFilename(outFile.getAbsolutePath()));
        }
        if (res.getZBuffer() != null) {
            new ImageWriter().saveImage(res.getZBuffer(), Tools.makeZBufferFilename(outFile.getAbsolutePath()));
        }
        if (prefs.isTinaSaveFlamesWhenImageIsSaved()) {
            new FlameWriter().writeFlame(flame, outFile.getParentFile().getAbsolutePath() + File.separator + Tools.trimFileExt(outFile.getName()) + ".flame");
        }
        finished = true;
        finishEvent.succeeded((t1 - t0) * 0.001);
    } catch (Throwable ex) {
        finished = true;
        finishEvent.failed(ex);
    }
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter) ImageWriter(org.jwildfire.io.ImageWriter) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 7 with ImageWriter

use of org.jwildfire.io.ImageWriter 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 8 with ImageWriter

use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.

the class MainController method saveImage.

public void saveImage() throws Exception {
    Buffer buffer = getActiveBuffer();
    if (buffer != null) {
        JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
        if (prefs.getOutputImagePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getOutputImagePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showSaveDialog(windowMenu) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            prefs.setLastOutputImageFile(file);
            if (buffer.getBufferType() == BufferType.IMAGE) {
                new ImageWriter().saveImage(buffer.getImage(), file.getAbsolutePath());
            } else if (buffer.getBufferType() == BufferType.HDR_IMAGE) {
                new ImageWriter().saveImage(buffer.getHDRImage(), file.getAbsolutePath());
            } else if (buffer.getBufferType() == BufferType.MESH3D) {
                new SunFlowWriter().saveMesh(buffer.getMesh3D(), file.getAbsolutePath());
            } else {
                showMessage("Not supported");
                return;
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) SunFlowWriter(org.jwildfire.io.SunFlowWriter) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File)

Example 9 with ImageWriter

use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.

the class ScriptProcessor method saveLastImage.

public void saveLastImage(String pFilename) throws Exception {
    SimpleImage img = getLastImage();
    if (img == null)
        throw new IllegalStateException();
    new ImageWriter().saveAsJPEG(img, pFilename);
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageWriter(org.jwildfire.io.ImageWriter)

Example 10 with ImageWriter

use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.

the class RasterTools method saveZBufImg.

public static void saveZBufImg(float[][] zbuf, String filename) {
    double zmin = 0.0, zmax = 0.0;
    for (int i = 0; i < zbuf.length; i++) {
        for (int j = 0; j < zbuf[0].length; j++) {
            if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
                zmin = zmax = zbuf[i][j];
                break;
            }
        }
    }
    for (int i = 0; i < zbuf.length; i++) {
        for (int j = 0; j < zbuf[0].length; j++) {
            if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
                if (zbuf[i][j] < zmin)
                    zmin = zbuf[i][j];
                else if (zbuf[i][j] > zmax)
                    zmax = zbuf[i][j];
            }
        }
    }
    double dz = zmax - zmin;
    SimpleImage img = new SimpleImage(zbuf.length, zbuf[0].length);
    for (int i = 0; i < zbuf.length; i++) {
        for (int j = 0; j < zbuf[0].length; j++) {
            if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
                int a = Tools.roundColor((zbuf[i][j] - zmin) / dz * 255.0);
                img.setARGB(i, j, 255, a, a, a);
            } else {
                img.setARGB(i, j, 255, 0, 0, 0);
            }
        }
    }
    try {
        new ImageWriter().saveAsPNG(img, filename);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageWriter(org.jwildfire.io.ImageWriter)

Aggregations

ImageWriter (org.jwildfire.io.ImageWriter)11 File (java.io.File)6 JFileChooser (javax.swing.JFileChooser)4 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)4 SimpleImage (org.jwildfire.image.SimpleImage)4 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)3 ImageFileChooser (org.jwildfire.swing.ImageFileChooser)3 Flame (org.jwildfire.create.tina.base.Flame)2 FACLFlameWriter (org.jwildfire.create.tina.faclrender.FACLFlameWriter)2 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)2 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PCPoint (org.jwildfire.create.tina.base.raster.RasterPointCloud.PCPoint)1 FACLRenderResult (org.jwildfire.create.tina.faclrender.FACLRenderResult)1 FlameReader (org.jwildfire.create.tina.io.FlameReader)1 SunFlowWriter (org.jwildfire.io.SunFlowWriter)1