Bitmap reserve(), capacity(), and trim_to_fit()
Journeyman1337 opened this issue · 2 comments
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.
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.
This is exactly what I need, thank you very much!