Skip to content
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

[Issue-46] Clamp sRGB display values #53

Merged
merged 3 commits into from
Mar 20, 2023

Conversation

mpospese
Copy link
Contributor

@mpospese mpospese commented Mar 20, 2023

Introduction

We format RGB values as hex without considering that with extended sRGB, channel values might be less than 0x00 or greater than 0xFF. We should restrict the values to this range but provide a warning.

Purpose

Fix #46 Make sure displayed hex channel values are between 0x00 and 0xFF

Scope

  • Adjust implementation of UIColor.rgbDisplayValue()
  • Add test coverage

Discussion

When a value falls outside of the range, we will clamp it to 0x00-0xFF and log a console warning (unless logging has been disabled). This adopts a similar logging mechanism to what we use when ImageAsset or SystemImage fails to load an image and must resort to the fallback.

For the newly added rgbDebugDisplayValue() method we will also append a "⚠️" emoji to the output string for colors that fall outside of the sRGB color space.

📱 Screenshots

Before After
ycui_46_before ycui_46_after

📈 Coverage

Code

100%
image

Documentation

100%
image

@mpospese mpospese added the bug Something isn't working label Mar 20, 2023
@mpospese mpospese self-assigned this Mar 20, 2023
@mpospese mpospese merged commit 271bcdd into main Mar 20, 2023
@mpospese mpospese deleted the issue/46-clamp-rgb-channel-values branch March 20, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Clamp rgb channel values to {0...1} (i.e. 0x00 – 0xFF) when displaying as hex string
3 participants