-
Notifications
You must be signed in to change notification settings - Fork 408
Fix Python Interfaces For Image Loaders #2541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix Python Interfaces For Image Loaders #2541
Conversation
- Sample OIIO Loader test added.
| namespace py = pybind11; | ||
| namespace mx = MaterialX; | ||
|
|
||
| uintptr_t getResourceBuffer(const mx::Image& image) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 @@ | |||
| """ | |||
There was a problem hiding this comment.
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.
ld-kerley
left a comment
There was a problem hiding this 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
jstone-lucasfilm
left a comment
There was a problem hiding this 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 @@ | |||
| """ | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Updates
Tests
ImageHanderinterfaceaquireImagewhich will check extensions EXR is not by default supported so will find the sample OIIO loaderloadImageoverride. Also displays the image usingmatplotlibif availableImageis cached in memory after load.saveImageon theImageHandlerpassing the MaterialXImagewhich will again check extensions and call back to the OIIO loader.saveImageoverride. Also displays the imsage usingmatplotlibif available.Results:
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.exrPossible 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