Blender V5.0
BLI_color.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <ostream>
12
13#include "BLI_color_types.hh"
14#include "BLI_colorspace.hh"
15#include "BLI_compiler_compat.h"
16#include "BLI_math_color.h"
17#include "BLI_math_vector.h"
18
19namespace blender {
20
21/*
22 * Stream output.
23 */
24
25std::ostream &operator<<(std::ostream &stream, const eAlpha &space);
26std::ostream &operator<<(std::ostream &stream, const eSpace &space);
27
28template<typename ChannelStorageType, eSpace Space, eAlpha Alpha>
29std::ostream &operator<<(std::ostream &stream,
31
32namespace color {
33
38{
39 ColorTheme4b theme4b;
40 rgba_float_to_uchar(theme4b, theme4f);
41 return theme4b;
42}
43
45{
46 return theme4b;
47}
48
49template<eAlpha Alpha>
51{
52 float4 value = static_cast<const float *>(color);
55 }
57 linearrgb_to_srgb_uchar4(encoded, value);
58 return encoded;
59}
60
65{
66 ColorTheme4f theme4f;
67 rgba_uchar_to_float(theme4f, theme4b);
68 return theme4f;
69}
70
72{
73 return theme4f;
74}
75
76template<eAlpha Alpha>
86
92template<eAlpha Alpha>
94{
95 if constexpr (Alpha == eAlpha::Straight) {
97 straight_to_premul_v4_v4(premultiplied, color);
98 return premultiplied;
99 }
100 else {
101 return color;
102 }
103}
104
110template<eAlpha Alpha>
112{
113 if constexpr (Alpha == eAlpha::Premultiplied) {
115 premul_to_straight_v4_v4(straighten, color);
116 return straighten;
117 }
118 else {
119 return color;
120 }
121}
122
127{
129 srgb_to_linearrgb_v4(scene_linear, theme4f);
130 return scene_linear;
131}
132
134{
136 srgb_to_linearrgb_uchar4(scene_linear, theme4b);
137 return scene_linear;
138}
139
141{
142 ColorTheme4f theme4f;
143 linearrgb_to_srgb_v4(theme4f, scene_linear);
144 return theme4f;
145}
146
148{
149 ColorTheme4b theme4b;
150 linearrgb_to_srgb_uchar4(theme4b, scene_linear);
151 return theme4b;
152}
153
154} // namespace color
155
156} // namespace blender
#define BLI_INLINE
MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
MINLINE void srgb_to_linearrgb_uchar4(float linear[4], const unsigned char srgb[4])
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
MINLINE void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void premul_to_straight_v4_v4(float straight[4], const float premul[4])
MINLINE void linearrgb_to_srgb_uchar4(unsigned char srgb[4], const float linear[4])
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
BLI_INLINE ColorTheme4f to_float(const ColorTheme4b &theme4b)
Definition BLI_color.hh:64
BLI_INLINE ColorSceneLinear4f< eAlpha::Straight > to_scene_linear(const ColorTheme4f &theme4f)
Definition BLI_color.hh:126
BLI_INLINE ColorTheme4f to_theme4f(const ColorSceneLinear4f< eAlpha::Straight > &scene_linear)
Definition BLI_color.hh:140
BLI_INLINE ColorSceneLinear4f< Alpha > decode(const ColorSceneLinearByteEncoded4b< Alpha > &color)
Definition BLI_color.hh:77
BLI_INLINE ColorTheme4b to_byte(const ColorTheme4f &theme4f)
Definition BLI_color.hh:37
ColorSceneLinear4f< eAlpha::Straight > unpremultiply_alpha(const ColorSceneLinear4f< Alpha > &color)
Definition BLI_color.hh:111
ColorSceneLinear4f< eAlpha::Premultiplied > premultiply_alpha(const ColorSceneLinear4f< Alpha > &color)
Definition BLI_color.hh:93
BLI_INLINE ColorSceneLinearByteEncoded4b< Alpha > encode(const ColorSceneLinear4f< Alpha > &color)
Definition BLI_color.hh:50
BLI_INLINE ColorTheme4b to_theme4b(const ColorSceneLinear4f< eAlpha::Straight > &scene_linear)
Definition BLI_color.hh:147
float3x3 rec709_to_scene_linear
float3x3 scene_linear_to_rec709
ColorTheme4< uint8_t > ColorTheme4b
std::ostream & operator<<(std::ostream &stream, const eAlpha &space)
Definition BLI_color.cc:15
VecBase< float, 4 > float4
ColorTheme4< float > ColorTheme4f
VecBase< float, 3 > float3
VecBase< T, 3 > xyz() const