This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <mbgl/util/optional.hpp> | ||
#include <string> | ||
|
||
namespace mbgl { | ||
|
||
// Stores a LAB color, with all four channels ranging from 0..1 | ||
class ColorLAB { | ||
public: | ||
float l = 0.0f; | ||
float a = 0.0f; | ||
float b = 0.0f; | ||
float A = 0.0f; | ||
}; | ||
|
||
constexpr bool operator==(const ColorLAB& colorA, const ColorLAB& colorB) { | ||
return colorA.l == colorB.l && colorA.a == colorB.a && colorA.b == colorB.b && colorA.A == colorB.A; | ||
} | ||
|
||
constexpr bool operator!=(const ColorLAB& colorA, const ColorLAB& colorB) { | ||
return !(colorA == colorB); | ||
} | ||
|
||
} // namespace mbgl |
This file contains 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <mbgl/test/util.hpp> | ||
|
||
#include <mbgl/util/constants.hpp> | ||
#include <mbgl/util/color.hpp> | ||
#include <mbgl/util/color_lab.hpp> | ||
|
||
using namespace mbgl; | ||
|
||
TEST(Color, CanParse) { | ||
optional<Color> result = Color::parse("#00ff00"); | ||
ASSERT_DOUBLE_EQ( result->r, 0); | ||
ASSERT_DOUBLE_EQ( result->g, 1); | ||
ASSERT_DOUBLE_EQ( result->b, 0); | ||
} | ||
|
||
TEST(Color, InvalidColor) { | ||
optional<Color> result = Color::parse(" not a color value"); | ||
|
||
ASSERT_DOUBLE_EQ( result->r, 0); | ||
ASSERT_DOUBLE_EQ( result->g, 0); | ||
ASSERT_DOUBLE_EQ( result->b, 0); | ||
} | ||
|
||
TEST(Color, ColorLAB) { | ||
optional<Color> result = Color::parse("#00ff00"); | ||
optional<ColorLAB> labColor = result->to_lab(); | ||
|
||
ASSERT_DOUBLE_EQ( labColor->l, 100); | ||
ASSERT_DOUBLE_EQ( labColor->a, 0); | ||
ASSERT_DOUBLE_EQ( labColor->b, 0); | ||
} |