From: Officer Barbrady
Well I have it included but the 2nd one gives me tons of errors:

"RGBA cannot be resolved to a type" on abunch of lines
Can you give me a quick example of the parameters used just to click a color?
Here goes.. just finished writing this.. Nothing has been tested. Its a direct port from Cpp.. The boxed types such as "Integer" and "Double" is my way of saying, these values should be pass by reference.. I think you'd actually have to make a class to pass them by value reference via Get/Set. Extra stupid but sure..
Use the ImageFinding to get a screenshot of your RSPS window.. Use the ImageFinder to find whatever it is you're looking for. Use ImageIO to read an image from file to a BufferedImage so you can search for it.. Use FindColour functions to find colours on the screen. Use Robot to click it I guess..
Again, I never tested these yet as I just finished writing them. I'll leave that up to you or someone else for now. They work in Cpp though.
Here is everything:
package imagefinding;
public class HSL {
public double Hue, Sat, Lum;
}
package imagefinding;
public class LAB {
public double L, A, B;
}
package imagefinding;
public class XYZ {
public double X, Y, Z;
}
package imagefinding;
import java.awt.Color;
public class ColourSpace {
public XYZ XYZ(Color C) {
XYZ Result = new XYZ();
double Red = (C.getRed() / 255.0);
double Green = (C.getGreen() / 255.0);
double Blue = (C.getBlue() / 255.0);
Red = (Red > 0.04045) ? Math.pow(((Red + 0.055) / 1.055), 2.4) * 100 : Red / 12.92;
Green = (Green > 0.04045) ? Math.pow(((Green + 0.055) / 1.055), 2.4) * 100.0 : Green / 12.92;
Blue = (Blue > 0.04045) ? Math.pow(((Blue + 0.055) / 1.055), 2.4) * 100.0 : Blue / 12.92;
Result.X = Red * 0.4124 + Green * 0.3576 + Blue * 0.1805;
Result.Y = Red * 0.2126 + Green * 0.7152 + Blue * 0.0722;
Result.Z = Red * 0.0193 + Green * 0.1192 + Blue * 0.9505;
return Result;
}
public Color Rgba(XYZ Xyz) {
double X = Xyz.X / 100.0;
double Y = Xyz.Y / 100.0;
double Z = Xyz.Z / 100.0;
double Red = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
double Green = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
double Blue = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
Red = (Red > 0.0031308) ? (1.055 * Math.pow(Red, (1 / 2.4)) - 0.055) : 12.92 * Red;
Green = (Green > 0.0031308) ? (1.055 * Math.pow(Green, (1 / 2.4)) - 0.055) : 12.92 * Green;
Blue = (Blue > 0.0031308) ? (1.055 * Math.pow(Blue, (1 / 2.4)) - 0.055) : 12.92 * Blue;
long R = Math.round(Red * 255.0);
long G = Math.round(Green * 255.0);
long B = Math.round(Blue * 255.0);
return new Color(R, G, B);
}
public HSL Hsl(Color Rgba) {
HSL Result = new HSL();
double Red, Green, Blue;
Red = Rgba.getRed() / 255.0;
Green = Rgba.getGreen() / 255.0;
Blue = Rgba.getBlue() / 255.0;
double Max = Red > Blue ? Red > Green ? Red : Green : Blue > Green ? Blue : Green;
double Min = Red < Blue ? Red < Green ? Red : Green : Blue < Green ? Blue : Green;
Result.Lum = (Max + Min) / 2.0;
if (Max == Min) {
Result.Hue = Result.Sat = 0.0;
} else {
double Delta = Max - Min;
Result.Sat = Result.Lum > 0.5 ? Delta / (2.0 - Max - Min) : Delta / (Max + Min);
if (Max == Red) {
Result.Hue = (Green - Blue) / Delta + (Green < Blue ? 6.0 : 0.0);
} else if (Max == Green) {
Result.Hue = (Blue - Red) / Delta + 2.0;
} else {
Result.Hue = (Red - Green) / Delta + 4.0;
}
Result.Hue /= 6.0;
}
Result.Hue *= 100.0;
Result.Sat *= 100.0;
Result.Lum *= 100.0;
return Result;
}
private static double HSLToRGBHelper(double I, double J, double Hue) {
if (Hue < 0.0) {
Hue += 1.0;
}
if (Hue > 1.0) {
Hue -= 1.0;
}
if (Hue < (1.0 / 6.0)) {
return Math.round((I + (J - I) * 6.0 * Hue) * 255.0);
} else if (Hue < (1.0 / 2.0)) {
return Math.round(J * 255.0);
} else if (Hue < (2.0 / 3.0)) {
return Math.round((I + (J - I) * 6.0 * ((2.0 / 3.0) - Hue)) * 255.0);
} else {
return Math.round(I * 255.0);
}
}
public Color Rgba(HSL Hsl) {
double H = Hsl.Hue / 100.0;
double S = Hsl.Sat / 100.0;
double L = Hsl.Lum / 100.0;
Color Result = null;
if (S == 0.0) {
double Value = L * 255.0;
Result = new Color((int) Value, (int) Value, (int) Value);
} else {
double J = (L < 0.5) ? (L * (1.0 + S)) : ((L + S) - (S * L));
double I = 2.0 * L - J;
double R = HSLToRGBHelper(I, J, H + (1.0 / 3.0));
double G = HSLToRGBHelper(I, J, H);
double B = HSLToRGBHelper(I, J, H - (1.0 / 3.0));
Result = new Color((int) R, (int) G, (int) B);
}
return Result;
}
public LAB Lab(XYZ Xyz) {
double X = Xyz.X / 95.047;
double Y = Xyz.Y / 100.000;
double Z = Xyz.Z / 108.883;
X = (X > 0.008856) ? Math.pow(X, (1.0 / 3.0)) : (X * 7.787) + (16.0 / 116.0);
Y = (Y > 0.008856) ? Math.pow(Y, (1.0 / 3.0)) : (Y * 7.787) + (16.0 / 116.0);
Z = (Z > 0.008856) ? Math.pow(Z, (1.0 / 3.0)) : (Z * 7.787) + (16.0 / 116.0);
LAB Result = new LAB();
Result.L = ((Y * 116.0) - 16.0);
Result.A = ((X - Y) * 500);
Result.B = ((Y - Z) * 200);
return Result;
}
public XYZ Xyz(LAB Lab) {
double Y = (Lab.L + 16.0) / 116.0;
double X = ((Lab.A / 500.0) + Y);
double Z = (Y - (Lab.B / 200.0));
Y = (Math.pow(Y, 3) > 0.008856) ? Math.pow(Y, 3) : ((Y - (16.0 / 116.0)) / 7.787);
X = (Math.pow(X, 3) > 0.008856) ? Math.pow(X, 3) : ((X - (16.0 / 116.0)) / 7.787);
Z = (Math.pow(Z, 3) > 0.008856) ? Math.pow(Z, 3) : ((Z - (16.0 / 116.0)) / 7.787);
XYZ Result = new XYZ();
Result.X = (X * 95.047);
Result.Y = (Y * 100.000);
Result.Z = (Z * 108.883);
return Result;
}
public static ColourSpace Instance = new ColourSpace();
private ColourSpace() {
}
public static ColourSpace getInstance() {
return Instance;
}
}
package imagefinding;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.nio.ByteBuffer;
public final class ImageHandler {
private int ByteSize;
public BufferedImage Screenshot(int X, int Y, int Width, int Height) throws AWTException {
Rectangle Rect = new Rectangle(X, Y, Width, Height);
return new Robot().createScreenCapture(Rect);
}
public BufferedImage ImageFromBytes(byte[] Bytes, int Width, int Height) {
BufferedImage Image = new BufferedImage(Width, Height, BufferedImage.TYPE_INT_BGR);
WritableRaster raster = (WritableRaster) Image.getData();
raster.setPixels(0, 0, Width, Height, ByteBufferToIntBuffer(Bytes));
Image.setData(raster);
return Image;
}
public BufferedImage ImageFromByteBuffer(ByteBuffer ByteBuffer, int Width, int Height) {
byte Bytes[] = new byte[ByteSize];
ByteBuffer.get(Bytes);
return ImageFromBytes(Bytes, Width, Height);
}
public int[] ByteBufferToIntBuffer(byte[] Data) {
int IntBuffer[] = new int[Data.length];
for (int I = 0; I < Data.length; I++) {
IntBuffer[I] = (int)Data[I] & 0xFF;
}
return IntBuffer;
}
}
package imagefinding;
import java.awt.Color;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
public class ImageFinder {
private int CTSValue;
private double TMod, HueMod, SatMod;
private BufferedImage TargetImage;
public void SetTargetImage(BufferedImage IMG) {
this.TargetImage = null;
this.TargetImage = IMG;
}
public void Reset() {
CTSValue = 1;
TMod = 4.0;
HueMod = 0.2;
SatMod = 0.2;
}
public int GetColourToleranceSpeed() {
return this.CTSValue;
}
void SetColourToleranceSpeed(int Value) {
this.CTSValue = Value;
if (Value < -1 || Value > 3) {
this.CTSValue = 1;
}
}
void GetSpeed2Modifiers(Double HueMod, Double SatMod) {
HueMod = this.HueMod;
SatMod = this.SatMod;
}
void SetSpeed2Modifiers(double HueMod, double SatMod) {
this.HueMod = HueMod;
this.SatMod = SatMod;
}
double GetSpeed3Modifier() {
return TMod;
}
void SetSpeed3Modifier(double TMod) {
this.TMod = TMod;
}
boolean SimilarColours(Color FirstColour, Color SecondColour, int Tolerance) {
switch (CTSValue) {
case -1:
return CTSN(FirstColour, SecondColour, Tolerance);
case 0:
return CTS0(FirstColour, SecondColour, Tolerance);
case 1:
return CTS1(FirstColour, SecondColour, Tolerance);
case 2:
return CTS2(FirstColour, SecondColour, Tolerance);
case 3:
return CTS3(FirstColour, SecondColour, Tolerance);
default:
return CTS1(FirstColour, SecondColour, Tolerance);
}
}
private boolean CTSN(Color FirstCol, Color SecondCol, int Tol) {
return (FirstCol.getRGB() == SecondCol.getRGB());
}
private boolean CTS0(Color FirstCol, Color SecondCol, int Tol) {
return Math.abs(FirstCol.getRed() - SecondCol.getRed()) <= Tol && Math.abs(FirstCol.getGreen() - SecondCol.getGreen()) <= Tol && Math.abs(FirstCol.getBlue() - SecondCol.getBlue()) <= Tol;
}
private boolean CTS1(Color FirstCol, Color SecondCol, int Tol) {
return ((FirstCol.getRed() - SecondCol.getRed()) * (FirstCol.getRed() - SecondCol.getRed()) + (FirstCol.getGreen() - SecondCol.getGreen()) * (FirstCol.getGreen() - SecondCol.getGreen()) + (FirstCol.getBlue() - SecondCol.getBlue()) * (FirstCol.getBlue() - SecondCol.getBlue())) <= (Tol * Tol);
}
private boolean CTS2(Color FirstCol, Color SecondCol, int Tol) {
HSL HFirstCol = new HSL();
HSL HSecondCol = new HSL();
if (FirstCol.getRGB() != 0) {
HFirstCol = ColourSpace.getInstance().Hsl(FirstCol);
}
if (SecondCol.getRGB() != 0) {
HSecondCol = ColourSpace.getInstance().Hsl(SecondCol);
}
return (Math.abs(HSecondCol.Hue - HFirstCol.Hue) <= (Tol * HueMod)) && (Math.abs(HSecondCol.Sat - HFirstCol.Sat) <= (Tol * SatMod));
}
private boolean CTS3(Color FirstCol, Color SecondCol, int Tol) {
LAB LabFirstCol = new LAB(), LabSecondCol = new LAB();
if (FirstCol.getRGB() != 0) {
LabFirstCol = ColourSpace.getInstance().Lab(ColourSpace.getInstance().XYZ(FirstCol));
}
if (SecondCol.getRGB() != 0) {
LabSecondCol = ColourSpace.getInstance().Lab(ColourSpace.getInstance().XYZ(SecondCol));
}
double L = (LabSecondCol.L - LabFirstCol.L);
double A = (LabSecondCol.A - LabFirstCol.A);
double B = (LabSecondCol.B - LabFirstCol.B);
return ((L * L) + (A * A) + (B * B)) <= Math.ceil(Math.sqrt(Tol * TMod));
}
public int CountColour(Color Colour, int X1, int Y1, int X2, int Y2) {
int TemporaryCTS = this.CTSValue;
SetColourToleranceSpeed(-1);
int Result = CountColourTolerance(Colour, X1, Y1, X2, Y2, 0);
SetColourToleranceSpeed(TemporaryCTS);
return Result;
}
public int CountColourTolerance(Color Colour, int X1, int Y1, int X2, int Y2, int Tolerance) {
int Result = 0;
for (int I = Y1; I < Y2; ++I) {
for (int J = X1; J < X2; ++J) {
if (SimilarColours(Colour, new Color(TargetImage.getRGB(J, I)), Tolerance)) {
++Result;
}
}
}
return Result;
}
public boolean FindColour(Integer X, Integer Y, Color Colour, int X1, int Y1, int X2, int Y2) {
int TemporaryCTS = CTSValue;
SetColourToleranceSpeed(-1);
boolean Result = FindColourTolerance(X, Y, Colour, X1, Y1, X2, Y2, 0);
SetColourToleranceSpeed(TemporaryCTS);
return Result;
}
public boolean FindColours(ArrayList<Point> Points, Color Colour, int X1, int Y1, int X2, int Y2) {
int TemporaryCTS = CTSValue;
SetColourToleranceSpeed(-1);
boolean Result = FindColoursTolerance(Points, Colour, X1, Y1, X2, Y2, 0);
SetColourToleranceSpeed(TemporaryCTS);
return Result;
}
public boolean FindColourTolerance(Integer X, Integer Y, Color Colour, int X1, int Y1, int X2, int Y2, int Tolerance) {
for (int I = Y1; I < Y2; ++I) {
for (int J = X1; J < X2; ++J) {
if (SimilarColours(new Color(TargetImage.getRGB(J, I)), Colour, Tolerance)) {
X = J;
Y = I;
return true;
}
}
}
return false;
}
public boolean FindColoursTolerance(ArrayList<Point> Points, Color Colour, int X1, int Y1, int X2, int Y2, int Tolerance) {
for (int I = Y1; I < Y2; ++I) {
for (int J = X1; J < X2; ++J) {
if (SimilarColours(new Color(TargetImage.getRGB(J, I)), Colour, Tolerance)) {
Points.add(new Point(J, I));
}
}
}
return (!Points.isEmpty());
}
public boolean FindImage(BufferedImage ImageToFind, Integer X, Integer Y) {
return FindImageIn(ImageToFind, X, Y, 0, 0, TargetImage.getWidth(), TargetImage.getHeight());
}
public boolean FindImageIn(BufferedImage ImageToFind, Integer X, Integer Y, int X1, int Y1, int X2, int Y2) {
int TemporaryCTS = CTSValue;
boolean Result = FindImageToleranceIn(ImageToFind, X, Y, X1, Y1, X2, Y2, 0);
SetColourToleranceSpeed(TemporaryCTS);
return Result;
}
public boolean FindImageToleranceIn(BufferedImage ImageToFind, Integer X, Integer Y, int X1, int Y1, int X2, int Y2, int Tolerance) {
int dX = (X2 - X1) - (ImageToFind.getWidth() - 1);
int dY = (Y2 - Y1) - (ImageToFind.getHeight() - 1);
for (int I = 0; I < dY; ++I) {
for (int J = 0; J < dX; ++J) {
Skip:
for (int YY = 0; YY < ImageToFind.getHeight(); ++YY) {
for (int XX = 0; XX < ImageToFind.getWidth(); ++XX) {
if (ImageToFind.getRGB(XX, YY) != 0) {
if (!SimilarColours(new Color(ImageToFind.getRGB(XX, YY)), new Color(TargetImage.getRGB(XX + J, YY + I)), Tolerance)) {
++J;
break Skip; //Java doesn't have goto :S
}
}
}
}
X = J + X1;
Y = I + Y1;
return true;
}
}
X = -1;
Y = -1;
return false;
}
}