use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class SWFAnimationRenderThread method saveImage.
private void saveImage(SimpleImage pImage, int pFrame) throws Exception {
String filename = generateFilename(pFrame, Tools.FILEEXT_PNG);
new ImageWriter().saveAsPNG(pImage, filename);
}
use of org.jwildfire.io.ImageWriter 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.io.ImageWriter in project JWildfire by thargor6.
the class RasterTools method saveFloatBuffer.
public static void saveFloatBuffer(float[][] buf, String filename) {
double min, max;
min = max = buf[0][0];
for (int i = 0; i < buf.length; i++) {
for (int j = 0; j < buf[0].length; j++) {
if (inRange(buf[i][j])) {
min = max = buf[i][j];
break;
}
}
}
for (int i = 0; i < buf.length; i++) {
for (int j = 0; j < buf[0].length; j++) {
if (inRange(buf[i][j])) {
if (buf[i][j] < min)
min = buf[i][j];
else if (buf[i][j] > max && !Double.isInfinite(buf[i][j]))
max = buf[i][j];
}
}
}
double d = max - min;
System.out.println("Saving float buffer \"" + new File(filename).getName() + "\", min = " + min + ", max = " + max);
SimpleImage img = new SimpleImage(buf.length, buf[0].length);
for (int i = 0; i < buf.length; i++) {
for (int j = 0; j < buf[0].length; j++) {
int a = Tools.roundColor((buf[i][j] - min) / d * 255.0);
img.setARGB(i, j, 255, a, a, a);
}
}
try {
new ImageWriter().saveAsPNG(img, filename);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.jwildfire.io.ImageWriter 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);
}
}
use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class TinaInteractiveRendererController method saveZBufferButton_clicked.
public void saveZBufferButton_clicked() {
try {
pauseRenderThreads();
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();
double zBufferScale = Double.parseDouble(JOptionPane.showInputDialog(imageRootPanel, "Enter ZBuffer-Scale", currFlame.getZBufferScale()));
currFlame.setZBufferScale(zBufferScale);
RenderedFlame res = renderer.finishZBuffer(displayUpdater.getSampleCount());
if (res.getZBuffer() != null) {
new ImageWriter().saveImage(res.getZBuffer(), file.getAbsolutePath());
if (autoLoadImageCBx.isSelected()) {
parentCtrl.mainController.loadImage(file.getAbsolutePath(), false);
}
}
}
} finally {
resumeRenderThreads();
}
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
}
Aggregations