1
1
##########################################################################
2
2
#
3
- # Copyright (c) 2013, Image Engine Design Inc. All rights reserved.
3
+ # Copyright (c) 2013-2014 , Image Engine Design Inc. All rights reserved.
4
4
#
5
5
# Redistribution and use in source and binary forms, with or without
6
6
# modification, are permitted provided that the following conditions are
49
49
## cache needs to be refreshed before the deepSample returns a correct result. This may be due to a bug in nuke
50
50
## or an error in the IECoreNuke::DeepImageReader code. Further investigation is required.
51
51
class DeepImageReaderTest ( IECoreNuke .TestCase ) :
52
+
53
+ __smokeWithoutZBack = "test/IECoreRI/data/exr/smokeWithoutZBack.dexr"
54
+ __output = "test/IECoreRI/data/exr/smokeWithZBack.exr"
52
55
53
56
def __inputPaths ( self ) :
54
57
return { "exr" : "test/IECoreRI/data/exr/primitives.exr" , "shw" : "test/IECoreRI/data/shw/primitives.shw" }
55
58
59
+ def testCreationOfZBack ( self ) :
60
+
61
+ if not IECore .withDeepEXR :
62
+ return
63
+
64
+ # Create a DeepReader to read the deep EXR.
65
+ reader = nuke .createNode ( "DeepRead" )
66
+ reader ["file" ].setText ( DeepImageReaderTest .__smokeWithoutZBack )
67
+
68
+ # Write it back out. We do this because nuke's DeepSample node is un
69
+ writer = nuke .createNode ( "DeepWrite" )
70
+ writer ["file" ].setText ( DeepImageReaderTest .__output )
71
+ nuke .execute ( writer , 1 , 1 )
72
+
73
+ # Read the image back in and check the values of it's ZBack channel.
74
+ reader = IECore .EXRDeepImageReader ( DeepImageReaderTest .__output )
75
+ header = reader .readHeader ()
76
+ resolution = reader ['dataWindow' ].size () + IECore .V2i ( 1 )
77
+
78
+ self .assertEqual ( set ( header ['channelNames' ] ), set ( [ 'R' , 'G' , 'B' , 'A' , 'ZBack' ] ) )
79
+
80
+ for y in range ( 0 , resolution [0 ] ) :
81
+ for x in range ( 0 , resolution [1 ] ) :
82
+
83
+ p = reader .readPixel ( x , y )
84
+ n = p .numSamples ()
85
+ zBackIndex = p .channelIndex ( 'ZBack' )
86
+
87
+ if n >= 1 :
88
+ n = n - 1
89
+
90
+ for s in range ( 0 , n ) :
91
+ front = p .getDepth ( s )
92
+ back = p .getDepth ( s + 1 )
93
+ actualBack = p .channelData ( s )[ zBackIndex ]
94
+ self .assertEqual ( back , actualBack )
95
+
56
96
def testReadOfShwAgainstExr ( self ) :
57
97
import IECoreRI
58
98
59
99
# Create a DeepReader to read a deep EXR.
60
- readerExr = nuke .createNode ( "DeepRead" )
61
- readerExr ["file" ].setText ( self .__inputPaths ()["exr" ] )
100
+ reader = nuke .createNode ( "DeepRead" )
101
+ reader ["file" ].setText ( self .__inputPaths ()["exr" ] )
62
102
63
103
# Create an ieDeepImageReader to read the deep SHW.
64
104
readerShw = nuke .createNode ("DeepRead" )
@@ -72,15 +112,20 @@ def testReadOfShwAgainstExr( self ) :
72
112
y = random .randint ( 0 , 511 )
73
113
74
114
# Check that both image have the same number of samples.
75
- nSamplesExr = readerExr .deepSampleCount ( x , y )
115
+ nSamplesExr = reader .deepSampleCount ( x , y )
76
116
nSamplesShw = readerShw .deepSampleCount ( x , y )
77
117
self .assertEqual ( nSamplesExr , nSamplesShw )
78
118
79
119
for channel in [ "front" , "back" , "A" ] :
80
120
for idx in range ( 0 , nSamplesExr ) :
81
- frontExr = readerExr .deepSample ( channel , x , y , idx )
121
+ frontExr = reader .deepSample ( channel , x , y , idx )
82
122
frontShw = readerShw .deepSample ( channel , x , y , idx )
83
123
self .assertEqual ( frontExr , frontShw )
124
+
125
+ def tearDown ( self ) :
126
+
127
+ if os .path .isfile ( DeepImageReaderTest .__output ) :
128
+ os .remove ( DeepImageReaderTest .__output )
84
129
85
130
if __name__ == "__main__" :
86
131
unittest .main ()
0 commit comments