use of org.jwildfire.create.tina.render.AbstractRenderThread in project JWildfire by thargor6.
the class DetachedPreviewController method cancelRender.
public void cancelRender() {
if (refreshing || threads == null)
return;
if (state == State.PAUSE) {
togglePause();
}
if (updateDisplayThread != null) {
updateDisplayThread.cancel();
}
try {
for (Thread thread : threads.getExecutingThreads()) {
try {
thread.setPriority(Thread.NORM_PRIORITY);
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (updateDisplayExecuteThread != null) {
updateDisplayExecuteThread.setPriority(Thread.NORM_PRIORITY);
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (state == State.RENDER) {
while (true) {
boolean done = true;
for (AbstractRenderThread thread : threads.getRenderThreads()) {
if (!thread.isFinished()) {
done = false;
thread.cancel();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (done) {
break;
}
}
threads = null;
if (updateDisplayThread != null) {
updateDisplayThread.cancel();
while (!updateDisplayThread.isFinished()) {
try {
updateDisplayThread.cancel();
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
updateDisplayThread = null;
}
state = State.IDLE;
}
}
use of org.jwildfire.create.tina.render.AbstractRenderThread in project JWildfire by thargor6.
the class TinaInteractiveRendererController method cancelRender.
private void cancelRender() {
if (state == State.RENDER) {
if (updateDisplayThread != null) {
updateDisplayThread.cancel();
}
while (true) {
boolean done = true;
for (AbstractRenderThread thread : threads.getRenderThreads()) {
if (!thread.isFinished()) {
done = false;
thread.cancel();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (done) {
break;
}
}
if (updateDisplayThread != null) {
while (!updateDisplayThread.isFinished()) {
try {
updateDisplayThread.cancel();
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
updateDisplayThread = null;
}
state = State.IDLE;
}
}
use of org.jwildfire.create.tina.render.AbstractRenderThread in project JWildfire by thargor6.
the class TinaInteractiveRendererController method resumeBtn_clicked.
public void resumeBtn_clicked() {
try {
JFileChooser chooser = new JWFRenderFileChooser(prefs);
if (prefs.getInputFlamePath() != null) {
try {
chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (chooser.showOpenDialog(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
cancelRender();
File file = chooser.getSelectedFile();
Flame newFlame = new Flame();
FlameRenderer newRenderer = new FlameRenderer(newFlame, prefs, newFlame.isBGTransparency(), false);
ResumedFlameRender resumedRender = newRenderer.resumeRenderFlame(file.getAbsolutePath());
threads = new RenderThreads(resumedRender.getThreads(), new ArrayList<Thread>());
Flame flame = currFlame = newRenderer.getFlame();
// setup size profile
{
int width = newRenderer.getRenderInfo().getImageWidth();
int height = newRenderer.getRenderInfo().getImageHeight();
ResolutionProfile selected = null;
boolean full = false;
boolean halve = false;
boolean quarter = false;
for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
if (profile.getWidth() == width && profile.getHeight() == height) {
selected = profile;
full = true;
break;
}
}
if (selected == null) {
for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
if (profile.getWidth() / 2 == width && profile.getHeight() / 2 == height) {
selected = profile;
halve = true;
break;
}
}
}
if (selected == null) {
for (int i = 0; i < interactiveResolutionProfileCmb.getItemCount(); i++) {
ResolutionProfile profile = (ResolutionProfile) interactiveResolutionProfileCmb.getItemAt(i);
if (profile.getWidth() / 4 == width && profile.getHeight() / 4 == height) {
selected = profile;
quarter = true;
break;
}
}
}
if (selected == null) {
selected = new ResolutionProfile(false, width, height);
full = true;
interactiveResolutionProfileCmb.addItem(selected);
}
boolean wasQuarterSelected = quarterSizeButton.isSelected();
boolean wasHalveSelected = halveSizeButton.isSelected();
boolean wasFullSelected = fullSizeButton.isSelected();
refreshing = true;
try {
quarterSizeButton.setSelected(quarter);
halveSizeButton.setSelected(halve);
fullSizeButton.setSelected(full);
} finally {
refreshing = false;
}
ResolutionProfile currSel = (ResolutionProfile) interactiveResolutionProfileCmb.getSelectedItem();
if (currSel == null || !currSel.equals(selected) || wasQuarterSelected != quarter || wasHalveSelected != halve || wasFullSelected != full) {
interactiveResolutionProfileCmb.setSelectedItem(selected);
refreshImagePanel();
} else {
clearScreen();
}
}
//
renderer = newRenderer;
setupProfiles(currFlame);
if (flame.getBgColorRed() > 0 || flame.getBgColorGreen() > 0 || flame.getBgColorBlue() > 0) {
image.fillBackground(flame.getBgColorRed(), flame.getBgColorGreen(), flame.getBgColorBlue());
}
renderer.registerIterationObserver(this);
displayUpdater = createDisplayUpdater();
displayUpdater.initRender(threads.getRenderThreads().size());
pausedRenderTime = resumedRender.getHeader().getElapsedMilliseconds();
renderStartTime = System.currentTimeMillis();
lastQuality = 0.0;
lastQualitySpeed = 0.0;
lastQualityTime = 0;
for (int i = 0; i < threads.getRenderThreads().size(); i++) {
AbstractRenderThread rThread = threads.getRenderThreads().get(i);
Thread eThread = startRenderThread(rThread);
threads.getExecutingThreads().add(eThread);
}
updateDisplayThread = new UpdateDisplayThread();
startDisplayThread(updateDisplayThread);
state = State.RENDER;
enableControls();
}
} catch (Throwable ex) {
errorHandler.handleError(ex);
}
}
use of org.jwildfire.create.tina.render.AbstractRenderThread in project JWildfire by thargor6.
the class JWildfireApplet method cancelRender.
private void cancelRender() {
if (state == State.RENDER) {
while (true) {
boolean done = true;
for (AbstractRenderThread thread : threads.getRenderThreads()) {
if (!thread.isFinished()) {
done = false;
thread.cancel();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
break;
}
}
if (done) {
break;
}
}
state = State.IDLE;
}
}
use of org.jwildfire.create.tina.render.AbstractRenderThread in project JWildfire by thargor6.
the class FlamePreviewHelper method cancelBackgroundRender.
public void cancelBackgroundRender() {
if (threads == null)
return;
if (updateDisplayThread != null) {
updateDisplayThread.cancel();
}
try {
for (Thread thread : threads.getExecutingThreads()) {
try {
thread.setPriority(Thread.NORM_PRIORITY);
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (updateDisplayExecuteThread != null) {
updateDisplayExecuteThread.setPriority(Thread.MAX_PRIORITY);
}
} catch (Exception ex) {
ex.printStackTrace();
}
while (true) {
boolean done = true;
for (AbstractRenderThread thread : threads.getRenderThreads()) {
if (!thread.isFinished()) {
done = false;
thread.cancel();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if (done) {
break;
}
}
threads = null;
if (updateDisplayThread != null) {
updateDisplayThread.cancel();
while (!updateDisplayThread.isFinished()) {
try {
updateDisplayThread.cancel();
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
updateDisplayThread = null;
}
}
Aggregations