-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Create util functions to convert Color <-> uint8_t RGBA values #45139
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Summary: ## Changelog Sometimes we pass down int RGBA values in [0, 255] to represent color components in ReactNative; and other times we use float. Since we introduce display P3, we probably want to use color depth more than 8bit In the first case, when RGBA are passed down as uint8_t, we can directly calculate Color/SharedColor without normalizing them to [0,1] and scale back to [0, 255] as `colorFromComponents` does; otherwise there could be some precision loss.. So here I'm adding some new utils for that purpose: see `colorFromRGBA`, `redFromColor`, `greenFromColor`, etc [Internal] Examples in codebase: * rgba in [0, 255]: https://www.internalfb.com/code/fbsource/[67148a47147b0e15f0f0748003394040611c2bc2]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/graphics/fromRawValueShared.h?lines=28-35 * rgba in [0, 1]: https://www.internalfb.com/code/fbsource/[67148a47147b0e15f0f0748003394040611c2bc2]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/graphics/fromRawValueShared.h?lines=37-45 https://www.internalfb.com/code/fbsource/[67148a47147b0e15f0f0748003394040611c2bc2]/xplat/js/react-native-github/packages/react-native/ReactCommon/react/renderer/graphics/fromRawValueShared.h?lines=47-64 Reviewed By: rshest Differential Revision: D58872165
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D58872165 |
Base commit: 4273571 |
Contributor
|
This pull request has been merged in b5683a7. |
|
This pull request was successfully merged by @zeyap in b5683a7. When will my fix make it into a release? | How to file a pick request? |
zeyap
added a commit
to zeyap/react-native
that referenced
this pull request
Jul 10, 2024
Summary: ## Changelog As a followup to facebook#45139 There I only implemented `hostPlatformColorFromRGBA` and `alpha/red/green/blueFromHostPlatformColor` on cxx platform, then used cxx platform specific method at some places. but really I should implement and use methods in `Color.h` that are platform agnostic * cxx/android: platform color format is int32_t, RGBA are 8bit unsigned int ([0,255]) * windows: platform color format is `winrt::Windows::UI::Color` where RGBA props are 8bit unsigned ints ([0,255]) * apple: platform color format is `UIColor` where RGBA props are floats in [0,1] [Internal] previous change D58872165 Differential Revision: D59593659
facebook-github-bot
pushed a commit
that referenced
this pull request
Jul 15, 2024
Summary: Pull Request resolved: #45365 ## Changelog As a followup to #45139 There I only implemented `hostPlatformColorFromRGBA` and `alpha/red/green/blueFromHostPlatformColor` on cxx platform, then used cxx platform specific method at some places. but really I should implement and use methods in `Color.h` that are platform agnostic * cxx/android: platform color format is int32_t, RGBA are 8bit unsigned int ([0,255]) * windows: platform color format is `winrt::Windows::UI::Color` where RGBA props are 8bit unsigned ints ([0,255]) * apple: platform color format is `UIColor` where RGBA props are floats in [0,1] [Internal] previous change D58872165 Reviewed By: christophpurrer Differential Revision: D59593659 fbshipit-source-id: 5d18419039817510e607d4e3f632c207d25c30a3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
CLA Signed
This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
fb-exported
Merged
This PR has been merged.
p: Facebook
Partner: Facebook
Partner
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.
Summary:
Changelog
Sometimes we pass down int RGBA values in [0, 255] to represent color components in ReactNative;
and other times we use float. Since we introduce display P3, we probably want to use color depth more than 8bit
In the first case, when RGBA are passed down as uint8_t, we can directly calculate Color/SharedColor without normalizing them to [0,1] and scale back to [0, 255] as
colorFromComponentsdoes; otherwise there could be some precision loss..So here I'm adding some new utils for that purpose: see
colorFromRGBA,redFromColor,greenFromColor, etcReviewed By: rshest
Differential Revision: D58872165