Search in sources :

Example 6 with FlameWriter

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

the class IFlamesController method importFromFlameLibrary.

public void importFromFlameLibrary(int pIdx) {
    if (pIdx >= 0 && pIdx < flameLibrary.size() && getIFlamesFunc() != null) {
        Flame flame = flameLibrary.get(pIdx).getFlame();
        saveUndoPoint();
        try {
            String flameXML = new FlameWriter().getFlameXML(flame);
            getIFlamesFunc().getFlameParams(getCurrFlameIndex()).setFlameXML(flameXML);
        } catch (Exception e) {
            errorHandler.handleError(e);
        }
        enableControls();
        baseFlameCmb_changed();
        refreshIFlame();
    }
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 7 with FlameWriter

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

the class FlameMorphService method morphXForms.

private static XForm morphXForms(Prefs pPrefs, XForm pXForm1, XForm pXForm2, double pFScl, int pFrame, int pFrames) {
    pXForm1 = pXForm1.makeCopy();
    pXForm2 = pXForm2.makeCopy();
    prepareMorphXForm(pXForm1);
    prepareMorphXForm(pXForm2);
    XForm res = new XForm();
    res.setWeight(morphValue(pXForm1.getWeight(), pXForm2.getWeight(), pFScl));
    res.setColor(morphValue(pXForm1.getColor(), pXForm2.getColor(), pFScl));
    res.setColorSymmetry(morphValue(pXForm1.getColorSymmetry(), pXForm2.getColorSymmetry(), pFScl));
    res.setMaterial(morphValue(pXForm1.getMaterial(), pXForm2.getMaterial(), pFScl));
    res.setMaterialSpeed(morphValue(pXForm1.getMaterialSpeed(), pXForm2.getMaterialSpeed(), pFScl));
    res.setXYCoeff00(morphValue(pXForm1.getXYCoeff00(), pXForm2.getXYCoeff00(), pFScl));
    res.setXYCoeff01(morphValue(pXForm1.getXYCoeff01(), pXForm2.getXYCoeff01(), pFScl));
    res.setXYCoeff10(morphValue(pXForm1.getXYCoeff10(), pXForm2.getXYCoeff10(), pFScl));
    res.setXYCoeff11(morphValue(pXForm1.getXYCoeff11(), pXForm2.getXYCoeff11(), pFScl));
    res.setXYCoeff20(morphValue(pXForm1.getXYCoeff20(), pXForm2.getXYCoeff20(), pFScl));
    res.setXYCoeff21(morphValue(pXForm1.getXYCoeff21(), pXForm2.getXYCoeff21(), pFScl));
    res.setYZCoeff00(morphValue(pXForm1.getYZCoeff00(), pXForm2.getYZCoeff00(), pFScl));
    res.setYZCoeff01(morphValue(pXForm1.getYZCoeff01(), pXForm2.getYZCoeff01(), pFScl));
    res.setYZCoeff10(morphValue(pXForm1.getYZCoeff10(), pXForm2.getYZCoeff10(), pFScl));
    res.setYZCoeff11(morphValue(pXForm1.getYZCoeff11(), pXForm2.getYZCoeff11(), pFScl));
    res.setYZCoeff20(morphValue(pXForm1.getYZCoeff20(), pXForm2.getYZCoeff20(), pFScl));
    res.setYZCoeff21(morphValue(pXForm1.getYZCoeff21(), pXForm2.getYZCoeff21(), pFScl));
    res.setZXCoeff00(morphValue(pXForm1.getZXCoeff00(), pXForm2.getZXCoeff00(), pFScl));
    res.setZXCoeff01(morphValue(pXForm1.getZXCoeff01(), pXForm2.getZXCoeff01(), pFScl));
    res.setZXCoeff10(morphValue(pXForm1.getZXCoeff10(), pXForm2.getZXCoeff10(), pFScl));
    res.setZXCoeff11(morphValue(pXForm1.getZXCoeff11(), pXForm2.getZXCoeff11(), pFScl));
    res.setZXCoeff20(morphValue(pXForm1.getZXCoeff20(), pXForm2.getZXCoeff20(), pFScl));
    res.setZXCoeff21(morphValue(pXForm1.getZXCoeff21(), pXForm2.getZXCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setXYPostCoeff00(morphValue(pXForm1.getXYPostCoeff00(), pXForm2.getXYPostCoeff00(), pFScl));
    res.setXYPostCoeff01(morphValue(pXForm1.getXYPostCoeff01(), pXForm2.getXYPostCoeff01(), pFScl));
    res.setXYPostCoeff10(morphValue(pXForm1.getXYPostCoeff10(), pXForm2.getXYPostCoeff10(), pFScl));
    res.setXYPostCoeff11(morphValue(pXForm1.getXYPostCoeff11(), pXForm2.getXYPostCoeff11(), pFScl));
    res.setXYPostCoeff20(morphValue(pXForm1.getXYPostCoeff20(), pXForm2.getXYPostCoeff20(), pFScl));
    res.setXYPostCoeff21(morphValue(pXForm1.getXYPostCoeff21(), pXForm2.getXYPostCoeff21(), pFScl));
    res.setYZPostCoeff00(morphValue(pXForm1.getYZPostCoeff00(), pXForm2.getYZPostCoeff00(), pFScl));
    res.setYZPostCoeff01(morphValue(pXForm1.getYZPostCoeff01(), pXForm2.getYZPostCoeff01(), pFScl));
    res.setYZPostCoeff10(morphValue(pXForm1.getYZPostCoeff10(), pXForm2.getYZPostCoeff10(), pFScl));
    res.setYZPostCoeff11(morphValue(pXForm1.getYZPostCoeff11(), pXForm2.getYZPostCoeff11(), pFScl));
    res.setYZPostCoeff20(morphValue(pXForm1.getYZPostCoeff20(), pXForm2.getYZPostCoeff20(), pFScl));
    res.setYZPostCoeff21(morphValue(pXForm1.getYZPostCoeff21(), pXForm2.getYZPostCoeff21(), pFScl));
    res.setZXPostCoeff00(morphValue(pXForm1.getZXPostCoeff00(), pXForm2.getZXPostCoeff00(), pFScl));
    res.setZXPostCoeff01(morphValue(pXForm1.getZXPostCoeff01(), pXForm2.getZXPostCoeff01(), pFScl));
    res.setZXPostCoeff10(morphValue(pXForm1.getZXPostCoeff10(), pXForm2.getZXPostCoeff10(), pFScl));
    res.setZXPostCoeff11(morphValue(pXForm1.getZXPostCoeff11(), pXForm2.getZXPostCoeff11(), pFScl));
    res.setZXPostCoeff20(morphValue(pXForm1.getZXPostCoeff20(), pXForm2.getZXPostCoeff20(), pFScl));
    res.setZXPostCoeff21(morphValue(pXForm1.getZXPostCoeff21(), pXForm2.getZXPostCoeff21(), pFScl));
    res.setOpacity(morphValue(pXForm1.getOpacity(), pXForm2.getOpacity(), pFScl));
    res.setDrawMode(pFScl >= 0.5 ? pXForm2.getDrawMode() : pXForm1.getDrawMode());
    for (int i = 0; i < pXForm1.getModifiedWeights().length; i++) {
        res.getModifiedWeights()[i] = morphValue(pXForm1.getModifiedWeights()[i], pXForm2.getModifiedWeights()[i], pFScl);
    }
    res.clearVariations();
    List<Variation> vars1 = new ArrayList<Variation>();
    List<Variation> vars2 = new ArrayList<Variation>();
    HashMap<String, String> processed = new HashMap<String, String>();
    for (int i = 0; i < pXForm1.getVariationCount(); i++) {
        Variation var1 = pXForm1.getVariation(i);
        String fncName = var1.getFunc().getName();
        processed.put(fncName, fncName);
        vars1.add(var1);
        // search the same func in xForm2
        Variation var2 = null;
        for (int j = 0; j < pXForm2.getVariationCount(); j++) {
            var2 = pXForm2.getVariation(j);
            if (var2.getFunc().getName().equals(fncName)) {
                break;
            } else {
                var2 = null;
            }
        }
        if (var2 != null) {
            vars2.add(var2);
        } else {
            vars2.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var1.getFunc().getName(), true)));
        }
    }
    for (int i = 0; i < pXForm2.getVariationCount(); i++) {
        Variation var2 = pXForm2.getVariation(i);
        String fncName = var2.getFunc().getName();
        if (processed.get(fncName) == null) {
            vars2.add(var2);
            vars1.add(new Variation(0.0, VariationFuncList.getVariationFuncInstance(var2.getFunc().getName(), true)));
        }
    }
    if (vars1.size() != vars2.size()) {
        throw new IllegalStateException();
    }
    for (int i = 0; i < vars1.size(); i++) {
        Variation var1 = vars1.get(i);
        Variation var2 = vars2.get(i);
        if (!var1.getFunc().getName().equals(var2.getFunc().getName())) {
            throw new IllegalStateException();
        }
        // System.out.println(i + ": " + var1.getFunc().getName() + " " + var1.getAmount() + " " + var2.getAmount());
        double amount = morphValue(var1.getAmount(), var2.getAmount(), pFScl);
        Variation var = res.addVariation(amount, var1.getFunc());
        // params
        if (var.getFunc().getParameterNames() != null && var.getFunc().getParameterNames().length > 0) {
            Object[] val = var.getFunc().getParameterValues();
            Object[] val1 = var1.getFunc().getParameterValues();
            Object[] val2 = var2.getFunc().getParameterValues();
            for (int j = 0; j < var.getFunc().getParameterNames().length; j++) {
                String name = var.getFunc().getParameterNames()[j];
                if (val[j] instanceof Integer) {
                    int mVal = morphValue((Integer) val1[j], (Integer) val2[j], pFScl);
                    if (mVal == 0 && name.equals("power")) {
                        mVal = 1;
                    }
                    // int mVal = pFScl >= 0.5 ? (Integer) val2[j] : (Integer) val1[j];
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else if (val[j] instanceof Double) {
                    double mVal = morphValue((Double) val1[j], (Double) val2[j], pFScl);
                    // System.out.println("  " + name + " " + mVal + " (" + val1[j] + " " + val2[j] + ")");
                    var.getFunc().setParameter(name, mVal);
                } else {
                    throw new IllegalStateException();
                }
            }
        }
        // ressources
        if (var.getFunc().getRessourceNames() != null && var.getFunc().getRessourceNames().length > 0) {
            Object[] ress1 = var1.getFunc().getRessourceValues();
            Object[] ress2 = var2.getFunc().getRessourceValues();
            for (int j = 0; j < var.getFunc().getRessourceNames().length; j++) {
                String name = var.getFunc().getRessourceNames()[j];
                if (name.equalsIgnoreCase(SubFlameWFFunc.RESSOURCE_FLAME) && var.getFunc().getName().indexOf("subflame_wf") >= 0) {
                    String flame1XML = new String((byte[]) ress1[j]);
                    String flame2XML = new String((byte[]) ress2[j]);
                    try {
                        Flame flame1 = new FlameReader(pPrefs).readFlamesfromXML(flame1XML).get(0);
                        Flame flame2 = new FlameReader(pPrefs).readFlamesfromXML(flame2XML).get(0);
                        Flame morphedFlame = morphFlames(pPrefs, FlameMorphType.MORPH, flame1, flame2, pFrame, pFrames);
                        String morphedFlameXML = new FlameWriter().getFlameXML(morphedFlame);
                        var.getFunc().setRessource(SubFlameWFFunc.RESSOURCE_FLAME, morphedFlameXML.getBytes());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    }
    return res;
}
Also used : FlameReader(org.jwildfire.create.tina.io.FlameReader) XForm(org.jwildfire.create.tina.base.XForm) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) Variation(org.jwildfire.create.tina.variation.Variation) Flame(org.jwildfire.create.tina.base.Flame)

Example 8 with FlameWriter

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

the class SWFAnimationRenderThread method saveFlame.

private void saveFlame(Flame pFlame, int pFrame) throws Exception {
    String filename = generateFilename(pFrame, Tools.FILEEXT_FLAME);
    new FlameWriter().writeFlame(pFlame, filename);
}
Also used : FlameWriter(org.jwildfire.create.tina.io.FlameWriter)

Example 9 with FlameWriter

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

the class PostRecordFlameGenerator method createRecordedFlameFiles.

public void createRecordedFlameFiles(String pAbsolutePath) throws Exception {
    if (recorder.getRecordedActions().size() >= 2) {
        List<Flame> flames = new ArrayList<Flame>();
        int actionIdx = 0;
        StartAction startAction = (StartAction) recorder.getRecordedActions().get(actionIdx++);
        DancingFlameStack flameStack = new DancingFlameStack(prefs);
        flameStack.addFlame(startAction.getFlame(), 0, project.getMotions(startAction.getFlame()));
        RecordedAction nextAction = recorder.getRecordedActions().get(actionIdx++);
        long timeRenderStarted = System.currentTimeMillis();
        long nextFrame = (long) (timeRenderStarted + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
        while (true) {
            long time = System.currentTimeMillis();
            while (time < nextFrame) {
                try {
                    Thread.sleep(1);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                time = System.currentTimeMillis();
            }
            nextFrame = (long) (time + 1000.0 / (double) thread.getFramesPerSecond() + 0.5);
            DancingFlame dancingFlame = flameStack.getFlame();
            Flame renderFlame;
            long currTime = time - timeRenderStarted;
            short[] currFFT;
            if (fftData == null) {
                // t.createTransformedFlame() --> motion.computeValue() handles null currFFT values
                // if _using_ fftMotion, currFFT == null will result in no change from base offset
                // if _not_using_ fftMotion, currFFT is ignored
                currFFT = null;
            } else {
                currFFT = fftData.getDataByTimeOffset(currTime);
            }
            Flame transformedFlame = transformer.createTransformedFlame(dancingFlame, currFFT, currTime, thread.getFramesPerSecond());
            renderFlame = new FlamePreparer(prefs).createRenderFlame(transformedFlame);
            flames.add(renderFlame);
            if (time >= timeRenderStarted + nextAction.getTime()) {
                if (nextAction instanceof StopAction) {
                    break;
                } else if (nextAction instanceof FlameChangeAction) {
                    Flame nextFlame = ((FlameChangeAction) nextAction).getFlame();
                    flameStack.addFlame(nextFlame, ((FlameChangeAction) nextAction).getMorphFrameCount(), project.getMotions(nextFlame));
                    nextAction = recorder.getRecordedActions().get(actionIdx++);
                } else {
                    throw new Exception("Unknown action type <" + nextAction.getClass() + ">");
                }
            }
        }
        if (flames.size() > 0) {
            File file = new File(pAbsolutePath);
            String fn = file.getName();
            {
                int p = fn.indexOf(".flame");
                if (p > 0 && p == fn.length() - 6) {
                    fn = fn.substring(0, p);
                }
            }
            int fileIdx = 1;
            for (Flame flame : flames) {
                String hs = String.valueOf(fileIdx++);
                while (hs.length() < 5) {
                    hs = "0" + hs;
                }
                new FlameWriter().writeFlame(flame, new File(file.getParent(), fn + hs + ".flame").getAbsolutePath());
            }
        } else {
            throw new Exception("No flame files where created");
        }
    } else {
        throw new Exception("No valid recording");
    }
}
Also used : ArrayList(java.util.ArrayList) DancingFlameStack(org.jwildfire.create.tina.dance.DancingFlameStack) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) DancingFlame(org.jwildfire.create.tina.dance.DancingFlame) FlamePreparer(org.jwildfire.create.tina.dance.FlamePreparer) File(java.io.File) DancingFlame(org.jwildfire.create.tina.dance.DancingFlame) Flame(org.jwildfire.create.tina.base.Flame)

Example 10 with FlameWriter

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

Aggregations

FlameWriter (org.jwildfire.create.tina.io.FlameWriter)25 Flame (org.jwildfire.create.tina.base.Flame)15 File (java.io.File)11 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)9 JFileChooser (javax.swing.JFileChooser)8 XForm (org.jwildfire.create.tina.base.XForm)6 Clipboard (java.awt.datatransfer.Clipboard)5 StringSelection (java.awt.datatransfer.StringSelection)5 ArrayList (java.util.ArrayList)5 Layer (org.jwildfire.create.tina.base.Layer)5 FACLFlameWriter (org.jwildfire.create.tina.faclrender.FACLFlameWriter)3 ImageWriter (org.jwildfire.io.ImageWriter)3 Test (org.junit.Test)2 QualityProfile (org.jwildfire.base.QualityProfile)2 ResolutionProfile (org.jwildfire.base.ResolutionProfile)2 HeadlessBatchRendererController (org.jwildfire.create.tina.batch.HeadlessBatchRendererController)2 Job (org.jwildfire.create.tina.batch.Job)2 JobRenderThread (org.jwildfire.create.tina.batch.JobRenderThread)2 JobRenderThreadController (org.jwildfire.create.tina.batch.JobRenderThreadController)2 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)2