Apply ICC Profile / Color Conversion when decoding PNG #3028
+62
−0
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.
Prerequisites
Description
I took a look at the code to see how to implements #3025 and I ends up writting a bit of code, so I'm sharing (There is not test yet, I'm not sure this is the right way to do this), if you are interested in this, let me know and I can continue the PR and add some tests
First I tried to do it the same way it's done in the
JpegDecoder, when the pixel data is read. But this seems to be impossible with the PngDecoder since the Chunk containing the ICC profile might be after the image data (It was on my tests images)Since the decoder is processing a stream (and the stream might not be rewindable) I abandon this idea (the only solution I see would be to store the bytes in memory to be able to find the profile first, but I think this would badly impact the performance / memory usage)
So I ends up doing the conversion at the end of the
PngDecoder.Decodeonce all the chunk have been read and the image is already process. I'm usingTPixel.ToScaledVector4()andTPixel.FromScaledVector4()to get the value directly as float for the profile conversion, and to avoid loosing precision if the image is 16 bit depth and TPixel isRgba64Let me know if this is the correct approach or if I missed something (all comments are welcome)