change a way to store image pixels as same as Java's PixelGrabber does
authoryeom <yeom>
Fri, 16 Sep 2011 18:03:21 +0000 (18:03 +0000)
committeryeom <yeom>
Fri, 16 Sep 2011 18:03:21 +0000 (18:03 +0000)
Robust/src/Benchmarks/SSJava/EyeTracking/EyeDetector.java
Robust/src/Benchmarks/SSJava/EyeTracking/Image.java
Robust/src/Benchmarks/SSJava/EyeTracking/ImageReader.java
Robust/src/Benchmarks/SSJava/EyeTracking/IntegralImageData.java

index 922961bbae44fb526d14f8cfa2f97a3271152be7..faf53f73bd6a8fe1441b3d9109488a385c38c4c3 100644 (file)
@@ -62,15 +62,14 @@ class EyeDetector {
   public Point detectEye() {
     Point eyePosition = null;
     float brightness = 255f;
-    System.out.println("detectEye=" + percent);
     for (int y = 0; y < height; ++y) {
       for (int x = 0; x < width; ++x) {
         final int position = y * width + x;
         final int[] color =
             new int[] { (pixelBuffer[position] & 0xFF0000) >> 16,
                 (pixelBuffer[position] & 0x00FF00) >> 8, pixelBuffer[position] & 0x0000FF };
+        // System.out.println("("+x+","+y+")="+color[0]+" "+color[1]+" "+color[2]);
         final float acBrightness = getBrightness(color);
-        System.out.println("p=" + pixelBuffer[position] + " acBrightness=" + acBrightness);
 
         if (acBrightness < brightness) {
           eyePosition = new Point(x + (int) percent, y + (int) percent);
@@ -80,7 +79,6 @@ class EyeDetector {
     }
 
     System.out.println("eyePosition=" + eyePosition);
-    System.exit(0);
 
     return eyePosition;
   }
index 7d4ce3a1161c782df2a54d4f3ae458b8c2d4a824..5e83b46177f61ea8ffb01262207c826bda1bed6c 100644 (file)
@@ -2,15 +2,31 @@ public class Image {
 
   int width;
   int height;
-  long pixel[][];
+  int pixel[][];
 
   public Image(int width, int height) {
     this.width = width;
     this.height = height;
-    pixel = new long[width][height];
+    pixel = new int[width][height];
   }
 
-  public void setPixel(int x, int y, long p) {
+  public void setPixel(int x, int y, int R, int G, int B) {
+    pixel[x][y] = (R << 16) | (G << 8) | B;
+  }
+
+  public int getRed(int x, int y) {
+    return (pixel[x][y] >> 16) & 0xff;
+  }
+
+  public int getGreen(int x, int y) {
+    return (pixel[x][y] >> 8) & 0xff;
+  }
+
+  public int getBlue(int x, int y) {
+    return pixel[x][y] & 0xff;
+  }
+
+  public void setPixel(int x, int y, int p) {
     pixel[x][y] = p;
   }
 
index 3428e7b37467526b045ad871608d93ac4afd356f..461971dd4e6a8bceee802424053f5f5abc5f12f3 100644 (file)
@@ -79,19 +79,21 @@ public class ImageReader {
           // (255 & 0xff) << 24 | (((int) brgb[nindex + 2] & 0xff) << 16)
           // | (((int) brgb[nindex + 1] & 0xff) << 8) | (int) brgb[nindex] &
           // 0xff;
-//           System.out.println("Encoded Color at (" + i + "," + j + ")is:" +
-//           brgb + " (R,G,B)= ("
-//           + ((int) (brgb[nindex + 2]) & 0xff) + "," + ((int) brgb[nindex + 1]
-//           & 0xff) + ","
-//           + ((int) brgb[nindex] & 0xff) + ")");
           int ta =
               ((3 * ((int) (brgb[nindex + 2]) & 0xff) + 6 * ((int) brgb[nindex + 1] & 0xff) + ((int) brgb[nindex] & 0xff))) / 10;
+
           // ndata[nwidth * (nheight - j - 1) + i + 4] = ta;
-          nindex += 3;
-          // image.setPixel(i, j, ta);
           yPos = nheight - j - 1;
-//          System.out.println("yPos=" + yPos + " nheight=" + nheight + " j=" + j);
-          image.setPixel(i, yPos, ta);
+          // System.out.println("yPos=" + yPos + " nheight=" + nheight + " j=" +
+          // j);
+          // System.out.println("Encoded Color at (" + i + "," + yPos + ")is:" +
+          // brgb + " (R,G,B)= ("
+          // + ((int) (brgb[nindex + 2]) & 0xff) + "," + ((int) brgb[nindex + 1]
+          // & 0xff) + ","
+          // + ((int) brgb[nindex] & 0xff) + ")" + "cufoff=" + ta);
+          image.setPixel(i, yPos, ((int) brgb[nindex + 2] & 0xff), ((int) brgb[nindex + 1] & 0xff),
+              ((int) brgb[nindex] & 0xff));
+          nindex += 3;
         }
         nindex += npad;
       }
@@ -174,5 +176,4 @@ public class ImageReader {
     // return ndata;
 
   }
-
 }
\ No newline at end of file
index 71125598a62035be9899a6fa3c07963a2f7739cf..8cc3cbaf2b794f248e2d6f2ec2cf84d5ab340a7e 100644 (file)
@@ -48,19 +48,20 @@ public class IntegralImageData {
     // pg.grabPixels();
     // } catch (InterruptedException ie) {
     // }
-    
-    // for (int y = 0; y < bufferedImage.getHeight(); ++y) {
-    // for (int x = 0; x < bufferedImage.getWidth(); ++x) {
-    // System.out.println(bufferedImage.getPixel(x, y) & 0xff);
-    // }
-    // }
-    // System.exit(0);
+
+//    for (int y = 0; y < bufferedImage.getHeight(); ++y) {
+//      for (int x = 0; x < bufferedImage.getWidth(); ++x) {
+//        System.out.println("(" + x + "," + y + ")=" + (bufferedImage.getPixel(x, y)));
+//      }
+//    }
+//    System.exit(0);
 
     long[][] s = new long[bufferedImage.getWidth()][bufferedImage.getHeight()];
     for (int y = 0; y < bufferedImage.getHeight(); ++y) {
       for (int x = 0; x < bufferedImage.getWidth(); ++x) {
-        s[x][y] = (y - 1 < 0 ? 0 : s[x][y - 1]) + (bufferedImage.getPixel(x, y) & 0xff);
+        s[x][y] = (y - 1 < 0 ? 0 : s[x][y - 1]) + (bufferedImage.getBlue(x, y) & 0xff);
         this.integral[x][y] = (x - 1 < 0 ? 0 : this.integral[x - 1][y]) + s[x][y];
+        // System.out.println("integral ("+x+","+y+")="+integral[x][y]);
       }
     }