Chlumsky / msdfgen

Multi-channel signed distance field generator
MIT License
3.9k stars 404 forks source link

Bitmap reserve(), capacity(), and trim_to_fit() #155

Closed Journeyman1337 closed 2 years ago

Journeyman1337 commented 2 years ago

It would be nice if the bitmap class maintained a byte capacity independent from the image size. This could be used to lower the amount of allocations required to generate multiple sprites in succession. The same byte array could be reused for multiple sprites, even if the sprites are of different pixel dimensions.

Chlumsky commented 2 years ago

Actually, this is the exact reason why the library doesn't enforce using the Bitmap class but instead lets you pass in bitmap references, whose underlying implementation is up to the user. That means that you can create your own bitmap class that supports the features you require and if you provide implicit conversions to msdfgen's bitmap references, you can use it as seamlessly as the original Bitmap class.

For example, in msdf-atlas-gen, a use case similar to the one you described is solved by simply allocating a buffer with the maximum number of pixels for a single glyph (times the number of threads) and interpreting it as a bitmap reference - each time with different dimensions.

Journeyman1337 commented 2 years ago

This is exactly what I need, thank you very much!