use of org.jwildfire.create.tina.render.RenderInfo in project JWildfire by thargor6.
the class RandomFlameGeneratorSampler method createSample.
public RandomFlameGeneratorSample createSample() {
RenderInfo info = new RenderInfo(imageWidth, imageHeight, RenderMode.PREVIEW);
Flame bestFlame = null;
int bgRed = prefs.getTinaRandomBatchBGColorRed();
int bgGreen = prefs.getTinaRandomBatchBGColorGreen();
int bgBlue = prefs.getTinaRandomBatchBGColorBlue();
RandomFlameGeneratorState randGenState = randGen.initState(prefs, randGradientGen);
double bestCoverage = 0.0;
for (int j = 0; j < quality.getMaxSamples(); j++) {
// create flame
Flame flame;
try {
flame = randGen.createFlame(prefs, randGenState);
if (randGen.supportsSymmetry()) {
randSymmGen.addSymmetry(flame);
}
} catch (Exception ex) {
flame = new Flame();
ex.printStackTrace();
}
flame.setWidth(imageWidth);
flame.setHeight(imageHeight);
flame.setPixelsPerUnit(10);
for (Layer layer : flame.getLayers()) {
RGBPalette palette = randGradientGen.generatePalette(paletteSize, fadePaletteColors, uniformWidth);
layer.setPalette(palette);
}
flame = randGen.postProcessFlameBeforeRendering(randGenState, flame);
// render it
flame.setSampleDensity(25);
RenderedFlame renderedFlame;
flame.applyFastOversamplingSettings();
try {
FlameRenderer renderer = new FlameRenderer(flame, prefs, false, true);
renderedFlame = renderer.renderFlame(info);
flame = randGen.postProcessFlameAfterRendering(randGenState, flame);
if (j == quality.getMaxSamples() - 1) {
renderedFlame = new FlameRenderer(bestFlame, prefs, false, true).renderFlame(info);
return new RandomFlameGeneratorSample(bestFlame, renderedFlame.getImage());
} else {
double fCoverage = calculateCoverage(renderedFlame.getImage(), bgRed, bgGreen, bgBlue, randGen.isUseFilter(randGenState));
if (fCoverage >= quality.getCoverage() && fCoverage < randGen.getMaxCoverage()) {
return new RandomFlameGeneratorSample(flame, renderedFlame.getImage());
} else {
if (bestFlame == null || fCoverage > bestCoverage) {
bestFlame = flame;
bestCoverage = fCoverage;
}
}
}
} finally {
flame.applyDefaultOversamplingSettings();
}
}
throw new IllegalStateException();
}
use of org.jwildfire.create.tina.render.RenderInfo in project JWildfire by thargor6.
the class AnimationService method renderFrame.
public static SimpleImage renderFrame(Flame flame, int pWidth, int pHeight, Prefs pPrefs) throws Exception {
RenderInfo info = new RenderInfo(pWidth, pHeight, 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());
FlameRenderer renderer = new FlameRenderer(flame, pPrefs, flame.isBGTransparency(), false);
RenderedFlame res = renderer.renderFlame(info);
return res.getImage();
}
use of org.jwildfire.create.tina.render.RenderInfo in project JWildfire by thargor6.
the class SWFAnimationRenderThread method renderFlame.
private SimpleImage renderFlame(Flame pFlame) {
RenderInfo info = new RenderInfo(flameMovie.getFrameWidth(), flameMovie.getFrameHeight(), RenderMode.PRODUCTION);
double wScl = (double) info.getImageWidth() / (double) pFlame.getWidth();
double hScl = (double) info.getImageHeight() / (double) pFlame.getHeight();
pFlame.setPixelsPerUnit((wScl + hScl) * 0.5 * pFlame.getPixelsPerUnit());
pFlame.setWidth(info.getImageWidth());
pFlame.setHeight(info.getImageHeight());
FlameRenderer renderer = new FlameRenderer(pFlame, Prefs.getPrefs(), pFlame.isBGTransparency(), false);
renderer.setProgressUpdater(null);
pFlame.setSampleDensity(flameMovie.getQuality());
RenderedFlame res = renderer.renderFlame(info);
return res.getImage();
}
use of org.jwildfire.create.tina.render.RenderInfo 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.render.RenderInfo in project JWildfire by thargor6.
the class BatchRendererController method renderBatchJobsTableClicked.
public void renderBatchJobsTableClicked() {
FlamePanel imgPanel = getBatchPreviewFlamePanel();
Rectangle bounds = imgPanel.getImageBounds();
int width = bounds.width;
int height = bounds.height;
Flame flame = getBatchRenderPreviewFlameHolder().getFlame();
if (width >= 16 && height >= 16) {
RenderInfo info = new RenderInfo(width, height, RenderMode.PREVIEW);
if (flame != null) {
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());
FlameRenderer renderer = new FlameRenderer(flame, prefs, data.toggleTransparencyButton.isSelected(), false);
flame.setSampleDensity(prefs.getTinaRenderRealtimeQuality());
flame.setSpatialFilterRadius(0.0);
RenderedFlame res = renderer.renderFlame(info);
imgPanel.setImage(res.getImage());
} else {
imgPanel.setImage(new SimpleImage(width, height));
}
}
data.batchPreviewRootPanel.invalidate();
data.batchPreviewRootPanel.validate();
}
Aggregations