-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Color interpolation with configurable color spaces #6442
Conversation
@tmcw, thanks for your PR! By analyzing this pull request, we identified @jfirebaugh and @yhahn to be potential reviewers. |
I think eventually we'll need a set of color-space-specific classes --
|
78ea832
to
e0f00fe
Compare
@jfirebaugh want to take a look at the code and the approach? This now passes unit tests locally, but there are at least three ways I could implement the to&from RGB/LCH conversion, and I chose the one I could get to work, not necessarily the most idiomatic. |
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.
Types look good, just a few small nits.
PropertyEvaluator<Color>::operator()
duplicates a lot of PropertyEvaluator<T>::operator()
but I imagine that's something you're still working on.
@@ -3,6 +3,14 @@ | |||
#include <vector> | |||
#include <utility> | |||
|
|||
using EnumType = uint32_t; | |||
|
|||
enum class ColorSpace : EnumType { |
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.
Delete EnumType
; let the compiler choose.
@@ -15,19 +23,26 @@ class Function { | |||
explicit Function(Stops stops_, float base_) | |||
: base(base_), stops(std::move(stops_)) {} | |||
|
|||
explicit Function(Stops stops_, float base_, ColorSpace colorSpace_) |
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.
Combine with the previous constructor using a default parameter (ColorSpace colorSpace_ = ColorSpace::RGB
).
@@ -14,9 +16,14 @@ class Color { | |||
float b = 0.0f; | |||
float a = 0.0f; | |||
|
|||
ColorLAB to_lab(); |
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.
toLAB
@@ -14,9 +16,14 @@ class Color { | |||
float b = 0.0f; | |||
float a = 0.0f; | |||
|
|||
ColorLAB to_lab(); | |||
ColorHCL to_hcl(); |
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.
toHCL
static constexpr Color black() { return { 0.0f, 0.0f, 0.0f, 1.0f }; }; | ||
static constexpr Color white() { return { 1.0f, 1.0f, 1.0f, 1.0f }; }; | ||
|
||
static Color from_lab(const ColorLAB); |
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.
fromLAB
/fromHCL
Parameter type should be const ColorLAB&
This is just a start so I can get an idea from the C++ illuminati about whether it's the right direction. Approach here is * Since colors are arrays in JS and objects in C++, instead of a rgbToLab() method, there's a to_lab() method on the color object
* Default parameter for colorSpace in Function * to_lab -> toLab, to_hcl -> toHCL, from_lab -> fromLAB, from_hcl -> fromHCL * Pass colors by reference, not value * Don't explicitly choose a type for the ColorSpace enum
f405e5e
to
7e264d1
Compare
Looks like the changes requested in #6442 (review) have been implemented. @tmcw, would you mind rebasing this PR and resolving the conflicts? |
This requires some non-trival rework now that data-driven properties have landed. |
This is just a start so I can get an idea from the C++ illuminati
about whether it's the right direction. Approach here is
rgbToLab() method, there's a to_lab() method on the color object
Connected to mapbox/mapbox-gl-js#3245 - the GL JS side