use of org.jwildfire.envelope.Envelope 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();
}
}
use of org.jwildfire.envelope.Envelope in project JWildfire by thargor6.
the class EnvelopeController method propertyCmbChanged.
public void propertyCmbChanged() {
String propName = (String) propertyCmb.getSelectedItem();
Parameter parameter = currAction.getParameterByName(propName);
Envelope envelope = (parameter != null) ? parameter.getEnvelope() : null;
setCurrEnvelope(envelope);
enableControls();
refreshEnvelope();
}
use of org.jwildfire.envelope.Envelope in project JWildfire by thargor6.
the class Action method saveToBuffer.
public void saveToBuffer(StringBuffer pBuffer, String pLineSeparator) {
// actiontype [parameter]
pBuffer.append(actionType);
if ((parameter != null) && (parameter.length() > 0)) {
pBuffer.append(" ");
pBuffer.append(parameter);
}
pBuffer.append(pLineSeparator);
// input <buffer>
if ((inputBuffer != null) && (inputBuffer.length() > 0)) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INPUT);
pBuffer.append(" ");
pBuffer.append(inputBuffer);
pBuffer.append(pLineSeparator);
}
// output <buffer>
if ((outputBuffer != null) && (outputBuffer.length() > 0)) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_OUTPUT);
pBuffer.append(" ");
pBuffer.append(outputBuffer);
pBuffer.append(pLineSeparator);
}
// outputHDR <buffer>
if ((outputHDRBuffer != null) && (outputHDRBuffer.length() > 0)) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_OUTPUT_HDR);
pBuffer.append(" ");
pBuffer.append(outputHDRBuffer);
pBuffer.append(pLineSeparator);
}
// output3d <buffer>
if ((outputBuffer3D != null) && (outputBuffer3D.length() > 0)) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_OUTPUT_3D);
pBuffer.append(" ");
pBuffer.append(outputBuffer3D);
pBuffer.append(pLineSeparator);
}
// dimension <width> <height>
if ((width > 0) || (height > 0)) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_DIMENSION);
pBuffer.append(" ");
pBuffer.append(width);
pBuffer.append(" ");
pBuffer.append(height);
pBuffer.append(pLineSeparator);
}
// param <paramname> <paramvalue>
for (Parameter param : parameterList) {
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_PARAM);
pBuffer.append(" ");
pBuffer.append(param.getName());
pBuffer.append(" ");
pBuffer.append(param.getValue());
pBuffer.append(pLineSeparator);
Envelope envelope = param.getEnvelope();
if (envelope != null) {
// envelope <paramname>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_ENVELOPE);
pBuffer.append(" ");
pBuffer.append(param.getName());
pBuffer.append(pLineSeparator);
// view <xmin> <xmax> <ymin> <ymax>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_VIEW);
pBuffer.append(" ");
pBuffer.append(Tools.doubleToString(envelope.getViewXMin()));
pBuffer.append(" ");
pBuffer.append(Tools.doubleToString(envelope.getViewXMax()));
pBuffer.append(" ");
pBuffer.append(Tools.doubleToString(envelope.getViewYMin()));
pBuffer.append(" ");
pBuffer.append(Tools.doubleToString(envelope.getViewYMax()));
pBuffer.append(pLineSeparator);
// points <x0> <y0> ... <xN> <yN>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_POINTS);
for (int p = 0; p < envelope.size(); p++) {
pBuffer.append(" ");
pBuffer.append(Tools.intToString(envelope.getX()[p]));
pBuffer.append(" ");
pBuffer.append(Tools.doubleToString(envelope.getY()[p]));
}
pBuffer.append(pLineSeparator);
// selected <selected>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_SELECTED);
pBuffer.append(" ");
pBuffer.append(Tools.intToString(envelope.getSelectedIdx()));
pBuffer.append(pLineSeparator);
// interpolation <interpolation>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INTERPOLATION);
pBuffer.append(" ");
pBuffer.append(envelope.getInterpolation().toString());
pBuffer.append(pLineSeparator);
// locked <locked>
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_INDENT);
pBuffer.append(TOKEN_LOCKED);
pBuffer.append(" ");
pBuffer.append(envelope.isLocked());
pBuffer.append(pLineSeparator);
}
}
//
pBuffer.append(pLineSeparator);
}
use of org.jwildfire.envelope.Envelope in project JWildfire by thargor6.
the class Action method readFromLines.
public static Action readFromLines(List<String> currLines) {
Action res = new Action();
// parse header and create appropriate action
{
String header = currLines.get(0);
Pattern pattern = Pattern.compile("([\\w_]+)(\\s+)(.+)");
Matcher matcher = pattern.matcher(header);
if (matcher.find()) {
String actionType = matcher.group(1);
String parameter = matcher.group(3);
res.setActionType(ActionType.valueOf(actionType));
res.setParameter(parameter);
} else
throw new IllegalArgumentException(header);
}
// parse and set params
{
final String intPattern = "([0-9\\+\\-]+)";
final String doublePattern = "([0-9\\+\\-\\.]+)";
final String spacePattern = "(\\s+)";
Pattern inputPattern = Pattern.compile("(\\s+)" + TOKEN_INPUT + "(\\s+)([\\w\\-_ \\(\\)\\.]+)");
Pattern outputPattern = Pattern.compile("(\\s+)" + TOKEN_OUTPUT + "(\\s+)([\\w\\-_ \\(\\)\\.]+)");
Pattern outputHDRPattern = Pattern.compile("(\\s+)" + TOKEN_OUTPUT_HDR + "(\\s+)([\\w\\-_ \\(\\)\\.]+)");
Pattern output3dPattern = Pattern.compile("(\\s+)" + TOKEN_OUTPUT_3D + "(\\s+)([\\w\\-_ \\(\\)\\.]+)");
Pattern dimensionPattern = Pattern.compile("(\\s+)" + TOKEN_DIMENSION + "(\\s+)([0-9\\-]+)(\\s+)([0-9\\-]+)");
Pattern paramPattern = Pattern.compile("(\\s+)" + TOKEN_PARAM + "(\\s+)([\\w_\\.]+)(\\s+)([\\w_\\-\\.\\+\\(\\)\\[\\] =^,:\\\\/\\*]*)");
Pattern envelopePattern = Pattern.compile(spacePattern + TOKEN_ENVELOPE + spacePattern + "([\\w_\\.]+)");
Pattern envelopeViewPattern = Pattern.compile(spacePattern + TOKEN_VIEW + spacePattern + doublePattern + spacePattern + doublePattern + spacePattern + doublePattern + spacePattern + doublePattern);
Pattern envelopePointsPattern = Pattern.compile(spacePattern + TOKEN_POINTS + "([0-9\\+\\-\\.\\s]+)");
Pattern envelopeSelectedPattern = Pattern.compile(spacePattern + TOKEN_SELECTED + spacePattern + intPattern);
Pattern envelopeInterpolationPattern = Pattern.compile(spacePattern + TOKEN_INTERPOLATION + spacePattern + "([A-Z]+)");
Pattern envelopeLockedPattern = Pattern.compile(spacePattern + TOKEN_LOCKED + spacePattern + "(true|false)");
int i = 0;
while (i < currLines.size() - 1) {
i++;
{
Matcher matcher = inputPattern.matcher(currLines.get(i));
if (matcher.find()) {
String input = matcher.group(3);
res.setInputBuffer(input);
continue;
}
}
{
Matcher matcher = outputPattern.matcher(currLines.get(i));
if (matcher.find()) {
String output = matcher.group(3);
res.setOutputBuffer(output);
continue;
}
}
{
Matcher matcher = outputHDRPattern.matcher(currLines.get(i));
if (matcher.find()) {
String outputHDR = matcher.group(3);
res.setOutputHDRBuffer(outputHDR);
continue;
}
}
{
Matcher matcher = output3dPattern.matcher(currLines.get(i));
if (matcher.find()) {
String output3d = matcher.group(3);
res.setOutputBuffer3D(output3d);
continue;
}
}
{
Matcher matcher = dimensionPattern.matcher(currLines.get(i));
if (matcher.find()) {
String width = matcher.group(3);
String height = matcher.group(5);
res.setWidth(Integer.parseInt(width));
res.setHeight(Integer.parseInt(height));
continue;
}
}
{
Matcher matcher = paramPattern.matcher(currLines.get(i));
if (matcher.find()) {
Parameter param = new Parameter();
res.parameterList.add(param);
String paramName = matcher.group(3);
String paramValue = matcher.group(5);
// System.out.println(paramName + " " + paramValue);
param.setName(paramName);
param.setValue(paramValue);
continue;
}
}
{
Matcher matcher = envelopePattern.matcher(currLines.get(i));
if (matcher.find()) {
String ident = matcher.group(1);
String paramName = matcher.group(3);
Parameter param = res.getParameterByName(paramName);
if (param == null)
throw new IllegalArgumentException(currLines.get(i));
Envelope envelope = new Envelope();
param.setEnvelope(envelope);
while (i < currLines.size() - 1) {
i++;
// view
{
Matcher subMatcher = envelopeViewPattern.matcher(currLines.get(i));
if (subMatcher.find()) {
String subIdent = subMatcher.group(1);
if (subIdent.length() < ident.length())
throw new IllegalArgumentException(currLines.get(i));
try {
envelope.setViewXMin(Tools.FTOI(Double.parseDouble(subMatcher.group(3))));
envelope.setViewXMax(Tools.FTOI(Double.parseDouble(subMatcher.group(5))));
envelope.setViewYMin(Double.parseDouble(subMatcher.group(7)));
envelope.setViewYMax(Double.parseDouble(subMatcher.group(9)));
} catch (Exception ex) {
throw new IllegalArgumentException(currLines.get(i));
}
continue;
}
}
// points
{
Matcher subMatcher = envelopePointsPattern.matcher(currLines.get(i));
if (subMatcher.find()) {
String subIdent = subMatcher.group(1);
if (subIdent.length() < ident.length())
throw new IllegalArgumentException(currLines.get(i));
try {
String[] points = subMatcher.group(2).trim().split(" ");
int[] x = new int[points.length / 2];
double[] y = new double[points.length / 2];
for (int j = 0; j < points.length; j += 2) {
x[j / 2] = Tools.FTOI(Double.parseDouble(points[j]));
y[j / 2] = Double.parseDouble(points[j + 1]);
}
envelope.setValues(x, y);
} catch (Exception ex) {
throw new IllegalArgumentException(currLines.get(i));
}
continue;
}
}
// selected
{
Matcher subMatcher = envelopeSelectedPattern.matcher(currLines.get(i));
if (subMatcher.find()) {
String subIdent = subMatcher.group(1);
if (subIdent.length() < ident.length())
throw new IllegalArgumentException(currLines.get(i));
try {
envelope.setSelectedIdx(Tools.FTOI(Double.parseDouble(subMatcher.group(3))));
} catch (Exception ex) {
throw new IllegalArgumentException(currLines.get(i));
}
continue;
}
}
// interpolation
{
Matcher subMatcher = envelopeInterpolationPattern.matcher(currLines.get(i));
if (subMatcher.find()) {
String subIdent = subMatcher.group(1);
if (subIdent.length() < ident.length())
throw new IllegalArgumentException(currLines.get(i));
try {
String interpolationStr = subMatcher.group(3);
envelope.setInterpolation(Envelope.Interpolation.valueOf(interpolationStr));
} catch (Exception ex) {
throw new IllegalArgumentException(currLines.get(i));
}
continue;
}
}
// locked
{
Matcher subMatcher = envelopeLockedPattern.matcher(currLines.get(i));
if (subMatcher.find()) {
String subIdent = subMatcher.group(1);
if (subIdent.length() < ident.length())
throw new IllegalArgumentException(currLines.get(i));
try {
String lockedStr = subMatcher.group(3);
envelope.setLocked(lockedStr.equalsIgnoreCase("true"));
} catch (Exception ex) {
throw new IllegalArgumentException(currLines.get(i));
}
continue;
}
}
i--;
break;
}
continue;
}
}
throw new IllegalArgumentException(currLines.get(i));
}
}
return res;
}
use of org.jwildfire.envelope.Envelope in project JWildfire by thargor6.
the class AnimationService method addEnvelope.
private static void addEnvelope(int pFrameCount, MotionCurve curve, int[] envX, double[] envY) {
Envelope envelope = new Envelope(envX, envY);
envelope.setViewXMin(-10);
envelope.setViewXMax(10 + pFrameCount);
envelope.setViewYMin(-10000.0);
envelope.setViewYMax(10000.0);
envelope.setInterpolation(Interpolation.SPLINE);
envelope.setSelectedIdx(0);
if (!curve.isEnabled()) {
curve.assignFromEnvelope(envelope);
curve.setEnabled(true);
} else {
MotionCurve newParentCurve = new MotionCurve();
newParentCurve.setEnabled(true);
newParentCurve.assignFromEnvelope(envelope);
while (curve.getParent() != null) {
curve = curve.getParent();
}
curve.setParent(newParentCurve);
}
}
Aggregations