use of org.jwildfire.script.ActionList in project JWildfire by thargor6.
the class RenderThread method run.
@Override
public void run() {
done = false;
try {
forceAbort = false;
error = null;
try {
for (int frame = frameMin; frame <= frameMax; frame++) {
if (forceAbort)
break;
ActionList actions = actionList.clone();
// generate Filename
String frameStr = String.valueOf(frame);
while (frameStr.length() < 4) frameStr = "0" + frameStr;
String filename = basePath + frameStr + ".jpg";
// calculate parameters
for (Action action : actions) {
if (action.hasEnvelopes()) {
for (Parameter parameter : action.getParameterList()) {
Envelope envelope = parameter.getEnvelope();
if (envelope != null) {
double val = envelope.evaluate(frame);
parameter.setValue(Tools.doubleToString(val));
}
}
}
}
// render the image
ScriptProcessor scriptProcessor = new ScriptProcessor(desktop);
scriptProcessor.setAddBuffersToDesktop(false);
// dummy image just to call the init-method of transformers (which makes sense if script lack some parameters)
SimpleImage paramInitImg = null;
for (Action action : actions) {
switch(action.getActionType()) {
case EXECUTE_CREATOR:
scriptProcessor.selectCreator(action.getParameter());
action.setProperties(scriptProcessor.getCreator(), scriptProcessor.getBufferList());
scriptProcessor.executeCreator(action.getWidth(), action.getHeight(), action.getOutputBuffer(), false);
break;
case EXECUTE_LOADER:
scriptProcessor.selectLoader(action.getParameter());
action.setProperties(scriptProcessor.getLoader(), scriptProcessor.getBufferList());
scriptProcessor.executeLoader(action.getOutputBuffer(), false);
break;
case EXECUTE_TRANSFORMER:
scriptProcessor.selectTransformer(action.getParameter());
if (paramInitImg == null)
paramInitImg = new SimpleImage(320, 256);
scriptProcessor.getTransformer().initDefaultParams(paramInitImg);
action.setProperties(scriptProcessor.getTransformer(), scriptProcessor.getBufferList());
scriptProcessor.executeTransformer(action.getInputBuffer(), action.getOutputBuffer3D() != null, action.getOutputBuffer(), action.getOutputBuffer3D(), false);
break;
case LOAD_IMAGE:
scriptProcessor.loadImage(action.getParameter());
break;
}
}
// Save file
SimpleImage img = scriptProcessor.getLastImage();
switch(mode) {
case BATCH:
scriptProcessor.saveLastImage(filename);
reporter.showProgress(frame, new File(filename).getName(), img);
break;
case SINGLE_FRAME:
lastImage = img;
break;
}
}
} catch (Exception ex) {
error = ex;
}
} finally {
done = true;
reporter.renderingFinished();
}
}
Aggregations