11#include "tiny_skia/Math.h"
12#include "tiny_skia/pipeline/Pipeline.h"
19constexpr AlphaU8 kAlphaU8Transparent = 0x00;
20constexpr AlphaU8 kAlphaU8Opaque = 0xFF;
31 : data_{red, green, blue, alpha} {}
34 return ColorU8(red, green, blue, alpha);
37 constexpr AlphaU8 red()
const {
return data_[0]; }
38 constexpr AlphaU8 green()
const {
return data_[1]; }
39 constexpr AlphaU8 blue()
const {
return data_[2]; }
40 constexpr AlphaU8 alpha()
const {
return data_[3]; }
42 [[nodiscard]]
bool isOpaque()
const {
return alpha() == kAlphaU8Opaque; }
47 bool operator==(
const ColorU8&)
const =
default;
50 std::array<AlphaU8, 4> data_{};
69 : data_{red, green, blue, alpha} {}
71 constexpr AlphaU8 red()
const {
return data_[0]; }
72 constexpr AlphaU8 green()
const {
return data_[1]; }
73 constexpr AlphaU8 blue()
const {
return data_[2]; }
74 constexpr AlphaU8 alpha()
const {
return data_[3]; }
76 [[nodiscard]]
bool isOpaque()
const {
return alpha() == kAlphaU8Opaque; }
84 std::array<AlphaU8, 4> data_{};
91 static const Color transparent;
92 static const Color black;
93 static const Color white;
96 : red_(red), green_(green), blue_(blue), alpha_(alpha) {}
101 static std::optional<Color>
fromRgba(
float red,
float green,
float blue,
float alpha);
105 float red()
const {
return red_.get(); }
106 float green()
const {
return green_.get(); }
107 float blue()
const {
return blue_.get(); }
108 float alpha()
const {
return alpha_.get(); }
120 [[nodiscard]]
bool isOpaque()
const {
return alpha_ == NormalizedF32::one(); }
126 bool operator==(
const Color&)
const =
default;
141 : red_(red), green_(green), blue_(blue), alpha_(alpha) {}
143 float red()
const {
return red_.get(); }
144 float green()
const {
return green_.get(); }
145 float blue()
const {
return blue_.get(); }
146 float alpha()
const {
return alpha_.get(); }
175NormalizedF32 expandChannel(ColorSpace colorSpace, NormalizedF32 x);
177Color expandColor(ColorSpace colorSpace, Color color);
179NormalizedF32 compressChannel(ColorSpace colorSpace, NormalizedF32 x);
182std::optional<pipeline::Stage> expandStage(ColorSpace colorSpace);
184std::optional<pipeline::Stage> expandDestStage(ColorSpace colorSpace);
186std::optional<pipeline::Stage> compressStage(ColorSpace colorSpace);
std::uint8_t AlphaU8
8-bit alpha value.
Definition Color.h:17
ColorSpace
Colorspace for gamma-correct blending.
Definition Color.h:167
@ Gamma2
Power-of-2 gamma approximation.
@ Linear
Linear RGB (no gamma).
@ FullSRGBGamma
Full sRGB gamma curve.
@ SimpleSRGB
Simplified sRGB transfer function.
Validated floating-point types: NormalizedF32 [0,1], FiniteF32, etc.
8-bit RGBA color (straight alpha).
Definition Color.h:27
PremultipliedColorU8 premultiply() const
Converts to premultiplied alpha.
Floating-point RGBA color [0,1] (straight alpha).
Definition Color.h:88
void applyOpacity(float opacity)
Multiplies alpha by opacity (clamped to [0,1]).
Definition Color.h:116
static Color fromRgbaUnchecked(float red, float green, float blue, float alpha)
Creates without validation (values must be in [0,1]).
PremultipliedColor premultiply() const
Converts to premultiplied alpha.
static Color fromRgba8(AlphaU8 red, AlphaU8 green, AlphaU8 blue, AlphaU8 alpha)
Creates from 8-bit components.
ColorU8 toColorU8() const
Converts to 8-bit color.
static std::optional< Color > fromRgba(float red, float green, float blue, float alpha)
Creates with validation. Returns nullopt if any component is outside [0,1].
A float guaranteed to be in [0, 1].
Definition FloatingPoint.h:12
static NormalizedF32 newClamped(float value)
Clamps to [0,1].
8-bit RGBA color (premultiplied alpha). Internal pixel format.
Definition Color.h:54
static constexpr PremultipliedColorU8 fromRgbaUnchecked(AlphaU8 red, AlphaU8 green, AlphaU8 blue, AlphaU8 alpha)
Creates from components without validation.
Definition Color.h:63
static std::optional< PremultipliedColorU8 > fromRgba(AlphaU8 red, AlphaU8 green, AlphaU8 blue, AlphaU8 alpha)
Creates from components. Returns nullopt if any channel > alpha.
ColorU8 demultiply() const
Converts to straight alpha.
Floating-point RGBA color [0,1] (premultiplied alpha).
Definition Color.h:136
PremultipliedColorU8 toColorU8() const
Converts to 8-bit premultiplied color.
Color demultiply() const
Converts to straight alpha.