use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class RenderMainFlameThread method run.
@Override
public void run() {
finished = forceAbort = false;
try {
int width = resProfile.getWidth();
int height = resProfile.getHeight();
RenderInfo info = new RenderInfo(width, height, RenderMode.PRODUCTION);
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());
boolean renderHDR = qualProfile.isWithHDR();
info.setRenderHDR(renderHDR);
boolean renderZBuffer = qualProfile.isWithZBuffer();
info.setRenderZBuffer(renderZBuffer);
flame.setSampleDensity(qualProfile.getQuality());
long t0, t1;
renderer = new FlameRenderer(flame, prefs, flame.isBGTransparency(), false);
renderer.setProgressUpdater(progressUpdater);
t0 = Calendar.getInstance().getTimeInMillis();
RenderedFlame res = renderer.renderFlame(info);
if (forceAbort) {
finished = true;
return;
}
t1 = Calendar.getInstance().getTimeInMillis();
new ImageWriter().saveImage(res.getImage(), outFile.getAbsolutePath());
if (res.getHDRImage() != null) {
new ImageWriter().saveImage(res.getHDRImage(), Tools.makeHDRFilename(outFile.getAbsolutePath()));
}
if (res.getZBuffer() != null) {
new ImageWriter().saveImage(res.getZBuffer(), Tools.makeZBufferFilename(outFile.getAbsolutePath()));
}
if (prefs.isTinaSaveFlamesWhenImageIsSaved()) {
new FlameWriter().writeFlame(flame, outFile.getParentFile().getAbsolutePath() + File.separator + Tools.trimFileExt(outFile.getName()) + ".flame");
}
finished = true;
finishEvent.succeeded((t1 - t0) * 0.001);
} catch (Throwable ex) {
finished = true;
finishEvent.failed(ex);
}
}
use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class FlameRenderer method renderSlices.
public void renderSlices(SliceRenderInfo pSliceRenderInfo, String pFilenamePattern) {
if (!flame.isRenderable())
throw new RuntimeException("Slices can not be created of empty flames");
int fileIdx = 1;
int passes = pSliceRenderInfo.getSlices() / pSliceRenderInfo.getSlicesPerRender();
if (pSliceRenderInfo.getSlices() % pSliceRenderInfo.getSlicesPerRender() != 0)
passes++;
progressDisplayPhaseCount = passes;
double zmin = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmin() : pSliceRenderInfo.getZmax();
double zmax = pSliceRenderInfo.getZmin() < pSliceRenderInfo.getZmax() ? pSliceRenderInfo.getZmax() : pSliceRenderInfo.getZmin();
double thickness = (zmax - zmin) / (double) pSliceRenderInfo.getSlices();
double currZ = zmax;
int currSlice = 0;
for (int pass = 0; pass < passes; pass++) {
if (forceAbort) {
break;
}
System.gc();
progressDisplayPhase = pass;
Flame currFlame = flame.makeCopy();
prepareFlameForSliceRendering(currFlame);
initRasterSizes(pSliceRenderInfo.getImageWidth(), pSliceRenderInfo.getImageHeight());
List<RenderSlice> slices = new ArrayList<RenderSlice>();
for (int i = 0; i < pSliceRenderInfo.getSlicesPerRender() && currSlice < pSliceRenderInfo.getSlices(); i++) {
RenderSlice slice = new RenderSlice(allocRaster(flame.getSpatialOversampling(), flame.getSampleDensity()), currZ - thickness, currZ);
slices.add(slice);
currZ -= thickness;
currSlice++;
}
List<List<RenderPacket>> renderFlames = new ArrayList<List<RenderPacket>>();
for (int t = 0; t < prefs.getTinaRenderThreads(); t++) {
renderFlames.add(createRenderPackets(flame, flame.getFrame()));
}
iterate(0, 1, renderFlames, slices);
if (!forceAbort) {
LogDensityPoint logDensityPnt = new LogDensityPoint(flame.getActiveLightCount());
while (slices.size() > 0) {
if (forceAbort) {
break;
}
RenderSlice slice = slices.get(0);
RenderedFlame renderedFlame = new RenderedFlame();
renderedFlame.init(pSliceRenderInfo.createRenderInfo(), flame);
SimpleImage img = renderedFlame.getImage();
logDensityFilter.setRaster(slice.getRaster(), rasterWidth, rasterHeight, img.getImageWidth(), img.getImageHeight());
GammaCorrectedRGBPoint rbgPoint = new GammaCorrectedRGBPoint();
for (int i = 0; i < img.getImageHeight(); i++) {
for (int j = 0; j < img.getImageWidth(); j++) {
logDensityFilter.transformPoint(logDensityPnt, j, i);
gammaCorrectionFilter.transformPoint(logDensityPnt, rbgPoint, j, i);
img.setARGB(j, i, rbgPoint.alpha, rbgPoint.red, rbgPoint.green, rbgPoint.blue);
}
}
String filename = String.format(pFilenamePattern, fileIdx++);
try {
new ImageWriter().saveImage(renderedFlame.getImage(), filename);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
slice = null;
slices.remove(0);
}
}
}
}
use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class MainController method saveImage.
public void saveImage() throws Exception {
Buffer buffer = getActiveBuffer();
if (buffer != null) {
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(windowMenu) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
prefs.setLastOutputImageFile(file);
if (buffer.getBufferType() == BufferType.IMAGE) {
new ImageWriter().saveImage(buffer.getImage(), file.getAbsolutePath());
} else if (buffer.getBufferType() == BufferType.HDR_IMAGE) {
new ImageWriter().saveImage(buffer.getHDRImage(), file.getAbsolutePath());
} else if (buffer.getBufferType() == BufferType.MESH3D) {
new SunFlowWriter().saveMesh(buffer.getMesh3D(), file.getAbsolutePath());
} else {
showMessage("Not supported");
return;
}
}
}
}
use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class ScriptProcessor method saveLastImage.
public void saveLastImage(String pFilename) throws Exception {
SimpleImage img = getLastImage();
if (img == null)
throw new IllegalStateException();
new ImageWriter().saveAsJPEG(img, pFilename);
}
use of org.jwildfire.io.ImageWriter in project JWildfire by thargor6.
the class RasterTools method saveZBufImg.
public static void saveZBufImg(float[][] zbuf, String filename) {
double zmin = 0.0, zmax = 0.0;
for (int i = 0; i < zbuf.length; i++) {
for (int j = 0; j < zbuf[0].length; j++) {
if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
zmin = zmax = zbuf[i][j];
break;
}
}
}
for (int i = 0; i < zbuf.length; i++) {
for (int j = 0; j < zbuf[0].length; j++) {
if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
if (zbuf[i][j] < zmin)
zmin = zbuf[i][j];
else if (zbuf[i][j] > zmax)
zmax = zbuf[i][j];
}
}
}
double dz = zmax - zmin;
SimpleImage img = new SimpleImage(zbuf.length, zbuf[0].length);
for (int i = 0; i < zbuf.length; i++) {
for (int j = 0; j < zbuf[0].length; j++) {
if (zbuf[i][j] != NormalsCalculator.ZBUF_ZMIN) {
int a = Tools.roundColor((zbuf[i][j] - zmin) / dz * 255.0);
img.setARGB(i, j, 255, a, a, a);
} else {
img.setARGB(i, j, 255, 0, 0, 0);
}
}
}
try {
new ImageWriter().saveAsPNG(img, filename);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations