changes: 1) fixes problems in the original EyeTracking benchmark 2) fix a bug in...
[IRC.git] / Robust / src / Benchmarks / SSJava / EyeTracking / EyeDetector.java
index 92a770419c1c14620a3194b08238c64d7855aa62..ffe8cb62e5ee45ac2263cb5844d0f7c83d3d6a14 100644 (file)
  * 
  * @author Florian Frankenberger
  */
+@LATTICE("IMG")
+@METHODDEFAULT("OUT<THIS,THIS<IN,OUT*,THISLOC=THIS,RETURNLOC=OUT,GLOBALLOC=THIS")
 class EyeDetector {
 
+  @LOC("IMG")
   private int width;
+  @LOC("IMG")
   private int height;
+  @LOC("IMG")
   private int[] pixelBuffer;
-
+  @LOC("IMG")
   double percent;
 
-  public EyeDetector(Image image, Rectangle2D faceRect) {
+  // public EyeDetector(Image image, Rectangle2D faceRect) {
+  public EyeDetector(Image image, double fx, double fy, double fwidth, double fheight) {
 
-    percent = 0.15 * faceRect.getWidth();
-    faceRect =
-        new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth()
-            - percent, faceRect.getHeight() - 2 * percent);
+    percent = 0.15 * fwidth;
+    Rectangle2D adjustedFaceRect =
+        new Rectangle2D(fx + percent, fy + percent, fwidth - percent, fheight - 2 * percent);
+    // percent = 0.15 * faceRect.getWidth();
+    // Rectangle2D adjustedFaceRect =
+    // new Rectangle2D(faceRect.getX() + percent, faceRect.getY() + percent, faceRect.getWidth()
+    // - percent, faceRect.getHeight() - 2 * percent);
 
-    width = (int) faceRect.getWidth() / 2;
-    height = (int) faceRect.getHeight() / 2;
+    width = (int) adjustedFaceRect.getWidth() / 2;
+    height = (int) adjustedFaceRect.getHeight() / 2;
     pixelBuffer = new int[width * height];
 
-    for (int y = (int) faceRect.getY(); y < faceRect.getY() + height; y++) {
-      for (int x = (int) faceRect.getX(); x < faceRect.getX() + width; x++) {
-        pixelBuffer[(y * width) + x] = (int) image.getPixel(x, y);
+    int startX = (int) adjustedFaceRect.getX();
+    int startY = (int) adjustedFaceRect.getY();
+
+    for (int y = 0; y < height; y++) {
+      for (int x = 0; x < width; x++) {
+        pixelBuffer[(y * width) + x] = (int) image.getPixel(x + startX, y + startY);
       }
     }
 
   }
 
+  @LATTICE("OUT<V,V<C,C<THIS,C*,V*,THISLOC=THIS,RETURNLOC=OUT,GLOBALLOC=THIS")
   public Point detectEye() {
-    Point eyePosition = null;
-    float brightness = 255f;
-
-    for (int y = 0; y < height; ++y) {
-      for (int x = 0; x < width; ++x) {
-        final int position = y * width + x;
-        final int[] color =
+    @LOC("OUT") Point eyePosition = null;
+    @LOC("V") float brightness = 255f;
+    for (@LOC("C") int y = 0; y < height; ++y) {
+      for (@LOC("C") int x = 0; x < width; ++x) {
+        @LOC("V") final int position = y * width + x;
+        @LOC("V") final int[] color =
             new int[] { (pixelBuffer[position] & 0xFF0000) >> 16,
                 (pixelBuffer[position] & 0x00FF00) >> 8, pixelBuffer[position] & 0x0000FF };
-        final float acBrightness = getBrightness(color);
+        // System.out.println("("+x+","+y+")="+color[0]+" "+color[1]+" "+color[2]);
+        @LOC("V") final float acBrightness = getBrightness(color);
 
         if (acBrightness < brightness) {
           eyePosition = new Point(x + (int) percent, y + (int) percent);
@@ -71,9 +84,10 @@ class EyeDetector {
     return eyePosition;
   }
 
-  private static float getBrightness(int[] color) {
-    int min = Math.min(Math.min(color[0], color[1]), color[2]);
-    int max = Math.max(Math.max(color[0], color[1]), color[2]);
+  @LATTICE("OUT<V,V<G,G<IN,G<THIS,THISLOC=THIS,GLOBALLOC=G,RETURNLOC=OUT")
+  private static float getBrightness(@LOC("IN") int[] color) {
+    @LOC("V") int min = Math.min(Math.min(color[0], color[1]), color[2]);
+    @LOC("V") int max = Math.max(Math.max(color[0], color[1]), color[2]);
 
     return 0.5f * (max + min);
   }