#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "third_party/blink/renderer/platform/graphics/color.h"
#include <math.h>
#include <optional>
#include <tuple>
#include "base/check_op.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/renderer/platform/geometry/blend.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/string_view.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/color_conversions.h"
namespace blink {
const Color Color::kBlack = …;
const Color Color::kWhite = …;
const Color Color::kDarkGray = …;
const Color Color::kGray = …;
const Color Color::kLightGray = …;
const Color Color::kTransparent = …;
namespace {
const RGBA32 kLightenedBlack = …;
const RGBA32 kDarkenedWhite = …;
const float kAchromaticChromaThreshold = …;
const int kCStartAlpha = …;
const int kCEndAlpha = …;
const int kCAlphaIncrement = …;
int BlendComponent(int c, int a) { … }
template <typename CharacterType>
inline bool ParseHexColorInternal(const CharacterType* name,
unsigned length,
Color& color) { … }
inline const NamedColor* FindNamedColor(const String& name) { … }
constexpr int RedChannel(RGBA32 color) { … }
constexpr int GreenChannel(RGBA32 color) { … }
constexpr int BlueChannel(RGBA32 color) { … }
constexpr int AlphaChannel(RGBA32 color) { … }
float AngleToUnitCircleDegrees(float angle) { … }
}
#if BUILDFLAG(IS_WIN)
static_assert(sizeof(Color) <= 24, "blink::Color should be <= 24 bytes.");
#else
static_assert …;
#endif
Color::Color(int r, int g, int b) { … }
Color::Color(int r, int g, int b, int a) { … }
Color Color::FromRGBALegacy(std::optional<int> r,
std::optional<int> g,
std::optional<int> b,
std::optional<int> a) { … }
Color Color::FromColorSpace(ColorSpace color_space,
std::optional<float> param0,
std::optional<float> param1,
std::optional<float> param2,
std::optional<float> alpha) { … }
Color Color::FromHSLA(std::optional<float> h,
std::optional<float> s,
std::optional<float> l,
std::optional<float> a) { … }
Color Color::FromHWBA(std::optional<float> h,
std::optional<float> w,
std::optional<float> b,
std::optional<float> a) { … }
Color Color::FromColorMix(Color::ColorSpace interpolation_space,
std::optional<HueInterpolationMethod> hue_method,
Color color1,
Color color2,
float percentage,
float alpha_multiplier) { … }
float Color::HueInterpolation(float value1,
float value2,
float percentage,
Color::HueInterpolationMethod hue_method) { … }
namespace {}
void Color::CarryForwardAnalogousMissingComponents(
Color color,
Color::ColorSpace prev_color_space) { … }
bool Color::SubstituteMissingParameters(Color& color1, Color& color2) { … }
Color Color::InterpolateColors(Color::ColorSpace interpolation_space,
std::optional<HueInterpolationMethod> hue_method,
Color color1,
Color color2,
float percentage) { … }
std::tuple<float, float, float> Color::ExportAsXYZD50Floats() const { … }
void Color::ResolveMissingComponents() { … }
void Color::ConvertToColorSpace(ColorSpace destination_color_space,
bool resolve_missing_components) { … }
SkColor4f Color::toSkColor4f() const { … }
SkColor4f
Color::ToGradientStopSkColor4f(ColorSpace interpolation_space) const { … }
bool Color::IsBakedGamutMappingEnabled() { … }
SkColor4f Color::ToSkColor4fInternal(bool gamut_map_oklab_oklch) const { … }
float Color::PremultiplyColor() { … }
void Color::UnpremultiplyColor() { … }
float NormalizeSign(float number) { … }
unsigned Color::GetHash() const { … }
int Color::Red() const { … }
int Color::Green() const { … }
int Color::Blue() const { … }
RGBA32 Color::Rgb() const { … }
bool Color::ParseHexColor(const LChar* name, unsigned length, Color& color) { … }
bool Color::ParseHexColor(const UChar* name, unsigned length, Color& color) { … }
bool Color::ParseHexColor(const StringView& name, Color& color) { … }
int DifferenceSquared(const Color& c1, const Color& c2) { … }
bool Color::SetFromString(const String& name) { … }
String Color::ColorSpaceToString(Color::ColorSpace color_space) { … }
static String ColorParamToString(float param, int precision = 6) { … }
String Color::SerializeAsCanvasColor() const { … }
String Color::SerializeLegacyColorAsCSSColor() const { … }
String Color::SerializeInternal() const { … }
String Color::SerializeAsCSSColor() const { … }
String Color::NameForLayoutTreeAsText() const { … }
bool Color::SetNamedColor(const String& name) { … }
Color Color::Light() const { … }
Color Color::Dark() const { … }
Color Color::Blend(const Color& source) const { … }
Color Color::BlendWithWhite() const { … }
void Color::GetRGBA(float& r, float& g, float& b, float& a) const { … }
void Color::GetRGBA(double& r, double& g, double& b, double& a) const { … }
void Color::GetHueMaxMin(double& hue, double& max, double& min) const { … }
void Color::GetHSL(double& hue, double& saturation, double& lightness) const { … }
void Color::GetHWB(double& hue, double& white, double& black) const { … }
Color ColorFromPremultipliedARGB(RGBA32 pixel_color) { … }
RGBA32 PremultipliedARGBFromColor(const Color& color) { … }
Color::ColorSpace Color::GetColorInterpolationSpace() const { … }
String Color::SerializeInterpolationSpace(
Color::ColorSpace color_space,
Color::HueInterpolationMethod hue_interpolation_method) { … }
static float ResolveNonFiniteChannel(float value,
float negative_infinity_substitution,
float positive_infinity_substitution) { … }
void Color::ResolveNonFiniteValues() { … }
std::ostream& operator<<(std::ostream& os, const Color& color) { … }
}