RadioPeirasmos / spriteme

Automatically exported from code.google.com/p/spriteme
0 stars 0 forks source link

Optimize sprite positions #53

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've noticed that a lot of times spriting the images, while reducing the 
number of round trips (which is great), will create a file that's 
ultimately larger (in bytes) than the original images. This behavior could 
be reduced by optimizing the way the sprite image is constructed to take 
advantage of empty space.

For example, when you have one image to be sprited that's 100x20px and 5 
that are 15x20px you could create a sprite image that has the 5 smaller 
images directly beneath the larger file. Instead of this:
___________
|xxxxxxxxx|
|x        |
|x        |
|x        |
|x        |
|x        |
___________

You could have this:
___________
|xxxxxxxxx|
|x x x x x|
___________

I know that this logic is much more difficult, but would result in much 
smaller file sizes because of a reduction in wasted space.

Original issue reported on code.google.com by ascal...@gmail.com on 16 Sep 2009 at 8:24

GoogleCodeExporter commented 9 years ago
I don't think this affects file size very much. It might affect memory size.

Original comment by stevesou...@gmail.com on 22 Sep 2009 at 3:02

GoogleCodeExporter commented 9 years ago
Steve, anyway it will be very useful. And algorithm can be quite simple: just 
sort 
images by x*x+y*y, then try to add to the Sprite one-by-one, checking for 
'filled' 
pixels.

Original comment by sunny.dr...@gmail.com on 22 Sep 2009 at 5:55

GoogleCodeExporter commented 9 years ago
It turns out that the memory implications here are pretty significant, as Steve 
mentions here: http://www.stevesouders.com/blog/2009/09/21/spriteme-part-3/ 

Original comment by bay...@gmail.com on 15 Oct 2010 at 12:34