@@ -79,6 +79,7 @@ def __init__(self):
7979
8080 self .preview = False
8181 self .identifier = "OpenImageIO Custom Image Loader"
82+ self .color_space = {}
8283
8384 def supportedExtensions (self ):
8485 """
@@ -98,7 +99,7 @@ def set_preview(self, value):
9899 def get_identifier (self ):
99100 return "OIIO Custom Loader"
100101
101- def previewImage (self , title , data , width , height , nchannels ):
102+ def previewImage (self , title , data , width , height , nchannels , color_space ):
102103 """
103104 Utility method to preview an image using matplotlib.
104105 Handles normalization and dtype for correct display.
@@ -108,6 +109,7 @@ def previewImage(self, title, data, width, height, nchannels):
108109 @param width: Image width
109110 @param height: Image height
110111 @param nchannels: Number of image channels
112+ @param color_space: Color space of the image
111113 """
112114 if not self .preview :
113115 return
@@ -142,9 +144,14 @@ def previewImage(self, title, data, width, height, nchannels):
142144 rgb_disp = rgb
143145
144146 # Set title bar text for the preview window
145- plt .title (f"{ title } ({ width } x{ height } , { nchannels } channels, dtype={ data .dtype } )" )
146- plt .imshow (rgb_disp )
147- plt .axis ('off' )
147+ fig , ax = plt .subplots ()
148+ ax .imshow (rgb_disp )
149+ ax .axis ("off" )
150+ #fig.patch.set_facecolor("black")
151+ fig .canvas .manager .set_window_title (title )
152+ info = f"Dimensions:({ width } x{ height } ), { nchannels } channels, type={ data .dtype } , colorspace={ color_space } "
153+ fig .suptitle (title , fontsize = 12 )
154+ plt .title (info , fontsize = 9 )
148155 plt .show ()
149156
150157 def loadImage (self , filePath ):
@@ -170,8 +177,9 @@ def loadImage(self, filePath):
170177
171178 # Get image specifications
172179 spec = img_input .spec ()
173- self .last_spec = spec
174- self .last_loaded_path = file_path_str
180+ color_space = spec .getattribute ("oiio:ColorSpace" )
181+ logger .info (f"ColorSpace: { color_space } " )
182+ self .color_space [file_path_str ] = color_space
175183
176184 # Check channel count
177185 channels = spec .nchannels
@@ -199,7 +207,7 @@ def loadImage(self, filePath):
199207 logger .error (f"Could not read image data." )
200208 return None
201209
202- self .previewImage ("Loaded MaterialX Image" , data , spec .width , spec .height , channels )
210+ self .previewImage ("Loaded MaterialX Image" , data , spec .width , spec .height , channels , color_space )
203211
204212 # Steps:
205213 # - Copy the OIIO data into the MaterialX image resource buffer
@@ -286,7 +294,16 @@ def saveImage(self, filePath, image, verticalFlip=False):
286294 pixels = np .flipud (pixels )
287295
288296 logger .info ("Previewing image after load into Image and reload for save..." )
289- self .previewImage ("OpenImageIO Output Image" , pixels , width , height , channels )
297+ # Remove "saved_" prefix if present
298+ search_name = filename .replace ("saved_" , "" )
299+ color_space = "Unknown"
300+ for key in self .color_space :
301+ value = self .color_space [key ]
302+ path = os .path .basename (key )
303+ if path in search_name :
304+ color_space = value
305+ logger .info (f"colorspace lookup for: { search_name } . list: { color_space } " )
306+ self .previewImage ("OpenImageIO Output Image" , pixels , width , height , channels , color_space )
290307
291308 except Exception as e :
292309 logger .error (f"Error copying buffer to pixels: { e } " )
0 commit comments