Search in sources :

Example 6 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader 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 7 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class FlameBrowserController method toMeshGenBtn_clicked.

public void toMeshGenBtn_clicked() {
    try {
        FlameFlatNode node = getSelectedFlame();
        if (node != null) {
            List<Flame> flames = new FlameReader(prefs).readFlames(node.getFilename());
            if (flames.size() > 0) {
                tinaController.getMeshGenController().importFlame(flames.get(0));
                tinaController.getDesktop().showInternalFrame(MeshGenInternalFrame.class);
            }
        }
    } catch (Exception ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) Flame(org.jwildfire.create.tina.base.Flame)

Example 8 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class FlameFilePreview method createThumbnail.

public void createThumbnail() {
    if (currFile == null) {
        currThumbnail = null;
        return;
    }
    try {
        if (currFile.exists()) {
            int imgWidth = this.getPreferredSize().width;
            int imgHeight = this.getPreferredSize().height - BUTTON_HEIGHT;
            int quality = 50;
            SimpleImage preview;
            String filename = currFile.getAbsolutePath();
            ThumbnailCacheKey cacheKey = new ThumbnailCacheKey(filename);
            preview = ThumbnailCacheProvider.getThumbnail(cacheKey, imgWidth, imgHeight, quality);
            if (preview == null) {
                List<Flame> flames = new FlameReader(prefs).readFlames(filename);
                Flame flame = flames.get(0);
                double wScl = (double) imgWidth / (double) flame.getWidth();
                double hScl = (double) imgHeight / (double) flame.getHeight();
                flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
                flame.setWidth(imgWidth);
                flame.setHeight(imgHeight);
                FlameRenderer renderer = new FlameRenderer(flame, prefs, false, true);
                renderer.setProgressUpdater(null);
                flame.setSampleDensity(quality);
                flame.setSpatialFilterRadius(0.0);
                RenderInfo info = new RenderInfo(imgWidth, imgHeight, RenderMode.PREVIEW);
                RenderedFlame res = renderer.renderFlame(info);
                preview = res.getImage();
                ThumbnailCacheProvider.storeThumbnail(cacheKey, imgWidth, imgHeight, quality, preview);
            }
            currThumbnail = new ImageIcon(preview.getBufferedImg());
        }
    } catch (Exception ex) {
        currThumbnail = null;
        if (ex.getCause() != null) {
            ex.getCause().printStackTrace();
        } else {
            ex.printStackTrace();
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) FlameReader(org.jwildfire.create.tina.io.FlameReader) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) SimpleImage(org.jwildfire.image.SimpleImage) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 9 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class FlamesGPURenderController method fromClipboardButton_clicked.

public void fromClipboardButton_clicked() {
    Flame newFlame = null;
    try {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable clipData = clipboard.getContents(clipboard);
        if (clipData != null) {
            if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
                List<Flame> flames = new FlameReader(prefs).readFlamesfromXML(xml);
                if (flames.size() > 0) {
                    newFlame = flames.get(0);
                }
            }
        }
        if (newFlame == null) {
            throw new Exception("There is currently no valid flame in the clipboard");
        } else {
            currFlame = newFlame;
            enableControls();
            setupProfiles(currFlame);
            renderFlame();
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) Transferable(java.awt.datatransfer.Transferable) Clipboard(java.awt.datatransfer.Clipboard) Flame(org.jwildfire.create.tina.base.Flame)

Example 10 with FlameReader

use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.

the class FlamesGPURenderController method loadFlameButton_clicked.

public void loadFlameButton_clicked() {
    try {
        JFileChooser chooser = new FlameFileChooser(prefs);
        if (prefs.getInputFlamePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showOpenDialog(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            List<Flame> flames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
            Flame newFlame = flames.get(0);
            prefs.setLastInputFlameFile(file);
            importFlame(newFlame);
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FlameReader(org.jwildfire.create.tina.io.FlameReader) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame)

Aggregations

FlameReader (org.jwildfire.create.tina.io.FlameReader)25 Flame (org.jwildfire.create.tina.base.Flame)24 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)20 File (java.io.File)12 JFileChooser (javax.swing.JFileChooser)10 Clipboard (java.awt.datatransfer.Clipboard)7 Transferable (java.awt.datatransfer.Transferable)7 FlameFileChooser (org.jwildfire.create.tina.swing.FlameFileChooser)5 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)3 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)3 ArrayList (java.util.ArrayList)2 ThumbnailCacheKey (org.jwildfire.create.tina.swing.ThumbnailCacheKey)2 HashMap (java.util.HashMap)1 ImageIcon (javax.swing.ImageIcon)1 XForm (org.jwildfire.create.tina.base.XForm)1 FACLFlameWriter (org.jwildfire.create.tina.faclrender.FACLFlameWriter)1 FACLRenderResult (org.jwildfire.create.tina.faclrender.FACLRenderResult)1 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)1 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)1 Variation (org.jwildfire.create.tina.variation.Variation)1