Search in sources :

Example 1 with ImageWriter

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

the class SWFAnimationRenderThread method saveImage.

private void saveImage(SimpleImage pImage, int pFrame) throws Exception {
    String filename = generateFilename(pFrame, Tools.FILEEXT_PNG);
    new ImageWriter().saveAsPNG(pImage, filename);
}
Also used : ImageWriter(org.jwildfire.io.ImageWriter)

Example 2 with ImageWriter

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

the class JobRenderThread method run.

@Override
public void run() {
    try {
        try {
            cancelSignalled = false;
            controller.getTotalProgressBar().setMinimum(0);
            controller.getTotalProgressBar().setValue(0);
            controller.getTotalProgressBar().setMaximum(activeJobList.size());
            for (Job job : activeJobList) {
                if (cancelSignalled) {
                    break;
                }
                try {
                    int width, height;
                    if (job.getCustomWidth() > 0 && job.getCustomHeight() > 0) {
                        width = job.getCustomWidth();
                        height = job.getCustomHeight();
                    } else {
                        width = resolutionProfile.getWidth();
                        height = resolutionProfile.getHeight();
                    }
                    RenderInfo info = new RenderInfo(width, height, RenderMode.PRODUCTION);
                    info.setRenderHDR(qualityProfile.isWithHDR());
                    info.setRenderZBuffer(qualityProfile.isWithZBuffer());
                    List<Flame> flames = new FlameReader(Prefs.getPrefs()).readFlames(job.getFlameFilename());
                    Flame flame = flames.get(0);
                    String primaryFilename = job.getImageFilename(flame.getStereo3dMode());
                    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());
                    double oldSampleDensity = flame.getSampleDensity();
                    double oldFilterRadius = flame.getSpatialFilterRadius();
                    try {
                        if (!doOverwriteExisting && new File(primaryFilename).exists()) {
                            controller.getJobProgressUpdater().initProgress(1);
                            controller.getJobProgressUpdater().updateProgress(1);
                        } else {
                            if (useOpenCl) {
                                String openClFlameFilename = Tools.trimFileExt(job.getFlameFilename()) + ".flam3";
                                try {
                                    Flame newFlame = AnimationService.evalMotionCurves(flame.makeCopy(), flame.getFrame());
                                    new FACLFlameWriter().writeFlame(newFlame, openClFlameFilename);
                                    long t0 = Calendar.getInstance().getTimeInMillis();
                                    FACLRenderResult openClRenderRes = FACLRenderTools.invokeFACLRender(openClFlameFilename, width, height, qualityProfile.getQuality());
                                    long t1 = Calendar.getInstance().getTimeInMillis();
                                    if (openClRenderRes.getReturnCode() != 0) {
                                        throw new Exception(openClRenderRes.getMessage());
                                    } else {
                                        job.setElapsedSeconds(((double) (t1 - t0) / 1000.0));
                                    }
                                } finally {
                                    if (!new File(openClFlameFilename).delete()) {
                                        new File(openClFlameFilename).deleteOnExit();
                                    }
                                }
                            } else {
                                flame.setSampleDensity(job.getCustomQuality() > 0 ? job.getCustomQuality() : qualityProfile.getQuality());
                                renderer = new FlameRenderer(flame, Prefs.getPrefs(), flame.isBGTransparency(), false);
                                renderer.setProgressUpdater(controller.getJobProgressUpdater());
                                long t0 = Calendar.getInstance().getTimeInMillis();
                                RenderedFlame res = renderer.renderFlame(info);
                                if (!cancelSignalled) {
                                    long t1 = Calendar.getInstance().getTimeInMillis();
                                    job.setElapsedSeconds(((double) (t1 - t0) / 1000.0));
                                    new ImageWriter().saveImage(res.getImage(), primaryFilename);
                                    if (res.getHDRImage() != null) {
                                        new ImageWriter().saveImage(res.getHDRImage(), Tools.makeHDRFilename(job.getImageFilename(flame.getStereo3dMode())));
                                    }
                                    if (res.getZBuffer() != null) {
                                        new ImageWriter().saveImage(res.getZBuffer(), Tools.makeZBufferFilename(job.getImageFilename(flame.getStereo3dMode())));
                                    }
                                }
                            }
                        }
                        if (!cancelSignalled) {
                            job.setFinished(true);
                        }
                        if (Prefs.getPrefs().isTinaFreeCacheInBatchRenderer()) {
                            RessourceManager.clearAll();
                            System.gc();
                        }
                        try {
                            {
                                controller.refreshRenderBatchJobsTable();
                                controller.getRenderBatchJobsTable().invalidate();
                                controller.getRenderBatchJobsTable().validate();
                            // Graphics g = controller.getRenderBatchJobsTable().getParent().getGraphics();
                            // if (g != null) {
                            // controller.getRenderBatchJobsTable().getParent().paint(g);
                            // }
                            }
                            {
                                controller.getTotalProgressBar().setValue(controller.getTotalProgressBar().getValue() + 1);
                                controller.getTotalProgressBar().invalidate();
                                controller.getTotalProgressBar().validate();
                            // Graphics g = controller.getTotalProgressBar().getGraphics();
                            // if (g != null) {
                            // controller.getTotalProgressBar().paint(g);
                            // }
                            }
                        } catch (Throwable ex) {
                        // ex.printStackTrace();
                        }
                    } finally {
                        flame.setSampleDensity(oldSampleDensity);
                        flame.setSpatialFilterRadius(oldFilterRadius);
                    }
                } catch (Throwable ex) {
                    job.setLastError(ex);
                // ex.printStackTrace();
                }
            }
            try {
                controller.getTotalProgressBar().setValue(controller.getTotalProgressBar().getMaximum());
                controller.getJobProgressBar().setValue(0);
            } catch (Throwable ex) {
            // ex.printStackTrace();
            }
        } catch (Throwable ex) {
            throw new RuntimeException(ex);
        }
    } finally {
        controller.onJobFinished();
    }
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) ImageWriter(org.jwildfire.io.ImageWriter) FACLFlameWriter(org.jwildfire.create.tina.faclrender.FACLFlameWriter) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) FACLRenderResult(org.jwildfire.create.tina.faclrender.FACLRenderResult) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 3 with ImageWriter

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

the class RasterTools method saveFloatBuffer.

public static void saveFloatBuffer(float[][] buf, String filename) {
    double min, max;
    min = max = buf[0][0];
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            if (inRange(buf[i][j])) {
                min = max = buf[i][j];
                break;
            }
        }
    }
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            if (inRange(buf[i][j])) {
                if (buf[i][j] < min)
                    min = buf[i][j];
                else if (buf[i][j] > max && !Double.isInfinite(buf[i][j]))
                    max = buf[i][j];
            }
        }
    }
    double d = max - min;
    System.out.println("Saving float buffer \"" + new File(filename).getName() + "\", min = " + min + ", max = " + max);
    SimpleImage img = new SimpleImage(buf.length, buf[0].length);
    for (int i = 0; i < buf.length; i++) {
        for (int j = 0; j < buf[0].length; j++) {
            int a = Tools.roundColor((buf[i][j] - min) / d * 255.0);
            img.setARGB(i, j, 255, a, a, a);
        }
    }
    try {
        new ImageWriter().saveAsPNG(img, filename);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File)

Example 4 with ImageWriter

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

the class FlamesGPURenderController method saveImageButton_clicked.

public void saveImageButton_clicked() {
    try {
        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(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            new ImageWriter().saveImage(image, file.getAbsolutePath());
            if (prefs.isTinaSaveFlamesWhenImageIsSaved()) {
                new FlameWriter().writeFlame(getCurrFlame(), file.getParentFile().getAbsolutePath() + File.separator + Tools.trimFileExt(file.getName()) + ".flame");
            }
            // if (autoLoadImageCBx.isSelected()) {
            parentCtrl.mainController.loadImage(file.getAbsolutePath(), false);
        // }
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FACLFlameWriter(org.jwildfire.create.tina.faclrender.FACLFlameWriter) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) JFileChooser(javax.swing.JFileChooser) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File)

Example 5 with ImageWriter

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

the class TinaInteractiveRendererController method saveZBufferButton_clicked.

public void saveZBufferButton_clicked() {
    try {
        pauseRenderThreads();
        try {
            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(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                double zBufferScale = Double.parseDouble(JOptionPane.showInputDialog(imageRootPanel, "Enter ZBuffer-Scale", currFlame.getZBufferScale()));
                currFlame.setZBufferScale(zBufferScale);
                RenderedFlame res = renderer.finishZBuffer(displayUpdater.getSampleCount());
                if (res.getZBuffer() != null) {
                    new ImageWriter().saveImage(res.getZBuffer(), file.getAbsolutePath());
                    if (autoLoadImageCBx.isSelected()) {
                        parentCtrl.mainController.loadImage(file.getAbsolutePath(), false);
                    }
                }
            }
        } finally {
            resumeRenderThreads();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

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