iOS10 Extended color spaces producing weird results.
chetstone opened this issue · comments
I was just verifying my app works correctly with colorGrabber on iOS before adding the Android stuff and I started seeing very strange results I hadn't noticed before. When loading an image where I expect the most dominant color to be white, it showed up as bright red. This is on an iPhone6+ running iOS10.1 where the app is built with xcode 8.1 (iOS 10 SDK). A console.log of the output of colorGrabber looks like this:
"UIExtendedSRGBColorSpace 0.843137 0.85098 0.827451 1":"0.375",
"UIExtendedSRGBColorSpace 0.980392 1.01176 1.01961 1":"0.5",
"UIExtendedSRGBColorSpace 0.654902 0.65098 0.623529 1":"0.125"
Super weird! I assume the color values are between 0 and 1.0 when I convert them to hex so who knows what I end up with.
When I run the same code built with XCode 7 (iOS 9 SDK) and load the same image on an iOS7 device, I get this:
"UIDeviceRGBColorSpace 0.654902 0.658824 0.623529 1":"0.1428571",
"UIDeviceRGBColorSpace 0.839216 0.827451 0.823529 1":"0.2857143",
"UIDeviceRGBColorSpace 0.984314 0.984314 1 1":"0.5714286"
and the answer is white as expected.
This SO answer may provide a hint as to what is happening.
This is fixed in react-native-palette which is derived from this project. Users of this component can work around this issue by converting the UIColor values to the rgb(255,255,255)
format rather than #RRGGBB
. The components could be greater than 255 or less than 0 but they will still display properly on the device.