2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2018-10-10 16:49:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2024-07-24 18:58:00 -06:00
|
|
|
#include <math.h>
|
|
|
|
|
|
2020-08-25 16:28:36 +02:00
|
|
|
#include <AK/Assertions.h>
|
2020-10-26 11:47:38 -04:00
|
|
|
#include <AK/Format.h>
|
2020-02-14 23:28:42 +01:00
|
|
|
#include <AK/Forward.h>
|
2023-01-18 16:46:08 -05:00
|
|
|
#include <AK/Math.h>
|
2020-02-14 23:28:42 +01:00
|
|
|
#include <AK/StdLibExtras.h>
|
2020-03-29 19:03:13 +02:00
|
|
|
#include <LibIPC/Forward.h>
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
namespace Gfx {
|
|
|
|
|
|
2022-03-04 22:05:20 +01:00
|
|
|
typedef u32 ARGB32;
|
2019-01-10 05:36:32 +01:00
|
|
|
|
2024-08-02 11:37:45 +02:00
|
|
|
enum class AlphaType {
|
|
|
|
|
Premultiplied,
|
|
|
|
|
Unpremultiplied,
|
|
|
|
|
};
|
|
|
|
|
|
LibGfx: Store alpha type information in `Gfx::Bitmap`
We use instances of `Gfx::Bitmap` to move pixel data all the way from
raw image bytes up to the Skia renderer. A vital piece of information
for correct blending of bitmaps is the alpha type, i.e. are we dealing
with premultiplied or unpremultiplied color values?
Premultiplied means that the RGB colors have been multiplied with the
associated alpha value, i.e. RGB(255, 255, 255) with an alpha of 2% is
stored as RGBA(5, 5, 5, 2%).
Unpremultiplied means that the original RGB colors are stored,
regardless of the alpha value. I.e. RGB(255, 255, 255) with an alpha of
2% is stored as RGBA(255, 255, 255, 2%).
It is important to know how the color data is stored in a
`Gfx::Bitmap`, because correct blending depends on knowing the alpha
type: premultiplied blending uses `S + (1 - A) * D`, while
unpremultiplied blending uses `A * S + (1 - A) * D`.
This adds the alpha type information to `Gfx::Bitmap` across the board.
It isn't used anywhere yet.
2024-08-02 12:52:14 +02:00
|
|
|
inline bool is_valid_alpha_type(u32 alpha_type)
|
|
|
|
|
{
|
|
|
|
|
switch (alpha_type) {
|
|
|
|
|
case (u32)AlphaType::Premultiplied:
|
|
|
|
|
case (u32)AlphaType::Unpremultiplied:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-07 18:29:52 +01:00
|
|
|
struct HSV {
|
|
|
|
|
double hue { 0 };
|
|
|
|
|
double saturation { 0 };
|
|
|
|
|
double value { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2022-08-17 18:03:41 +02:00
|
|
|
struct YUV {
|
|
|
|
|
float y { 0 };
|
|
|
|
|
float u { 0 };
|
|
|
|
|
float v { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2024-02-11 18:07:38 -07:00
|
|
|
struct Oklab {
|
|
|
|
|
float L { 0 };
|
|
|
|
|
float a { 0 };
|
|
|
|
|
float b { 0 };
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-10 16:49:36 +02:00
|
|
|
class Color {
|
|
|
|
|
public:
|
2024-05-23 22:44:33 -04:00
|
|
|
enum class NamedColor {
|
2020-06-13 20:03:19 +02:00
|
|
|
Transparent,
|
2018-10-12 20:05:11 +02:00
|
|
|
Black,
|
|
|
|
|
White,
|
|
|
|
|
Red,
|
|
|
|
|
Green,
|
2019-05-06 00:59:33 +02:00
|
|
|
Cyan,
|
2018-10-12 20:05:11 +02:00
|
|
|
Blue,
|
2019-01-12 04:02:36 +01:00
|
|
|
Yellow,
|
|
|
|
|
Magenta,
|
2018-10-12 23:02:23 +02:00
|
|
|
DarkGray,
|
|
|
|
|
MidGray,
|
|
|
|
|
LightGray,
|
2019-06-30 09:23:16 +02:00
|
|
|
WarmGray,
|
2019-11-18 19:02:10 +01:00
|
|
|
DarkCyan,
|
2019-03-18 20:56:45 +01:00
|
|
|
DarkGreen,
|
|
|
|
|
DarkBlue,
|
|
|
|
|
DarkRed,
|
2019-11-18 19:02:10 +01:00
|
|
|
MidCyan,
|
2019-03-20 04:21:58 +01:00
|
|
|
MidGreen,
|
|
|
|
|
MidRed,
|
|
|
|
|
MidBlue,
|
|
|
|
|
MidMagenta,
|
2022-11-27 02:10:23 +01:00
|
|
|
LightBlue,
|
2018-10-12 20:05:11 +02:00
|
|
|
};
|
|
|
|
|
|
2024-05-23 22:44:33 -04:00
|
|
|
using enum NamedColor;
|
|
|
|
|
|
2021-09-15 23:58:01 -07:00
|
|
|
constexpr Color() = default;
|
2021-02-07 16:51:17 +01:00
|
|
|
constexpr Color(NamedColor);
|
2020-05-30 16:06:59 +02:00
|
|
|
constexpr Color(u8 r, u8 g, u8 b)
|
2019-06-07 11:46:55 +02:00
|
|
|
: m_value(0xff000000 | (r << 16) | (g << 8) | b)
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-05-30 16:06:59 +02:00
|
|
|
constexpr Color(u8 r, u8 g, u8 b, u8 a)
|
2019-06-07 11:46:55 +02:00
|
|
|
: m_value((a << 24) | (r << 16) | (g << 8) | b)
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-02-19 01:42:53 +01:00
|
|
|
|
2020-05-30 16:06:59 +02:00
|
|
|
static constexpr Color from_rgb(unsigned rgb) { return Color(rgb | 0xff000000); }
|
2022-03-04 22:28:59 +01:00
|
|
|
static constexpr Color from_argb(unsigned argb) { return Color(argb); }
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2022-08-17 18:03:41 +02:00
|
|
|
static constexpr Color from_yuv(YUV const& yuv) { return from_yuv(yuv.y, yuv.u, yuv.v); }
|
|
|
|
|
static constexpr Color from_yuv(float y, float u, float v)
|
|
|
|
|
{
|
|
|
|
|
// https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en Table 4, Items 8 and 9 arithmetically inverted
|
|
|
|
|
float r = y + v / 0.877f;
|
|
|
|
|
float b = y + u / 0.493f;
|
|
|
|
|
float g = (y - 0.299f * r - 0.114f * b) / 0.587f;
|
|
|
|
|
r = clamp(r, 0.0f, 1.0f);
|
|
|
|
|
g = clamp(g, 0.0f, 1.0f);
|
|
|
|
|
b = clamp(b, 0.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
return { static_cast<u8>(floorf(r * 255.0f)), static_cast<u8>(floorf(g * 255.0f)), static_cast<u8>(floorf(b * 255.0f)) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://www.itu.int/rec/R-REC-BT.1700-0-200502-I/en Table 4
|
|
|
|
|
constexpr YUV to_yuv() const
|
|
|
|
|
{
|
|
|
|
|
float r = red() / 255.0f;
|
|
|
|
|
float g = green() / 255.0f;
|
|
|
|
|
float b = blue() / 255.0f;
|
|
|
|
|
// Item 8
|
|
|
|
|
float y = 0.299f * r + 0.587f * g + 0.114f * b;
|
|
|
|
|
// Item 9
|
|
|
|
|
float u = 0.493f * (b - y);
|
|
|
|
|
float v = 0.877f * (r - y);
|
|
|
|
|
y = clamp(y, 0.0f, 1.0f);
|
|
|
|
|
u = clamp(u, -1.0f, 1.0f);
|
|
|
|
|
v = clamp(v, -1.0f, 1.0f);
|
|
|
|
|
return { y, u, v };
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-21 17:13:52 +00:00
|
|
|
static constexpr Color from_hsl(float h_degrees, float s, float l) { return from_hsla(h_degrees, s, l, 1.0); }
|
|
|
|
|
static constexpr Color from_hsla(float h_degrees, float s, float l, float a)
|
2021-07-19 16:38:47 +01:00
|
|
|
{
|
|
|
|
|
// Algorithm from https://www.w3.org/TR/css-color-3/#hsl-color
|
2024-11-21 23:18:22 +01:00
|
|
|
|
|
|
|
|
float h = fmodf(h_degrees, 360.0f);
|
|
|
|
|
if (h < 0.0)
|
|
|
|
|
h += 360.0f;
|
|
|
|
|
|
2022-03-21 17:13:52 +00:00
|
|
|
s = clamp(s, 0.0f, 1.0f);
|
|
|
|
|
l = clamp(l, 0.0f, 1.0f);
|
|
|
|
|
a = clamp(a, 0.0f, 1.0f);
|
2021-07-19 16:38:47 +01:00
|
|
|
|
2024-11-21 23:18:22 +01:00
|
|
|
auto to_rgb = [](float h, float s, float l, float offset) {
|
|
|
|
|
float k = fmodf(offset + h / 30.0f, 12.0f);
|
|
|
|
|
float a = s * min(l, 1.0f - l);
|
|
|
|
|
return l - a * max(-1.0f, min(min(k - 3.0f, 9.0f - k), 1.0f));
|
2021-07-19 16:38:47 +01:00
|
|
|
};
|
|
|
|
|
|
2024-11-21 23:18:22 +01:00
|
|
|
float r = to_rgb(h, s, l, 0.0f);
|
|
|
|
|
float g = to_rgb(h, s, l, 8.0f);
|
|
|
|
|
float b = to_rgb(h, s, l, 4.0f);
|
|
|
|
|
|
2022-03-21 17:13:52 +00:00
|
|
|
u8 r_u8 = clamp(lroundf(r * 255.0f), 0, 255);
|
|
|
|
|
u8 g_u8 = clamp(lroundf(g * 255.0f), 0, 255);
|
|
|
|
|
u8 b_u8 = clamp(lroundf(b * 255.0f), 0, 255);
|
|
|
|
|
u8 a_u8 = clamp(lroundf(a * 255.0f), 0, 255);
|
2021-07-19 16:38:47 +01:00
|
|
|
return Color(r_u8, g_u8, b_u8, a_u8);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-13 23:17:40 -05:00
|
|
|
static Color from_a98rgb(float r, float g, float b, float alpha = 1.0f);
|
2024-11-14 00:26:39 -05:00
|
|
|
static Color from_display_p3(float r, float g, float b, float alpha = 1.0f);
|
LibGfx+LibWeb/CSS: Add support for the `lab()` color function
The support in LibWeb is quite easy as the previous commits introduced
helpers to support lab-like colors.
Now for the methods in Color:
- The formulas in `from_lab()` are derived from the CIEXYZ to CIELAB
formulas the "Colorimetry" paper published by the CIE.
- The conversion in `from_xyz50()` can be decomposed in multiple steps
XYZ D50 -> XYZ D65 -> Linear sRGB -> sRGB. The two first conversion
are done with a singular matrix operation. This matrix was generated
with a Python script [1].
This commit makes us pass all the `css/css-color/lab-00*.html` WPT
tests (0 to 7 at the time of writing).
[1] Python script used to generate the XYZ D50 -> Linear sRGB
conversion:
```python
import numpy as np
# http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
# First let's convert from D50 to D65 using the Bradford method.
m_a = np.array([
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
])
# D50
chromaticities_source = np.array([0.96422, 1, 0.82521])
# D65
chromaticities_destination = np.array([0.9505, 1, 1.0890])
cone_response_source = m_a @ chromaticities_source
cone_response_destination = m_a @ chromaticities_destination
cone_response_ratio = cone_response_destination / cone_response_source
m = np.linalg.inv(m_a) @ np.diagflat(cone_response_ratio) @ m_a
D50_to_D65 = m
# https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
# Then, the matrix to convert to linear sRGB.
xyz_65_to_srgb = np.array([
[3.2406, - 1.5372, - 0.4986],
[-0.9689, + 1.8758, 0.0415],
[0.0557, - 0.2040, 1.0570]
])
# Finally, let's retrieve the final transformation.
xyz_50_to_srgb = xyz_65_to_srgb @ D50_to_D65
print(xyz_50_to_srgb)
```
2024-10-26 17:16:13 -04:00
|
|
|
static Color from_lab(float L, float a, float b, float alpha = 1.0f);
|
2024-11-14 22:46:34 -05:00
|
|
|
static Color from_linear_srgb(float r, float g, float b, float alpha = 1.0f);
|
2024-11-14 22:10:16 -05:00
|
|
|
static Color from_pro_photo_rgb(float r, float g, float b, float alpha = 1.0f);
|
2024-11-14 22:43:43 -05:00
|
|
|
static Color from_rec2020(float r, float g, float b, float alpha = 1.0f);
|
LibGfx+LibWeb/CSS: Add support for the `lab()` color function
The support in LibWeb is quite easy as the previous commits introduced
helpers to support lab-like colors.
Now for the methods in Color:
- The formulas in `from_lab()` are derived from the CIEXYZ to CIELAB
formulas the "Colorimetry" paper published by the CIE.
- The conversion in `from_xyz50()` can be decomposed in multiple steps
XYZ D50 -> XYZ D65 -> Linear sRGB -> sRGB. The two first conversion
are done with a singular matrix operation. This matrix was generated
with a Python script [1].
This commit makes us pass all the `css/css-color/lab-00*.html` WPT
tests (0 to 7 at the time of writing).
[1] Python script used to generate the XYZ D50 -> Linear sRGB
conversion:
```python
import numpy as np
# http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
# First let's convert from D50 to D65 using the Bradford method.
m_a = np.array([
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
])
# D50
chromaticities_source = np.array([0.96422, 1, 0.82521])
# D65
chromaticities_destination = np.array([0.9505, 1, 1.0890])
cone_response_source = m_a @ chromaticities_source
cone_response_destination = m_a @ chromaticities_destination
cone_response_ratio = cone_response_destination / cone_response_source
m = np.linalg.inv(m_a) @ np.diagflat(cone_response_ratio) @ m_a
D50_to_D65 = m
# https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
# Then, the matrix to convert to linear sRGB.
xyz_65_to_srgb = np.array([
[3.2406, - 1.5372, - 0.4986],
[-0.9689, + 1.8758, 0.0415],
[0.0557, - 0.2040, 1.0570]
])
# Finally, let's retrieve the final transformation.
xyz_50_to_srgb = xyz_65_to_srgb @ D50_to_D65
print(xyz_50_to_srgb)
```
2024-10-26 17:16:13 -04:00
|
|
|
static Color from_xyz50(float x, float y, float z, float alpha = 1.0f);
|
2024-10-27 14:02:10 -04:00
|
|
|
static Color from_xyz65(float x, float y, float z, float alpha = 1.0f);
|
LibGfx+LibWeb/CSS: Add support for the `lab()` color function
The support in LibWeb is quite easy as the previous commits introduced
helpers to support lab-like colors.
Now for the methods in Color:
- The formulas in `from_lab()` are derived from the CIEXYZ to CIELAB
formulas the "Colorimetry" paper published by the CIE.
- The conversion in `from_xyz50()` can be decomposed in multiple steps
XYZ D50 -> XYZ D65 -> Linear sRGB -> sRGB. The two first conversion
are done with a singular matrix operation. This matrix was generated
with a Python script [1].
This commit makes us pass all the `css/css-color/lab-00*.html` WPT
tests (0 to 7 at the time of writing).
[1] Python script used to generate the XYZ D50 -> Linear sRGB
conversion:
```python
import numpy as np
# http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
# First let's convert from D50 to D65 using the Bradford method.
m_a = np.array([
[0.8951000, 0.2664000, -0.1614000],
[-0.7502000, 1.7135000, 0.0367000],
[0.0389000, -0.0685000, 1.0296000]
])
# D50
chromaticities_source = np.array([0.96422, 1, 0.82521])
# D65
chromaticities_destination = np.array([0.9505, 1, 1.0890])
cone_response_source = m_a @ chromaticities_source
cone_response_destination = m_a @ chromaticities_destination
cone_response_ratio = cone_response_destination / cone_response_source
m = np.linalg.inv(m_a) @ np.diagflat(cone_response_ratio) @ m_a
D50_to_D65 = m
# https://en.wikipedia.org/wiki/SRGB#From_CIE_XYZ_to_sRGB
# Then, the matrix to convert to linear sRGB.
xyz_65_to_srgb = np.array([
[3.2406, - 1.5372, - 0.4986],
[-0.9689, + 1.8758, 0.0415],
[0.0557, - 0.2040, 1.0570]
])
# Finally, let's retrieve the final transformation.
xyz_50_to_srgb = xyz_65_to_srgb @ D50_to_D65
print(xyz_50_to_srgb)
```
2024-10-26 17:16:13 -04:00
|
|
|
|
2024-02-11 18:07:38 -07:00
|
|
|
// https://bottosson.github.io/posts/oklab/
|
|
|
|
|
static constexpr Color from_oklab(float L, float a, float b, float alpha = 1.0f)
|
|
|
|
|
{
|
|
|
|
|
float l = L + 0.3963377774f * a + 0.2158037573f * b;
|
|
|
|
|
float m = L - 0.1055613458f * a - 0.0638541728f * b;
|
|
|
|
|
float s = L - 0.0894841775f * a - 1.2914855480f * b;
|
|
|
|
|
|
|
|
|
|
l = l * l * l;
|
|
|
|
|
m = m * m * m;
|
|
|
|
|
s = s * s * s;
|
|
|
|
|
|
|
|
|
|
float red = 4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s;
|
|
|
|
|
float green = -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s;
|
|
|
|
|
float blue = -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s;
|
|
|
|
|
|
2024-10-27 12:58:33 -04:00
|
|
|
return from_linear_srgb(red, green, blue, alpha);
|
2024-02-11 18:07:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://bottosson.github.io/posts/oklab/
|
|
|
|
|
constexpr Oklab to_oklab()
|
|
|
|
|
{
|
|
|
|
|
auto srgb_to_linear = [](float c) {
|
|
|
|
|
return c >= 0.04045f ? pow((c + 0.055f) / 1.055f, 2.4f) : c / 12.92f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
float r = srgb_to_linear(red() / 255.f);
|
|
|
|
|
float g = srgb_to_linear(green() / 255.f);
|
|
|
|
|
float b = srgb_to_linear(blue() / 255.f);
|
|
|
|
|
|
|
|
|
|
float l = cbrtf(0.4122214708f * r + 0.5363325363f * g + 0.0514459929f * b);
|
|
|
|
|
float m = cbrtf(0.2119034982f * r + 0.6806995451f * g + 0.1073969566f * b);
|
|
|
|
|
float s = cbrtf(0.0883024619f * r + 0.2817188376f * g + 0.6299787005f * b);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
0.2104542553f * l + 0.7936177850f * m - 0.0040720468f * s,
|
|
|
|
|
1.9779984951f * l - 2.4285922050f * m + 0.4505937099f * s,
|
|
|
|
|
0.0259040371f * l + 0.7827717662f * m - 0.8086757660f * s,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 02:35:41 +11:00
|
|
|
constexpr u8 red() const { return (m_value >> 16) & 0xff; }
|
|
|
|
|
constexpr u8 green() const { return (m_value >> 8) & 0xff; }
|
|
|
|
|
constexpr u8 blue() const { return m_value & 0xff; }
|
|
|
|
|
constexpr u8 alpha() const { return (m_value >> 24) & 0xff; }
|
2019-02-07 23:13:47 +01:00
|
|
|
|
2024-08-02 11:37:45 +02:00
|
|
|
constexpr void set_alpha(u8 value, AlphaType alpha_type = AlphaType::Unpremultiplied)
|
2019-02-07 23:13:47 +01:00
|
|
|
{
|
2024-08-02 11:37:45 +02:00
|
|
|
switch (alpha_type) {
|
|
|
|
|
case AlphaType::Premultiplied:
|
|
|
|
|
m_value = value << 24
|
|
|
|
|
| (red() * value / 255) << 16
|
|
|
|
|
| (green() * value / 255) << 8
|
|
|
|
|
| blue() * value / 255;
|
|
|
|
|
break;
|
|
|
|
|
case AlphaType::Unpremultiplied:
|
|
|
|
|
m_value = (m_value & 0x00ffffff) | value << 24;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
2019-02-07 23:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-20 10:19:03 -07:00
|
|
|
constexpr void set_red(u8 value)
|
2019-06-16 15:09:11 +02:00
|
|
|
{
|
|
|
|
|
m_value &= 0xff00ffff;
|
|
|
|
|
m_value |= value << 16;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 10:19:03 -07:00
|
|
|
constexpr void set_green(u8 value)
|
2019-06-16 15:09:11 +02:00
|
|
|
{
|
|
|
|
|
m_value &= 0xffff00ff;
|
|
|
|
|
m_value |= value << 8;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 10:19:03 -07:00
|
|
|
constexpr void set_blue(u8 value)
|
2019-06-16 15:09:11 +02:00
|
|
|
{
|
|
|
|
|
m_value &= 0xffffff00;
|
|
|
|
|
m_value |= value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-02 11:37:45 +02:00
|
|
|
constexpr Color with_alpha(u8 alpha, AlphaType alpha_type = AlphaType::Unpremultiplied) const
|
2019-02-19 01:42:53 +01:00
|
|
|
{
|
2024-08-02 11:37:45 +02:00
|
|
|
Color color_with_alpha = Color(m_value);
|
|
|
|
|
color_with_alpha.set_alpha(alpha, alpha_type);
|
|
|
|
|
return color_with_alpha;
|
2019-02-19 01:42:53 +01:00
|
|
|
}
|
|
|
|
|
|
2024-08-02 13:15:45 +02:00
|
|
|
constexpr Color to_unpremultiplied() const
|
|
|
|
|
{
|
|
|
|
|
if (alpha() == 0 || alpha() == 255)
|
|
|
|
|
return *this;
|
|
|
|
|
return Color(
|
|
|
|
|
red() * 255 / alpha(),
|
|
|
|
|
green() * 255 / alpha(),
|
|
|
|
|
blue() * 255 / alpha(),
|
|
|
|
|
alpha());
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr Color blend(Color source) const
|
2019-02-19 01:42:53 +01:00
|
|
|
{
|
2023-06-01 13:18:19 +02:00
|
|
|
if (alpha() == 0 || source.alpha() == 255)
|
2019-02-19 01:42:53 +01:00
|
|
|
return source;
|
|
|
|
|
|
2023-06-01 13:18:19 +02:00
|
|
|
if (source.alpha() == 0)
|
2019-02-19 01:42:53 +01:00
|
|
|
return *this;
|
|
|
|
|
|
2024-01-21 23:29:01 +00:00
|
|
|
int const d = 255 * (alpha() + source.alpha()) - alpha() * source.alpha();
|
|
|
|
|
u8 r = (red() * alpha() * (255 - source.alpha()) + source.red() * 255 * source.alpha()) / d;
|
|
|
|
|
u8 g = (green() * alpha() * (255 - source.alpha()) + source.green() * 255 * source.alpha()) / d;
|
|
|
|
|
u8 b = (blue() * alpha() * (255 - source.alpha()) + source.blue() * 255 * source.alpha()) / d;
|
|
|
|
|
u8 a = d / 255;
|
2019-02-19 01:42:53 +01:00
|
|
|
return Color(r, g, b, a);
|
|
|
|
|
}
|
2021-04-20 12:39:48 -07:00
|
|
|
|
2023-02-18 13:40:10 +00:00
|
|
|
ALWAYS_INLINE Color mixed_with(Color other, float weight) const
|
2023-02-17 19:02:03 +00:00
|
|
|
{
|
2023-02-17 19:03:40 +00:00
|
|
|
if (alpha() == other.alpha() || with_alpha(0) == other.with_alpha(0))
|
|
|
|
|
return interpolate(other, weight);
|
2023-02-17 19:02:03 +00:00
|
|
|
// Fallback to slower, but more visually pleasing premultiplied alpha mix.
|
|
|
|
|
// This is needed for linear-gradient()s in LibWeb.
|
|
|
|
|
auto mixed_alpha = mix<float>(alpha(), other.alpha(), weight);
|
|
|
|
|
auto premultiplied_mix_channel = [&](float channel, float other_channel, float weight) {
|
|
|
|
|
return round_to<u8>(mix<float>(channel * alpha(), other_channel * other.alpha(), weight) / mixed_alpha);
|
|
|
|
|
};
|
|
|
|
|
return Gfx::Color {
|
|
|
|
|
premultiplied_mix_channel(red(), other.red(), weight),
|
|
|
|
|
premultiplied_mix_channel(green(), other.green(), weight),
|
|
|
|
|
premultiplied_mix_channel(blue(), other.blue(), weight),
|
|
|
|
|
round_to<u8>(mixed_alpha),
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-15 08:31:22 +01:00
|
|
|
|
2023-02-18 13:40:10 +00:00
|
|
|
ALWAYS_INLINE Color interpolate(Color other, float weight) const noexcept
|
2021-04-20 12:39:48 -07:00
|
|
|
{
|
2023-02-17 19:03:40 +00:00
|
|
|
return Gfx::Color {
|
|
|
|
|
round_to<u8>(mix<float>(red(), other.red(), weight)),
|
|
|
|
|
round_to<u8>(mix<float>(green(), other.green(), weight)),
|
|
|
|
|
round_to<u8>(mix<float>(blue(), other.blue(), weight)),
|
|
|
|
|
round_to<u8>(mix<float>(alpha(), other.alpha(), weight)),
|
|
|
|
|
};
|
2021-04-20 12:39:48 -07:00
|
|
|
}
|
2019-01-25 05:01:27 +01:00
|
|
|
|
2022-12-06 19:43:46 +00:00
|
|
|
constexpr Color multiply(Color other) const
|
2021-01-02 18:15:27 +01:00
|
|
|
{
|
|
|
|
|
return Color(
|
|
|
|
|
red() * other.red() / 255,
|
|
|
|
|
green() * other.green() / 255,
|
|
|
|
|
blue() * other.blue() / 255,
|
|
|
|
|
alpha() * other.alpha() / 255);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 19:43:46 +00:00
|
|
|
constexpr float distance_squared_to(Color other) const
|
2022-09-30 12:26:13 -05:00
|
|
|
{
|
2022-11-28 22:27:38 +00:00
|
|
|
int delta_red = other.red() - red();
|
|
|
|
|
int delta_green = other.green() - green();
|
|
|
|
|
int delta_blue = other.blue() - blue();
|
|
|
|
|
int delta_alpha = other.alpha() - alpha();
|
|
|
|
|
auto rgb_distance = (delta_red * delta_red + delta_green * delta_green + delta_blue * delta_blue) / (3.0f * 255 * 255);
|
|
|
|
|
return delta_alpha * delta_alpha / (2.0f * 255 * 255) + rgb_distance * alpha() * other.alpha() / (255 * 255);
|
2022-09-30 12:26:13 -05:00
|
|
|
}
|
|
|
|
|
|
2021-09-02 17:50:06 -04:00
|
|
|
constexpr u8 luminosity() const
|
|
|
|
|
{
|
2024-05-13 10:55:29 -04:00
|
|
|
return round_to<u8>(red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
|
2021-09-02 17:50:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-12-06 19:43:46 +00:00
|
|
|
constexpr float contrast_ratio(Color other)
|
2022-05-09 00:07:24 +01:00
|
|
|
{
|
|
|
|
|
auto l1 = luminosity();
|
|
|
|
|
auto l2 = other.luminosity();
|
|
|
|
|
auto darkest = min(l1, l2) / 255.;
|
|
|
|
|
auto brightest = max(l1, l2) / 255.;
|
|
|
|
|
return (brightest + 0.05) / (darkest + 0.05);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr Color to_grayscale() const
|
2019-04-10 16:00:29 +02:00
|
|
|
{
|
2021-09-02 17:50:06 -04:00
|
|
|
auto gray = luminosity();
|
2019-04-10 16:00:29 +02:00
|
|
|
return Color(gray, gray, gray, alpha());
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-08 10:36:04 +01:00
|
|
|
constexpr Color sepia(float amount = 1.0f) const
|
|
|
|
|
{
|
|
|
|
|
auto blend_factor = 1.0f - amount;
|
|
|
|
|
|
|
|
|
|
auto r1 = 0.393f + 0.607f * blend_factor;
|
|
|
|
|
auto r2 = 0.769f - 0.769f * blend_factor;
|
|
|
|
|
auto r3 = 0.189f - 0.189f * blend_factor;
|
|
|
|
|
|
|
|
|
|
auto g1 = 0.349f - 0.349f * blend_factor;
|
|
|
|
|
auto g2 = 0.686f + 0.314f * blend_factor;
|
|
|
|
|
auto g3 = 0.168f - 0.168f * blend_factor;
|
|
|
|
|
|
|
|
|
|
auto b1 = 0.272f - 0.272f * blend_factor;
|
|
|
|
|
auto b2 = 0.534f - 0.534f * blend_factor;
|
|
|
|
|
auto b3 = 0.131f + 0.869f * blend_factor;
|
|
|
|
|
|
|
|
|
|
auto r = red();
|
|
|
|
|
auto g = green();
|
|
|
|
|
auto b = blue();
|
|
|
|
|
|
|
|
|
|
return Color(
|
|
|
|
|
clamp(lroundf(r * r1 + g * r2 + b * r3), 0, 255),
|
|
|
|
|
clamp(lroundf(r * g1 + g * g2 + b * g3), 0, 255),
|
|
|
|
|
clamp(lroundf(r * b1 + g * b2 + b * b3), 0, 255),
|
|
|
|
|
alpha());
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 19:02:00 +01:00
|
|
|
constexpr Color with_opacity(float opacity) const
|
|
|
|
|
{
|
2024-11-17 14:19:49 -05:00
|
|
|
VERIFY(opacity >= 0 && opacity <= 1);
|
|
|
|
|
return with_alpha(static_cast<u8>(round(alpha() * opacity)));
|
2023-05-18 19:02:00 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr Color darkened(float amount = 0.5f) const
|
2019-04-10 16:00:29 +02:00
|
|
|
{
|
2019-05-25 21:55:53 +02:00
|
|
|
return Color(red() * amount, green() * amount, blue() * amount, alpha());
|
2019-04-10 16:00:29 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr Color lightened(float amount = 1.2f) const
|
2019-04-12 02:50:43 +02:00
|
|
|
{
|
2019-12-24 02:24:49 +01:00
|
|
|
return Color(min(255, (int)((float)red() * amount)), min(255, (int)((float)green() * amount)), min(255, (int)((float)blue() * amount)), alpha());
|
2019-04-12 02:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
2021-11-10 11:05:21 +01:00
|
|
|
Vector<Color> shades(u32 steps, float max = 1.f) const;
|
|
|
|
|
Vector<Color> tints(u32 steps, float max = 1.f) const;
|
2021-08-31 01:48:03 +01:00
|
|
|
|
2022-08-17 18:04:08 +02:00
|
|
|
constexpr Color saturated_to(float saturation) const
|
|
|
|
|
{
|
|
|
|
|
auto hsv = to_hsv();
|
|
|
|
|
auto alpha = this->alpha();
|
|
|
|
|
auto color = Color::from_hsv(hsv.hue, static_cast<double>(saturation), hsv.value);
|
|
|
|
|
color.set_alpha(alpha);
|
|
|
|
|
return color;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr Color inverted() const
|
2019-06-11 07:28:59 +02:00
|
|
|
{
|
2020-09-07 22:25:30 -06:00
|
|
|
return Color(~red(), ~green(), ~blue(), alpha());
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-06 19:43:46 +00:00
|
|
|
constexpr Color xored(Color other) const
|
2020-09-07 22:25:30 -06:00
|
|
|
{
|
|
|
|
|
return Color(((other.m_value ^ m_value) & 0x00ffffff) | (m_value & 0xff000000));
|
2019-06-11 07:28:59 +02:00
|
|
|
}
|
|
|
|
|
|
2022-03-04 22:05:20 +01:00
|
|
|
constexpr ARGB32 value() const { return m_value; }
|
2018-10-10 16:49:36 +02:00
|
|
|
|
2022-12-06 19:43:46 +00:00
|
|
|
constexpr bool operator==(Color other) const
|
2019-06-14 19:10:43 +02:00
|
|
|
{
|
|
|
|
|
return m_value == other.m_value;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 14:10:07 +02:00
|
|
|
enum class HTMLCompatibleSerialization {
|
|
|
|
|
No,
|
|
|
|
|
Yes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[[nodiscard]] String to_string(HTMLCompatibleSerialization = HTMLCompatibleSerialization::No) const;
|
2023-11-20 20:31:39 +13:00
|
|
|
String to_string_without_alpha() const;
|
|
|
|
|
|
2023-12-16 17:49:34 +03:30
|
|
|
ByteString to_byte_string() const;
|
|
|
|
|
ByteString to_byte_string_without_alpha() const;
|
2021-11-11 00:55:02 +01:00
|
|
|
static Optional<Color> from_string(StringView);
|
2023-05-28 15:01:54 +12:00
|
|
|
static Optional<Color> from_named_css_color_string(StringView);
|
2019-03-18 04:53:09 +01:00
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
constexpr HSV to_hsv() const
|
2020-02-07 18:29:52 +01:00
|
|
|
{
|
|
|
|
|
HSV hsv;
|
|
|
|
|
double r = static_cast<double>(red()) / 255.0;
|
|
|
|
|
double g = static_cast<double>(green()) / 255.0;
|
|
|
|
|
double b = static_cast<double>(blue()) / 255.0;
|
|
|
|
|
double max = AK::max(AK::max(r, g), b);
|
|
|
|
|
double min = AK::min(AK::min(r, g), b);
|
|
|
|
|
double chroma = max - min;
|
|
|
|
|
|
|
|
|
|
if (!chroma)
|
|
|
|
|
hsv.hue = 0.0;
|
|
|
|
|
else if (max == r)
|
|
|
|
|
hsv.hue = (60.0 * ((g - b) / chroma)) + 360.0;
|
|
|
|
|
else if (max == g)
|
|
|
|
|
hsv.hue = (60.0 * ((b - r) / chroma)) + 120.0;
|
|
|
|
|
else
|
|
|
|
|
hsv.hue = (60.0 * ((r - g) / chroma)) + 240.0;
|
|
|
|
|
|
|
|
|
|
if (hsv.hue >= 360.0)
|
|
|
|
|
hsv.hue -= 360.0;
|
|
|
|
|
|
|
|
|
|
if (!max)
|
|
|
|
|
hsv.saturation = 0;
|
|
|
|
|
else
|
|
|
|
|
hsv.saturation = chroma / max;
|
|
|
|
|
|
|
|
|
|
hsv.value = max;
|
2020-08-25 16:28:36 +02:00
|
|
|
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
|
|
|
|
|
VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
|
|
|
|
|
VERIFY(hsv.value >= 0.0 && hsv.value <= 1.0);
|
2020-08-25 16:28:36 +02:00
|
|
|
|
2020-02-07 18:29:52 +01:00
|
|
|
return hsv;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-06 15:07:41 +01:00
|
|
|
static constexpr Color from_hsv(double hue, double saturation, double value)
|
2020-02-07 18:29:52 +01:00
|
|
|
{
|
|
|
|
|
return from_hsv({ hue, saturation, value });
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-24 15:22:26 +01:00
|
|
|
static constexpr Color from_hsv(HSV const& hsv)
|
2020-02-07 18:29:52 +01:00
|
|
|
{
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
|
|
|
|
|
VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
|
|
|
|
|
VERIFY(hsv.value >= 0.0 && hsv.value <= 1.0);
|
2020-08-25 16:28:36 +02:00
|
|
|
|
|
|
|
|
double hue = hsv.hue;
|
|
|
|
|
double saturation = hsv.saturation;
|
|
|
|
|
double value = hsv.value;
|
2020-02-07 18:29:52 +01:00
|
|
|
|
|
|
|
|
int high = static_cast<int>(hue / 60.0) % 6;
|
|
|
|
|
double f = (hue / 60.0) - high;
|
|
|
|
|
double c1 = value * (1.0 - saturation);
|
|
|
|
|
double c2 = value * (1.0 - saturation * f);
|
|
|
|
|
double c3 = value * (1.0 - saturation * (1.0 - f));
|
|
|
|
|
|
|
|
|
|
double r = 0;
|
|
|
|
|
double g = 0;
|
|
|
|
|
double b = 0;
|
|
|
|
|
|
|
|
|
|
switch (high) {
|
|
|
|
|
case 0:
|
|
|
|
|
r = value;
|
|
|
|
|
g = c3;
|
|
|
|
|
b = c1;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
r = c2;
|
|
|
|
|
g = value;
|
|
|
|
|
b = c1;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
r = c1;
|
|
|
|
|
g = value;
|
|
|
|
|
b = c3;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
r = c1;
|
|
|
|
|
g = c2;
|
|
|
|
|
b = value;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
r = c3;
|
|
|
|
|
g = c1;
|
|
|
|
|
b = value;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
r = value;
|
|
|
|
|
g = c1;
|
|
|
|
|
b = c2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 00:08:26 -05:00
|
|
|
auto out_r = static_cast<u8>(round(r * 255));
|
|
|
|
|
auto out_g = static_cast<u8>(round(g * 255));
|
|
|
|
|
auto out_b = static_cast<u8>(round(b * 255));
|
2020-02-07 18:29:52 +01:00
|
|
|
return Color(out_r, out_g, out_b);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-02 17:51:56 -04:00
|
|
|
constexpr Color suggested_foreground_color() const
|
|
|
|
|
{
|
|
|
|
|
return luminosity() < 128 ? Color::White : Color::Black;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 16:49:36 +02:00
|
|
|
private:
|
2022-05-01 19:02:55 +02:00
|
|
|
constexpr explicit Color(ARGB32 argb)
|
|
|
|
|
: m_value(argb)
|
2019-06-07 11:46:55 +02:00
|
|
|
{
|
|
|
|
|
}
|
2019-02-19 01:42:53 +01:00
|
|
|
|
2022-03-04 22:05:20 +01:00
|
|
|
ARGB32 m_value { 0 };
|
2018-10-10 16:49:36 +02:00
|
|
|
};
|
2019-07-23 14:56:17 +02:00
|
|
|
|
2021-04-21 11:11:38 -06:00
|
|
|
constexpr Color::Color(NamedColor named)
|
2021-02-07 16:51:17 +01:00
|
|
|
{
|
|
|
|
|
if (named == Transparent) {
|
|
|
|
|
m_value = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
u8 r;
|
|
|
|
|
u8 g;
|
|
|
|
|
u8 b;
|
|
|
|
|
} rgb;
|
|
|
|
|
|
|
|
|
|
switch (named) {
|
|
|
|
|
case Black:
|
|
|
|
|
rgb = { 0, 0, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case White:
|
|
|
|
|
rgb = { 255, 255, 255 };
|
|
|
|
|
break;
|
|
|
|
|
case Red:
|
|
|
|
|
rgb = { 255, 0, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case Green:
|
|
|
|
|
rgb = { 0, 255, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case Cyan:
|
|
|
|
|
rgb = { 0, 255, 255 };
|
|
|
|
|
break;
|
|
|
|
|
case DarkCyan:
|
|
|
|
|
rgb = { 0, 127, 127 };
|
|
|
|
|
break;
|
|
|
|
|
case MidCyan:
|
|
|
|
|
rgb = { 0, 192, 192 };
|
|
|
|
|
break;
|
|
|
|
|
case Blue:
|
|
|
|
|
rgb = { 0, 0, 255 };
|
|
|
|
|
break;
|
|
|
|
|
case Yellow:
|
|
|
|
|
rgb = { 255, 255, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case Magenta:
|
|
|
|
|
rgb = { 255, 0, 255 };
|
|
|
|
|
break;
|
|
|
|
|
case DarkGray:
|
|
|
|
|
rgb = { 64, 64, 64 };
|
|
|
|
|
break;
|
|
|
|
|
case MidGray:
|
|
|
|
|
rgb = { 127, 127, 127 };
|
|
|
|
|
break;
|
|
|
|
|
case LightGray:
|
|
|
|
|
rgb = { 192, 192, 192 };
|
|
|
|
|
break;
|
|
|
|
|
case MidGreen:
|
|
|
|
|
rgb = { 0, 192, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case MidBlue:
|
|
|
|
|
rgb = { 0, 0, 192 };
|
|
|
|
|
break;
|
|
|
|
|
case MidRed:
|
|
|
|
|
rgb = { 192, 0, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case MidMagenta:
|
|
|
|
|
rgb = { 192, 0, 192 };
|
|
|
|
|
break;
|
|
|
|
|
case DarkGreen:
|
|
|
|
|
rgb = { 0, 128, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case DarkBlue:
|
|
|
|
|
rgb = { 0, 0, 128 };
|
|
|
|
|
break;
|
|
|
|
|
case DarkRed:
|
|
|
|
|
rgb = { 128, 0, 0 };
|
|
|
|
|
break;
|
|
|
|
|
case WarmGray:
|
|
|
|
|
rgb = { 212, 208, 200 };
|
|
|
|
|
break;
|
2022-11-27 02:10:23 +01:00
|
|
|
case LightBlue:
|
|
|
|
|
rgb = { 173, 216, 230 };
|
|
|
|
|
break;
|
2021-02-07 16:51:17 +01:00
|
|
|
default:
|
2021-02-23 20:42:32 +01:00
|
|
|
VERIFY_NOT_REACHED();
|
2021-02-07 16:51:17 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-06 11:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using Gfx::Color;
|
2020-02-15 12:04:35 +01:00
|
|
|
|
2020-10-26 11:47:38 -04:00
|
|
|
namespace AK {
|
2020-12-30 12:14:15 +01:00
|
|
|
|
2024-05-14 12:21:52 -04:00
|
|
|
template<>
|
|
|
|
|
class Traits<Color> : public DefaultTraits<Color> {
|
|
|
|
|
public:
|
|
|
|
|
static unsigned hash(Color const& color)
|
|
|
|
|
{
|
|
|
|
|
return int_hash(color.value());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-26 11:47:38 -04:00
|
|
|
template<>
|
|
|
|
|
struct Formatter<Gfx::Color> : public Formatter<StringView> {
|
2022-12-06 19:43:46 +00:00
|
|
|
ErrorOr<void> format(FormatBuilder&, Gfx::Color);
|
2020-10-26 11:47:38 -04:00
|
|
|
};
|
2020-12-30 12:14:15 +01:00
|
|
|
|
2024-03-02 13:42:16 -07:00
|
|
|
template<>
|
|
|
|
|
struct Formatter<Gfx::YUV> : public Formatter<FormatString> {
|
|
|
|
|
ErrorOr<void> format(FormatBuilder&, Gfx::YUV);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct Formatter<Gfx::HSV> : public Formatter<FormatString> {
|
|
|
|
|
ErrorOr<void> format(FormatBuilder&, Gfx::HSV);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
struct Formatter<Gfx::Oklab> : public Formatter<FormatString> {
|
|
|
|
|
ErrorOr<void> format(FormatBuilder&, Gfx::Oklab);
|
|
|
|
|
};
|
|
|
|
|
|
2020-10-26 11:47:38 -04:00
|
|
|
}
|
|
|
|
|
|
2020-02-15 12:04:35 +01:00
|
|
|
namespace IPC {
|
2020-12-30 12:14:15 +01:00
|
|
|
|
2022-11-15 11:24:59 -05:00
|
|
|
template<>
|
2023-01-01 23:37:35 -05:00
|
|
|
ErrorOr<void> encode(Encoder&, Gfx::Color const&);
|
2022-11-15 11:24:59 -05:00
|
|
|
|
|
|
|
|
template<>
|
2022-12-22 20:40:33 -05:00
|
|
|
ErrorOr<Gfx::Color> decode(Decoder&);
|
2020-12-30 12:14:15 +01:00
|
|
|
|
2020-02-15 12:04:35 +01:00
|
|
|
}
|