Search in sources :

Example 1 with FlameRenderer

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

the class RandomFlameGeneratorSampler method createSample.

public RandomFlameGeneratorSample createSample() {
    RenderInfo info = new RenderInfo(imageWidth, imageHeight, RenderMode.PREVIEW);
    Flame bestFlame = null;
    int bgRed = prefs.getTinaRandomBatchBGColorRed();
    int bgGreen = prefs.getTinaRandomBatchBGColorGreen();
    int bgBlue = prefs.getTinaRandomBatchBGColorBlue();
    RandomFlameGeneratorState randGenState = randGen.initState(prefs, randGradientGen);
    double bestCoverage = 0.0;
    for (int j = 0; j < quality.getMaxSamples(); j++) {
        // create flame
        Flame flame;
        try {
            flame = randGen.createFlame(prefs, randGenState);
            if (randGen.supportsSymmetry()) {
                randSymmGen.addSymmetry(flame);
            }
        } catch (Exception ex) {
            flame = new Flame();
            ex.printStackTrace();
        }
        flame.setWidth(imageWidth);
        flame.setHeight(imageHeight);
        flame.setPixelsPerUnit(10);
        for (Layer layer : flame.getLayers()) {
            RGBPalette palette = randGradientGen.generatePalette(paletteSize, fadePaletteColors, uniformWidth);
            layer.setPalette(palette);
        }
        flame = randGen.postProcessFlameBeforeRendering(randGenState, flame);
        // render it
        flame.setSampleDensity(25);
        RenderedFlame renderedFlame;
        flame.applyFastOversamplingSettings();
        try {
            FlameRenderer renderer = new FlameRenderer(flame, prefs, false, true);
            renderedFlame = renderer.renderFlame(info);
            flame = randGen.postProcessFlameAfterRendering(randGenState, flame);
            if (j == quality.getMaxSamples() - 1) {
                renderedFlame = new FlameRenderer(bestFlame, prefs, false, true).renderFlame(info);
                return new RandomFlameGeneratorSample(bestFlame, renderedFlame.getImage());
            } else {
                double fCoverage = calculateCoverage(renderedFlame.getImage(), bgRed, bgGreen, bgBlue, randGen.isUseFilter(randGenState));
                if (fCoverage >= quality.getCoverage() && fCoverage < randGen.getMaxCoverage()) {
                    return new RandomFlameGeneratorSample(flame, renderedFlame.getImage());
                } else {
                    if (bestFlame == null || fCoverage > bestCoverage) {
                        bestFlame = flame;
                        bestCoverage = fCoverage;
                    }
                }
            }
        } finally {
            flame.applyDefaultOversamplingSettings();
        }
    }
    throw new IllegalStateException();
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) Layer(org.jwildfire.create.tina.base.Layer) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 2 with FlameRenderer

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

the class AnimationService method renderFrame.

public static SimpleImage renderFrame(Flame flame, int pWidth, int pHeight, Prefs pPrefs) throws Exception {
    RenderInfo info = new RenderInfo(pWidth, pHeight, 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());
    FlameRenderer renderer = new FlameRenderer(flame, pPrefs, flame.isBGTransparency(), 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 3 with FlameRenderer

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

the class SWFAnimationRenderThread method renderFlame.

private SimpleImage renderFlame(Flame pFlame) {
    RenderInfo info = new RenderInfo(flameMovie.getFrameWidth(), flameMovie.getFrameHeight(), RenderMode.PRODUCTION);
    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(info.getImageWidth());
    pFlame.setHeight(info.getImageHeight());
    FlameRenderer renderer = new FlameRenderer(pFlame, Prefs.getPrefs(), pFlame.isBGTransparency(), false);
    renderer.setProgressUpdater(null);
    pFlame.setSampleDensity(flameMovie.getQuality());
    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 4 with FlameRenderer

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

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

the class BatchRendererController method renderBatchJobsTableClicked.

public void renderBatchJobsTableClicked() {
    FlamePanel imgPanel = getBatchPreviewFlamePanel();
    Rectangle bounds = imgPanel.getImageBounds();
    int width = bounds.width;
    int height = bounds.height;
    Flame flame = getBatchRenderPreviewFlameHolder().getFlame();
    if (width >= 16 && height >= 16) {
        RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
        if (flame != null) {
            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, data.toggleTransparencyButton.isSelected(), false);
            flame.setSampleDensity(prefs.getTinaRenderRealtimeQuality());
            flame.setSpatialFilterRadius(0.0);
            RenderedFlame res = renderer.renderFlame(info);
            imgPanel.setImage(res.getImage());
        } else {
            imgPanel.setImage(new SimpleImage(width, height));
        }
    }
    data.batchPreviewRootPanel.invalidate();
    data.batchPreviewRootPanel.validate();
}
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