<s> import os <EOL> import shutil <EOL> import unittest <EOL> import subprocess <EOL> import IECore <EOL> import Gaffer <EOL> import GafferTest <EOL> import GafferImage <EOL> import GafferImageTest <EOL> class ResampleTest ( GafferImageTest . ImageTestCase ) : <EOL> def testDataWindow ( self ) : <EOL> c = GafferImage . Constant ( ) <EOL> c [ "<STR_LIT>" ] . setValue ( IECore . Color4f ( <NUM_LIT:1> ) ) <EOL> r = GafferImage . Resample ( ) <EOL> r [ "<STR_LIT>" ] . setInput ( c [ "<STR_LIT>" ] ) <EOL> r [ "<STR_LIT>" ] . setValue ( <EOL> IECore . Box2f ( <EOL> IECore . V2f ( <NUM_LIT> , <NUM_LIT> ) , <EOL> IECore . V2f ( <NUM_LIT> , <NUM_LIT> ) <EOL> ) <EOL> ) <EOL> self . assertEqual ( <EOL> r [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , <EOL> IECore . Box2i ( <EOL> IECore . V2i ( <NUM_LIT:10> , <NUM_LIT:11> ) , <EOL> IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) <EOL> ) <EOL> ) <EOL> def testExpectedOutput ( self ) : <EOL> def __test ( fileName , size , filter ) : <EOL> inputFileName = os . path . dirname ( __file__ ) + "<STR_LIT>" + fileName <EOL> reader = GafferImage . ImageReader ( ) <EOL> reader [ "<STR_LIT>" ] . setValue ( inputFileName ) <EOL> resample = GafferImage . Resample ( ) <EOL> resample [ "<STR_LIT>" ] . setInput ( reader [ "<STR_LIT>" ] ) <EOL> resample [ "<STR_LIT>" ] . setValue ( IECore . Box2f ( IECore . V2f ( <NUM_LIT:0> ) , IECore . V2f ( size . x , size . y ) ) ) <EOL> resample [ "<STR_LIT>" ] . setValue ( filter ) <EOL> resample [ "<STR_LIT>" ] . setValue ( GafferImage . Sampler . BoundingMode . Clamp ) <EOL> crop = GafferImage . Crop ( ) <EOL> crop [ "<STR_LIT>" ] . setInput ( resample [ "<STR_LIT>" ] ) <EOL> crop [ "<STR_LIT>" ] . setValue ( IECore . Box2i ( IECore . V2i ( <NUM_LIT:0> ) , size ) ) <EOL> outputFileName = self . temporaryDirectory ( ) + "<STR_LIT>" % ( os . path . splitext ( fileName ) [ <NUM_LIT:0> ] , size . x , size . y , filter ) <EOL> writer = GafferImage . ImageWriter ( ) <EOL> writer [ "<STR_LIT>" ] . setInput ( crop [ "<STR_LIT>" ] ) <EOL> writer [ "<STR_LIT>" ] . setValue ( outputFileName ) <EOL> writer [ "<STR_LIT>" ] . execute ( ) <EOL> result = GafferImage . ImageReader ( ) <EOL> result [ "<STR_LIT>" ] . setValue ( writer [ "<STR_LIT>" ] . getValue ( ) ) <EOL> expected = GafferImage . ImageReader ( ) <EOL> expected [ "<STR_LIT>" ] . setValue ( <EOL> "<STR_LIT>" % ( <EOL> os . path . dirname ( __file__ ) , <EOL> os . path . splitext ( fileName ) [ <NUM_LIT:0> ] , <EOL> size . x , <EOL> size . y , <EOL> filter <EOL> ) <EOL> ) <EOL> self . assertImagesEqual ( result [ "<STR_LIT>" ] , expected [ "<STR_LIT>" ] , maxDifference = <NUM_LIT> , ignoreMetadata = True ) <EOL> if False : <EOL> if not os . path . exists ( "<STR_LIT>" ) : <EOL> os . makedirs ( "<STR_LIT>" ) <EOL> shutil . copyfile ( outputFileName , "<STR_LIT>" + os . path . basename ( outputFileName ) ) <EOL> oiioOutputFileName = "<STR_LIT>" % ( os . path . splitext ( fileName ) [ <NUM_LIT:0> ] , size . x , size . y , filter ) <EOL> subprocess . check_call ( <EOL> "<STR_LIT>" % <EOL> ( <EOL> inputFileName , <EOL> filter , <EOL> size . x , size . y , <EOL> oiioOutputFileName <EOL> ) , <EOL> shell = True <EOL> ) <EOL> tests = [ <EOL> ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT:4> ) , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> ) , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> ) , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , IECore . V2i ( <NUM_LIT> ) , "<STR_LIT>" ) , <EOL> ] <EOL> for args in tests : <EOL> __test ( * args ) <EOL> def testSincUpsize ( self ) : <EOL> c = GafferImage . Constant ( ) <EOL> c [ "<STR_LIT>" ] . setValue ( GafferImage . Format ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> c [ "<STR_LIT>" ] . setValue ( IECore . Color4f ( <NUM_LIT:1> ) ) <EOL> r = GafferImage . Resample ( ) <EOL> r [ "<STR_LIT>" ] . setValue ( IECore . Box2f ( IECore . V2f ( <NUM_LIT:0> ) , IECore . V2f ( <NUM_LIT> ) ) ) <EOL> r [ "<STR_LIT>" ] . setValue ( GafferImage . Sampler . BoundingMode . Clamp ) <EOL> r [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> r [ "<STR_LIT>" ] . setInput ( c [ "<STR_LIT>" ] ) <EOL> i = r [ "<STR_LIT>" ] . image ( ) <EOL> self . assertEqual ( i [ "<STR_LIT:R>" ] . data , IECore . FloatVectorData ( [ <NUM_LIT:1.0> ] * <NUM_LIT> * <NUM_LIT> ) ) <EOL> def testExpandDataWindow ( self ) : <EOL> d = IECore . Box2i ( IECore . V2i ( <NUM_LIT:5> , <NUM_LIT:6> ) , IECore . V2i ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> c = GafferImage . Constant ( ) <EOL> c [ "<STR_LIT>" ] . setValue ( GafferImage . Format ( d ) ) <EOL> r = GafferImage . Resample ( ) <EOL> r [ "<STR_LIT>" ] . setInput ( c [ "<STR_LIT>" ] ) <EOL> r [ "<STR_LIT>" ] . setValue ( IECore . Box2f ( IECore . V2f ( d . min ) , IECore . V2f ( d . max ) ) ) <EOL> r [ "<STR_LIT>" ] . setValue ( "<STR_LIT>" ) <EOL> self . assertEqual ( r [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , d ) <EOL> r [ "<STR_LIT>" ] . setValue ( True ) <EOL> self . assertEqual ( r [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , IECore . Box2i ( d . min - IECore . V2i ( <NUM_LIT:1> ) , d . max + IECore . V2i ( <NUM_LIT:1> ) ) ) <EOL> r [ "<STR_LIT>" ] . setValue ( IECore . V2f ( <NUM_LIT:10> ) ) <EOL> self . assertEqual ( r [ "<STR_LIT>" ] [ "<STR_LIT>" ] . getValue ( ) , IECore . Box2i ( d . min - IECore . V2i ( <NUM_LIT:5> ) , d . max + IECore . V2i ( <NUM_LIT:5> ) ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
