Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

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

Open
planetbeing wants to merge 2 commits intocarrotsearch:masterfrom
planetbeing:master
Open

Sprite fitting layout, related to SMARTSPRITES-64 and SMARTSPRITES-72#1
planetbeing wants to merge 2 commits intocarrotsearch:masterfrom
planetbeing:master

Conversation

@planetbeing
Copy link

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!

…y to pack subimages as tightly as possible to reduce total image size.
@stanislawosinski
Copy link
Member

Hi!

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.

Thanks!

S.

…t images. AreaComparator should make sure to say they are different so that the list of images to place can be complete.
stanislawosinski pushed a commit that referenced this pull request Apr 12, 2013
Fixed java lib path in windows commandline batch
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants