use of org.jwildfire.create.tina.io.FlameReader 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();
}
}
use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.
the class FlameBrowserController method toMeshGenBtn_clicked.
public void toMeshGenBtn_clicked() {
try {
FlameFlatNode node = getSelectedFlame();
if (node != null) {
List<Flame> flames = new FlameReader(prefs).readFlames(node.getFilename());
if (flames.size() > 0) {
tinaController.getMeshGenController().importFlame(flames.get(0));
tinaController.getDesktop().showInternalFrame(MeshGenInternalFrame.class);
}
}
} catch (Exception ex) {
errorHandler.handleError(ex);
}
}
use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.
the class FlameFilePreview method createThumbnail.
public void createThumbnail() {
if (currFile == null) {
currThumbnail = null;
return;
}
try {
if (currFile.exists()) {
int imgWidth = this.getPreferredSize().width;
int imgHeight = this.getPreferredSize().height - BUTTON_HEIGHT;
int quality = 50;
SimpleImage preview;
String filename = currFile.getAbsolutePath();
ThumbnailCacheKey cacheKey = new ThumbnailCacheKey(filename);
preview = ThumbnailCacheProvider.getThumbnail(cacheKey, imgWidth, imgHeight, quality);
if (preview == null) {
List<Flame> flames = new FlameReader(prefs).readFlames(filename);
Flame flame = flames.get(0);
double wScl = (double) imgWidth / (double) flame.getWidth();
double hScl = (double) imgHeight / (double) flame.getHeight();
flame.setPixelsPerUnit((wScl + hScl) * 0.5 * flame.getPixelsPerUnit());
flame.setWidth(imgWidth);
flame.setHeight(imgHeight);
FlameRenderer renderer = new FlameRenderer(flame, prefs, false, true);
renderer.setProgressUpdater(null);
flame.setSampleDensity(quality);
flame.setSpatialFilterRadius(0.0);
RenderInfo info = new RenderInfo(imgWidth, imgHeight, RenderMode.PREVIEW);
RenderedFlame res = renderer.renderFlame(info);
preview = res.getImage();
ThumbnailCacheProvider.storeThumbnail(cacheKey, imgWidth, imgHeight, quality, preview);
}
currThumbnail = new ImageIcon(preview.getBufferedImg());
}
} catch (Exception ex) {
currThumbnail = null;
if (ex.getCause() != null) {
ex.getCause().printStackTrace();
} else {
ex.printStackTrace();
}
}
}
use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.
the class FlamesGPURenderController method fromClipboardButton_clicked.
public void fromClipboardButton_clicked() {
Flame newFlame = null;
try {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable clipData = clipboard.getContents(clipboard);
if (clipData != null) {
if (clipData.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String xml = (String) (clipData.getTransferData(DataFlavor.stringFlavor));
List<Flame> flames = new FlameReader(prefs).readFlamesfromXML(xml);
if (flames.size() > 0) {
newFlame = flames.get(0);
}
}
}
if (newFlame == null) {
throw new Exception("There is currently no valid flame in the clipboard");
} else {
currFlame = newFlame;
enableControls();
setupProfiles(currFlame);
renderFlame();
enableControls();
}
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
}
use of org.jwildfire.create.tina.io.FlameReader in project JWildfire by thargor6.
the class FlamesGPURenderController method loadFlameButton_clicked.
public void loadFlameButton_clicked() {
try {
JFileChooser chooser = new FlameFileChooser(prefs);
if (prefs.getInputFlamePath() != null) {
try {
chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (chooser.showOpenDialog(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
List<Flame> flames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
Flame newFlame = flames.get(0);
prefs.setLastInputFlameFile(file);
importFlame(newFlame);
}
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
}
Aggregations