Skip to content

Commit

Permalink
Renamed the mask plugs.
Browse files Browse the repository at this point in the history
Also switched to a borrowed context
  • Loading branch information
andrewkaufman committed Nov 23, 2015
1 parent d9215da commit cdfbb36
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 63 deletions.
25 changes: 13 additions & 12 deletions include/GafferImage/ImageReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ class ImageReader : public ImageNode
};

/// The FrameMaskMode controls how to handle images
/// outside of the values provided by frameRangeMask().
/// outside of the values provided by the start
/// and end frame masks.
enum FrameMaskMode
{
None = 0,
BlackOutside,
ClampToRange,
ClampToFrame,
};

Gaffer::StringPlug *fileNamePlug();
Expand All @@ -94,17 +95,17 @@ class ImageReader : public ImageNode
Gaffer::IntPlug *missingFrameModePlug();
const Gaffer::IntPlug *missingFrameModePlug() const;

Gaffer::IntPlug *frameStartMaskModePlug();
const Gaffer::IntPlug *frameStartMaskModePlug() const;
Gaffer::IntPlug *startModePlug();
const Gaffer::IntPlug *startModePlug() const;

Gaffer::IntPlug *frameStartMaskPlug();
const Gaffer::IntPlug *frameStartMaskPlug() const;
Gaffer::IntPlug *startFramePlug();
const Gaffer::IntPlug *startFramePlug() const;

Gaffer::IntPlug *frameEndMaskModePlug();
const Gaffer::IntPlug *frameEndMaskModePlug() const;
Gaffer::IntPlug *endModePlug();
const Gaffer::IntPlug *endModePlug() const;

Gaffer::IntPlug *frameEndMaskPlug();
const Gaffer::IntPlug *frameEndMaskPlug() const;
Gaffer::IntPlug *endFramePlug();
const Gaffer::IntPlug *endFramePlug() const;

virtual void affects( const Gaffer::Plug *input, AffectedPlugsContainer &outputs ) const;

Expand Down Expand Up @@ -136,8 +137,8 @@ class ImageReader : public ImageNode
GafferImage::ImagePlug *intermediateImagePlug();
const GafferImage::ImagePlug *intermediateImagePlug() const;

void hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToRange = false ) const;
void computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToRange = false ) const;
void hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToFrame = false ) const;
void computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToFrame = false ) const;

bool computeFrameMask( const Gaffer::Context *context, Gaffer::ContextPtr &maskedContext ) const;

Expand Down
18 changes: 9 additions & 9 deletions python/GafferImageTest/ImageReaderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import GafferImage
import GafferImageTest

class ImageReaderTest( GafferTest.TestCase ) :
class ImageReaderTest( GafferImageTest.ImageTestCase ) :

fileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/circles.exr" )
offsetDataWindowFileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/rgb.100x100.exr" )
Expand Down Expand Up @@ -301,20 +301,20 @@ def assertHold( holdFrame ) :
self.assertEqual( reader["out"].channelData( "R", IECore.V2i( 0 ) ), holdTile )
self.assertEqual( reader["out"].image(), holdImage )

reader["frameStartMask"]["frame"].setValue( 4 )
reader["frameEndMask"]["frame"].setValue( 7 )
reader["start"]["frame"].setValue( 4 )
reader["end"]["frame"].setValue( 7 )

# frame 0 errors, match from 1-10
reader["frameStartMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.None )
reader["frameEndMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.None )
reader["start"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.None )
reader["end"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.None )
with context :

for i in range( 0, 11 ) :
context.setFrame( i )
assertMatch()

# black from 0-3, match from 4-10
reader["frameStartMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.BlackOutside )
reader["start"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.BlackOutside )
with context :

for i in range( 0, 4 ) :
Expand All @@ -326,7 +326,7 @@ def assertHold( holdFrame ) :
assertMatch()

# black from 0-3, match from 4-7, black from 8-10
reader["frameEndMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.BlackOutside )
reader["end"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.BlackOutside )
with context :

for i in range( 0, 4 ) :
Expand All @@ -342,7 +342,7 @@ def assertHold( holdFrame ) :
assertBlack()

# hold frame 4 from 0-3, match from 4-7, black from 8-10
reader["frameStartMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.ClampToRange )
reader["start"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.ClampToFrame )
with context :

for i in range( 0, 4 ) :
Expand All @@ -358,7 +358,7 @@ def assertHold( holdFrame ) :
assertBlack()

# hold frame 4 from 0-3, match from 4-7, hold frame 7 from 8-10
reader["frameEndMask"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.ClampToRange )
reader["end"]["mode"].setValue( GafferImage.ImageReader.FrameMaskMode.ClampToFrame )
with context :

for i in range( 0, 4 ) :
Expand Down
2 changes: 1 addition & 1 deletion python/GafferImageTest/OpenImageIOReaderTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import GafferImage
import GafferImageTest

class OpenImageIOReaderTest( GafferImageTest.TestCase ) :
class OpenImageIOReaderTest( GafferImageTest.ImageTestCase ) :

fileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/checker.exr" )
offsetDataWindowFileName = os.path.expandvars( "$GAFFER_ROOT/python/GafferImageTest/images/rgb.100x100.exr" )
Expand Down
16 changes: 8 additions & 8 deletions python/GafferImageUI/ImageReaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

],

"frameStartMask" : [
"start" : [

"description",
"""
Expand All @@ -118,7 +118,7 @@

],

"frameStartMask.mode" : [
"start.mode" : [

"description",
"""
Expand All @@ -127,13 +127,13 @@

"preset:None", GafferImage.ImageReader.FrameMaskMode.None,
"preset:Black Outside", GafferImage.ImageReader.FrameMaskMode.BlackOutside,
"preset:Clamp to Range", GafferImage.ImageReader.FrameMaskMode.ClampToRange,
"preset:Clamp to Range", GafferImage.ImageReader.FrameMaskMode.ClampToFrame,

"plugValueWidget:type", "GafferUI.PresetsPlugValueWidget",

],

"frameStartMask.frame" : [
"start.frame" : [

"description",
"""
Expand All @@ -145,7 +145,7 @@

],

"frameEndMask" : [
"end" : [

"description",
"""
Expand All @@ -160,7 +160,7 @@

],

"frameEndMask.mode" : [
"end.mode" : [

"description",
"""
Expand All @@ -169,13 +169,13 @@

"preset:None", GafferImage.ImageReader.FrameMaskMode.None,
"preset:Black Outside", GafferImage.ImageReader.FrameMaskMode.BlackOutside,
"preset:Clamp to Range", GafferImage.ImageReader.FrameMaskMode.ClampToRange,
"preset:Clamp to Range", GafferImage.ImageReader.FrameMaskMode.ClampToFrame,

"plugValueWidget:type", "GafferUI.PresetsPlugValueWidget",

],

"frameEndMask.frame" : [
"end.frame" : [

"description",
"""
Expand Down
64 changes: 32 additions & 32 deletions src/GafferImage/ImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ ImageReader::ImageReader( const std::string &name )
addChild( new IntPlug( "refreshCount" ) );
addChild( new IntPlug( "missingFrameMode", Plug::In, Error, /* min */ Error, /* max */ Hold ) );

ValuePlugPtr frameStartMaskPlug = new ValuePlug( "frameStartMask", Plug::In );
frameStartMaskPlug->addChild( new IntPlug( "mode", Plug::In, None, /* min */ None, /* max */ ClampToRange ) );
frameStartMaskPlug->addChild( new IntPlug( "frame", Plug::In, 0 ) );
addChild( frameStartMaskPlug );
ValuePlugPtr startPlug = new ValuePlug( "start", Plug::In );
startPlug->addChild( new IntPlug( "mode", Plug::In, None, /* min */ None, /* max */ ClampToFrame ) );
startPlug->addChild( new IntPlug( "frame", Plug::In, 0 ) );
addChild( startPlug );

ValuePlugPtr frameEndMaskPlug = new ValuePlug( "frameEndMask", Plug::In );
frameEndMaskPlug->addChild( new IntPlug( "mode", Plug::In, None, /* min */ None, /* max */ ClampToRange ) );
frameEndMaskPlug->addChild( new IntPlug( "frame", Plug::In, 0 ) );
addChild( frameEndMaskPlug );
ValuePlugPtr endPlug = new ValuePlug( "end", Plug::In );
endPlug->addChild( new IntPlug( "mode", Plug::In, None, /* min */ None, /* max */ ClampToFrame ) );
endPlug->addChild( new IntPlug( "frame", Plug::In, 0 ) );
addChild( endPlug );

addChild( new CompoundObjectPlug( "__intermediateMetadata", Plug::In, new CompoundObject, Plug::Default & ~Plug::Serialisable ) );
addChild( new StringPlug( "__intermediateColorSpace", Plug::Out, "", Plug::Default & ~Plug::Serialisable ) );
Expand Down Expand Up @@ -139,42 +139,42 @@ const IntPlug *ImageReader::missingFrameModePlug() const
return getChild<IntPlug>( g_firstChildIndex + 2 );
}

IntPlug *ImageReader::frameStartMaskModePlug()
IntPlug *ImageReader::startModePlug()
{
return getChild<ValuePlug>( g_firstChildIndex + 3 )->getChild<IntPlug>( 0 );
}

const IntPlug *ImageReader::frameStartMaskModePlug() const
const IntPlug *ImageReader::startModePlug() const
{
return getChild<ValuePlug>( g_firstChildIndex + 3 )->getChild<IntPlug>( 0 );
}

IntPlug *ImageReader::frameStartMaskPlug()
IntPlug *ImageReader::startFramePlug()
{
return getChild<ValuePlug>( g_firstChildIndex + 3 )->getChild<IntPlug>( 1 );
}

const IntPlug *ImageReader::frameStartMaskPlug() const
const IntPlug *ImageReader::startFramePlug() const
{
return getChild<ValuePlug>( g_firstChildIndex + 3 )->getChild<IntPlug>( 1 );
}

IntPlug *ImageReader::frameEndMaskModePlug()
IntPlug *ImageReader::endModePlug()
{
return getChild<ValuePlug>( g_firstChildIndex + 4 )->getChild<IntPlug>( 0 );
}

const IntPlug *ImageReader::frameEndMaskModePlug() const
const IntPlug *ImageReader::endModePlug() const
{
return getChild<ValuePlug>( g_firstChildIndex + 4 )->getChild<IntPlug>( 0 );
}

IntPlug *ImageReader::frameEndMaskPlug()
IntPlug *ImageReader::endFramePlug()
{
return getChild<ValuePlug>( g_firstChildIndex + 4 )->getChild<IntPlug>( 1 );
}

const IntPlug *ImageReader::frameEndMaskPlug() const
const IntPlug *ImageReader::endFramePlug() const
{
return getChild<ValuePlug>( g_firstChildIndex + 4 )->getChild<IntPlug>( 1 );
}
Expand Down Expand Up @@ -248,10 +248,10 @@ void ImageReader::affects( const Plug *input, AffectedPlugsContainer &outputs )
outputs.push_back( outPlug()->getChild<ValuePlug>( input->getName() ) );
}
else if (
input == frameStartMaskPlug() ||
input == frameStartMaskModePlug() ||
input == frameEndMaskPlug() ||
input == frameEndMaskModePlug()
input == startFramePlug() ||
input == startModePlug() ||
input == endFramePlug() ||
input == endModePlug()
)
{
for( ValuePlugIterator it( outPlug() ); it != it.end(); ++it )
Expand All @@ -276,7 +276,7 @@ void ImageReader::hash( const ValuePlug *output, const Context *context, IECore:
{
// we always want to match the windows
// we would get inside the frame mask
hashMaskedOutput( output, context, h, /* alwaysClampToRange */ true );
hashMaskedOutput( output, context, h, /* alwaysClampToFrame */ true );
}
else if(
output == outPlug()->metadataPlug() ||
Expand Down Expand Up @@ -313,7 +313,7 @@ void ImageReader::compute( ValuePlug *output, const Context *context ) const
{
// we always want to match the windows
// we would get inside the frame mask
computeMaskedOutput( output, context, /* alwaysClampToRange */ true );
computeMaskedOutput( output, context, /* alwaysClampToFrame */ true );
}
else if(
output == outPlug()->metadataPlug() ||
Expand All @@ -329,21 +329,21 @@ void ImageReader::compute( ValuePlug *output, const Context *context ) const
}
}

void ImageReader::hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToRange ) const
void ImageReader::hashMaskedOutput( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h, bool alwaysClampToFrame ) const
{
ContextPtr maskedContext = NULL;
if( !computeFrameMask( context, maskedContext ) || alwaysClampToRange )
if( !computeFrameMask( context, maskedContext ) || alwaysClampToFrame )
{
Context::Scope scope( maskedContext.get() );
h = intermediateImagePlug()->getChild<ValuePlug>( output->getName() )->hash();
}
}

void ImageReader::computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToRange ) const
void ImageReader::computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::Context *context, bool alwaysClampToFrame ) const
{
ContextPtr maskedContext = NULL;
bool blackOutside = computeFrameMask( context, maskedContext );
if( blackOutside && !alwaysClampToRange )
if( blackOutside && !alwaysClampToFrame )
{
output->setToDefault();
return;
Expand All @@ -355,10 +355,10 @@ void ImageReader::computeMaskedOutput( Gaffer::ValuePlug *output, const Gaffer::

bool ImageReader::computeFrameMask( const Context *context, ContextPtr &maskedContext ) const
{
int frameStartMask = frameStartMaskPlug()->getValue();
int frameEndMask = frameEndMaskPlug()->getValue();
FrameMaskMode frameStartMaskMode = (FrameMaskMode)frameStartMaskModePlug()->getValue();
FrameMaskMode frameEndMaskMode = (FrameMaskMode)frameEndMaskModePlug()->getValue();
int frameStartMask = startFramePlug()->getValue();
int frameEndMask = endFramePlug()->getValue();
FrameMaskMode frameStartMaskMode = (FrameMaskMode)startModePlug()->getValue();
FrameMaskMode frameEndMaskMode = (FrameMaskMode)endModePlug()->getValue();

int origFrame = (int)context->getFrame();
int maskedFrame = std::min( frameEndMask, std::max( frameStartMask, origFrame ) );
Expand All @@ -380,11 +380,11 @@ bool ImageReader::computeFrameMask( const Context *context, ContextPtr &maskedCo
}

// we need to create the masked context
// for both BlackOutSide and ClampToRange,
// for both BlackOutSide and ClampToFrame,
// because some plugs require valid data
// from the mask range even in either way.

maskedContext = new Gaffer::Context( *context, Context::Shared );
maskedContext = new Gaffer::Context( *context, Context::Borrowed );
maskedContext->setFrame( maskedFrame );

return ( maskMode == BlackOutside );
Expand Down
2 changes: 1 addition & 1 deletion src/GafferImageBindings/ImageReaderBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void GafferImageBindings::bindImageReader()
boost::python::enum_<ImageReader::FrameMaskMode>( "FrameMaskMode" )
.value( "None", ImageReader::None )
.value( "BlackOutside", ImageReader::BlackOutside )
.value( "ClampToRange", ImageReader::ClampToRange )
.value( "ClampToFrame", ImageReader::ClampToFrame )
;

}

0 comments on commit cdfbb36

Please sign in to comment.