Add support for saving WebP images#61770
Merged
akien-mga merged 1 commit intogodotengine:masterfrom Jun 21, 2022
Merged
Conversation
Contributor
|
I like the proposed API with default parameters, +1. It makes for concise code and I'll never need to remember what |
fire
approved these changes
Jun 7, 2022
akien-mga
reviewed
Jun 7, 2022
akien-mga
reviewed
Jun 7, 2022
akien-mga
reviewed
Jun 7, 2022
akien-mga
reviewed
Jun 7, 2022
Member
akien-mga
left a comment
There was a problem hiding this comment.
Looks good to me overall, still have to do a closer review.
akien-mga
reviewed
Jun 21, 2022
core/io/image.h
Outdated
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Godot already has code to save WebP images, but it's not exposed to the user. This PR refactors this code, adding and exposing APIs for saving WebP images.
The bulk of the saving code already existed in
image_loader_webp.cpp, it has been moved to a new filewebp_common.cpp, which is used by both the loader and the new fileresource_saver_webp.cpp. This mimics the structure of the PNG code.In addition to moving this code, this PR also fixes a bug @lyuma and @Macksaur discovered where Godot was adding an extra
WEBPprefix that made the saved file not be a valid WebP file. This bug wasn't affecting us before because Godot only used this code to save stuff internally and then we stripped that prefix when loading internally, but it's technically a pre-existing bug that resulted in compressed textures being invalid WebPs and 4 bytes bigger than they needed to be.The exposed methods are in the
Imageclass. They mimic the API for saving PNG files, except that WebP has both lossy and lossless so there is an extra parameter for the quality setting. Passing intruefor thelossyparameter will save lossy, and the quality can be set to a value between0.0and1.0. Users can writeimage.save_webp("res://test.webp")to save a lossless WebP file, orimage.save_webp("res://test.webp", true)to save a lossy WebP file at 75% quality, orimage.save_webp("res://test.webp", true, 0.5)to save a lossy WebP file at 50% quality.Special thanks to @lyuma and @Macksaur. My work on this was sponsored by The Mirror.