Search in sources :

Example 1 with FlamePanelConfig

use of org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig in project JWildfire by thargor6.

the class FlamePreviewHelper method fastRenderFlameImage.

public SimpleImage fastRenderFlameImage(boolean pQuickRender, boolean pMouseDown, int pDownScale) {
    FlamePanel imgPanel = flamePanelProvider.getFlamePanel();
    FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
    Rectangle panelBounds = imgPanel.getParentImageBounds();
    Rectangle bounds;
    if (pDownScale != 1) {
        bounds = new Rectangle(panelBounds.width / pDownScale, panelBounds.height / pDownScale);
    } else {
        bounds = panelBounds;
    }
    int renderScale = pQuickRender && pMouseDown ? 2 : 1;
    int width = bounds.width / renderScale;
    int height = bounds.height / renderScale;
    if (width >= 16 && height >= 16) {
        RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
        Flame flame = flameHolder.getFlame();
        if (flame != null) {
            double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
            double oldSampleDensity = flame.getSampleDensity();
            int oldSpatialOversampling = flame.getSpatialOversampling();
            boolean oldPostNoiseFilter = flame.isPostNoiseFilter();
            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());
                try {
                    FlameRenderer renderer;
                    if (isDrawFocusPointEnabled(cfg)) {
                        renderer = new DrawFocusPointFlameRenderer(flame, prefs, isTransparencyEnabled());
                    } else {
                        renderer = new FlameRenderer(flame, prefs, isTransparencyEnabled(), false);
                    }
                    renderer.setProgressUpdater(null);
                    flame.setSampleDensity(prefs.getTinaRenderRealtimeQuality());
                    flame.applyFastOversamplingSettings();
                    renderer.setRenderScale(renderScale);
                    RenderedFlame res = renderer.renderFlame(info);
                    SimpleImage img = res.getImage();
                    img.getBufferedImg().setAccelerationPriority(1.0f);
                    return img;
                } catch (Throwable ex) {
                    errorHandler.handleError(ex);
                }
            } finally {
                flame.setSampleDensity(oldSampleDensity);
                flame.setSpatialFilterRadius(oldSpatialFilterRadius);
                flame.setSpatialOversampling(oldSpatialOversampling);
                flame.setPostNoiseFilter(oldPostNoiseFilter);
            }
        }
    }
    return null;
}
Also used : Rectangle(java.awt.Rectangle) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) XYZProjectedPoint(org.jwildfire.create.tina.base.XYZProjectedPoint) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) SimpleImage(org.jwildfire.image.SimpleImage) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 2 with FlamePanelConfig

use of org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig in project JWildfire by thargor6.

the class FlamePreviewHelper method createLayerPreview.

private SimpleImage createLayerPreview(SimpleImage img, int renderScale, int width, int height) {
    FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
    Flame flame = flameHolder.getFlame();
    Layer onlyVisibleLayer = null;
    for (Layer layer : flameHolder.getFlame().getLayers()) {
        if (layer.isVisible()) {
            if (onlyVisibleLayer == null) {
                onlyVisibleLayer = layer;
            } else {
                onlyVisibleLayer = null;
                break;
            }
        }
    }
    boolean drawSubLayer = flame.getLayers().size() > 1 && layerHolder.getLayer() != null && layerHolder.getLayer() != onlyVisibleLayer && !cfg.isNoControls();
    if (drawSubLayer) {
        Flame singleLayerFlame = new Flame();
        singleLayerFlame.assign(flame);
        singleLayerFlame.getLayers().clear();
        singleLayerFlame.getLayers().add(layerHolder.getLayer().makeCopy());
        singleLayerFlame.getFirstLayer().setVisible(true);
        singleLayerFlame.getFirstLayer().setWeight(1.0);
        RenderInfo lInfo = new RenderInfo(width / 4 * renderScale, height / 4 * renderScale, RenderMode.PREVIEW);
        double lWScl = (double) lInfo.getImageWidth() / (double) singleLayerFlame.getWidth();
        double lHScl = (double) lInfo.getImageHeight() / (double) singleLayerFlame.getHeight();
        singleLayerFlame.setPixelsPerUnit((lWScl + lHScl) * 0.5 * singleLayerFlame.getPixelsPerUnit() * 0.5);
        singleLayerFlame.setWidth(lInfo.getImageWidth());
        singleLayerFlame.setHeight(lInfo.getImageHeight());
        singleLayerFlame.setSampleDensity(prefs.getTinaRenderRealtimeQuality() * 2.0 / 3.0);
        FlameRenderer lRenderer = new FlameRenderer(singleLayerFlame, prefs, false, false);
        RenderedFlame lRes = lRenderer.renderFlame(lInfo);
        SimpleImage layerImg = lRes.getImage();
        boolean drawLayerNumber = true;
        if (drawLayerNumber) {
            RectangleTransformer rT = new RectangleTransformer();
            int textWidth = 28;
            int textHeight = 22;
            int margin = 2;
            rT.setColor(new java.awt.Color(0, 0, 0));
            rT.setLeft(layerImg.getImageWidth() - textWidth - 2 * margin);
            rT.setTop(layerImg.getImageHeight() - textHeight - 2 * margin);
            rT.setThickness(textHeight / 2 + 1);
            rT.setWidth(textWidth);
            rT.setHeight(textHeight);
            rT.transformImage(layerImg);
            TextTransformer txt = new TextTransformer();
            txt.setText1("  " + (flame.getLayers().indexOf(layerHolder.getLayer()) + 1) + "  ");
            txt.setAntialiasing(true);
            txt.setColor(new java.awt.Color(200, 200, 200));
            txt.setMode(Mode.NORMAL);
            txt.setFontStyle(FontStyle.BOLD);
            txt.setFontName("Arial");
            txt.setFontSize(16);
            txt.setHAlign(HAlignment.NONE);
            txt.setPosX(layerImg.getImageWidth() - textWidth - margin);
            txt.setPosY(layerImg.getImageHeight() - textHeight - margin);
            txt.setVAlign(VAlignment.NONE);
            txt.transformImage(layerImg);
        }
        RectangleTransformer rT = new RectangleTransformer();
        rT.setColor(new java.awt.Color(200, 200, 200));
        rT.setLeft(0);
        rT.setTop(0);
        rT.setThickness(3);
        rT.setWidth(lInfo.getImageWidth());
        rT.setHeight(lInfo.getImageHeight());
        rT.transformImage(layerImg);
        return layerImg;
    }
    return null;
}
Also used : Color(java.awt.Color) TextTransformer(org.jwildfire.transform.TextTransformer) Layer(org.jwildfire.create.tina.base.Layer) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) XYZProjectedPoint(org.jwildfire.create.tina.base.XYZProjectedPoint) SimpleImage(org.jwildfire.image.SimpleImage) RectangleTransformer(org.jwildfire.transform.RectangleTransformer) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 3 with FlamePanelConfig

use of org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig in project JWildfire by thargor6.

the class FlamePreviewHelper method renderFlameImage.

public SimpleImage renderFlameImage(boolean pQuickRender, boolean pMouseDown, int pDownScale, boolean pAllowUseCache) {
    if (!pAllowUseCache) {
        prevRaster = null;
    }
    FlamePanel imgPanel = flamePanelProvider.getFlamePanel();
    FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
    Rectangle panelBounds = imgPanel.getParentImageBounds();
    Rectangle bounds;
    if (pDownScale != 1) {
        bounds = new Rectangle(panelBounds.width / pDownScale, panelBounds.height / pDownScale);
    } else {
        bounds = panelBounds;
    }
    int renderScale = pQuickRender && pMouseDown ? 2 : 1;
    int width = bounds.width / renderScale;
    int height = bounds.height / renderScale;
    if (width >= 16 && height >= 16) {
        RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
        Flame flame = flameHolder.getFlame();
        if (flame != null) {
            double oldSpatialFilterRadius = flame.getSpatialFilterRadius();
            double oldSampleDensity = flame.getSampleDensity();
            int oldSpatialOversampling = flame.getSpatialOversampling();
            boolean oldPostNoiseFilter = flame.isPostNoiseFilter();
            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());
                try {
                    FlameRenderer renderer;
                    if (pQuickRender) {
                        flame.setSampleDensity(prefs.getTinaRenderRealtimeQuality());
                        flame.applyFastOversamplingSettings();
                        flame.setSpatialOversampling(oldSpatialOversampling);
                    } else {
                        flame.setSampleDensity(prefs.getTinaRenderPreviewQuality());
                    }
                    if (isDrawFocusPointEnabled(cfg)) {
                        renderer = new DrawFocusPointFlameRenderer(flame, prefs, isTransparencyEnabled());
                    } else {
                        renderer = new FlameRenderer(flame, prefs, isTransparencyEnabled(), false);
                    }
                    if (pQuickRender) {
                        renderer.setProgressUpdater(null);
                    } else {
                        renderer.setProgressUpdater(mainProgressUpdater);
                    }
                    long t0 = System.currentTimeMillis();
                    renderer.setRenderScale(renderScale);
                    RenderedFlame res;
                    if (prevRaster != null && pAllowUseCache) {
                        info.setStoreRaster(false);
                        info.setRestoredRaster(prevRaster);
                        flame.setSampleDensity(prevRaster.getSampleDensity());
                        res = renderer.renderFlame(info);
                    } else {
                        info.setStoreRaster(true);
                        res = renderer.renderFlame(info);
                        prevRaster = res.getRaster();
                    }
                    SimpleImage img = res.getImage();
                    long t1 = System.currentTimeMillis();
                    img.getBufferedImg().setAccelerationPriority(1.0f);
                    if (layerAppendBtn != null && layerAppendBtn.isSelected() && !pMouseDown) {
                        showLayerAppendModeIndicator(img);
                    }
                    if (layerPreviewBtn != null && layerPreviewBtn.isSelected() && layerHolder != null) {
                        SimpleImage layerImg = createLayerPreview(img, renderScale, width, height);
                        showLayerPreview(img, layerImg, renderScale, width, height);
                    }
                    if (pDownScale != 1) {
                        SimpleImage background = new SimpleImage(panelBounds.width, panelBounds.height);
                        ComposeTransformer cT = new ComposeTransformer();
                        cT.setHAlign(ComposeTransformer.HAlignment.CENTRE);
                        cT.setVAlign(ComposeTransformer.VAlignment.CENTRE);
                        cT.setForegroundImage(img);
                        cT.transformImage(background);
                        img = background;
                    }
                    if (!cfg.isNoControls() && messageHelper != null) {
                        messageHelper.showStatusMessage(flame, "render time: " + Tools.doubleToString((t1 - t0) * 0.001) + "s");
                    }
                    return img;
                } catch (Throwable ex) {
                    errorHandler.handleError(ex);
                }
            } finally {
                flame.setSpatialFilterRadius(oldSpatialFilterRadius);
                flame.setSampleDensity(oldSampleDensity);
                flame.setSpatialOversampling(oldSpatialOversampling);
                flame.setPostNoiseFilter(oldPostNoiseFilter);
            }
        }
    }
    return null;
}
Also used : ComposeTransformer(org.jwildfire.transform.ComposeTransformer) Rectangle(java.awt.Rectangle) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) XYZProjectedPoint(org.jwildfire.create.tina.base.XYZProjectedPoint) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame) SimpleImage(org.jwildfire.image.SimpleImage) DrawFocusPointFlameRenderer(org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer) FlameRenderer(org.jwildfire.create.tina.render.FlameRenderer) RenderInfo(org.jwildfire.create.tina.render.RenderInfo) FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 4 with FlamePanelConfig

use of org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig in project JWildfire by thargor6.

the class FlamePreviewHelper method refreshFlameImage.

public void refreshFlameImage(boolean pQuickRender, boolean pMouseDown, int pDownScale, boolean pReRender, boolean pAllowUseCache) {
    cancelBackgroundRender();
    if (pQuickRender && detachedPreviewProvider != null && detachedPreviewProvider.getDetachedPreviewController() != null && pDownScale == 1) {
        detachedPreviewProvider.getDetachedPreviewController().setFlame(flameHolder.getFlame());
    }
    FlamePanel imgPanel = flamePanelProvider.getFlamePanel();
    FlamePanelConfig cfg = flamePanelProvider.getFlamePanelConfig();
    if (pReRender) {
        if (!pQuickRender || !isProgressivePreviewEnabled(cfg)) {
            SimpleImage img = renderFlameImage(pQuickRender, pMouseDown, pDownScale, pAllowUseCache);
            if (img != null) {
                imgPanel.setImage(img);
            }
        }
    }
    imgPanel.setBounds(imgPanel.getParentImageBounds());
    if (!cfg.isNoControls()) {
        centerPanel.getParent().validate();
        centerPanel.repaint();
    } else {
        imgPanel.repaint();
    }
    if (pReRender && isProgressivePreviewEnabled(cfg) && pQuickRender) {
        if (pAllowUseCache) {
            SimpleImage img = renderFlameImage(pQuickRender, pMouseDown, pDownScale, pAllowUseCache);
            if (img != null) {
                imgPanel.setImage(img);
            }
        } else {
            startBackgroundRender(imgPanel);
        }
    }
    if (pQuickRender && !cfg.isNoControls() && randomBatchHolder != null) {
        refreshThumbnail();
    }
}
Also used : SimpleImage(org.jwildfire.image.SimpleImage) FlamePanel(org.jwildfire.create.tina.swing.flamepanel.FlamePanel) FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig)

Example 5 with FlamePanelConfig

use of org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig in project JWildfire by thargor6.

the class AnimationController method keyFrameSliderChanged.

public void keyFrameSliderChanged() {
    if (!tinaController.isNoRefresh()) {
        boolean oldNoRefresh = tinaController.isNoRefresh();
        try {
            tinaController.setNoRefresh(true);
            int frame = keyframesFrameSlider.getValue();
            if (playPreviewThread == null) {
                adjustFrameControls(frame);
            }
            if (tinaController.getCurrFlame() != null) {
                tinaController.getCurrFlame().setFrame(frame);
            }
            if (playPreviewThread != null) {
                FlamePanelConfig cfg = tinaController.getFlamePanelConfig();
                boolean oldNoControls = cfg.isNoControls();
                try {
                    cfg.setNoControls(true);
                    tinaController.refreshFlameImage(true, true, 1, true, false);
                } finally {
                    cfg.setNoControls(oldNoControls);
                }
            } else {
                tinaController.refreshFlameImage(true, false, 1, true, false);
            }
        } finally {
            tinaController.setNoRefresh(oldNoRefresh);
        }
    }
}
Also used : FlamePanelConfig(org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig)

Aggregations

FlamePanelConfig (org.jwildfire.create.tina.swing.flamepanel.FlamePanelConfig)5 SimpleImage (org.jwildfire.image.SimpleImage)4 Flame (org.jwildfire.create.tina.base.Flame)3 XYZProjectedPoint (org.jwildfire.create.tina.base.XYZProjectedPoint)3 DrawFocusPointFlameRenderer (org.jwildfire.create.tina.render.DrawFocusPointFlameRenderer)3 FlameRenderer (org.jwildfire.create.tina.render.FlameRenderer)3 RenderInfo (org.jwildfire.create.tina.render.RenderInfo)3 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)3 FlamePanel (org.jwildfire.create.tina.swing.flamepanel.FlamePanel)3 Rectangle (java.awt.Rectangle)2 Color (java.awt.Color)1 Layer (org.jwildfire.create.tina.base.Layer)1 ComposeTransformer (org.jwildfire.transform.ComposeTransformer)1 RectangleTransformer (org.jwildfire.transform.RectangleTransformer)1 TextTransformer (org.jwildfire.transform.TextTransformer)1