-
Notifications
You must be signed in to change notification settings - Fork 53
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
Rendering with gd_is_bgcolor is inheritly flawed #25
Comments
This is a modified version of
The code below works for me, but YMMV, use at your own risk.
|
Hello marcakafoddex I havn't used the original lib and went straight to yours, so i don't know if this issue is with yours or from the original lib, but it seems theres an issue with transparency. While the background colour is correctly ignored, it seems on some images (quite a lot) theres other colours being incorrectly treated as transparent. The screenshot for example: My code is here. This code creates an SDL surface with the palette. I've also used the code in your example and got the same result.: `gd_GIF* gif = gd_open_gif(getFileName().c_str());
}` Previously was using stb gif decoder without issue (except no animation) |
I get a better result by ignoring the bgindex altogether. Instead i use gif->gce.tindex ` gd_GIF* gif = gd_open_gif(getFileName().c_str());
}` |
Interesting, i can render all my gifs with the code i showed earlier. I wonder what makes your gifs different. Kudos for sharing your experiences and improvements though! |
As far as i can tell, if "gif->gce.transparency" is true, then "gif->gce.tindex" should be used as the "transparent" colour, and bgindex should be ignored. if "gif->gce.transparency" is false, then use bgindex as the transparent color. ` while (gd_get_frame(gif))
}` |
Thank you for this lib! Appreciate the work.
However, rendering a frame to its RGB colors, and then using gd_is_bgcolor is inheritly flawed. It's not at all impossible that the bgcolor is set to a "color" that also appears elsewhere in the palette.
gd_is_bgcolor
will mark those non-transparent pixels as bg colors incorrectly.The solution is to fill the "render" buffer not with 3-byte RGB colors, but with 1-byte indices instead, and then check each index against the background index instead. Just pointing this out for other people, in case they run into the same problem as me.
The text was updated successfully, but these errors were encountered: