nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
25.9k stars 7.67k forks source link

stb_image: read image into a buffer allocated outside of stbi #58

Open attilaz opened 9 years ago

attilaz commented 9 years ago

It could be implemented to output into a preallocated buffer like in stb_image_resize or with the ability to set a custom allocator for output buffer alloc/free. I am not interested in using custom allocator for internal, temporary buffers but others might find that useful too.

attilaz commented 9 years ago

The current STBI_MALLOC in stb_image v2.0 is good enough for me. Thanks for adding it. So If you don't plan to modify the interface to add a preallocated buffer for output this issue can be closed.

nothings commented 9 years ago

I still want to add that.

attilaz commented 9 years ago

Great. Thanks.

ratchetfreak commented 7 years ago

I mentioned this in #435 but I'll repeat it here for prosperity

Providing a row stride with the buffer would then be very nice addition for the APIs that require aligned rows.

fishcu commented 5 years ago

I'm also interested in this, for reasons already mentioned in #435 (namely non-trivial row stride). Is this still on the todo list, or maybe available in a fork already somewhere?

mokafolio commented 5 years ago

I'd be interested in this addition, too.

kayomn commented 4 years ago

I'm also interested in this. My game engine uses custom allocators everywhere and while I've done some hacks to STB image in order to accommodate, I think it would be nicer if it was exposed as part of the header by default.

ronaaron commented 3 years ago

Adding my voice to the "I'm interested in this" as well. Really interested!

Karutoh commented 2 years ago

This feature would be nice in Vulkan so that you may decode directly to the ppData parameter in vkMapMemory for a VkBuffer. This would reduce the amount of processing required. Otherwise the end-user will be forced to copy all data themselves to the mapped memory.

troberti commented 1 year ago

Would like this too 👍

rygorous commented 1 year ago

You never ever want to decode directly to a mapped buffer. Those are usually write-combined (uncached) memory and several of the stb_image decoders rely on reading from the decompression buffer. Reading from uncached memory is ballpark ~50-200x slower than reading from cached memory. Trust me, the extra copy is way cheaper than the alternative.

troberti commented 1 year ago

Well, in our case we have an already allocated buffer (not mapped). I found this issue because I was looking if it was possible to direct the output directly to this buffer. Would reduce some additional memory use and the extra copy.

Parad0x84 commented 1 year ago

Is there any progress on this feature? I'm basically storing seperated channels in a single heap allocated memory for my purposes and I have to use memcpy to put channels in place after loading them to different buffers.

It would be nice to have this feature. At least any estimations on when this feature will be implemented, so I may choose to dig code and try to implement myself, if it's not soon

nothings commented 1 year ago

I mean, I last commented on it in 2014, so as you might imagine, there has been no effort to implement it in that time, and no estimates for when it might get done.