Skip to content

Conversation

kwokcb
Copy link
Contributor

@kwokcb kwokcb commented Sep 3, 2025

Updates

  • Fixes Python Interface for ImageLoader and Image cannot support custom loaders #2528
  • Patches to make image loaders declared in Python to work properly.
    • Fixes image data passing (void*) cannot resolve properly.
    • Virtualize extension support query and pass by reference to get data returned properly from derived classes.
    • Add in trampoline classes so that derived classes get called properly
    • Fix missing type enumerations in pybind bindings.

Tests

  • Sample OIIO Loader test added along with sample image from OpenEXR tests
    • Registers the custom load with ImageHander interface
    • Calls aquireImage which will check extensions EXR is not by default supported so will find the sample OIIO loader
    • Calls virtual loadImage override. Also displays the image using matplotlib if available
    • The MaterialX Image is cached in memory after load.
    • Calls saveImage on the ImageHandler passing the MaterialX Image which will again check extensions and call back to the OIIO loader.
    • Calls saveImage override. Also displays the imsage using matplotlib if available.

Results:

  • EXR Image loaded
image
  • EXR Image saved
image

Possible Integration

This is a possible integration where the loader is used inside of the Graph Editor. Two format not supported by default but available via OIIO shown: EXR and WEBP

image image

@@ -10,11 +10,18 @@
namespace py = pybind11;
namespace mx = MaterialX;

uintptr_t getResourceBuffer(const mx::Image& image)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot pass back and forth void pointers for buffer data.
Add a concrete type to wrap.

@@ -18,7 +18,39 @@ void bindPyImageHandler(py::module& mod)
.def_readwrite("filterType", &mx::ImageSamplingProperties::filterType)
.def_readwrite("defaultColor", &mx::ImageSamplingProperties::defaultColor);

py::class_<mx::ImageLoader, mx::ImageLoaderPtr>(mod, "ImageLoader")
// Trampoline class for Python overrides
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this glue code was not added, Python loader code would never be called.

void bindPyImage(py::module& mod)
{
py::enum_<mx::Image::BaseType>(mod, "BaseType")
.value("UINT8", mx::Image::BaseType::UINT8)
.value("INT8", mx::Image::BaseType::INT8)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add missing types.

@@ -0,0 +1,429 @@
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample code which works for EXR and other image types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python Interface for ImageLoader and Image cannot support custom loaders
1 participant