Apply ICC Profile / Color Conversion when decoding PNG
Prerequisites
- [x] I have written a descriptive pull-request title
- [x] I have verified that there are no overlapping pull-requests open
- [x] I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules :cop:.
- [ ] I have provided test coverage for my change (where applicable)
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.Decode once all the chunk have been read and the image is already process. I'm using TPixel.ToScaledVector4() and TPixel.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 is Rgba64
Let me know if this is the correct approach or if I missed something (all comments are welcome)