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

Allow WriteImageDataFunction() callback to be called with empty images #496

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

ptc-tgamper
Copy link
Contributor

@ptc-tgamper ptc-tgamper commented Jul 9, 2024

Allow WriteImageDataFunction() callback to be called with empty images.

The motivation on our side is that we want to avoid to load any image data into memory at all, as we have to deal with models that use multiple Gigabytes (compressed size) of textures. Thus we are looking to employ a custom image loader and writer, where the first does not load/decode any image data, and the second is still called for those empty images.

tiny_gltf.h Outdated Show resolved Hide resolved
@syoyo
Copy link
Owner

syoyo commented Jul 11, 2024

Please create PR for each issues(if issues are orthogonal)

Fix issues that block custom image loaders and writers to deal with empty images
@@ -2767,6 +2767,12 @@ bool WriteImageData(const std::string *basepath, const std::string *filename,
const Image *image, bool embedImages,
const FsCallbacks* fs_cb, const URICallbacks *uri_cb,
std::string *out_uri, void *) {
// Early out on empty images, report the original uri if the image was not written.
if (image->image.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this we keep the previous behaviour, although the callback is now invoked for empty images.

bool imageWritten = false;
if (WriteImageData != nullptr && !filename.empty() && !image.image.empty()) {
if (WriteImageData != nullptr && !filename.empty()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invoke the callback for empty images

@ptc-tgamper
Copy link
Contributor Author

I tailored this branch now to the specific issue, nothing more. Please review.
I will open separate issues for the other changes.

@syoyo
Copy link
Owner

syoyo commented Jul 23, 2024

You should describe the summary of what this PR is.

@ptc-tgamper ptc-tgamper changed the title Fix issues that block custom image loaders and writers to allow empty images Allow WriteImageDataFunction() callback to be called with empty images Jul 23, 2024
@ptc-tgamper
Copy link
Contributor Author

ptc-tgamper commented Jul 24, 2024

Is it ok to merge now, or am I still missing something? @syoyo ?

@syoyo syoyo merged commit 10b23b6 into syoyo:release Jul 26, 2024
8 checks passed
@syoyo
Copy link
Owner

syoyo commented Jul 26, 2024

Good! Merged! The description become clear.

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

Successfully merging this pull request may close these issues.

2 participants