All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
56#define GF_COLORSPACE_NAME_TOKENS \
57 ((CIEXYZ, "lin_ciexyzd65_scene")) \
58 ((Data, "data")) \
59 ((Raw, "raw")) \
60 ((Unknown, "unknown")) \
61 ((LinearAdobeRGB, "lin_adobergb_scene")) \
62 ((LinearAP0, "lin_ap0_scene")) \
63 ((LinearAP1, "lin_ap1_scene")) \
64 ((LinearDisplayP3, "lin_displayp3_scene")) \
65 ((LinearRec2020, "lin_rec2020_scene")) \
66 ((LinearRec709, "lin_rec709_scene")) \
67 ((G18Rec709, "g18_rec709_scene")) \
68 ((G22AdobeRGB, "g22_adobergb_scene")) \
69 ((G22AP1, "g22_ap1_scene")) \
70 ((G22Rec709, "g22_rec709_scene")) \
71 ((SRGBP3D65, "srgb_p3d65_scene")) \
72 ((SRGBRec709, "srgb_rec709_scene")) \
73 ((SRGBAP1, "srgb_ap1_scene"))
74
75TF_DECLARE_PUBLIC_TOKENS(GfColorSpaceNames, GF_API,
76 GF_COLORSPACE_NAME_TOKENS);
77
78class GfColor;
79
94
96 friend class GfColor;
97public:
101 GF_API
102 explicit GfColorSpace(const TfToken& name);
103
106 GF_API
107 static bool IsValid(const TfToken& name);
108
118 GF_API
119 explicit GfColorSpace(const TfToken& name,
120 const GfVec2f &redChroma,
121 const GfVec2f &greenChroma,
122 const GfVec2f &blueChroma,
123 const GfVec2f &whitePoint,
124 float gamma,
125 float linearBias);
126
133 GF_API
134 explicit GfColorSpace(const TfToken& name,
135 const GfMatrix3f &rgbToXYZ,
136 float gamma,
137 float linearBias);
138
142 GF_API
144
149 GF_API
150 bool operator ==(const GfColorSpace &rh) const;
151
156 bool operator !=(const GfColorSpace &rh) const { return !(*this == rh); }
157
162 GF_API
163 void ConvertRGBSpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgb) const;
164
169 GF_API
170 void ConvertRGBASpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgba) const;
171
173 GF_API
174 GfColor Convert(const GfColorSpace& srcColorSpace, const GfVec3f& rgb) const;
175
179 GF_API
181
185 GF_API
186 float GetGamma() const;
187
191 GF_API
192 float GetLinearBias() const;
193
196 GF_API
197 std::pair<float, float> GetTransferFunctionParams() const;
198
207 GF_API
208 std::tuple<GfVec2f, GfVec2f, GfVec2f, GfVec2f>
210
211private:
212 struct _Data;
213 std::shared_ptr<_Data> _data;
214};
215
216PXR_NAMESPACE_CLOSE_SCOPE
217
218#endif // PXR_BASE_GF_COLORSPACE_H
Represents a color in a specific color space.
Definition: color.h:41
Basic type: ColorSpace.
Definition: colorSpace.h:95
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.
bool operator!=(const GfColorSpace &rh) const
Check if two color spaces are not equal.
Definition: colorSpace.h:156
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.
Definition: staticTokens.h:81