Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to merge multi small pngs into a single one with smallest size?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Rubbio   Members   -  Reputation: 122

Like
0Likes
Like

Posted 22 December 2008 - 09:47 PM

Hi all, I am writing a 2d animation editor, and the artist uses many small png as modules of a character. so i want to write a programe to auto merge those small pngs into a large single png. i googled a lot, but still can not find any good way to ensure the final single png's size(widthXheight) is smallest, is anyone can help me? Thx a lot!

Sponsor:

#2 ToohrVyk   Members   -  Reputation: 1591

Like
0Likes
Like

Posted 22 December 2008 - 09:53 PM

Rectangle packing is an NP-complete problem. Enjoy.

However, why merge things in the same rectagle? Why not just zip your file folder and use a ZIP library to access individual images?

#3 sb01234   Members   -  Reputation: 122

Like
0Likes
Like

Posted 22 December 2008 - 11:12 PM

Quote:
Original post by ToohrVyk
However, why merge things in the same rectagle? Why not just zip your file folder and use a ZIP library to access individual images?

Texture atlas, perhaps?


#4 Rubbio   Members   -  Reputation: 122

Like
0Likes
Like

Posted 23 December 2008 - 07:26 PM

Thansk for your replies!!

yes, it's texture problem~~

bind texture is a heavy job, so combine textures may helpful a lot~

#5 Cornstalks   Crossbones+   -  Reputation: 6991

Like
0Likes
Like

Posted 23 December 2008 - 08:50 PM

I found this to be very useful when I had to pack a bunch of character textures into a large texture for using fonts in my game. It's pretty quick, easy, straightforward, and actually does a great job I've found. While it doesn't guarantee that it actually generates the smallest texture, it does have great results. Of course, if you want to tackle this NP-complete problem and pack them into the smallest texture possible, then you'll want to use a different, much more complex, and expensive algorithm.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

#6 Spodi   Members   -  Reputation: 642

Like
0Likes
Like

Posted 24 December 2008 - 07:59 AM

Quote:
Original post by MikeTacular
I found this to be very useful


I always recommend that site for those looking into making a texture atlas. It is, by far, the fastest way to get it done that I have seen. I was able to pack a couple thousand textures into a 4096x4096 atlas in around 100ms I believe it was.

It definitely won't give you the best fit, but it will give you great scalability and performance. If you want an example of bad scalability, the XNA website has an example that just scans every pixel from the start until a fit is found. Works fine up until you want to pack more than about 5 textures.

If the size of the atlas really is that important, I'd suggest you build the atlas first by guessing the size. You know the width will need to be at least >= the largest item's width, and >= the sum of all width. Same goes for height. The area will also need to be >= the sum of the area of all items packed. Using that, you can take the first two power-of-twos that fit those conditions.

Since it is not unlikely that the first atlas will fail, even if it fits those conditions, you just keep trying by moving to the next atlas that fits those conditions, ordering them by the atlas's total area (since that is what matters to you the most).
NetGore - Open source multiplayer RPG engine




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS