finding a color with a robot

Hey i am making this program and i need an efficient findcolor algorithm i am currently using this:

public Point FindColor(Color c,int x1,int y1,int x2,int y2,int tol){

for (int i=y1;i<=y2;i++){

for(int j=x1;j<=x2;j++){

if (colorSimilarity(getPixelColor(j, i),c)*100>100-tol){

return new Point(j,i);

}

}

}

return null;

}

public double colorSimilarity ( Color col1, Color col2 )

{

double dr, dg, db;

dr = col1.getRed() - col2.getRed();

dg = col1.getGreen() - col2.getGreen();

db = col1.getBlue() - col2.getBlue();

return 1-(( Math.sqrt ( ( dr * dr ) + ( dg * dg ) + ( db * db ) ) )/(255*Math.sqrt(3)));

}

but it takes forever to search the whole screen (by forever i mean 8-9 seconds). any ideas as to how i could improve its efficiency to more like .1-.5 seconds

[892 byte] By [nickmagusa] at [2007-11-26 15:10:11]
# 1
Crosspost: http://forum.java.sun.com/thread.jspa?threadID=5125012
doremifasollatidoa at 2007-7-8 9:00:55 > top of Java-index,Other Topics,Algorithms...