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);
}
System.out.println("eyePosition=" + eyePosition);
- System.exit(0);
return eyePosition;
}
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;
}
// (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;
}
// return ndata;
}
-
}
\ No newline at end of file
// 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]);
}
}