-
Notifications
You must be signed in to change notification settings - Fork 218
Use context2D to convert CSS4 colors to display-p3 #2145
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
Open
Fil
wants to merge
7
commits into
main
Choose a base branch
from
fil/colorSpace-hack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
38cf4a8
raster colorSpace
mbostock 0d3455b
Use context2D to convert CSS4 colors to display-p3
Fil 0e0ea85
* use the canvas converter for colors that d3.rgb can't parse (CSS4)
Fil d84d5bf
Merge branch 'main' into fil/colorSpace-hack
Fil 743ffc9
support opacity in literal colors
Fil 2eb64b2
fix test
Fil fc7ed80
prestier
Fil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t like switching to the
canvasConverterin the sRGB case when the opacity is NaN… I would prefer to always use the simplergbConvertin the sRGB case (the current behavior), and allow the user to opt-in to thecanvasConverterimplementation if desired (to have the browser handle color conversion), and make thecanvasConverterimplementation the default in the non-sRGB case. We could also expose these converter implementations similar to how we exposeinterpolatorBarycentricetc. This would also allow you to force “direct” (or “vivid”) conversion from RGB bytes to P3 XYZ if desired, though perhaps ill-advised.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This converter adds support both for (a) CSS4 color strings in the
sRGBspace, and (b)display-p3. (The NaN check is only for additional speed in thesRGBcase whered3.rgbwould be faster, so we try that first, then switch to canvas as a fall-back; but it has an additional cost for all invalid color strings.)I can see how we could want (a) to be opt-in, so that by default we only use
d3.rgb, for simplicity—I'm not sure if it's better for the user but at least it would not be slower in the case where many colors are invalid strings.I feel that the fact that we are converting the color string through canvas is an implementation detail, so I'd be wary about exposing this under the name "canvas". Maybe
colorConverter: "css4"would be a better name?And imo using this converter with
sRGBshould still try to parse withd3.rgbfirst, for speed.PS: Re-reading the code I see that it doesn't support
rgbacolors, as it drops theapart. This feels wrong. (Edit: FIXED)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think given the complexity it is inherently a leaky abstraction and the user can decide whether to use our limited color parser or (at the expense of performance) the canvas-based one.