@@ -84,8 +84,13 @@ def halfsToFloat(half1, half2):
8484# 'floats' read from OpenImageIO.
8585# Each 4 byte 'float' is the binary equivalent of two packed 2-byte half-floats.
8686def oiioFloatPixelsToNPHalfArray (width , height , channels , oiioFloats ):
87- # Read float pixels into a numpy half-float pixel array
88- npPixels = np .frombuffer (np .getbuffer (np .float32 (oiioFloats )), dtype = np .float16 )
87+
88+ if oiio .VERSION < 10800 :
89+ # Read float pixels into a numpy half-float pixel array
90+ npPixels = np .frombuffer (np .getbuffer (np .float32 (oiioFloats )), dtype = np .float16 )
91+ else :
92+ # Convert uint16 values into a numpy half-float pixel array
93+ npPixels = np .frombuffer (np .getbuffer (np .uint16 (oiioFloats )), dtype = np .float16 )
8994
9095 return npPixels
9196# oiioFloatPixelsToNPHalfArray
@@ -95,8 +100,12 @@ def oiioFloatPixelsToNPHalfArray(width, height, channels, oiioFloats):
95100# is a numpy array of half-float pixels.
96101# Each 4 byte 'float' is the binary equivalent of two packed 2-byte half-floats.
97102def npHalfArrayToOIIOFloatPixels (width , height , channels , npPixels ):
98- # Read half-float pixels into a numpy float pixel array
99- oiioFloatsArray = np .frombuffer (np .getbuffer (np .float16 (npPixels )), dtype = np .float32 )
103+ if oiio .VERSION < 10800 :
104+ # Read half-float pixels into a numpy float pixel array
105+ oiioFloatsArray = np .frombuffer (np .getbuffer (np .float16 (npPixels )), dtype = np .float32 )
106+ else :
107+ # Read half-float pixels into a numpy float pixel array
108+ oiioFloatsArray = np .frombuffer (np .getbuffer (np .float16 (npPixels )), dtype = np .uint16 )
100109
101110 return oiioFloatsArray
102111# npHalfArrayToOIIOFloatPixels
@@ -136,11 +145,14 @@ def readPixelArray(inputPath,
136145 width = inputImageSpec .width
137146 height = inputImageSpec .height
138147 channels = inputImageSpec .nchannels
148+ channelnames = inputImageSpec .channelnames
139149 metadata = inputImageSpec .extra_attribs
140150 metanames = [attr .name for attr in metadata ]
141151
142152 bitShift = 0
143153
154+ print ( "Loading image - spects : %d x %d - %d channels, %s bit depth, %s" % (width , height , channels , type , channelnames ))
155+
144156 # Handle automatic bit-depth conversions
145157 if bitDepthOverride :
146158 if bitDepthOverride == "auto" :
@@ -176,15 +188,15 @@ def readPixelArray(inputPath,
176188 for i in range (len (sourceData )):
177189 sourceData [i ] = sourceData [i ] >> bitShift
178190
179- # OIIO doesn 't return half-float values directly, so this will
180- # convert from the packed representation to half-floats
191+ # OIIO versions < 1.8 didn 't return half-float values directly
192+ # so this will convert from the packed representation to half-floats
181193 if type == oiio .HALF :
182194 print ( "Unpacking half-float values" )
183195 sourceData = oiioFloatPixelsToNPHalfArray (width , height , channels , sourceData )
184196 else :
185- (sourceData , bitDepth , width , height , channels , metadata ) = (None , clf .bitDepths ["UINT10" ], 0 , 0 , 0 , None )
197+ (sourceData , bitDepth , width , height , channels , metadata ) = (None , clf .bitDepths ["UINT10" ], 0 , 0 , 0 , None , None )
186198
187- return (sourceData , bitDepth , width , height , channels , metadata )
199+ return (sourceData , bitDepth , width , height , channels , metadata , channelnames )
188200# readPixelArray
189201
190202#
@@ -197,6 +209,7 @@ def writePixelArray(outputPath,
197209 height ,
198210 channels ,
199211 metadata ,
212+ channelnames ,
200213 compression = None ,
201214 compressionQuality = 0 ):
202215 print ( "Writing image - path : %s" % outputPath )
@@ -251,6 +264,7 @@ def writePixelArray(outputPath,
251264 outputSpec .width = width
252265 outputSpec .height = height
253266 outputSpec .nchannels = channels
267+ outputSpec .channelnames = channelnames
254268
255269 # Mapping between bit depth and 'oiio:BitsPerSample' metadata value
256270 bitDepthValue = {
@@ -389,7 +403,7 @@ def filterRow_stride(row,
389403
390404 # Process values
391405 #print( "Processing %04d, %04d : %s" % (i, j, ovalue))
392- pvalue = processList .process (pvalue , stride = channels )
406+ pvalue = processList .process (pvalue , stride = channels , verbose = verbose )
393407
394408 # Reset values if output image and CLF output bit depths don't match
395409 if OutRange :
@@ -477,7 +491,7 @@ def filterImageWithCLF(inputPath,
477491 #
478492 t0 = timeit .default_timer ()
479493
480- pixels , inBitDepth , width , height , channels , metadata = readPixelArray (inputPath )
494+ pixels , inBitDepth , width , height , channels , metadata , channelnames = readPixelArray (inputPath )
481495 if pixels == None :
482496 print ( "\n Image %s could not be opened. Filtering aborted.\n " % inputPath )
483497 return
@@ -571,7 +585,9 @@ def filterImageWithCLF(inputPath,
571585 else :
572586 print ( "Filtering image - single threaded" )
573587
574- for j in range (height ):
588+ #for j in range(height):
589+ j = 5
590+ if True :
575591 # Using filterRow_stride instead of filterRow_pixel
576592 # Processing a full row is ~10% faster than processing individual pixels
577593 filterRow_stride (j ,
@@ -590,7 +606,7 @@ def filterImageWithCLF(inputPath,
590606 t0 = timeit .default_timer ()
591607
592608 writePixelArray (outputPath , processedPixels , outBitDepth , width , height , channels , metadata ,
593- compression , compressionQuality )
609+ channelnames , compression , compressionQuality )
594610
595611 t1 = timeit .default_timer ()
596612 elapsed = t1 - t0
0 commit comments