4 ms·
Tangential - this reminds me of a tricky bug I once fixed. I had this code that lets you choose a brighter or darker variant of a color palette, and initially
by jordansmithnz 7y ago
Tangential - this reminds me of a tricky bug I once fixed.
I had this code that lets you choose a brighter or darker variant of a color palette, and initially bright yellow looked awfully close to white, so I decided to do this conversion through CIELAB (similar to HSLuv). Some unrelated code was storing these colors in the cloud using hex format, and clients would sync these colors back and forth with the cloud.
Usually, everything worked great. I had no problems, however a couple of users started emailing to complain that their colors had ‘disappeared’! As in - the stored colors had become transparent. I spent at least a few hours auditing syncing code, but found nothing.
A few weeks later I stumbled on the issue by chance: if you select dark green (this specific color configuration only), the color would eventually become transparent.
The thing is - some platforms (e.g. iOS) support wide color, which use RGB values outside the 0 to 1 range. Green would go through the CIELAB brightness conversion, and come out with a negative number for one of the RGB values. This is OK, until you convert it to hex and send it to the cloud for syncing... naive color -> hex conversion will freak out with negative numbers. This got sent to the cloud, and later on, the cloud would send this back to the client, which would use it as a source of truth (and so dark green colors would disappear).
The fix was to write a less naive hex converter. This was a few years back, perhaps by now most color -> hex libraries consider this case.
- smohare 7y agoThis sounds more like a fundamental misunderstanding of color spaces (and gamuts) than anything.
- jordansmithnz 7y agoDo you mind explaining that? If you increase the brightness of a color space like RGB or HSL, the perceived brightness color increase is different depending on hue. This is why CIELAB was used, because like the linked HSLuv color space, you can increase brightness across hues with the same perceived brightness shift. The fact that CIELAB can covert to RGB values outside the usual range is fine, e.g. negative values are fine in wide RGB color space.
- mark-r 7y agoWide RGB color support is almost non-existent.
- jordansmithnz 7y agoEvery iPhone since the iPhone 7 supports wide color RGB by default...
- mark-r 7y agoIt depends on how you define "wide color". Yes they use a color space with a wider gamut, but if you're trying to display a regular JPEG image it won't look any different.
- jordansmithnz 7y agoYep, most JPEG images might not look different, however the OS allows RGB values outside the regular range for any color specific API. When working directly with colors, the wide color support is still relevant (and for me, led to the bug I described - devices prior to iPhone 7 didn’t exhibit the bug, because the OS clamped RGB values to the standard range.).