chromium/ui/gfx/color_conversions.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/gfx/color_conversions.h"

#include <cmath>
#include <numeric>
#include <tuple>

#include "base/compiler_specific.h"
#include "base/numerics/angle_conversions.h"
#include "skia/ext/skcolorspace_primaries.h"
#include "skia/ext/skcolorspace_trfn.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/modules/skcms/skcms.h"
#include "ui/gfx/color_space.h"

namespace gfx {

// Namespace containing some of the helper methods for color conversions.
namespace {
// https://en.wikipedia.org/wiki/CIELAB_color_space#Converting_between_CIELAB_and_CIEXYZ_coordinates
constexpr float kD50_x =;
constexpr float kD50_y =;
constexpr float kD50_z =;

// Evaluate the specified transfer function. This can be replaced by
// skcms_TransferFunction_eval when b/331320414 is fixed.
float skcmsTrFnEvalExt(const skcms_TransferFunction* fn, float x) {}

// Power function extended to all real numbers by point symmetry.
float powExt(float x, float p) {}

const skcms_Matrix3x3* getXYDZ65toXYZD50matrix() {}

const skcms_Matrix3x3* getXYDZ50toXYZD65matrix() {}

const skcms_Matrix3x3* getXYZD50TosRGBLinearMatrix() {}

const skcms_Matrix3x3* getXYZD65tosRGBLinearMatrix() {}

const skcms_Matrix3x3* getProPhotoRGBtoXYZD50Matrix() {}

const skcms_Matrix3x3* getXYZD50toProPhotoRGBMatrix() {}

const skcms_Matrix3x3* getXYZD50toDisplayP3Matrix() {}

const skcms_Matrix3x3* getXYZD50toAdobeRGBMatrix() {}

const skcms_Matrix3x3* getXYZD50toRec2020Matrix() {}

const skcms_Matrix3x3* getXYZToLMSMatrix() {}

const skcms_Matrix3x3* getLMSToXYZMatrix() {}

const skcms_Matrix3x3* getOklabToLMSMatrix() {}

const skcms_Matrix3x3* getLMSToOklabMatrix() {}

skcms_Vector3;

skcms_Vector2;

float dot(const skcms_Vector2& a, const skcms_Vector2& b) {}

static skcms_Vector3 skcms_Matrix3x3_apply(const skcms_Matrix3x3* m,
                                           const skcms_Vector3* v) {}

skcms_TransferFunction* getSRGBInverseTransferFunction() {}

std::tuple<float, float, float> ApplyInverseTransferFnsRGB(float r,
                                                           float g,
                                                           float b) {}

std::tuple<float, float, float> ApplyTransferFnsRGB(float r, float g, float b) {}

std::tuple<float, float, float> ApplyTransferFnProPhoto(float r,
                                                        float g,
                                                        float b) {}

std::tuple<float, float, float> ApplyTransferFnAdobeRGB(float r,
                                                        float g,
                                                        float b) {}

skcms_TransferFunction* getProPhotoInverseTransferFunction() {}

std::tuple<float, float, float> ApplyInverseTransferFnProPhoto(float r,
                                                               float g,
                                                               float b) {}

skcms_TransferFunction* getAdobeRGBInverseTransferFunction() {}

std::tuple<float, float, float> ApplyInverseTransferFnAdobeRGB(float r,
                                                               float g,
                                                               float b) {}

std::tuple<float, float, float> ApplyTransferFnRec2020(float r,
                                                       float g,
                                                       float b) {}

skcms_TransferFunction* getRec2020nverseTransferFunction() {}

std::tuple<float, float, float> ApplyInverseTransferFnRec2020(float r,
                                                              float g,
                                                              float b) {}
}  // namespace

std::tuple<float, float, float> LabToXYZD50(float l, float a, float b) {}

std::tuple<float, float, float> XYZD50ToLab(float x, float y, float z) {}

// Projects the color (l,a,b) to be within a polyhedral approximation of the
// Rec2020 gamut. This is done by finding the maximum value of alpha such that
// (l, alpha*a, alpha*b) is within that polyhedral approximation.
std::tuple<float, float, float> OklabGamutMap(float l, float a, float b) {}

std::tuple<float, float, float> OklabToXYZD65(float l, float a, float b) {}

std::tuple<float, float, float> XYZD65ToOklab(float x, float y, float z) {}

std::tuple<float, float, float> LchToLab(float l, float c, float h) {}
std::tuple<float, float, float> LabToLch(float l, float a, float b) {}

std::tuple<float, float, float> DisplayP3ToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> XYZD50ToDisplayP3(float x, float y, float z) {}

std::tuple<float, float, float> ProPhotoToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> XYZD50ToProPhoto(float x, float y, float z) {}

std::tuple<float, float, float> AdobeRGBToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> XYZD50ToAdobeRGB(float x, float y, float z) {}

std::tuple<float, float, float> Rec2020ToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> XYZD50ToRec2020(float x, float y, float z) {}

std::tuple<float, float, float> XYZD50ToD65(float x, float y, float z) {}

std::tuple<float, float, float> XYZD65ToD50(float x, float y, float z) {}

std::tuple<float, float, float> SRGBToSRGBLegacy(float r, float g, float b) {}

std::tuple<float, float, float> SRGBLegacyToSRGB(float r, float g, float b) {}

std::tuple<float, float, float> XYZD50TosRGB(float x, float y, float z) {}

std::tuple<float, float, float> XYZD65TosRGBLinear(float x, float y, float z) {}

std::tuple<float, float, float> XYZD50TosRGBLinear(float x, float y, float z) {}

std::tuple<float, float, float> SRGBLinearToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> SRGBToXYZD50(float r, float g, float b) {}

std::tuple<float, float, float> HSLToSRGB(float h, float s, float l) {}

std::tuple<float, float, float> SRGBToHSL(float r, float g, float b) {}

std::tuple<float, float, float> HWBToSRGB(float h, float w, float b) {}

std::tuple<float, float, float> SRGBToHWB(float r, float g, float b) {}

SkColor4f SRGBLinearToSkColor4f(float r, float g, float b, float alpha) {}

SkColor4f XYZD50ToSkColor4f(float x, float y, float z, float alpha) {}

SkColor4f XYZD65ToSkColor4f(float x, float y, float z, float alpha) {}

SkColor4f LabToSkColor4f(float l, float a, float b, float alpha) {}

SkColor4f ProPhotoToSkColor4f(float r, float g, float b, float alpha) {}

SkColor4f OklabToSkColor4f(float l, float a, float b, float alpha) {}

SkColor4f OklabGamutMapToSkColor4f(float l, float a, float b, float alpha) {}

SkColor4f DisplayP3ToSkColor4f(float r, float g, float b, float alpha) {}

SkColor4f LchToSkColor4f(float l_input, float c, float h, float alpha) {}
SkColor4f AdobeRGBToSkColor4f(float r, float g, float b, float alpha) {}

SkColor4f Rec2020ToSkColor4f(float r, float g, float b, float alpha) {}

SkColor4f OklchToSkColor4f(float l_input, float c, float h, float alpha) {}

SkColor4f OklchGamutMapToSkColor4f(float l_input,
                                   float c,
                                   float h,
                                   float alpha) {}

SkColor4f HSLToSkColor4f(float h, float s, float l, float alpha) {}

SkColor4f HWBToSkColor4f(float h, float w, float b, float alpha) {}
}  // namespace gfx