MCPcopy Create free account
hub / github.com/AcademySoftwareFoundation/MaterialX / OiioImageLoader

Class OiioImageLoader

python/Scripts/oiio_loader.py:53–370  ·  view source on GitHub ↗

A MaterialX ImageLoader implementation that uses OpenImageIO to read image files. Inherits from MaterialX.ImageLoader and implements the required interface methods. Supports common image formats like PNG, JPEG, TIFF, EXR, HDR, etc.

Source from the content-addressed store, hash-verified

51 logger.warning("matplotlib module not found. Image preview display is disabled.")
52
53class OiioImageLoader(mx_render.ImageLoader):
54 """
55 A MaterialX ImageLoader implementation that uses OpenImageIO to read image files.
56
57 Inherits from MaterialX.ImageLoader and implements the required interface methods.
58 Supports common image formats like PNG, JPEG, TIFF, EXR, HDR, etc.
59 """
60
61 def __init__(self):
62 """
63 Initialize the OiioImageLoader and set supported extensions."""
64 super().__init__()
65
66 # Set all extensions supported by OpenImageIO. e.g.
67 # openexr:exr,sxr,mxr;tiff:tif,tiff,tx,env,sm,vsm;jpeg:jpg,jpe,jpeg,jif,jfif,jfi;bmp:bmp,dib;cineon:cin;dds:dds;dpx:dpx;fits:fits;hdr:hdr,rgbe;ico:ico;iff:iff,z;null:null,nul;png:png;pnm:ppm,pgm,pbm,pnm,pfm;psd:psd,pdd,psb;rla:rla;sgi:sgi,rgb,rgba,bw,int,inta;softimage:pic;targa:tga,tpic;term:term;webp:webp;zfile:zfile
68 self._extensions = set()
69 oiio_extensions = oiio.get_string_attribute("extension_list")
70 # Split string by ";"
71 for group in oiio_extensions.split(";"):
72 # Each group is like "openexr:exr,sxr,mxr"
73 if ":" in group:
74 _, exts = group.split(":", 1)
75 self._extensions.update(ext.strip() for ext in exts.split(","))
76 else:
77 self._extensions.update(ext.strip() for ext in group.split(","))
78 logger.debug(f"Cache supported extensions: {self._extensions}")
79
80 self.preview = False
81 self.identifier = "OpenImageIO Custom Image Loader"
82 self.color_space = {}
83
84 def supportedExtensions(self):
85 """
86 Derived method to return a set of supported image file extensions.
87 """
88 logger.info(f"OIIO supported extensions: {self._extensions}")
89 return self._extensions
90
91 def set_preview(self, value):
92 """
93 Set whether to preview images when loading and saving
94
95 @param value: Boolean indicating whether to enable preview
96 """
97 self.preview = value
98
99 def get_identifier(self):
100 return "OIIO Custom Loader"
101
102 def previewImage(self, title, data, width, height, nchannels, color_space):
103 """
104 Utility method to preview an image using matplotlib.
105 Handles normalization and dtype for correct display.
106
107 @param title: Title for the preview window
108 @param data: Image data array
109 @param width: Image width
110 @param height: Image height

Callers 1

test_load_saveFunction · 0.70

Calls

no outgoing calls

Tested by 1

test_load_saveFunction · 0.56