# 50 * 256x256 bitmaps into one huge bitmap. But how huge?

This topic is 3877 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I got 50 bitmaps, each being 256x256 large. How do I calculate how large a bitmap I need to allocate to be able to fit all these into one huge bitmap? Simple math, but I haven't figured it out so far. I remember studying this in school, but it seems so long ago.. Thanks in advance!

...

12800x256?

##### Share on other sites
Quote:
 Original post by Sneftel...12800x256?

That's hardly a calculation, but okay. My question was vague, sorry.
I'll rephrase:

---------------------------------
4 bitmaps, each 256x256 fit into a larger bitmap of 512x512. But how do I calculate this, if I know how many bitmaps I have, and their size? That's for square bitmaps, power of two.

##### Share on other sites
If you have n=a*b bitmaps, and each one has size w×h, you can fit them into a (w*a)×(h*b) bitmap. If n happens to be a square number, you can set a=b=sqrt(n). Is... any of this helping?

##### Share on other sites
Quote:
 Original post by SymLinkedI got 50 bitmaps, each being 256x256 large.How do I calculate how large a bitmap I need to allocate to be able to fit all these into one huge bitmap? Simple math, but I haven't figured it out so far. I remember studying this in school, but it seems so long ago..

5x10 * bitmap.
or 8x8 if you need perfect square.
or an array of 50 bitmaps.

##### Share on other sites
I think he wants the (approx) square root of the number of bitmaps... probably rounded up..

50^0.5 = 7.07106781

rounded up, 8x8 tiles, so 8*256 x 8*256 = 2048x2048

##### Share on other sites
Hmm, and if you require the final size to be a power of two...

Take the square root of the number of tiles in the texure

Take the base-2 logarithm of that value

Round up to the next integer

the number of tiles across and down should then each be 2^result

Ex:

You have 99 tiles

99^0.5 = 9.94987437

log2(9.94987437) = ln(9.94987437) / ln(2) = 3.31467831

ceiling(3.31467831) = 4

2^4 = 16

...so 16x16 tiles

16*256 x 16*256 = 4096x4096

##### Share on other sites
To have a power of two texture you need a power of two number of 256x256 tiles. The total number of tiles required is 2ceil(log2(n)). In the case of 50 tiles the formula gives 2ceil(log2(50)) = 26 = 64

The possible ways to form that texture are 256x16384(1x64 tiles), 512x8192(2x32), 1024x4096(4x16), 2048x2048(8x8). If you want to minimize the difference between the width and the height you can use the following formula:

m = ceil(log2(n))
width = 2ceil(m/2)
height = 2floor(m/2)

##### Share on other sites
most likely you will end up using either:

2048x2048
or 4096x4096
or 8192x8192

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633768
• Total Posts
3013748
×