NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
color类 参考

RGB颜色类 更多...

#include <color.hpp>

类 color 继承关系图:
[图例]

Public 成员函数

constexpr color () noexcept=default
 默认构造函数,创建黑色(0,0,0,255)
constexpr color (const int gray) noexcept
 从灰度值构造
constexpr color (const int gray, const int alpha) noexcept
 从灰度值和透明度构造
constexpr color (const int red, const int green, const int blue) noexcept
 从RGB分量构造
constexpr color (const int red, const int green, const int blue, const int alpha) noexcept
 从RGBA分量构造
constexpr color (const string_view str)
 从十六进制字符串构造
constexpr color (const string &str)
 从字符串对象构造
constexpr color (const char *str)
 从C风格字符串构造
constexpr color (color &&other) noexcept
 移动构造函数
constexpr coloroperator= (color &&other) noexcept
 移动赋值运算符
constexpr int R () const noexcept
 获取红色分量
constexpr int G () const noexcept
 获取绿色分量
constexpr int B () const noexcept
 获取蓝色分量
constexpr int A () const noexcept
 获取透明度
constexpr void setR (const int red) noexcept
 设置红色分量
constexpr void setG (const int green) noexcept
 设置绿色分量
constexpr void setB (const int blue) noexcept
 设置蓝色分量
constexpr void setA (const int alpha) noexcept
 设置透明度
constexpr void set_color (const int red, const int green, const int blue) noexcept
 设置RGB颜色
constexpr void set_color (const int red, const int green, const int blue, const int alpha) noexcept
 设置RGBA颜色
constexpr void set_gray (const int gray) noexcept
 设置灰度值
constexpr void set_gray (const int gray, const int alpha) noexcept
 设置灰度值和透明度
constexpr bool is_transparent () const noexcept
 检查是否完全透明
constexpr bool is_opaque () const noexcept
 检查是否完全不透明
constexpr double opacity () const noexcept
 获取不透明度(0.0-1.0)
constexpr void set_opacity (double opacity) noexcept
 设置不透明度
constexpr color operator+ (const color &other) const noexcept
 颜色加法
constexpr color operator- (const color &other) const noexcept
 颜色减法
constexpr color operator* (const double scalar) const noexcept
 颜色乘以标量
constexpr color operator* (const int scalar) const noexcept
 颜色乘以整数标量
constexpr coloroperator+= (const color &other) noexcept
 颜色加等赋值
constexpr coloroperator-= (const color &other) noexcept
 颜色减等赋值
constexpr coloroperator*= (const double scalar) noexcept
 颜色乘等赋值
constexpr bool equal_to (const color &other) const noexcept
 相等比较
constexpr bool less_than (const color &other) const noexcept
 小于比较
constexpr color blend (const color &background) const noexcept
 将当前颜色与背景色混合
constexpr double gray_value () const noexcept
 计算灰度值
constexpr string to_string () const
 转换为十六进制字符串
constexpr int to_ansi_256 () const noexcept
 转换为256色ANSI颜色索引
constexpr int to_ansi_basic (const bool is_background=false) const noexcept
 转换为基本ANSI颜色代码
constexpr integer32 to_ansi_foreground (const bool use_256_color=true) const noexcept
 转换为ANSI前景色代码
constexpr integer32 to_ansi_background (const bool use_256_color=true) const noexcept
 转换为ANSI背景色代码
constexpr color to_premultiplied () const noexcept
 转换为标准预乘 Alpha 表示
constexpr color from_premultiplied () const noexcept
 从预乘 Alpha 转换回直通 Alpha(Straight Alpha)
constexpr integer32 to_integer32 (const bool use_256_color=true) const noexcept
 转换为整数表示
constexpr size_t to_hash () const noexcept
 计算哈希值
constexpr void swap (color &other) noexcept
 交换两个颜色对象
Public 成员函数 继承自 iobject< color >
constexpr bool try_parse (const string_view str) noexcept
 尝试从字符串解析对象
Public 成员函数 继承自 istringify< color >
constexpr string to_string () const
 转换为字符串
Public 成员函数 继承自 icomparable< color >
constexpr bool operator== (const color &rhs) const noexcept(noexcept(derived().equal_to(rhs)))
 相等比较运算符
constexpr bool operator!= (const color &rhs) const noexcept(noexcept(!(derived().equal_to(rhs))))
 不等比较运算符
constexpr bool operator< (const color &rhs) const noexcept(noexcept(derived().less_than(rhs)))
 小于比较运算符
constexpr bool operator> (const color &rhs) const noexcept(noexcept(rhs.less_than(derived())))
 大于比较运算符
constexpr bool operator<= (const color &rhs) const noexcept(noexcept(!(rhs.less_than(derived()))))
 小于等于比较运算符
constexpr bool operator>= (const color &rhs) const noexcept(noexcept(!(derived().less_than(rhs))))
 大于等于比较运算符
Public 成员函数 继承自 ihashable< color >
constexpr size_t to_ihash () const noexcept(noexcept(derived().to_hash()))
 获取对象的哈希值

静态 Public 成员函数

static constexpr color lerp (const color &from, const color &to, double t) noexcept
 线性插值两个颜色
static constexpr color parse (const string_view hex)
 从十六进制字符串解析颜色
static constexpr color black () noexcept
 黑色
static constexpr color white () noexcept
 白色
static constexpr color gray () noexcept
 灰色
static constexpr color red () noexcept
 红色
static constexpr color green () noexcept
 绿色
static constexpr color blue () noexcept
 蓝色
static constexpr color yellow () noexcept
 黄色
static constexpr color magenta () noexcept
 品红
static constexpr color cyan () noexcept
 青色
static constexpr color transparent () noexcept
 完全透明
静态 Public 成员函数 继承自 iobject< color >
static constexpr color parse (const string_view str)
 从字符串解析对象

详细描述

RGB颜色类

表示一个RGB颜色,包含红、绿、蓝和透明度四个分量。 每个分量的取值范围为0-255,透明度255表示不透明。 支持颜色混合、线性插值、ANSI终端颜色转换等操作。

在文件 color.hpp164 行定义.

构造及析构函数说明

◆ color() [1/7]

color::color ( const int gray)
inlineexplicitconstexprnoexcept

从灰度值构造

参数
gray灰度值(0-255)

在文件 color.hpp242 行定义.

引用了 color() , 以及 gray().

◆ color() [2/7]

color::color ( const int gray,
const int alpha )
inlineconstexprnoexcept

从灰度值和透明度构造

参数
gray灰度值(0-255)
alpha透明度(0-255)

在文件 color.hpp252 行定义.

引用了 gray().

◆ color() [3/7]

color::color ( const int red,
const int green,
const int blue )
inlineconstexprnoexcept

从RGB分量构造

参数
red红色分量(0-255)
green绿色分量(0-255)
blue蓝色分量(0-255)

在文件 color.hpp264 行定义.

引用了 blue(), green() , 以及 red().

◆ color() [4/7]

color::color ( const int red,
const int green,
const int blue,
const int alpha )
inlineconstexprnoexcept

从RGBA分量构造

参数
red红色分量(0-255)
green绿色分量(0-255)
blue蓝色分量(0-255)
alpha透明度(0-255)

在文件 color.hpp276 行定义.

引用了 blue(), green() , 以及 red().

◆ color() [5/7]

color::color ( const string_view str)
inlineexplicitconstexpr

从十六进制字符串构造

参数
str十六进制字符串(格式:RRGGBB 或 RRGGBBAA)
异常
value_exception格式无效时抛出

在文件 color.hpp287 行定义.

引用了 parse().

◆ color() [6/7]

color::color ( const string & str)
inlineexplicitconstexpr

从字符串对象构造

参数
str十六进制字符串
异常
value_exception格式无效时抛出

在文件 color.hpp294 行定义.

引用了 parse() , 以及 basic_string< CharT, Traits, Alloc >::view().

◆ color() [7/7]

color::color ( const char * str)
inlineexplicitconstexpr

从C风格字符串构造

参数
str十六进制字符串
异常
value_exception格式无效时抛出

在文件 color.hpp301 行定义.

引用了 parse().

成员函数说明

◆ A()

int color::A ( ) const
inlinenodiscardconstexprnoexcept

获取透明度

返回
透明度值

在文件 color.hpp359 行定义.

◆ B()

int color::B ( ) const
inlinenodiscardconstexprnoexcept

获取蓝色分量

返回
蓝色分量值

在文件 color.hpp353 行定义.

◆ blend()

color color::blend ( const color & background) const
inlinenodiscardconstexprnoexcept

将当前颜色与背景色混合

参数
background背景色
返回
混合后的颜色

符合 W3C Compositing and Blending Level 1 规范。

在文件 color.hpp581 行定义.

引用了 color(), round() , 以及 transparent().

◆ equal_to()

bool color::equal_to ( const color & other) const
inlinenodiscardconstexprnoexcept

相等比较

参数
other另一个颜色
返回
是否相等

在文件 color.hpp552 行定义.

引用了 color().

◆ from_premultiplied()

color color::from_premultiplied ( ) const
inlinenodiscardconstexprnoexcept

从预乘 Alpha 转换回直通 Alpha(Straight Alpha)

返回
还原后的颜色对象
注解
符合 ISO 32000-2 对于 PDF 透明组的处理要求。

在文件 color.hpp769 行定义.

引用了 color(), round() , 以及 transparent().

◆ G()

int color::G ( ) const
inlinenodiscardconstexprnoexcept

获取绿色分量

返回
绿色分量值

在文件 color.hpp347 行定义.

◆ gray_value()

double color::gray_value ( ) const
inlinenodiscardconstexprnoexcept

计算灰度值

返回
灰度值(基于人眼感知的加权平均)

在文件 color.hpp614 行定义.

◆ is_opaque()

bool color::is_opaque ( ) const
inlinenodiscardconstexprnoexcept

检查是否完全不透明

返回
是否完全不透明

在文件 color.hpp437 行定义.

◆ is_transparent()

bool color::is_transparent ( ) const
inlinenodiscardconstexprnoexcept

检查是否完全透明

返回
是否完全透明

在文件 color.hpp431 行定义.

◆ lerp()

constexpr color color::lerp ( const color & from,
const color & to,
double t )
inlinestaticconstexprnoexcept

线性插值两个颜色

参数
from起始颜色
to目标颜色
t插值因子(0.0-1.0)
返回
插值结果
注解
插值在直通 Alpha (non-premultiplied) 空间进行,符合 W3C 标准。

在文件 color.hpp463 行定义.

引用了 color().

◆ less_than()

bool color::less_than ( const color & other) const
inlinenodiscardconstexprnoexcept

小于比较

参数
other另一个颜色
返回
是否小于

在文件 color.hpp561 行定义.

引用了 color().

◆ opacity()

double color::opacity ( ) const
inlinenodiscardconstexprnoexcept

获取不透明度(0.0-1.0)

返回
不透明度

在文件 color.hpp443 行定义.

被这些函数引用 set_opacity().

◆ operator*() [1/2]

color color::operator* ( const double scalar) const
inlineconstexprnoexcept

颜色乘以标量

参数
scalar浮点标量
返回
缩放后的颜色

在文件 color.hpp492 行定义.

引用了 color() , 以及 round().

◆ operator*() [2/2]

color color::operator* ( const int scalar) const
inlineconstexprnoexcept

颜色乘以整数标量

参数
scalar整数标量
返回
缩放后的颜色

在文件 color.hpp504 行定义.

引用了 color().

◆ operator*=()

color & color::operator*= ( const double scalar)
inlineconstexprnoexcept

颜色乘等赋值

参数
scalar浮点标量
返回
自身引用

在文件 color.hpp539 行定义.

引用了 color() , 以及 round().

◆ operator+()

color color::operator+ ( const color & other) const
inlineconstexprnoexcept

颜色加法

参数
other另一个颜色
返回
相加后的颜色

在文件 color.hpp474 行定义.

引用了 color().

◆ operator+=()

color & color::operator+= ( const color & other)
inlineconstexprnoexcept

颜色加等赋值

参数
other另一个颜色
返回
自身引用

在文件 color.hpp513 行定义.

引用了 color().

◆ operator-()

color color::operator- ( const color & other) const
inlineconstexprnoexcept

颜色减法

参数
other另一个颜色
返回
相减后的颜色

在文件 color.hpp483 行定义.

引用了 color().

◆ operator-=()

color & color::operator-= ( const color & other)
inlineconstexprnoexcept

颜色减等赋值

参数
other另一个颜色
返回
自身引用

在文件 color.hpp526 行定义.

引用了 color().

◆ parse()

constexpr color color::parse ( const string_view hex)
inlinestaticconstexpr

从十六进制字符串解析颜色

参数
hex十六进制字符串(支持#RRGGBB或#RRGGBBAA格式)
返回
解析得到的颜色
异常
value_exception格式无效时抛出

在文件 color.hpp630 行定义.

引用了 color(), basic_string_view< CharT, Traits >::length(), hexadecimal::parse(), basic_string_view< CharT, Traits >::substr(), basic_string_view< CharT, Traits >::tail(), unreachable() , 以及 ipackage< T, PackageT >::value().

被这些函数引用 color(), color() , 以及 color().

◆ R()

int color::R ( ) const
inlinenodiscardconstexprnoexcept

获取红色分量

返回
红色分量值

在文件 color.hpp341 行定义.

◆ set_color() [1/2]

void color::set_color ( const int red,
const int green,
const int blue )
inlineconstexprnoexcept

设置RGB颜色

参数
red红色分量
green绿色分量
blue蓝色分量

在文件 color.hpp391 行定义.

引用了 blue(), green() , 以及 red().

◆ set_color() [2/2]

void color::set_color ( const int red,
const int green,
const int blue,
const int alpha )
inlineconstexprnoexcept

设置RGBA颜色

参数
red红色分量
green绿色分量
blue蓝色分量
alpha透明度

在文件 color.hpp404 行定义.

引用了 blue(), green() , 以及 red().

◆ set_gray() [1/2]

void color::set_gray ( const int gray)
inlineconstexprnoexcept

设置灰度值

参数
gray灰度值

在文件 color.hpp415 行定义.

引用了 gray().

被这些函数引用 set_gray().

◆ set_gray() [2/2]

void color::set_gray ( const int gray,
const int alpha )
inlineconstexprnoexcept

设置灰度值和透明度

参数
gray灰度值
alpha透明度

在文件 color.hpp422 行定义.

引用了 gray() , 以及 set_gray().

◆ set_opacity()

void color::set_opacity ( double opacity)
inlineconstexprnoexcept

设置不透明度

参数
opacity不透明度(0.0-1.0)

在文件 color.hpp449 行定义.

引用了 max(), min(), opacity() , 以及 round().

◆ setA()

void color::setA ( const int alpha)
inlineconstexprnoexcept

设置透明度

参数
alpha透明度值

在文件 color.hpp383 行定义.

◆ setB()

void color::setB ( const int blue)
inlineconstexprnoexcept

设置蓝色分量

参数
blue蓝色分量值

在文件 color.hpp377 行定义.

引用了 blue().

◆ setG()

void color::setG ( const int green)
inlineconstexprnoexcept

设置绿色分量

参数
green绿色分量值

在文件 color.hpp371 行定义.

引用了 green().

◆ setR()

void color::setR ( const int red)
inlineconstexprnoexcept

设置红色分量

参数
red红色分量值

在文件 color.hpp365 行定义.

引用了 red().

◆ swap()

void color::swap ( color & other)
inlineconstexprnoexcept

交换两个颜色对象

参数
other要交换的对象

在文件 color.hpp803 行定义.

引用了 color() , 以及 move().

◆ to_ansi_256()

int color::to_ansi_256 ( ) const
inlinenodiscardconstexprnoexcept

转换为256色ANSI颜色索引

返回
ANSI 256色索引(0-255)

符合 XTerm 256-Color Cube 规范。 彩色部分使用标准区间: 0, 95, 135, 175, 215, 255

在文件 color.hpp660 行定义.

被这些函数引用 to_ansi_background(), to_ansi_foreground() , 以及 to_integer32().

◆ to_ansi_background()

integer32 color::to_ansi_background ( const bool use_256_color = true) const
inlinenodiscardconstexprnoexcept

转换为ANSI背景色代码

参数
use_256_color是否使用256色模式
返回
ANSI背景色代码(包装为integer32)

在文件 color.hpp746 行定义.

引用了 to_ansi_256() , 以及 to_ansi_basic().

◆ to_ansi_basic()

int color::to_ansi_basic ( const bool is_background = false) const
inlinenodiscardconstexprnoexcept

转换为基本ANSI颜色代码

参数
is_background是否为背景色
返回
基本ANSI颜色代码

在文件 color.hpp692 行定义.

被这些函数引用 to_ansi_background(), to_ansi_foreground() , 以及 to_integer32().

◆ to_ansi_foreground()

integer32 color::to_ansi_foreground ( const bool use_256_color = true) const
inlinenodiscardconstexprnoexcept

转换为ANSI前景色代码

参数
use_256_color是否使用256色模式
返回
ANSI前景色代码(包装为integer32)

在文件 color.hpp734 行定义.

引用了 to_ansi_256() , 以及 to_ansi_basic().

◆ to_hash()

size_t color::to_hash ( ) const
inlinenodiscardconstexprnoexcept

计算哈希值

返回
哈希值

在文件 color.hpp794 行定义.

◆ to_integer32()

integer32 color::to_integer32 ( const bool use_256_color = true) const
inlinenodiscardconstexprnoexcept

转换为整数表示

参数
use_256_color是否使用256色模式
返回
颜色索引(包装为integer32)

在文件 color.hpp783 行定义.

引用了 to_ansi_256() , 以及 to_ansi_basic().

◆ to_premultiplied()

color color::to_premultiplied ( ) const
inlinenodiscardconstexprnoexcept

转换为标准预乘 Alpha 表示

返回
预乘后的颜色对象
注解
仅用于需要预乘数据的图形 API,结果不宜直接用于 blend 输入。

在文件 color.hpp758 行定义.

引用了 color() , 以及 round().

◆ to_string()

string color::to_string ( ) const
inlinenodiscardconstexpr

转换为十六进制字符串

返回
格式为RRGGBBAA的十六进制字符串

在文件 color.hpp620 行定义.

引用了 format().


该类的文档由以下文件生成: