#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "ui/gfx/color_utils.h"
#include <stdint.h>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <ostream>
#include <vector>
#include "base/check_op.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/color_palette.h"
#if BUILDFLAG(IS_WIN)
#include <windows.h>
#include "skia/ext/skia_utils_win.h"
#endif
namespace color_utils {
namespace {
SkColor g_darkest_color = …;
float g_luminance_midpoint = …;
constexpr float kWhiteLuminance = …;
int calcHue(float temp1, float temp2, float hue) { … }
float Linearize(float component) { … }
constexpr size_t kNumGoogleColors = …;
constexpr SkColor kGrey[kNumGoogleColors] = …;
constexpr SkColor kRed[kNumGoogleColors] = …;
constexpr SkColor kOrange[kNumGoogleColors] = …;
constexpr SkColor kYellow[kNumGoogleColors] = …;
constexpr SkColor kGreen[kNumGoogleColors] = …;
constexpr SkColor kCyan[kNumGoogleColors] = …;
constexpr SkColor kBlue[kNumGoogleColors] = …;
constexpr SkColor kPurple[kNumGoogleColors] = …;
constexpr SkColor kMagenta[kNumGoogleColors] = …;
constexpr SkColor kPink[kNumGoogleColors] = …;
SkColor PickGoogleColor(const SkColor (&colors)[kNumGoogleColors],
SkColor color,
SkColor background_color_a,
SkColor background_color_b,
float min_contrast,
float max_contrast_with_nearer) { … }
template <typename T>
SkColor PickGoogleColorImpl(SkColor color, T pick_color) { … }
}
SkColor PickGoogleColor(SkColor color,
SkColor background_color,
float min_contrast,
float max_contrast) { … }
SkColor PickGoogleColorTwoBackgrounds(SkColor color,
SkColor background_color_a,
SkColor background_color_b,
float min_contrast,
float max_contrast_with_nearer) { … }
float GetContrastRatio(SkColor color_a, SkColor color_b) { … }
float GetContrastRatio(SkColor4f color_a, SkColor4f color_b) { … }
float GetContrastRatio(float luminance_a, float luminance_b) { … }
float GetRelativeLuminance(SkColor color) { … }
float GetRelativeLuminance4f(SkColor4f color) { … }
uint8_t GetLuma(SkColor color) { … }
void SkColorToHSL(SkColor c, HSL* hsl) { … }
SkColor HSLToSkColor(const HSL& hsl, SkAlpha alpha) { … }
bool IsWithinHSLRange(const HSL& hsl,
const HSL& lower_bound,
const HSL& upper_bound) { … }
void MakeHSLShiftValid(HSL* hsl) { … }
bool IsHSLShiftMeaningful(const HSL& hsl) { … }
SkColor HSLShift(SkColor color, const HSL& shift) { … }
SkColor AlphaBlend(SkColor foreground, SkColor background, SkAlpha alpha) { … }
SkColor AlphaBlend(SkColor foreground, SkColor background, float alpha) { … }
SkColor GetResultingPaintColor(SkColor foreground, SkColor background) { … }
bool IsDark(SkColor color) { … }
SkColor GetColorWithMaxContrast(SkColor color) { … }
SkColor GetEndpointColorWithMinContrast(SkColor color) { … }
SkColor BlendTowardMaxContrast(SkColor color, SkAlpha alpha) { … }
SkColor PickContrastingColor(SkColor foreground1,
SkColor foreground2,
SkColor background) { … }
BlendResult BlendForMinContrast(SkColor default_foreground,
SkColor background,
std::optional<SkColor> high_contrast_foreground,
float contrast_ratio) { … }
SkColor InvertColor(SkColor color) { … }
SkColor GetSysSkColor(int which) { … }
SkColor DeriveDefaultIconColor(SkColor text_color) { … }
std::string SkColorToRgbaString(SkColor color) { … }
std::string SkColor4fToRgbaString(SkColor4f color) { … }
std::string SkColorToRgbString(SkColor color) { … }
std::string SkColor4fToRgbString(SkColor4f color) { … }
SkColor SetDarkestColorForTesting(SkColor color) { … }
std::tuple<float, float, float> GetLuminancesForTesting() { … }
}