Search in sources :

Example 16 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class MapFilePreview method createThumbnail.

public void createThumbnail() {
    if (currFile == null) {
        currThumbnail = null;
        return;
    }
    try {
        if (currFile.exists()) {
            List<RGBPalette> gradients = new MapGradientReader().readPalettes(currFile.getAbsolutePath());
            int imgWidth = this.getPreferredSize().width;
            int imgHeight = this.getPreferredSize().height - BUTTON_HEIGHT;
            SimpleImage img = new RGBPaletteRenderer().renderHorizPalette(gradients.get(0), imgWidth, imgHeight);
            currThumbnail = new ImageIcon(img.getBufferedImg());
        }
    } catch (Exception ex) {
        currThumbnail = null;
        if (ex.getCause() != null) {
            ex.getCause().printStackTrace();
        } else {
            ex.printStackTrace();
        }
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) MapGradientReader(org.jwildfire.create.tina.io.MapGradientReader) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) RGBPaletteRenderer(org.jwildfire.create.tina.palette.RGBPaletteRenderer)

Example 17 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class MeshGenController method generateButton_clicked.

public void generateButton_clicked() {
    if (renderSlicesThread != null) {
        renderSlicesThread.setForceAbort();
        while (renderSlicesThread.isFinished()) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        renderSlicesThread = null;
        enableControls();
    } else if (currBaseFlame != null) {
        try {
            JFileChooser chooser;
            if (isPointCloudMode()) {
                chooser = new PointCloudOutputFileChooser(Tools.FILEEXT_PLY);
                if (prefs.getTinaMeshPath() != null) {
                    try {
                        chooser.setCurrentDirectory(new File(prefs.getTinaMeshPath()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            } else {
                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(rootPanel) == JFileChooser.APPROVE_OPTION) {
                final File file = chooser.getSelectedFile();
                prefs.setLastOutputImageFile(file);
                MeshGenGenerateThreadFinishEvent finishEvent = new MeshGenGenerateThreadFinishEvent() {

                    @Override
                    public void succeeded(double pElapsedTime) {
                        try {
                            tinaController.getMessageHelper().showStatusMessage(currBaseFlame, "render time: " + Tools.doubleToString(pElapsedTime) + "s");
                        } catch (Throwable ex) {
                            errorHandler.handleError(ex);
                        }
                        renderSlicesThread = null;
                        enableControls();
                    }

                    @Override
                    public void failed(Throwable exception) {
                        errorHandler.handleError(exception);
                        renderSlicesThread = null;
                        enableControls();
                    }
                };
                Flame flame = currBaseFlame.makeCopy();
                switch(getOutputType()) {
                    case VOXELSTACK:
                        {
                            String outfilenamePattern = SequenceFilenameGen.createFilenamePattern(file);
                            Flame grayFlame = flame.makeCopy();
                            RGBPalette gradient = new RGBPalette();
                            for (int i = 0; i < RGBPalette.PALETTE_SIZE; i++) {
                                gradient.setColor(i, 225, 225, 225);
                            }
                            grayFlame.getFirstLayer().setPalette(gradient);
                            renderSlicesThread = new RenderSlicesThread(prefs, grayFlame, outfilenamePattern, finishEvent, renderSequenceProgressUpdater, renderWidthREd.getIntValue(), renderHeightREd.getIntValue(), sliceCountREd.getIntValue(), slicesPerRenderREd.getIntValue(), renderQualityREd.getIntValue(), zminREd.getDoubleValue(), zmaxREd.getDoubleValue());
                            lastRenderedSequenceOutFilePattern = outfilenamePattern;
                            break;
                        }
                    case POINTCLOUD:
                        {
                            renderSlicesThread = new RenderPointCloudThread(prefs, flame, file.getAbsolutePath(), finishEvent, renderSequenceProgressUpdater, renderWidthREd.getIntValue(), renderHeightREd.getIntValue(), renderQualityREd.getIntValue(), zminREd.getDoubleValue(), zmaxREd.getDoubleValue(), meshGenCellSizeREd.getDoubleValue());
                            break;
                        }
                }
                enableControls();
                new Thread(renderSlicesThread).start();
            }
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) RenderSlicesThread(org.jwildfire.create.tina.meshgen.render.RenderSlicesThread) RenderPointCloudThread(org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread) MeshGenRenderThread(org.jwildfire.create.tina.meshgen.render.MeshGenRenderThread) RenderSlicesThread(org.jwildfire.create.tina.meshgen.render.RenderSlicesThread) RenderPointCloudThread(org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread) JFileChooser(javax.swing.JFileChooser) PointCloudOutputFileChooser(org.jwildfire.swing.PointCloudOutputFileChooser) File(java.io.File) Flame(org.jwildfire.create.tina.base.Flame) RenderedFlame(org.jwildfire.create.tina.render.RenderedFlame)

Example 18 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class ImgPaletteReader method readPaletteFromMapData.

public List<RGBPalette> readPaletteFromMapData(String pMapData, String pFilename) throws Exception {
    List<RGBPalette> res = new ArrayList<RGBPalette>();
    RGBPalette gradient = new RGBPalette();
    res.add(gradient);
    gradient.setFlam3Name(new File(pFilename).getName());
    SimpleImage img = new ImageReader().loadImage(pFilename);
    if (img.getImageWidth() > 0 && img.getImageHeight() > 0) {
        Map<Integer, RGBColor> colors = new HashMap<Integer, RGBColor>();
        Pixel rgbPixel = new Pixel();
        for (int i = 0; i < img.getImageWidth(); i++) {
            rgbPixel.setARGBValue(img.getARGBValue(i, 0));
            RGBColor color = new RGBColor(rgbPixel.r, rgbPixel.g, rgbPixel.b);
            colors.put(i, color);
        }
        gradient.setColors(colors, false, false);
    }
    return res;
}
Also used : HashMap(java.util.HashMap) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) SimpleImage(org.jwildfire.image.SimpleImage) ArrayList(java.util.ArrayList) RGBColor(org.jwildfire.create.tina.palette.RGBColor) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) Pixel(org.jwildfire.image.Pixel)

Example 19 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class JWFFlameWriter method getFlameXML.

public String getFlameXML(Flame pFlame) throws Exception {
    SimpleXMLBuilder xb = new SimpleXMLBuilder();
    // Flame
    List<SimpleXMLBuilder.Attribute<?>> attrList = createFlameAttributes(pFlame, xb);
    xb.beginElement("jwf-flame", attrList);
    for (Layer layer : pFlame.getLayers()) {
        List<SimpleXMLBuilder.Attribute<?>> layerAttrList = new ArrayList<SimpleXMLBuilder.Attribute<?>>();
        layerAttrList.add(xb.createAttr("weight", layer.getWeight()));
        layerAttrList.add(xb.createAttr("visible", layer.isVisible() ? 1 : 0));
        {
            String name = layer.getName().replaceAll("\"", "");
            if (!name.equals("")) {
                layerAttrList.add(xb.createAttr("name", name));
            }
        }
        {
            String gradientMapFilename = layer.getGradientMapFilename().replaceAll("\"", "");
            if (!gradientMapFilename.equals("")) {
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP, gradientMapFilename));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_HOFFSET, layer.getGradientMapHorizOffset()));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_HSCALE, layer.getGradientMapHorizScale()));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_VOFFSET, layer.getGradientMapVertOffset()));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_VSCALE, layer.getGradientMapVertScale()));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_LCOLOR_ADD, layer.getGradientMapLocalColorAdd()));
                layerAttrList.add(xb.createAttr(ATTR_GRADIENT_MAP_LCOLOR_SCALE, layer.getGradientMapLocalColorScale()));
            }
        }
        layerAttrList.add(xb.createAttr(ATTR_SMOOTH_GRADIENT, layer.isSmoothGradient() ? "1" : "0"));
        List<String> blackList = Collections.emptyList();
        writeMotionCurves(layer, xb, layerAttrList, null, blackList);
        RGBPalette palette = layer.getPalette();
        writeMotionCurves(palette, xb, layerAttrList, "palette_", Collections.<String>emptyList());
        xb.beginElement("layer", layerAttrList);
        // XForm
        for (XForm xForm : layer.getXForms()) {
            xb.emptyElement("xform", createXFormAttrList(xb, layer, xForm));
        }
        // FinalXForms
        for (XForm xForm : layer.getFinalXForms()) {
            xb.emptyElement("finalxform", createXFormAttrList(xb, layer, xForm));
        }
        // Palette
        {
            xb.beginElement("palette", xb.createAttr("count", palette.getSize()), xb.createAttr("format", "RGB"));
            StringBuilder rgb = new StringBuilder();
            for (int i = 0; i < palette.getSize(); i++) {
                String hs;
                hs = Integer.toHexString(palette.getColor(i).getRed()).toUpperCase();
                rgb.append(hs.length() > 1 ? hs : "0" + hs);
                hs = Integer.toHexString(palette.getColor(i).getGreen()).toUpperCase();
                rgb.append(hs.length() > 1 ? hs : "0" + hs);
                hs = Integer.toHexString(palette.getColor(i).getBlue()).toUpperCase();
                rgb.append(hs.length() > 1 ? hs : "0" + hs);
                if ((i + 1) % 12 == 0) {
                    rgb.append("\n");
                }
            }
            xb.addContent(rgb.toString());
            xb.endElement("palette");
        }
        xb.endElement("layer");
    }
    xb.endElement("jwf-flame");
    return xb.buildXML();
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ArrayList(java.util.ArrayList) Layer(org.jwildfire.create.tina.base.Layer)

Example 20 with RGBPalette

use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.

the class Boarders2Test method visual.

// @Ignore
@Test
public void visual() throws Exception {
    Prefs.getPrefs().setTinaRandomNumberGenerator(RandomGeneratorType.JAVA_INTERNAL);
    System.out.println(Prefs.getPrefs().getTinaRandomNumberGenerator().name());
    int side = 600;
    ResolutionProfile respro = new ResolutionProfile(true, side, side);
    int quality = 80;
    Flame f = new Flame();
    f.setWidth(side);
    f.setHeight(side);
    f.setGamma(4.0);
    f.setBGTransparency(false);
    f.setAntialiasAmount(1.0);
    f.setAntialiasRadius(.1);
    Layer l = new Layer();
    XForm xf = new XForm();
    Boarders2Func bf = new Boarders2Func();
    bf.setParameter("c", .6);
    bf.setParameter("left", .65);
    bf.setParameter("right", .35);
    xf.addVariation(1.0, bf);
    f.setCamZoom(6.461);
    xf.setWeight(5.5);
    l.getXForms().add(xf);
    RGBPalette pal = new RGBPalette();
    for (int i = 0; i < 256; i++) pal.addColor(0, i, 255);
    pal.setFlam3Name("test");
    l.setPalette(pal);
    f.setResolutionProfile(respro);
    f.getLayers().clear();
    f.getLayers().add(l);
    // this is "scale"
    f.setPixelsPerUnit(43.75);
    new FlameWriter().writeFlame(f, "/dev/shm/test.flame");
    JobRenderThreadController controller = new HeadlessBatchRendererController();
    List<Job> joblist = new ArrayList<>();
    Job j = new Job();
    j.setCustomHeight(side);
    j.setCustomWidth(side);
    j.setCustomQuality(quality);
    j.setFlameFilename("/dev/shm/test.flame");
    joblist.add(j);
    QualityProfile qualpro = new QualityProfile();
    qualpro.setQuality(quality);
    JobRenderThread job = new JobRenderThread(controller, joblist, respro, qualpro, true);
    job.run();
}
Also used : ResolutionProfile(org.jwildfire.base.ResolutionProfile) XForm(org.jwildfire.create.tina.base.XForm) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) HeadlessBatchRendererController(org.jwildfire.create.tina.batch.HeadlessBatchRendererController) ArrayList(java.util.ArrayList) Layer(org.jwildfire.create.tina.base.Layer) XYZPoint(org.jwildfire.create.tina.base.XYZPoint) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) JobRenderThread(org.jwildfire.create.tina.batch.JobRenderThread) QualityProfile(org.jwildfire.base.QualityProfile) Job(org.jwildfire.create.tina.batch.Job) JobRenderThreadController(org.jwildfire.create.tina.batch.JobRenderThreadController) Flame(org.jwildfire.create.tina.base.Flame) Test(org.junit.Test)

Aggregations

RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)29 ArrayList (java.util.ArrayList)12 Layer (org.jwildfire.create.tina.base.Layer)9 File (java.io.File)8 Flame (org.jwildfire.create.tina.base.Flame)8 RGBColor (org.jwildfire.create.tina.palette.RGBColor)5 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)5 SimpleImage (org.jwildfire.image.SimpleImage)5 Field (java.lang.reflect.Field)4 JFileChooser (javax.swing.JFileChooser)4 XForm (org.jwildfire.create.tina.base.XForm)4 ImageReader (org.jwildfire.io.ImageReader)4 List (java.util.List)3 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)3 HashMap (java.util.HashMap)2 JLabel (javax.swing.JLabel)2 Test (org.junit.Test)2 QualityProfile (org.jwildfire.base.QualityProfile)2 ResolutionProfile (org.jwildfire.base.ResolutionProfile)2 MotionCurve (org.jwildfire.create.tina.base.motion.MotionCurve)2