Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to reuse a buffer when reading .gif files #1568

Open
sam20908 opened this issue Oct 30, 2023 · 2 comments
Open

A way to reuse a buffer when reading .gif files #1568

sam20908 opened this issue Oct 30, 2023 · 2 comments

Comments

@sam20908
Copy link

Is your feature request related to a problem? Please describe.
When stb_image loads .gif files, it creates a buffer for the entire file. This can get troublesome for big files, as the memory allocated grows very large. This is very noticeable as in some cases it can take up to a few seconds just to allocate the memory.

Describe the solution you'd like
I suggest adding an alternative method to load the files and show how it can be used. the library could take a buffer that it will use to fill the data for the current frame. This way, we only need to allocate a buffer for one frame, thus reducing memory allocations.

Pseudocode of the API:

gif = stbi_load_gif_v2("filename.gif", ...);
unsigned char buffer[...];
while (stbi_gif_has_frame(gif)) {
    error =  stbi_gif_decode_frame(gif, buffer);
    // do something with buffer if no error occurred
    stbi_gif_advance_frame(gif);
}

Let me know what you think!

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@DavinPride
Copy link

gif = stbi_load_gif_v2("filename.gif", ...);
unsigned char buffer[...];
while (stbi_gif_has_frame(gif)) {
error = stbi_gif_decode_frame(gif, buffer);
// do something with buffer if no error occurred
stbi_gif_advance_frame(gif);
}

@nothings
Copy link
Owner

The plan is to remove all support for animated gifs from stb_image and fork them into a separate library (which I personally will not be maintaing), because this has just been a source of headaches and it's really outside the original intent of stb_image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants