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();
}
}
}
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);
}
}
}
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;
}
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();
}
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();
}
Aggregations