Search in sources :

Example 11 with FlameRenderer

use of org.jwildfire.create.tina.render.FlameRenderer in project JWildfire by thargor6.

the class TinaController method renderRandomizedFlame.

private SimpleImage renderRandomizedFlame(Flame pFlame, Dimension pImgSize) {
    int imageWidth = pImgSize.width, imageHeight = pImgSize.height;
    RenderInfo info = new RenderInfo(imageWidth, imageHeight, RenderMode.PREVIEW);
    double wScl = (double) info.getImageWidth() / (double) pFlame.getWidth();
    double hScl = (double) info.getImageHeight() / (double) pFlame.getHeight();
    pFlame.setPixelsPerUnit((wScl + hScl) * 0.5 * pFlame.getPixelsPerUnit());
    pFlame.setWidth(imageWidth);
    pFlame.setHeight(imageHeight);
    pFlame.setSampleDensity(40.0);
    FlameRenderer renderer = new FlameRenderer(pFlame, prefs, false, false);
    RenderedFlame res = renderer.renderFlame(info);
    return res.getImage();
}
Also used : FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 12 with FlameRenderer

use of org.jwildfire.create.tina.render.FlameRenderer in project JWildfire by thargor6.

the class TinaInteractiveRendererController method resumeBtn_clicked.

public void resumeBtn_clicked() {
    try {
        JFileChooser chooser = new JWFRenderFileChooser(prefs);
        if (prefs.getInputFlamePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showOpenDialog(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
            cancelRender();
            File file = chooser.getSelectedFile();
            Flame newFlame = new Flame();
            FlameRenderer newRenderer = new FlameRenderer(newFlame, prefs, newFlame.isBGTransparency(), false);
            ResumedFlameRender resumedRender = newRenderer.resumeRenderFlame(file.getAbsolutePath());
            threads = new RenderThreads(resumedRender.getThreads(), new ArrayList<Thread>());
            Flame flame = currFlame = newRenderer.getFlame();
            // setup size profile
            {
                int width = newRenderer.getRenderInfo().getImageWidth();
                int height = newRenderer.getRenderInfo().getImageHeight();
                ResolutionProfile selected = null;
                boolean full = false;
                boolean halve = false;
                boolean quarter = false;
                for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
                    ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
                    if (profile.getWidth() == width && profile.getHeight() == height) {
                        selected = profile;
                        full = true;
                        break;
                    }
                }
                if (selected == null) {
                    for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
                        ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
                        if (profile.getWidth() / 2 == width && profile.getHeight() / 2 == height) {
                            selected = profile;
                            halve = true;
                            break;
                        }
                    }
                }
                if (selected == null) {
                    for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
                        ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
                        if (profile.getWidth() / 4 == width && profile.getHeight() / 4 == height) {
                            selected = profile;
                            quarter = true;
                            break;
                        }
                    }
                }
                if (selected == null) {
                    selected = new ResolutionProfile(false, width, height);
                    full = true;
                    interactiveResolutionProfileCmb.addItem(selected);
                }
                boolean wasQuarterSelected = quarterSizeButton.isSelected();
                boolean wasHalveSelected = halveSizeButton.isSelected();
                boolean wasFullSelected = fullSizeButton.isSelected();
                refreshing = true;
                try {
                    quarterSizeButton.setSelected(quarter);
                    halveSizeButton.setSelected(halve);
                    fullSizeButton.setSelected(full);
                } finally {
                    refreshing = false;
                }
                ResolutionProfile currSel = (ResolutionProfile) interactiveResolutionProfileCmb.getSelectedItem();
                if (currSel == null || !currSel.equals(selected) || wasQuarterSelected != quarter || wasHalveSelected != halve || wasFullSelected != full) {
                    interactiveResolutionProfileCmb.setSelectedItem(selected);
                    refreshImagePanel();
                } else {
                    clearScreen();
                }
            }
            // 
            renderer = newRenderer;
            setupProfiles(currFlame);
            if (flame.getBgColorRed() > 0 || flame.getBgColorGreen() > 0 || flame.getBgColorBlue() > 0) {
                image.fillBackground(flame.getBgColorRed(), flame.getBgColorGreen(), flame.getBgColorBlue());
            }
            renderer.registerIterationObserver(this);
            displayUpdater = createDisplayUpdater();
            displayUpdater.initRender(threads.getRenderThreads().size());
            pausedRenderTime = resumedRender.getHeader().getElapsedMilliseconds();
            renderStartTime = System.currentTimeMillis();
            lastQuality = 0.0;
            lastQualitySpeed = 0.0;
            lastQualityTime = 0;
            for (int i = 0; i < threads.getRenderThreads().size(); i++) {
                AbstractRenderThread rThread = threads.getRenderThreads().get(i);
                Thread eThread = startRenderThread(rThread);
                threads.getExecutingThreads().add(eThread);
            }
            updateDisplayThread = new UpdateDisplayThread();
            startDisplayThread(updateDisplayThread);
            state = State.RENDER;
            enableControls();
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : ResolutionProfile(org.jwildfire.base.ResolutionProfile) ArrayList(java.util.ArrayList) XYZProjectedPoint(org.jwildfire.create.tina.base.XYZProjectedPoint) AbstractRenderThread(org.jwildfire.create.tina.render.AbstractRenderThread) RenderThreads(org.jwildfire.create.tina.render.RenderThreads) JFileChooser(javax.swing.JFileChooser) ResumedFlameRender(org.jwildfire.create.tina.render.ResumedFlameRender) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) File(java.io.File) AbstractRenderThread(org.jwildfire.create.tina.render.AbstractRenderThread) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 13 with FlameRenderer

use of org.jwildfire.create.tina.render.FlameRenderer 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 14 with FlameRenderer

use of org.jwildfire.create.tina.render.FlameRenderer in project JWildfire by thargor6.

the class JWFRenderFilePreview method createThumbnail.

public void createThumbnail() {
    if (currFile == null) {
        currThumbnail = null;
        return;
    }
    try {
        if (currFile.exists()) {
            JWFRenderHeader header = new JWFRenderHeaderReader().readRenderHeader(currFile.getAbsolutePath());
            Flame flame = header.getFlame();
            if (flame != null) {
                int imgWidth = this.getPreferredSize().width;
                int imgHeight = this.getPreferredSize().height;
                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(50);
                flame.setSpatialFilterRadius(0.0);
                RenderInfo info = new RenderInfo(imgWidth, imgHeight, RenderMode.PREVIEW);
                RenderedFlame res = renderer.renderFlame(info);
                currThumbnail = new ImageIcon(res.getImage().getBufferedImg());
            }
        }
    } catch (Exception ex) {
        currThumbnail = null;
        if (ex.getCause() != null) {
            ex.getCause().printStackTrace();
        } else {
            ex.printStackTrace();
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) JWFRenderHeader(org.jwildfire.create.tina.io.JWFRenderHeader) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) JWFRenderHeaderReader(org.jwildfire.create.tina.io.JWFRenderHeaderReader) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 15 with FlameRenderer

use of org.jwildfire.create.tina.render.FlameRenderer in project JWildfire by thargor6.

the class TinaSWFAnimatorController method refreshFlameImage.

public void refreshFlameImage(boolean pQuickRender) {
    if (!noRefresh) {
        FlamePanel imgPanel = getFlamePanel();
        Rectangle bounds = imgPanel.getImageBounds();
        int width = bounds.width;
        int height = bounds.height;
        if (width >= 16 && height >= 16) {
            RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
            Flame flame = getCurrFlame();
            if (flame != null) {
                double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
                double oldSampleDensity = flame.getSampleDensity();
                try {
                    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());
                    FlameRenderer renderer = new FlameRenderer(flame, prefs, false, false);
                    if (pQuickRender) {
                        renderer.setProgressUpdater(null);
                        flame.setSampleDensity(1.0);
                        flame.setSpatialFilterRadius(0.0);
                    } else {
                        renderer.setProgressUpdater(renderProgressUpdater);
                        flame.setSampleDensity(prefs.getTinaRenderPreviewQuality());
                    }
                    RenderedFlame res = renderer.renderFlame(info);
                    imgPanel.setImage(res.getImage());
                } finally {
                    flame.setSpatialFilterRadius(oldSpatialFilterRadius);
                    flame.setSampleDensity(oldSampleDensity);
                }
            }
        } else {
            imgPanel.setImage(new SimpleImage(width, height));
        }
        swfAnimatorPreviewRootPanel.repaint();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) Rectangle(java.awt.Rectangle) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Aggregations

FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)34 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)28 Flame (org.jwildfire.create.tina.base.Flame)27 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)25 SimpleImage (org.jwildfire.image.SimpleImage)12 Rectangle (java.awt.Rectangle)10 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)9 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)5 Test (org.junit.Test)4 XForm (org.jwildfire.create.tina.base.XForm)4 XYZPoint (org.jwildfire.create.tina.base.XYZPoint)4 ZigguratRandomGenerator (org.jwildfire.create.tina.random.ZigguratRandomGenerator)4 AbstractRenderThread (org.jwildfire.create.tina.render.AbstractRenderThread)4 DrawFocusPointFlameRenderer (org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer)4 ImageIcon (javax.swing.ImageIcon)3 FlameReader (org.jwildfire.create.tina.io.FlameReader)3 FlamePanelConfig (org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig)3 File (java.io.File)2 ResolutionProfile (org.jwildfire.base.ResolutionProfile)2 Layer (org.jwildfire.create.tina.base.Layer)2