diff --git a/plugins/ScreenPanel2.java b/plugins/ScreenPanel2.java index 3278abb..fdb0f79 100644 --- a/plugins/ScreenPanel2.java +++ b/plugins/ScreenPanel2.java @@ -42,6 +42,8 @@ import ch.psi.pshell.imaging.Renderer; import ch.psi.pshell.imaging.RendererListener; import ch.psi.pshell.imaging.RendererMode; import ch.psi.pshell.imaging.Source; +import ch.psi.pshell.imaging.SourceBase; +import ch.psi.pshell.imaging.Utils; import ch.psi.pshell.scripting.InterpreterResult; import ch.psi.pshell.scripting.ScriptManager; import ch.psi.pshell.swing.DeviceValueChart; @@ -144,6 +146,7 @@ public class ScreenPanel2 extends Panel { String camServerUrl; String instanceName; Overlay titleOv = null; + int integration = 0; String pipelineSuffix = "_sp"; @@ -304,7 +307,18 @@ public class ScreenPanel2 extends Panel { if (App.hasArgument("suffix")) { pipelineSuffix = App.getArgumentValue("suffix"); } - + if (App.hasArgument("integration")) { + try { + integration = Integer.valueOf(App.getArgumentValue("integration")); + if (integration !=0){ + buttonFit.setSelected(false); + buttonProfile.setSelected(false); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + renderer.setProfileNormalized(true); renderer.setShowProfileLimits(false); @@ -823,7 +837,11 @@ public class ScreenPanel2 extends Panel { } updateButtons(); camera.getConfig().save(); - renderer.setDevice(camera); + if (Math.abs(integration)>1) { + renderer.setDevice(new ImageIntegrator(integration)); + } else { + renderer.setDevice(camera); + } renderer.setAutoScroll(true); renderer.setMarker(marker); imageSize = null; @@ -944,6 +962,58 @@ public class ScreenPanel2 extends Panel { } } } + + class ImageIntegrator extends ColormapSource { + + ImageIntegrator(int num) { + super("Image Averager", camera.getConfig()); + boolean continuous = (num<0); + final int numImages = Math.abs(num); + + camera.addListener(new ImageListener() { + final ArrayList buffer = new ArrayList(); + Data integration = null; + @Override + public void onImage(Object o, BufferedImage bi, Data data) { + if (continuous){ + buffer.add(data); + if (buffer.size()>=numImages){ + for (Data d: buffer){ + process(d); + } + } + } else { + buffer.add(null); //Just to count + process(data); + } + if (buffer.size()>=numImages){ + if (continuous){ + buffer.remove(0); + } else { + buffer.clear(); + } + if (integration!=null){ + //integration.div(numImages); + ImageIntegrator.this.pushData(integration); + } + integration = null; + } + } + void process(Data data){ + if (integration == null){ + integration = new Data(data); + } else { + integration.sum(data); + } + } + + @Override + public void onError(Object origin, Exception ex) { + } + }); + + } + } volatile Dimension imageSize;