!7

static ScreenLens lens;
static JLabel lblResult;
static new SingleThread singleThread;
static long time;

p-substance {
  lens = new ScreenLens().start();
  lblResult = jMinWidth(50, jlabel());
  addToWindow(lens.is, withTopMargin(lblResult));
  lens.onImageChange = r {
    //if (time != 0) print((sysNow()-time) + " ms");
    //time = sysNow();
    singleThread.run(r {
      setText(lblResult, analyze(lens.is.getImage()))
    });
  };
}

static S analyze(BufferedImage img) {
  //RGBImage rgb = new RGBImage(img);
  BWImage bw = new BWImage(img);
  ret "Brightness: " + bw.averageBrightness();
}