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
53#define GF_COLORSPACE_NAME_TOKENS \
54 ((Identity, "identity")) \
55 ((Raw, "raw")) \
56 ((ACEScg, "acescg")) \
57 ((AdobeRGB, "adobergb")) \
58 ((LinearAdobeRGB, "lin_adobergb")) \
59 ((CIEXYZ, "CIEXYZ")) \
60 ((LinearAP0, "lin_ap0")) \
61 ((LinearAP1, "lin_ap1")) \
62 ((G18AP1, "g18_ap1")) \
63 ((G22AP1, "g22_ap1")) \
64 ((LinearRec2020, "lin_rec2020")) \
65 ((LinearRec709, "lin_rec709")) \
66 ((G18Rec709, "g18_rec709")) \
67 ((G22Rec709, "g22_rec709")) \
68 ((LinearDisplayP3, "lin_displayp3")) \
69 ((LinearSRGB, "lin_srgb")) \
70 ((SRGBTexture, "srgb_texture")) \
71 ((SRGB, "sRGB")) \
72 ((SRGBDisplayP3, "srgb_displayp3")) \
73
74TF_DECLARE_PUBLIC_TOKENS(GfColorSpaceNames, GF_API,
75 GF_COLORSPACE_NAME_TOKENS);
76
77class GfColor;
78
93
95 friend class GfColor;
96public:
100 GF_API
101 explicit GfColorSpace(const TfToken& name);
102
114 GF_API
115 explicit GfColorSpace(const TfToken& name,
116 const GfVec2f &redChroma,
117 const GfVec2f &greenChroma,
118 const GfVec2f &blueChroma,
119 const GfVec2f &whitePoint,
120 float gamma,
121 float linearBias);
122
131 GF_API
132 explicit GfColorSpace(const TfToken& name,
133 const GfMatrix3f &rgbToXYZ,
134 float gamma,
135 float linearBias);
136
140 GF_API
142
147 GF_API
148 bool operator ==(const GfColorSpace &rh) const;
149
154 bool operator !=(const GfColorSpace &rh) const { return !(*this == rh); }
155
160 GF_API
161 void ConvertRGBSpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgb) const;
162
167 GF_API
168 void ConvertRGBASpan(const GfColorSpace& srcColorSpace, TfSpan<float> rgba) const;
169
171 GF_API
172 GfColor Convert(const GfColorSpace& srcColorSpace, const GfVec3f& rgb) const;
173
177 GF_API
179
183 GF_API
184 float GetGamma() const;
185
189 GF_API
190 float GetLinearBias() const;
191
194 GF_API
195 std::pair<float, float> GetTransferFunctionParams() const;
196
205 GF_API
206 std::tuple<GfVec2f, GfVec2f, GfVec2f, GfVec2f>
208
209private:
210 struct _Data;
211 std::shared_ptr<_Data> _data;
212};
213
214PXR_NAMESPACE_CLOSE_SCOPE
215
216#endif // PXR_BASE_GF_COLORSPACE_H
Represents a color in a specific color space.
Definition: color.h:41
Basic type: ColorSpace.
Definition: colorSpace.h:94
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:154
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.
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