Skip to content

Commit 9eb736b

Browse files
hodoulpdoug-walker
andauthored
Adsk Contrib - Various code & doc cleanups (#1414) (#1444)
* Adsk Contrib - Various code & doc cleanups Signed-off-by: Patrick Hodoul <[email protected]> * Fix more Python examples Signed-off-by: Patrick Hodoul <[email protected]> Co-authored-by: doug-walker <[email protected]>
1 parent 0472317 commit 9eb736b

File tree

4 files changed

+126
-60
lines changed

4 files changed

+126
-60
lines changed

docs/guides/authoring/looks_example.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Example Python API call:
5252
.. code-block:: python
5353
5454
look = OCIO.Look(name='di', processSpace='rclg16')
55-
t = OCIO.FileTransform('look_di.cc', interpolation=OCIO.Constants.INTERP_LINEAR)
55+
t = OCIO.FileTransform('look_di.cc', interpolation=OCIO.INTERP_LINEAR)
5656
look.setTransform(t)
5757
config.addLook(look)
5858

docs/guides/developing/usage_examples.rst

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,16 @@ Python
9393
import PyOpenColorIO as OCIO
9494
9595
try:
96-
config = OCIO.GetCurrentConfig()
97-
processor = config.getProcessor(OCIO.Constants.ROLE_COMPOSITING_LOG,
98-
OCIO.Constants.ROLE_SCENE_LINEAR)
99-
cpu = processor->getDefaultCPUProcessor()
96+
config = OCIO.GetCurrentConfig()
97+
processor = config.getProcessor(OCIO.ROLE_COMPOSITING_LOG,
98+
OCIO.ROLE_SCENE_LINEAR)
99+
cpu = processor.getDefaultCPUProcessor()
100100
101-
# Apply the color transform to the existing RGBA pixel data
102-
img = cpu.applyRGBA(img)
103-
except Exception, e:
104-
print "OpenColorIO Error",e
101+
# Apply the color transform to the existing RGBA pixel data
102+
img = [1, 0, 0, 0]
103+
img = cpu.applyRGBA(img)
104+
except Exception as e:
105+
print("OpenColorIO Error: ", e)
105106
106107
.. _usage_displayimage:
107108

@@ -137,17 +138,18 @@ C++
137138
138139
try
139140
{
140-
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
141+
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
141142
142-
const char * display = config->getDefaultDisplay();
143-
const char * view = config->getDefaultView(display);
143+
const char * display = config->getDefaultDisplay();
144+
const char * view = config->getDefaultView(display);
144145
145-
OCIO::ConstProcessorRcPtr processor = config->getProcessor(OCIO::ROLE_SCENE_LINEAR,
146-
display, view);
147-
OCIO::ConstCPUProcessorRcPtr cpu = processor->getDefaultCPUProcessor();
146+
OCIO::ConstProcessorRcPtr processor = config->getProcessor(OCIO::ROLE_SCENE_LINEAR,
147+
display, view,
148+
OCIO::TRANSFORM_DIR_FORWARD);
149+
OCIO::ConstCPUProcessorRcPtr cpu = processor->getDefaultCPUProcessor();
148150
149-
OCIO::PackedImageDesc img(imageData, width, height, 4);
150-
cpu->apply(img);
151+
OCIO::PackedImageDesc img(imageData, width, height, 4);
152+
cpu->apply(img);
151153
}
152154
catch(OCIO::Exception & exception)
153155
{
@@ -159,21 +161,21 @@ Python
159161

160162
.. code-block:: python
161163
162-
import PyOpenColorIO as OCIO
164+
import PyOpenColorIO as OCIO
163165
164166
try:
165-
config = OCIO.GetCurrentConfig()
167+
config = OCIO.GetCurrentConfig()
166168
167-
display = config.getDefaultDisplay()
168-
view = config.getDefaultView(display)
169+
display = config.getDefaultDisplay()
170+
view = config.getDefaultView(display)
169171
170-
processor = config.getProcessor(OCIO.Constants.ROLE_SCENE_LINEAR, display, view)
171-
cpu = processor.getDefaultCPUProcessor()
172+
processor = config.getProcessor(OCIO.ROLE_SCENE_LINEAR, display, view, OCIO.TRANSFORM_DIR_FORWARD)
173+
cpu = processor.getDefaultCPUProcessor()
172174
173-
imageData = [1, 0, 0]
174-
cpu.applyRGB(img)
175-
except Exception, e:
176-
print "OpenColorIO Error",e
175+
img = [1, 0, 0]
176+
cpu.applyRGB(img)
177+
except Exception as e:
178+
print("OpenColorIO Error: ", e)
177179
178180
Displaying an image, using the CPU (Full Display Pipeline)
179181
**********************************************************
@@ -246,30 +248,30 @@ Python
246248

247249
.. code-block:: python
248250
249-
import PyOpenColorIO as OCIO
251+
import PyOpenColorIO as OCIO
250252
251-
# Step 1: Get the config
252-
config = OCIO.GetCurrentConfig()
253+
# Step 1: Get the config
254+
config = OCIO.GetCurrentConfig()
253255
254-
# Step 2: Lookup the display ColorSpace
255-
display = config.getDefaultDisplay()
256-
view = config.getDefaultView(display)
256+
# Step 2: Lookup the display ColorSpace
257+
display = config.getDefaultDisplay()
258+
view = config.getDefaultView(display)
257259
258-
# Step 3: Create a DisplayTransform, and set the input, display, and view
259-
# (This example assumes the input is scene linear. Adapt as needed.)
260+
# Step 3: Create a DisplayViewTransform, and set the input, display, and view
261+
# (This example assumes the input is a role. Adapt as needed.)
260262
261-
transform = OCIO.DisplayTransform()
262-
transform.setInputColorSpaceName(OCIO.Constants.ROLE_SCENE_LINEAR)
263-
transform.setDisplay(display)
264-
transform.setView(view)
263+
transform = OCIO.DisplayViewTransform()
264+
transform.setSrc(OCIO.Constants.ROLE_SCENE_LINEAR)
265+
transform.setDisplay(display)
266+
transform.setView(view)
265267
266-
# Step 4: Create the processor
267-
processor = config.getProcessor(transform)
268-
cpu = processor.getDefaultCPUProcessor()
268+
# Step 4: Create the processor
269+
processor = config.getProcessor(transform)
270+
cpu = processor.getDefaultCPUProcessor()
269271
270-
# Step 5: Apply the color transform to an existing RGB pixel
271-
imageData = [1, 0, 0]
272-
print cpu.applyRGB(imageData)
272+
# Step 5: Apply the color transform to an existing RGB pixel
273+
imageData = [1, 0, 0]
274+
print(cpu.applyRGB(imageData))
273275
274276
275277
Displaying an image, using the GPU

include/OpenColorIO/OpenColorIO.h

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,15 +2720,59 @@ class OCIOEXPORT PlanarImageDesc : public ImageDesc
27202720
// GpuShaderCreator
27212721
/**
27222722
* Inherit from the class to fully customize the implementation of a GPU shader program
2723-
* from a color transformation.
2723+
* from a color transformation.
27242724
*
2725-
* When no customizations are needed then the :cpp:class:`GpuShaderDesc` is a better choice.
2725+
* When no customizations are needed and the intermediate in-memory step is acceptable then the
2726+
* \ref GpuShaderDesc is a better choice.
27262727
*
2727-
* To better decouple the DynamicProperties from their GPU implementation, the code provides
2728-
* several addUniform() methods i.e. one per access function types. For example, an
2729-
* ExposureContrastTransform instance owns three DynamicProperties and they are all
2730-
* implemented by a double. When creating the GPU fragment shader program, the addUniform() with
2731-
* GpuShaderCreator::DoubleGetter is called when property is dynamic, up to three times.
2728+
* \note
2729+
* To better decouple the \ref DynamicProperties from their GPU implementation, the code provides
2730+
* several addUniform() methods i.e. one per access function types. For example, an
2731+
* \ref ExposureContrastTransform instance owns three \ref DynamicProperties and they are all
2732+
* implemented by a double. When creating the GPU fragment shader program, the addUniform() with
2733+
* GpuShaderCreator::DoubleGetter is called when property is dynamic, up to three times.
2734+
*
2735+
* **An OCIO shader program could contain:**
2736+
*
2737+
* * A declaration part e.g., uniform sampled3D tex3;
2738+
*
2739+
* * Some helper methods
2740+
*
2741+
* * The OCIO shader function may be broken down as:
2742+
*
2743+
* * The function header e.g., void OCIODisplay(in vec4 inColor) {
2744+
* * The function body e.g., vec4 outColor.rgb = texture3D(tex3, inColor.rgb).rgb;
2745+
* * The function footer e.g., return outColor; }
2746+
*
2747+
*
2748+
* **Usage Example:**
2749+
*
2750+
* Below is a code snippet to highlight the different parts of the OCIO shader program.
2751+
*
2752+
* \code{.cpp}
2753+
*
2754+
* // All global declarations
2755+
* uniform sampled3D tex3;
2756+
*
2757+
* // All helper methods
2758+
* vec3 computePosition(vec3 color)
2759+
* {
2760+
* vec3 coords = color;
2761+
* // Some processing...
2762+
* return coords;
2763+
* }
2764+
*
2765+
* // The shader function
2766+
* vec4 OCIODisplay(in vec4 inColor) //
2767+
* { // Function Header
2768+
* vec4 outColor = inColor; //
2769+
*
2770+
* outColor.rgb = texture3D(tex3, computePosition(inColor.rgb)).rgb;
2771+
*
2772+
* return outColor; // Function Footer
2773+
* } //
2774+
*
2775+
* \endcode
27322776
*/
27332777
class OCIOEXPORT GpuShaderCreator
27342778
{
@@ -2774,8 +2818,8 @@ class OCIOEXPORT GpuShaderCreator
27742818
virtual unsigned getTextureMaxWidth() const noexcept = 0;
27752819

27762820
/**
2777-
* To avoid texture/unform name clashes always append
2778-
* an increasing number to the resource name.
2821+
* To avoid global texture sampler and uniform name clashes always append an increasing index
2822+
* to the resource name.
27792823
*/
27802824
unsigned getNextResourceIndex() noexcept;
27812825

@@ -2825,17 +2869,32 @@ class OCIOEXPORT GpuShaderCreator
28252869

28262870
enum TextureType
28272871
{
2828-
TEXTURE_RED_CHANNEL, ///< Only use the red channel of the texture
2829-
TEXTURE_RGB_CHANNEL
2872+
TEXTURE_RED_CHANNEL, ///< Only need a red channel texture
2873+
TEXTURE_RGB_CHANNEL ///< Need a RGB texture
28302874
};
28312875

2876+
/**
2877+
* Add a 2D texture (1D texture if height equals 1).
2878+
*
2879+
* \note
2880+
* The 'values' parameter contains the LUT data which must be used as-is as the dimensions and
2881+
* origin are hard-coded in the fragment shader program. So, it means one GPU texture per entry.
2882+
**/
28322883
virtual void addTexture(const char * textureName,
28332884
const char * samplerName,
28342885
unsigned width, unsigned height,
28352886
TextureType channel,
28362887
Interpolation interpolation,
28372888
const float * values) = 0;
28382889

2890+
/**
2891+
* Add a 3D texture with RGB channel type.
2892+
*
2893+
* \note
2894+
* The 'values' parameter contains the 3D LUT data which must be used as-is as the dimension
2895+
* and origin are hard-coded in the fragment shader program. So, it means one GPU 3D texture
2896+
* per entry.
2897+
**/
28392898
virtual void add3DTexture(const char * textureName,
28402899
const char * samplerName,
28412900
unsigned edgelen,

src/OpenColorIO/Config.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,16 +1170,21 @@ ConstConfigRcPtr Config::CreateFromEnv()
11701170
Platform::Getenv(OCIO_CONFIG_ENVVAR, file);
11711171
if(!file.empty()) return CreateFromFile(file.c_str());
11721172

1173-
std::ostringstream os;
1174-
os << "Color management disabled. ";
1175-
os << "(Specify the $OCIO environment variable to enable.)";
1176-
LogInfo(os.str());
1173+
static const char err[] =
1174+
"Color management disabled. (Specify the $OCIO environment variable to enable.)";
1175+
1176+
LogInfo(err);
11771177

11781178
return CreateRaw();
11791179
}
11801180

11811181
ConstConfigRcPtr Config::CreateFromFile(const char * filename)
11821182
{
1183+
if (!filename || !*filename)
1184+
{
1185+
throw ExceptionMissingFile ("The config filepath is missing.");
1186+
}
1187+
11831188
std::ifstream istream(filename);
11841189
if (istream.fail())
11851190
{

0 commit comments

Comments
 (0)