-
-
Notifications
You must be signed in to change notification settings - Fork 422
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) { | ||
*out_uri = *filename; | ||
return true; | ||
} | ||
|
||
const std::string ext = GetFilePathExtension(*filename); | ||
|
||
// Write image to temporary buffer | ||
|
@@ -3309,11 +3315,12 @@ static bool UpdateImageObject(const Image &image, std::string &baseDir, | |
filename = std::to_string(index) + "." + ext; | ||
} | ||
|
||
// If callback is set and image data exists, modify image data object. If | ||
// image data does not exist, this is not considered a failure and the | ||
// original uri should be maintained. | ||
// If callback is set, modify image data object. | ||
// Note that the callback is also invoked for images without data. | ||
// The default callback implementation simply returns true for | ||
// empty images and sets the out URI to filename. | ||
bool imageWritten = false; | ||
if (WriteImageData != nullptr && !filename.empty() && !image.image.empty()) { | ||
if (WriteImageData != nullptr && !filename.empty()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invoke the callback for empty images |
||
imageWritten = WriteImageData(&baseDir, &filename, &image, embedImages, | ||
fs_cb, uri_cb, out_uri, user_data); | ||
if (!imageWritten) { | ||
|
@@ -4387,7 +4394,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err, | |
} | ||
} else { | ||
// Assume external file | ||
// Keep texture path (for textures that cannot be decoded) | ||
// Unconditionally keep the external URI of the image | ||
image->uri = uri; | ||
#ifdef TINYGLTF_NO_EXTERNAL_IMAGE | ||
return true; | ||
|
@@ -4434,6 +4441,7 @@ static bool ParseImage(Image *image, const int image_idx, std::string *err, | |
} | ||
return false; | ||
} | ||
|
||
return LoadImageData(image, image_idx, err, warn, 0, 0, &img.at(0), | ||
static_cast<int>(img.size()), load_image_user_data); | ||
} | ||
|
Oops, something went wrong.
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.
There was a problem hiding this comment.
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.