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
73#define GF_COLORSPACE_NAME_TOKENS \
74 ((LinearAP1, "lin_ap1_scene")) \
75 ((LinearAP0, "lin_ap0_scene")) \
76 ((LinearRec709, "lin_rec709_scene")) \
77 ((LinearP3D65, "lin_p3d65_scene")) \
78 ((LinearRec2020, "lin_rec2020_scene")) \
79 ((LinearAdobeRGB, "lin_adobergb_scene")) \
80 ((LinearCIEXYZD65, "lin_ciexyzd65_scene")) \
81 ((SRGBRec709, "srgb_rec709_scene")) \
82 ((G22Rec709, "g22_rec709_scene")) \
83 ((G18Rec709, "g18_rec709_scene")) \
84 ((SRGBAP1, "srgb_ap1_scene")) \
85 ((G22AP1, "g22_ap1_scene")) \
86 ((SRGBP3D65, "srgb_p3d65_scene")) \
87 ((G22AdobeRGB, "g22_adobergb_scene")) \
88 ((Identity, "identity")) \
89 ((Data, "data")) \
90 ((Raw, "raw")) \
91 ((Unknown, "unknown")) \
92 ((CIEXYZ, "lin_ciexyzd65_scene")) \
93 ((LinearDisplayP3, "lin_p3d65_scene"))
94
95TF_DECLARE_PUBLIC_TOKENS(GfColorSpaceNames, GF_API,
96 GF_COLORSPACE_NAME_TOKENS);
97
98class GfColor;
99
114
116 friend class GfColor;
117public:
121 GF_API
122 explicit GfColorSpace(const TfToken& name);
123
126 GF_API
127 static bool IsValid(const TfToken& name);
128
138 GF_API
139 explicit GfColorSpace(const TfToken& name,
140 const GfVec2f &redChroma,
141 const GfVec2f &greenChroma,
142 const GfVec2f &blueChroma,
143 const GfVec2f &whitePoint,
144 float gamma,
145 float linearBias);
146
153 GF_API
154 explicit GfColorSpace(const TfToken& name,
155 const GfMatrix3f &rgbToXYZ,
156 float gamma,
157 float linearBias);
158
162 GF_API
164
169 GF_API
170 bool operator ==(const GfColorSpace &rh) const;
171
176 bool operator !=(const GfColorSpace &rh) const { return !(*this == rh); }
177
182 GF_API
183 void ConvertRGBSpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgb) const;
184
189 GF_API
190 void ConvertRGBASpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgba) const;
191
193 GF_API
194 GfColor Convert(const GfColorSpace& srcColorSpace, const GfVec3f& rgb) const;
195
199 GF_API
201
205 GF_API
206 GfMatrix3f GetRGBToRGB(const GfColorSpace& srcColorSpace) const;
207
211 GF_API
212 float GetGamma() const;
213
217 GF_API
218 float GetLinearBias() const;
219
222 GF_API
223 std::pair<float, float> GetTransferFunctionParams() const;
224
233 GF_API
234 std::tuple<GfVec2f, GfVec2f, GfVec2f, GfVec2f>
236
237private:
238 struct _Data;
239 std::shared_ptr<_Data> _data;
240};
241
242PXR_NAMESPACE_CLOSE_SCOPE
243
244#endif // PXR_BASE_GF_COLORSPACE_H
Represents a color in a specific color space.
Definition: color.h:41
Basic type: ColorSpace.
Definition: colorSpace.h:115
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:176
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:92