Sprite fitting layout, related to SMARTSPRITES-64 and SMARTSPRITES-72 #1

wants to merge 2 commits into


None yet
2 participants

I'm not really a Java developer by any means, but I just thought I'd contribute this rough patch to do a reasonably good job at fitting sprites tightly in the generated image. It uses a greedy algorithm, which is probably suboptimal for this type of problem, but on my site it generates good results with no obvious errors.

The patch does change your hashCode algorithm for images, which I found generated quite a lot of collisions even in a small space if images are similar. I don't think there's really going to be much of a significant penalty to CRC'ing every pixel on modern machines, and a collision-free hashCode was necessary for TreeSet to function properly (at least in my naive implementation).

The patch also fails some of your test cases, but I think it's just because the order of the images shifted from the order expected in your tests. Due to the implementation, in all cases, images will be placed in order of total size descending.

Thanks for developing this excellent piece of software!

@planetbeing planetbeing Added support for the FIT layout, which uses a greedy algorithm to tr…
…y to pack subimages as tightly as possible to reduce total image size.

stanislawosinski commented Feb 23, 2011


Thanks for the patch! Compact image layout, even if not optimal (an optimal layout problem is probably NP-complete anyway), would be a big improvement.

Later this week I'll review the path, fix unit tests, write some new ones, update the documentation and merge the whole thing.



Jacques Fix crasher bug when there are CRC32 hash collisions between differen…
…t images. AreaComparator should make sure to say they are different so that the list of images to place can be complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment