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
feature: Implement load_lossy
#1753
base: main
Are you sure you want to change the base?
Conversation
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.
Succinct and little surface changes, very neat. I'd be in favor. The only concern that comes to mind would be that completely discarding the error information may be suboptimal for few cases. But we can take a look later, I'd generally treat them as warnings and defer this to warning reports in either case.
pub fn decode(mut self) -> ImageResult<DynamicImage> { | ||
let format = self.require_format()?; | ||
free_functions::load_inner(self.inner, self.limits, format) | ||
free_functions::load_inner(self.inner, self.limits, format, LoadErrorHandling::Strict) | ||
} |
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.
Preferrably you'd add fn decode_lossy
for Reader
instead of image::load_lossy
. Use of the module functions is somewhat discouraged due to lack of limit handling and imprecise error reporting.
This PR assumes that I like the overall API/feature, but I wouldn't be comfortable merging without both (a) changing the spec for |
Thank you for your quick feedback.
|
110cccf
to
c7510a5
Compare
Add support for lossy image loading. The new `load_lossy` function adds error recovery. If loading reaches the step where it allocates the pixel buffer, then it always succeeds: any error following this step will result in a partially filled buffer where the missing pixels will use their default "zero" value. This allows for example to read truncated files or other minor issues. - Closes image-rs#1752
c7510a5
to
6faaf1f
Compare
I believe perfect is the enemy of good, in this case, as long as the error interface is available (i.e. it's possible for the caller to know that only partial information is available). The corruptness of the image is part of the intent afterall ;) It may be interesting if the decoder could indicate a region of the image as being correct regardless but by no means would I personally see this as a requirement. (It can be added as a defaulted extension method of |
Add support for lossy image loading.
The new
load_lossy
function adds error recovery.If loading reaches the step where it allocates the pixel buffer, then it always succeeds: any error following this step will result in a partially filled buffer where the missing pixels will use their default "zero" value.
This allows for example to read truncated files or other minor issues.
I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.