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:

  • Running:
python python/Scripts/oiio_loader.py resources/Images/gamma_chart.exr
  • Log:
INFO:OIIOLoad:OIIO supported extensions: {'pnm', 'null', 'tif', 'pbm', 'sxr', 'tiff', 'mxr', 'exr', 'jpg', 'tpic', 'dds', 'hdr', 'pfm', 'rgb', 'rgbe', 'iff', 'jpeg', 'cin', 'int', 'sgi', 'z', 'ppm', 'rla', 'fits', 'nul', 'sm', 'psd', 'ico', 'webp', 'pic', 'zfile', 'jfif', 'dib', 'pgm', 'tx', 'psb', 'jif', 'jfi', 'jpe', 'pdd', 'term', 'env', 'vsm', 'png', 'bmp', 'bw', 'rgba', 'inta', 'tga', 'dpx'}
INFO:OIIOLoad:Created image handler with loader (OIIO Custom Loader): True
INFO:OIIOLoad:OIIO supported extensions: {'pnm', 'null', 'tif', 'pbm', 'sxr', 'tiff', 'mxr', 'exr', 'jpg', 'tpic', 'dds', 'hdr', 'pfm', 'rgb', 'rgbe', 'iff', 'jpeg', 'cin', 'int', 'sgi', 'z', 'ppm', 'rla', 'fits', 'nul', 'sm', 'psd', 'ico', 'webp', 'pic', 'zfile', 'jfif', 'dib', 'pgm', 'tx', 'psb', 'jif', 'jfi', 'jpe', 'pdd', 'term', 'env', 'vsm', 'png', 'bmp', 'bw', 'rgba', 'inta', 'tga', 'dpx'}
INFO:OIIOLoad:---------------------------------------------
INFO:OIIOLoad:Loading image from path: resources\Images\gamma_chart.exr
INFO:OIIOLoad:Load using OIIO loader: resources\Images\gamma_chart.exr
INFO:OIIOLoad:ColorSpace: lin_rec709
INFO:OIIOLoad:Total bytes read in: 3840000 (width: 800, height: 800, channels: 3, format: half)
INFO:OIIOLoad:MaterialX Image loaded via Image Handler:
INFO:OIIOLoad:  Dimensions: 800x800
INFO:OIIOLoad:  Channels: 3
INFO:OIIOLoad:  Base type: BaseType.HALF
INFO:OIIOLoad:---------------------------------------------
INFO:OIIOLoad:mx_basetype: BaseType.HALF, oiio_format: BASETYPE.HALF, base_stride: 2
INFO:OIIOLoad:Previewing image after load into Image and reload for save...
INFO:OIIOLoad:colorspace lookup for: gamma_chart.exr. list: lin_rec709
INFO:OIIOLoad:Image saved to saved_gamma_chart.exr (w=800, h=800, c=3, type=BaseType.HALF)
INFO:OIIOLoad:MaterialX Image saved to saved_gamma_chart.exr
  • Running:
python python/Scripts/oiio_loader.py resources/Images/gamma_chart.exr --preview
EXR Image loaded EXR Image saved
image 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

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.

.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.

{
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.

@kwokcb kwokcb requested a review from ld-kerley November 6, 2025 15:20
Copy link
Contributor

@ld-kerley ld-kerley left a comment

Choose a reason for hiding this comment

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

Looks like a good fix and a good addition to me - thanks

Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me, thanks @kwokcb, and I had just minor notes on following surrounding naming conventions for new files.

@@ -0,0 +1,429 @@
"""
Copy link
Member

Choose a reason for hiding this comment

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

Just to match the surrounding naming conventions, I'd recommend naming this script oiio_loader.py.

Copy link
Member

Choose a reason for hiding this comment

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

Just to match the surrounding naming conventions, I'd recommend naming this image gamma_chart.exr.

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

3 participants