Thanks for all the help. You guys gave me great insight into how byte arrays work, I never could figure them out in the past. The whole concept of holding X and Y values (and the pixel’s color too!) in a single array is just mind bogglingly confusing to me.
Sadly though, I realized the major issue isnt coming from getColor, it’s coming from where getColor has to get it’s data. I was pulling the source image from a very large spritesheet and the problem is when .getColor (or any of your methods) are used it has to grab that value off a huge 1024x512 spritesheet, and there in lies the slowdown. I wasn’t realizing that even though I am only looking at a 32x32 image I pulled from the sheet, when it has to calculate color values it has to load up the entire sheet into memory. Thus, the major slowdown. Problem with that is, even your guy’s methods of snagging the byte array still has similar issues because of that. So your methods are a lot faster, but not fast enough!
In my tests with my current code, if I use a single 32x32 image I can run the code literally about 200 times faster. It executes using my old slow code countless times faster than even your guy’s versions. But, that’s not acceptable, I still need the source information to exist on the sprite sheet.
So, I’ve have a possible idea that may actually be even faster than the byte array examples you’ve been showing me. Basically it involves creating the data only once, based off the image (sort of a “first time load” deal) and saving it as a string of 0s and 1s in a .properties file. Then, I can build the array in-game off a 1024-digit long (height*width) properties key and skipping the need to even look at the image anymore.
Once that’s done, I can add a check on game load to just doublecheck all the last modified dates on the images I’m working with, if they’ve changed I can rebuild the data in the properties files, if they haven’t, just use the existing binary keys.
The final product should mean that the images are only touched once, ever. Unless I update the image, then the program will detect the change and regenerate the files specific to that one sprite sheet.
But even if my idea works out, I’ll probably still use the help you’ve given me and use your methods to do the initial build, because it’s still faster than mine. 