The way i do it (which is not exactly very smart) is that for each icon of the pool I have, i pick a number of sample pixels and average them.
For example, for each icon that is 21x21 (441 pixels) i pick ~30-40 pixels at regular intervals and for each i record the Red, Green and Blue values.
Then I average up all reds, all greens and all blues separately and I get my average RGB color for that icon.
I store all that info in a database, and then, when i parse the pixels of the image to render, i select the 'closest' matching icon by comparing the R, G and B values.
the closest is basically the one with the smallest difference = ( (Abs(Ricon - Rimage) + Abs(Gicon-Gimage) + Abs(Bicon-Bimage) )
As I said, not exactly very precise, but it work reasonably so far. In a future version i might try and map areas (left, top, right, bottom) and have separate RGB averages for each of those to try and make the images smoother. But it feels like alot of work and I can't be asked so far ;-)
Connect With Us