I'm trying to get the method to complete in less than 50 milliseconds, but I can't seem to figure out how I can increase the overall speed of the method. I'm using an object for the pixel because I need to be able to check for null when I'm compressing the data.
public static Frame getFrame(Dimension d, Robot r, Rectangle s, Resolution rs)
{
int w = d.width;
int h = d.height;
BufferedImage b = r.createScreenCapture(s);
Pixel[] pixels = new Pixel[w * h];
for(int i = 0; i < w; i++)
{
for(int j = 0; j < h; j++)
{
pixels[j * w + i] = new Pixel(b.getRGB(i, j));
}
}
return new Frame(rs, pixels, true);
}
Here's the constructor for the Pixel class
public Pixel(int c)
{
if((c & 0xFF) == 0xA || (c & 0xFF) == 0xD)
c++;
if((c & 0xFF00) == 0xA00 || (c & 0xFF00) == 0xD00)
c += 0x100;
if((c & 0xFF0000) == 0xA0000 || (c & 0xFF0000) == 0xD0000)
c += 0x10000;
if((c & 0xFF000000) == 0xA000000 || (c & 0xFF000000) == 0xD000000)
c += 0x1000000;
color = c;
}
And here's the constructor for the Frame class
public Frame(Resolution res, Pixel[] pix, boolean ignoreCheck)
{
if(!ignoreCheck)
{
if(pix.length < res.getTotalPixels())
throw new NotEnoughPixelsException(res.getTotalPixels() - pix.length);
else if(pix.length > res.getTotalPixels())
throw new TooManyPixelsException(pix.length - res.getTotalPixels());
}
resolution = res;
pixels = pix;
}