From 168f0fb55002f9b14d7cb894584c216bf038531a Mon Sep 17 00:00:00 2001 From: Hugh Macdonald Date: Fri, 18 Dec 2015 18:13:08 +0000 Subject: [PATCH 1/6] ImageAlgo : Add additional channelExists method --- include/GafferImage/ImageAlgo.h | 3 +++ include/GafferImage/ImageAlgo.inl | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/GafferImage/ImageAlgo.h b/include/GafferImage/ImageAlgo.h index b218ccaaf55..90f86d53c0e 100644 --- a/include/GafferImage/ImageAlgo.h +++ b/include/GafferImage/ImageAlgo.h @@ -81,6 +81,9 @@ inline int colorIndex( const std::string &channelName ); /// Returns true if the specified channel exists in image inline bool channelExists( const ImagePlug *image, const std::string &channelName ); +/// Returns true if the specified channel exists in channelNames +inline bool channelExists( const std::vector &channelNames, const std::string &channelName ); + enum TileOrder { Unordered, diff --git a/include/GafferImage/ImageAlgo.inl b/include/GafferImage/ImageAlgo.inl index 8c2a22a5b4f..1ef27a3eed2 100644 --- a/include/GafferImage/ImageAlgo.inl +++ b/include/GafferImage/ImageAlgo.inl @@ -484,6 +484,11 @@ inline bool channelExists( const ImagePlug *image, const std::string &channelNam IECore::ConstStringVectorDataPtr channelNamesData = image->channelNamesPlug()->getValue(); const std::vector &channelNames = channelNamesData->readable(); + return channelExists( channelNames, channelName ); +} + +inline bool channelExists( const std::vector &channelNames, const std::string &channelName ) +{ return std::find( channelNames.begin(), channelNames.end(), channelName ) != channelNames.end(); } From e41992abd6bfc505e49b3f383133c76c9b2c3e0c Mon Sep 17 00:00:00 2001 From: Hugh Macdonald Date: Fri, 18 Dec 2015 18:13:18 +0000 Subject: [PATCH 2/6] ImageAlgoBinding : Add binding for new channelExists method --- src/GafferImageBindings/ImageAlgoBinding.cpp | 36 +++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/GafferImageBindings/ImageAlgoBinding.cpp b/src/GafferImageBindings/ImageAlgoBinding.cpp index ab6ab86a94f..c9ccaba9639 100644 --- a/src/GafferImageBindings/ImageAlgoBinding.cpp +++ b/src/GafferImageBindings/ImageAlgoBinding.cpp @@ -42,13 +42,47 @@ using namespace boost::python; namespace GafferImageBindings { +// Register a conversion from StringVectorData. +/// \todo We could instead do this in the Cortex bindings for all +/// VectorTypedData types. +struct StringListFromStringVectorData +{ + + StringListFromStringVectorData() + { + boost::python::converter::registry::push_back( + &convertible, + NULL, + boost::python::type_id >() + ); + } + + static void *convertible( PyObject *obj ) + { + extract dataExtractor( obj ); + if( dataExtractor.check() ) + { + if( IECore::StringVectorData *data = dataExtractor() ) + { + return &(data->writable()); + } + } + + return NULL; + } + +}; + void bindImageAlgo() { def( "layerName", &GafferImage::layerName ); def( "baseName", &GafferImage::baseName ); def( "colorIndex", &GafferImage::colorIndex ); - def( "channelExists", &GafferImage::channelExists ); + def( "channelExists", ( bool (*)( const GafferImage::ImagePlug *image, const std::string &channelName ) )&GafferImage::channelExists ); + def( "channelExists", ( bool (*)( const std::vector &channelNames, const std::string &channelName ) )&GafferImage::channelExists ); + + StringListFromStringVectorData(); } From 93057c28262af7f35b7f11f649a2cb6178bfbf04 Mon Sep 17 00:00:00 2001 From: Hugh Macdonald Date: Sun, 20 Dec 2015 15:57:12 +0000 Subject: [PATCH 3/6] ImageAlgoTest : Add test for alternate binding for channelExists --- python/GafferImageTest/ImageAlgoTest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/python/GafferImageTest/ImageAlgoTest.py b/python/GafferImageTest/ImageAlgoTest.py index 6675ed477e4..c5e3912bb7b 100644 --- a/python/GafferImageTest/ImageAlgoTest.py +++ b/python/GafferImageTest/ImageAlgoTest.py @@ -111,6 +111,21 @@ def testChannelExists( self ) : d["channels"].setValue( IECore.StringVectorData( [ chan ] ) ) self.assertFalse( GafferImage.channelExists( d["out"], chan ) ) + def testChannelExistsBindings( self ) : + # Test that both forms of binding to channelExists return the same + # value + + c = GafferImage.Constant() + + d = GafferImage.DeleteChannels() + d["in"].setInput( c["out"] ) + d["mode"].setValue( GafferImage.DeleteChannels.Mode.Delete ) + d["channels"].setValue( IECore.StringVectorData( [ "R", "A" ] ) ) + + for chan in [ "R", "G", "B", "A" ] : + self.assertEqual( GafferImage.channelExists( d["out"], chan ), GafferImage.channelExists( d["out"]["channelNames"].getValue(), chan ) ) + + def testParallelProcessEmptyDataWindow( self ) : d = GafferImage.Display() From 002c6a729e1ee2752f8bbb14f567696f83cc0855 Mon Sep 17 00:00:00 2001 From: Hugh Macdonald Date: Sun, 20 Dec 2015 15:56:40 +0000 Subject: [PATCH 4/6] Merge : Update channelExists calls to use alternative overload. --- src/GafferImage/Merge.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/GafferImage/Merge.cpp b/src/GafferImage/Merge.cpp index e90c095edb7..2edb2c34373 100644 --- a/src/GafferImage/Merge.cpp +++ b/src/GafferImage/Merge.cpp @@ -199,12 +199,15 @@ void Merge::hashChannelData( const GafferImage::ImagePlug *output, const Gaffer: continue; } - if( channelExists( it->get(), channelName ) ) + IECore::ConstStringVectorDataPtr channelNamesData = (*it)->channelNamesPlug()->getValue(); + const std::vector &channelNames = channelNamesData->readable(); + + if( channelExists( channelNames, channelName ) ) { (*it)->channelDataPlug()->hash( h ); } - if( channelExists( it->get(), "A" ) ) + if( channelExists( channelNames, "A" ) ) { h.append( (*it)->channelDataHash( "A", tileOrigin ) ); } @@ -275,10 +278,13 @@ IECore::ConstFloatVectorDataPtr Merge::merge( F f, const std::string &channelNam continue; } + IECore::ConstStringVectorDataPtr channelNamesData = (*it)->channelNamesPlug()->getValue(); + const std::vector &channelNames = channelNamesData->readable(); + ConstFloatVectorDataPtr channelData; ConstFloatVectorDataPtr alphaData; - if( channelExists( it->get(), channelName ) ) + if( channelExists( channelNames, channelName ) ) { channelData = (*it)->channelDataPlug()->getValue(); } @@ -287,7 +293,7 @@ IECore::ConstFloatVectorDataPtr Merge::merge( F f, const std::string &channelNam channelData = ImagePlug::blackTile(); } - if( channelExists( it->get(), "A" ) ) + if( channelExists( channelNames, "A" ) ) { alphaData = (*it)->channelData( "A", tileOrigin ); } From cda1f4199c8b26549aec7257e001e501b7eb3222 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 22 Dec 2015 15:26:13 +0000 Subject: [PATCH 5/6] ImageAlgoBinding : Fix name. Vectors are not lists. --- src/GafferImageBindings/ImageAlgoBinding.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/GafferImageBindings/ImageAlgoBinding.cpp b/src/GafferImageBindings/ImageAlgoBinding.cpp index c9ccaba9639..aded678e663 100644 --- a/src/GafferImageBindings/ImageAlgoBinding.cpp +++ b/src/GafferImageBindings/ImageAlgoBinding.cpp @@ -45,10 +45,10 @@ namespace GafferImageBindings // Register a conversion from StringVectorData. /// \todo We could instead do this in the Cortex bindings for all /// VectorTypedData types. -struct StringListFromStringVectorData +struct StringVectorFromStringVectorData { - StringListFromStringVectorData() + StringVectorFromStringVectorData() { boost::python::converter::registry::push_back( &convertible, @@ -82,7 +82,7 @@ void bindImageAlgo() def( "channelExists", ( bool (*)( const GafferImage::ImagePlug *image, const std::string &channelName ) )&GafferImage::channelExists ); def( "channelExists", ( bool (*)( const std::vector &channelNames, const std::string &channelName ) )&GafferImage::channelExists ); - StringListFromStringVectorData(); + StringVectorFromStringVectorData(); } From 02078819ce58310edc588ace27ea2186273c01a7 Mon Sep 17 00:00:00 2001 From: John Haddon Date: Tue, 22 Dec 2015 15:30:59 +0000 Subject: [PATCH 6/6] ImageAlgoTest : Tweak formatting. --- python/GafferImageTest/ImageAlgoTest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/GafferImageTest/ImageAlgoTest.py b/python/GafferImageTest/ImageAlgoTest.py index c5e3912bb7b..ed2f4595eaa 100644 --- a/python/GafferImageTest/ImageAlgoTest.py +++ b/python/GafferImageTest/ImageAlgoTest.py @@ -112,6 +112,7 @@ def testChannelExists( self ) : self.assertFalse( GafferImage.channelExists( d["out"], chan ) ) def testChannelExistsBindings( self ) : + # Test that both forms of binding to channelExists return the same # value @@ -125,7 +126,6 @@ def testChannelExistsBindings( self ) : for chan in [ "R", "G", "B", "A" ] : self.assertEqual( GafferImage.channelExists( d["out"], chan ), GafferImage.channelExists( d["out"]["channelNames"].getValue(), chan ) ) - def testParallelProcessEmptyDataWindow( self ) : d = GafferImage.Display() @@ -135,6 +135,5 @@ def testParallelProcessEmptyDataWindow( self ) : d["out"].image() d["out"].imageHash() - if __name__ == "__main__": unittest.main()