Loading...
Searching...
No Matches
dataSourceAttributeColorSpace.h
1//
2// Copyright 2023 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_USD_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
8#define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
9
10#include "pxr/usd/usd/attribute.h"
11#include "pxr/usdImaging/usdImaging/api.h"
12#include "pxr/imaging/hd/dataSource.h"
13#include "pxr/imaging/hd/dataSourceTypeDefs.h"
15
16PXR_NAMESPACE_OPEN_SCOPE
17
23{
24public:
25
26 HD_DECLARE_DATASOURCE(UsdImagingDataSourceAttributeColorSpace);
27
30 VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
31 {
32 return VtValue(GetTypedValue(shutterOffset));
33 }
34
38 TfToken GetTypedValue(HdSampledDataSource::Time shutterOffset) override
39 {
40 if (!_usdAttr) {
41 return {};
42 }
43
44 TF_UNUSED(shutterOffset);
45
46 // Special Case handling of UsdUVTexture Nodes which has an
47 // 'inputs:sourceColorSpace' that we want to consolidate on the
48 // 'inputs:file' parameter
49 TfToken sourceColorSpaceInput = _GetSourceColorSpaceInput();
50 if (!sourceColorSpaceInput.IsEmpty()) {
51 return sourceColorSpaceInput;
52 }
53
54 // If there is no inputs:sourceColorSpace value authored, use the
55 // ColorspaceAPI to find the resolved color space for the attribute.
57 }
58
63 HdSampledDataSource::Time startTime,
64 HdSampledDataSource::Time endTime,
65 std::vector<HdSampledDataSource::Time> *outSampleTimes) override
66 {
67 TF_UNUSED(startTime);
68 TF_UNUSED(endTime);
69 return false;
70 }
71
72private:
73
78
79
80 // Helper to get the TfToken authored to the 'inputs:sourceColorSpace'
81 // for the 'inputs:file' attribute
82 TfToken _GetSourceColorSpaceInput() {
83 static TfToken inputSourceColorSpace("inputs:sourceColorSpace");
84
85 // Only add add the source color space to the file attribute
86 if (_usdAttr.GetName() != "inputs:file") {
87 return TfToken();
88 }
89
90 TfToken sourceColorSpace;
91 UsdPrim prim = _usdAttr.GetPrim();
92 if (prim.HasAttribute(inputSourceColorSpace)) {
93 VtValue sourceCSValue;
94 prim.GetAttribute(inputSourceColorSpace).Get(&sourceCSValue);
95 if (sourceCSValue.IsHolding<TfToken>()) {
96 sourceColorSpace = sourceCSValue.UncheckedGet<TfToken>();
97 }
98 }
99 return sourceColorSpace;
100 }
101
102private:
103 UsdAttribute _usdAttr;
104};
105
106
107PXR_NAMESPACE_CLOSE_SCOPE
108
109#endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
A datasource representing a concretely-typed sampled value.
Definition: dataSource.h:193
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of this attribute at the requested UsdTimeCode time,...
Definition: attribute.h:468
static USD_API TfToken ComputeColorSpaceName(const UsdAttribute &attribute, ColorSpaceCache *cache=nullptr)
Computes the color space name for the given attribute.
A data source that represents the metadata on a USD Attribute.
TfToken GetTypedValue(HdSampledDataSource::Time shutterOffset) override
Returns the extracted TfToken value of the color space for the attribute.
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
Returns false since we do not expect the color space value to vary over time.
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
Returns the VtValue of the colorspace for the attribute.
UsdPrim GetPrim() const
Return this object if it is a prim, otherwise return this object's nearest owning prim.
Definition: prim.h:2801
const TfToken & GetName() const
Return the full name of this object, i.e.
Definition: object.h:222
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
Return a UsdAttribute with the name attrName.
USD_API bool HasAttribute(const TfToken &attrName) const
Return true if this prim has an attribute named attrName, false otherwise.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
Definition: value.h:1002
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1046
#define TF_UNUSED(x)
Stops compiler from producing unused argument or variable warnings.
Definition: tf.h:168