Skip to content

Commit

Permalink
Merge branch 'HughMacdonald-channelExistsUpdate'
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhaddon committed Dec 22, 2015
2 parents 01471fb + 0207881 commit d418a6a
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
3 changes: 3 additions & 0 deletions include/GafferImage/ImageAlgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &channelNames, const std::string &channelName );

enum TileOrder
{
Unordered,
Expand Down
5 changes: 5 additions & 0 deletions include/GafferImage/ImageAlgo.inl
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ inline bool channelExists( const ImagePlug *image, const std::string &channelNam
IECore::ConstStringVectorDataPtr channelNamesData = image->channelNamesPlug()->getValue();
const std::vector<std::string> &channelNames = channelNamesData->readable();

return channelExists( channelNames, channelName );
}

inline bool channelExists( const std::vector<std::string> &channelNames, const std::string &channelName )
{
return std::find( channelNames.begin(), channelNames.end(), channelName ) != channelNames.end();
}

Expand Down
16 changes: 15 additions & 1 deletion python/GafferImageTest/ImageAlgoTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -120,6 +135,5 @@ def testParallelProcessEmptyDataWindow( self ) :
d["out"].image()
d["out"].imageHash()


if __name__ == "__main__":
unittest.main()
14 changes: 10 additions & 4 deletions src/GafferImage/Merge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &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 ) );
}
Expand Down Expand Up @@ -275,10 +278,13 @@ IECore::ConstFloatVectorDataPtr Merge::merge( F f, const std::string &channelNam
continue;
}

IECore::ConstStringVectorDataPtr channelNamesData = (*it)->channelNamesPlug()->getValue();
const std::vector<std::string> &channelNames = channelNamesData->readable();

ConstFloatVectorDataPtr channelData;
ConstFloatVectorDataPtr alphaData;

if( channelExists( it->get(), channelName ) )
if( channelExists( channelNames, channelName ) )
{
channelData = (*it)->channelDataPlug()->getValue();
}
Expand All @@ -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 );
}
Expand Down
36 changes: 35 additions & 1 deletion src/GafferImageBindings/ImageAlgoBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 StringVectorFromStringVectorData
{

StringVectorFromStringVectorData()
{
boost::python::converter::registry::push_back(
&convertible,
NULL,
boost::python::type_id<std::vector<std::string> >()
);
}

static void *convertible( PyObject *obj )
{
extract<IECore::StringVectorData *> 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<std::string> &channelNames, const std::string &channelName ) )&GafferImage::channelExists );

StringVectorFromStringVectorData();

}

Expand Down

0 comments on commit d418a6a

Please sign in to comment.