/** * Gets the Java run-time class code generated from the compiled script. * * @return the run-time source code * * @throws JiffleException if the script has not been set yet or if * compilation errors occur */ public String getRuntimeSource() throws JiffleException { if (script == null) { throw new IllegalStateException("Jiffle script has not been set yet"); } Jiffle jiffle = new Jiffle(script, imageParams); return jiffle.getRuntimeSource(Jiffle.RuntimeModel.DIRECT, true); }
/** * Gets the Java run-time class code generated from the compiled script. * * @return the run-time source code * * @throws JiffleException if the script has not been set yet or if * compilation errors occur */ public String getRuntimeSource() throws JiffleException { if (script == null) { throw new IllegalStateException("Jiffle script has not been set yet"); } Jiffle jiffle = new Jiffle(script, imageParams); return jiffle.getRuntimeSource(Jiffle.RuntimeModel.DIRECT, true); }
public void getSourceFromJiffleObject(String script) throws JiffleException { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); // You have to compile the script before getting the runtime // source otherwise an Exception will be thrown jiffle.compile(); // Get the Java source. The boolean argument specifies that we // want the input script copied into the class javadocs String runtimeSource = jiffle.getRuntimeSource(true); } // docs end getSourceFromJiffleObject
@Test(expected=JiffleException.class) public void passingEmptyScriptToConstructor() throws Exception { System.out.println(" Jiffle(script, imageParams) with empty script"); String script = ""; imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle = new Jiffle(script, imageParams); }
@Before public void setup() { jiffle = new Jiffle(); imageParams = new HashMap<>(); }
private JiffleDirectRuntime getRuntimeWithImageParams() throws Exception { String script = "dest1 = src1; dest2 = src2; dest3 = src3;" ; Map<String, Jiffle.ImageRole> imageParams = new HashMap<>(); imageParams.put("dest1", Jiffle.ImageRole.DEST); imageParams.put("dest2", Jiffle.ImageRole.DEST); imageParams.put("dest3", Jiffle.ImageRole.DEST); imageParams.put("src1", Jiffle.ImageRole.SOURCE); imageParams.put("src2", Jiffle.ImageRole.SOURCE); imageParams.put("src3", Jiffle.ImageRole.SOURCE); Jiffle jiffle = new Jiffle(script, imageParams); return jiffle.getRuntimeInstance(); }
@Before public void setup() { jiffle = new Jiffle(); imageParams = new HashMap<>(); }
/** * Compiles a script read from a file and submits it for execution. * * @param scriptFile file containing the Jiffle script * @throws Exception on problems compiling the script */ public void compileAndRun(File scriptFile) throws Exception { Map<String, Jiffle.ImageRole> imageParams = new HashMap<>(); imageParams.put("result", Jiffle.ImageRole.DEST); Jiffle jiffle = new Jiffle(scriptFile, imageParams); JiffleDirectRuntime runtime = jiffle.getRuntimeInstance(); WritableRenderedImage destImage = ImageUtilities.createConstantImage(WIDTH, HEIGHT, 0d); runtime.setDestinationImage("result", destImage); executor.submit(runtime, new NullProgressListener()); }
@Test public void fileWithParamsConstructor() throws Exception { System.out.println(" Jiffle(scriptFile, imageParams)"); URL url = JiffleBasicTest.class.getResource("constant.jfl"); File file = new File(url.toURI()); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle = new Jiffle(file, imageParams); assertTrue(jiffle.isCompiled()); }
@Test public void scriptWithParamsConstructor() throws Exception { System.out.println(" Jiffle(script, imageParams)"); String script = "dest = 42;"; imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle = new Jiffle(script, imageParams); assertTrue(jiffle.isCompiled()); }
protected void compileScript(String script) throws JiffleException { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); } }
private Jiffle getCompiledJiffle(String script) throws JiffleException { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); return jiffle; }
@Test(expected=JiffleException.class) public void emptyImagesBlock() throws Exception { System.out.println(" empty images block and no parameters causes exception"); String script = "images { } dest = 42;" ; Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); }
private JiffleDirectRuntime getRuntime(String script) throws Exception { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); Map<String, Jiffle.ImageRole> params = new HashMap<>(); params.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(params); jiffle.compile(); return jiffle.getRuntimeInstance(); }
protected void testScript(String script, RenderedImage srcImg, Evaluator evaluator) throws Exception { imageParams = new HashMap<>(); imageParams.put("dest", Jiffle.ImageRole.DEST); imageParams.put("src", Jiffle.ImageRole.SOURCE); // test the direct runtime Jiffle jiffle = new Jiffle(script, imageParams); directRuntimeInstance = jiffle.getRuntimeInstance(); testDirectRuntime(srcImg, directRuntimeInstance, evaluator); // and now the indirect one indirectRuntimeInstance = (JiffleIndirectRuntime) jiffle.getRuntimeInstance(Jiffle.RuntimeModel.INDIRECT); evaluator.reset(); testIndirectRuntime(srcImg, indirectRuntimeInstance, evaluator); }
private JiffleDirectRuntime getRuntimeWithImagesBlock() throws Exception { String script = "images {" + " src1=read; src2=read; src3=read;" + " dest1=write; dest2=write; dest3=write;" + "}" + "dest1 = src1; dest2 = src2; dest3 = src3;" ; Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); return jiffle.getRuntimeInstance(); }
private JiffleDirectRuntime getRuntime(String script) throws Exception { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); return jiffle.getRuntimeInstance(); } }
private JiffleDirectRuntime getRuntime(String script) throws Exception { Jiffle jiffle = new Jiffle(); jiffle.setScript(script); Map<String, Jiffle.ImageRole> imageParams = new HashMap<>(); imageParams.put("dest", Jiffle.ImageRole.DEST); jiffle.setImageParams(imageParams); jiffle.compile(); JiffleDirectRuntime runtime = jiffle.getRuntimeInstance(); WritableRenderedImage destImg = ImageUtilities.createConstantImage(WIDTH, WIDTH, 0d); runtime.setDestinationImage("dest", destImg); return runtime; }
@Test public void noDestImage() throws Exception { System.out.println(" destination-less script with images block"); String script = String.format( "images { inimage = read; } \n" + "init { n = 0; } \n" + "n += inimage >= %d;", NUM_PIXELS - 5); Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); directRuntimeInstance = jiffle.getRuntimeInstance(); directRuntimeInstance.setSourceImage("inimage", createSequenceImage()); directRuntimeInstance.evaluateAll(null); Double var = directRuntimeInstance.getVar("n"); assertNotNull(var); assertEquals(5, var.intValue()); }
private void assertScriptResult(String script, Evaluator e, String srcVarName, String destVarName) throws Exception { RenderedImage srcImg = null; WritableRenderedImage destImg = null; Jiffle jiffle = new Jiffle(); jiffle.setScript(script); jiffle.compile(); directRuntimeInstance = (JiffleDirectRuntime) jiffle.getRuntimeInstance(); if (srcVarName != null && srcVarName.length() > 0) { srcImg = createSequenceImage(); directRuntimeInstance.setSourceImage(srcVarName, srcImg); } if (destVarName != null && destVarName.length() > 0) { destImg = ImageUtilities.createConstantImage(IMG_WIDTH, IMG_WIDTH, 0d); directRuntimeInstance.setDestinationImage(destVarName, destImg); } directRuntimeInstance.evaluateAll(null); assertImage(srcImg, destImg, e); }