Loading...
Searching...
No Matches
colorSpace.h
1//
2// Copyright 2024 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_GF_COLORSPACE_H
8#define PXR_BASE_GF_COLORSPACE_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/vec2f.h"
16#include "pxr/base/gf/api.h"
17#include "pxr/base/tf/span.h"
19
20PXR_NAMESPACE_OPEN_SCOPE
21
74#define GF_COLORSPACE_NAME_TOKENS \
75 ((LinearAP1, "lin_ap1_scene")) \
76 ((LinearAP0, "lin_ap0_scene")) \
77 ((LinearRec709, "lin_rec709_scene")) \
78 ((LinearP3D65, "lin_p3d65_scene")) \
79 ((LinearRec2020, "lin_rec2020_scene")) \
80 ((LinearAdobeRGB, "lin_adobergb_scene")) \
81 ((LinearCIEXYZD65, "lin_ciexyzd65_scene")) \
82 ((SRGBRec709, "srgb_rec709_scene")) \
83 ((G24Rec709, "g24_rec709_scene")) \
84 ((G22Rec709, "g22_rec709_scene")) \
85 ((G18Rec709, "g18_rec709_scene")) \
86 ((SRGBAP1, "srgb_ap1_scene")) \
87 ((G22AP1, "g22_ap1_scene")) \
88 ((SRGBP3D65, "srgb_p3d65_scene")) \
89 ((G22AdobeRGB, "g22_adobergb_scene")) \
90 ((Identity, "identity")) \
91 ((Data, "data")) \
92 ((Raw, "raw")) \
93 ((Unknown, "unknown")) \
94 ((CIEXYZ, "lin_ciexyzd65_scene")) \
95 ((LinearDisplayP3, "lin_p3d65_scene"))
96
97TF_DECLARE_PUBLIC_TOKENS(GfColorSpaceNames, GF_API,
98 GF_COLORSPACE_NAME_TOKENS);
99
100class GfColor;
101
116
118 friend class GfColor;
119public:
123 GF_API
124 explicit GfColorSpace(const TfToken& name);
125
128 GF_API
129 static bool IsValid(const TfToken& name);
130
140 GF_API
141 explicit GfColorSpace(const TfToken& name,
142 const GfVec2f &redChroma,
143 const GfVec2f &greenChroma,
144 const GfVec2f &blueChroma,
145 const GfVec2f &whitePoint,
146 float gamma,
147 float linearBias);
148
155 GF_API
156 explicit GfColorSpace(const TfToken& name,
157 const GfMatrix3f &rgbToXYZ,
158 float gamma,
159 float linearBias);
160
164 GF_API
166
171 GF_API
172 bool operator ==(const GfColorSpace &rh) const;
173
178 bool operator !=(const GfColorSpace &rh) const { return !(*this == rh); }
179
184 GF_API
185 void ConvertRGBSpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgb) const;
186
191 GF_API
192 void ConvertRGBASpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgba) const;
193
195 GF_API
196 GfColor Convert(const GfColorSpace& srcColorSpace, const GfVec3f& rgb) const;
197
201 GF_API
203
207 GF_API
208 GfMatrix3f GetRGBToRGB(const GfColorSpace& srcColorSpace) const;
209
213 GF_API
214 float GetGamma() const;
215
219 GF_API
220 float GetLinearBias() const;
221
224 GF_API
225 std::pair<float, float> GetTransferFunctionParams() const;
226
235 GF_API
236 std::tuple<GfVec2f, GfVec2f, GfVec2f, GfVec2f>
238
239private:
240 struct _Data;
241 std::shared_ptr<_Data> _data;
242};
243
244PXR_NAMESPACE_CLOSE_SCOPE
245
246#endif // PXR_BASE_GF_COLORSPACE_H
Represents a color in a specific color space.
Definition color.h:41
Basic type: ColorSpace.
Definition colorSpace.h:117
GF_API void ConvertRGBASpan(const GfColorSpace &srcColorSpace, TfSpan< float > rgba) const
Convert in place a packed array of RGBA values from one color space to "this one.
GF_API std::tuple< GfVec2f, GfVec2f, GfVec2f, GfVec2f > GetPrimariesAndWhitePoint() const
Get the chromaticity coordinates and white point if the color space was constructed from primaries.
GF_API TfToken GetName() const
Get the name of the color space.
GF_API GfMatrix3f GetRGBToRGB(const GfColorSpace &srcColorSpace) const
Get the RGB to RGB conversion matrix from srcColorSpace to "this" color space.
bool operator!=(const GfColorSpace &rh) const
Check if two color spaces are not equal.
Definition colorSpace.h:178
GF_API GfColorSpace(const TfToken &name, const GfMatrix3f &rgbToXYZ, float gamma, float linearBias)
Construct a color space from a 3x3 matrix and linearization parameters.
GF_API GfColorSpace(const TfToken &name, const GfVec2f &redChroma, const GfVec2f &greenChroma, const GfVec2f &blueChroma, const GfVec2f &whitePoint, float gamma, float linearBias)
Construct a custom color space from raw values.
GF_API GfMatrix3f GetRGBToXYZ() const
Get the RGB to XYZ conversion matrix.
GF_API float GetGamma() const
Get the gamma value of the color space.
GF_API bool operator==(const GfColorSpace &rh) const
Check if two color spaces are equal.
static GF_API bool IsValid(const TfToken &name)
Check if a color space name is valid for constructing a GfColorSpace by name.
GF_API void ConvertRGBSpan(const GfColorSpace &srcColorSpace, TfSpan< float > rgb) const
Convert in place a packed array of RGB values from one color space to "this" one.
GF_API GfColor Convert(const GfColorSpace &srcColorSpace, const GfVec3f &rgb) const
Convert a rgb triplet in a certain color space to "this" color space.
GF_API float GetLinearBias() const
Get the linear bias of the color space.
GF_API GfColorSpace(const TfToken &name)
Construct a GfColorSpace from a name token.
GF_API std::pair< float, float > GetTransferFunctionParams() const
Get the computed K0 and Phi values for use in the transfer function.
Stores a 3x3 matrix of float elements.
Definition matrix3f.h:65
Basic type for a vector of 2 float components.
Definition vec2f.h:46
Basic type for a vector of 3 float components.
Definition vec3f.h:46
Represents a range of contiguous elements.
Definition span.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:71
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.