Skip to content

Commit

Permalink
Merge pull request #1542 from andrewkaufman/uberImageReader
Browse files Browse the repository at this point in the history
 Added a more user friendly ImageReader
  • Loading branch information
johnhaddon committed Nov 23, 2015
2 parents 21487ec + cdfbb36 commit db2e27d
Show file tree
Hide file tree
Showing 31 changed files with 2,589 additions and 655 deletions.
4 changes: 4 additions & 0 deletions include/Gaffer/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ class Context : public IECore::RefCounted
/// Destruction of the Scope pops the previously pushed context.
~Scope();

private :

const Context *m_context;

};

/// Returns the current context for the calling thread.
Expand Down
103 changes: 72 additions & 31 deletions include/GafferImage/ImageReader.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, John Haddon. All rights reserved.
// Copyright (c) 2012-2014, Image Engine Design Inc. All rights reserved.
// Copyright (c) 2015, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -35,10 +34,10 @@
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERSCENE_IMAGEREADER_H
#define GAFFERSCENE_IMAGEREADER_H
#ifndef GAFFERIMAGE_IMAGEREADER_H
#define GAFFERIMAGE_IMAGEREADER_H

#include "Gaffer/NumericPlug.h"
#include "Gaffer/CompoundNumericPlug.h"

#include "GafferImage/ImageNode.h"

Expand All @@ -52,11 +51,9 @@ IE_CORE_FORWARDDECLARE( StringPlug )
namespace GafferImage
{

/// \todo Linearise images. Perhaps this should be done by a super-node which just
/// packages up an internal ImageReader and OpenColorIO node? If so then perhaps
/// we should rename this class to SimpleImageReader or something? Perhaps we could
/// also have a metaData() plug in the ImagePlug, fill it with the file metadata,
/// and use that to pass the input colorspace into the internal OpenColorIO node.
IE_CORE_FORWARDDECLARE( ColorSpace )
IE_CORE_FORWARDDECLARE( OpenImageIOReader )

class ImageReader : public ImageNode
{

Expand All @@ -67,46 +64,90 @@ class ImageReader : public ImageNode

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferImage::ImageReader, ImageReaderTypeId, ImageNode );

/// The MissingFrameMode controls how to handle missing images.
/// It is distinct from OpenImageIOReader::MissingFrameMode so
/// that we can provide alternate modes using higher
/// level approaches in the future (e.g interpolation).
enum MissingFrameMode
{
Error = 0,
Black,
Hold,
};

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

Gaffer::StringPlug *fileNamePlug();
const Gaffer::StringPlug *fileNamePlug() const;

/// Number of times the node has been refreshed.
Gaffer::IntPlug *refreshCountPlug();
const Gaffer::IntPlug *refreshCountPlug() const;


Gaffer::IntPlug *missingFrameModePlug();
const Gaffer::IntPlug *missingFrameModePlug() const;

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

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

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

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

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

static size_t supportedExtensions( std::vector<std::string> &extensions );

/// Returns the maximum amount of memory in Mb to use for the cache.
static size_t getCacheMemoryLimit();
/// Sets the maximum amount of memory the cache may use in Mb.
static void setCacheMemoryLimit( size_t mb );

protected :

virtual void hashFormat( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashDataWindow( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashMetadata( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashChannelNames( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashChannelData( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;

virtual GafferImage::Format computeFormat( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual Imath::Box2i computeDataWindow( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstCompoundObjectPtr computeMetadata( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstStringVectorDataPtr computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstFloatVectorDataPtr computeChannelData( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual void hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const;

private :

void plugSet( Gaffer::Plug *plug );

static size_t g_firstPlugIndex;
// We use internal nodes to do all the hard work,
// but we need to store intermediate results between
// those nodes in order to affect the outcome.

OpenImageIOReader *oiioReader();
const OpenImageIOReader *oiioReader() const;

Gaffer::CompoundObjectPlug *intermediateMetadataPlug();
const Gaffer::CompoundObjectPlug *intermediateMetadataPlug() const;

Gaffer::StringPlug *intermediateColorSpacePlug();
const Gaffer::StringPlug *intermediateColorSpacePlug() const;

ColorSpace *colorSpace();
const ColorSpace *colorSpace() const;

GafferImage::ImagePlug *intermediateImagePlug();
const GafferImage::ImagePlug *intermediateImagePlug() 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;

static size_t g_firstChildIndex;

};

IE_CORE_DECLAREPTR( ImageReader )

} // namespace GafferImage

#endif // GAFFERSCENE_IMAGEREADER_H
#endif // GAFFERIMAGE_IMAGEREADER_H
4 changes: 4 additions & 0 deletions include/GafferImage/OpenColorIOTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class OpenColorIOTransform : public ColorProcessor
OpenColorIOTransform( const std::string &name=defaultName<OpenColorIOTransform>() );
virtual ~OpenColorIOTransform();

/// Fills the vector will the available color spaces,
/// as defined by the current OpenColorIO config.
static void availableColorSpaces( std::vector<std::string> &colorSpaces );

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferImage::OpenColorIOTransform, OpenColorIOTransformTypeId, ColorProcessor );

protected :
Expand Down
125 changes: 125 additions & 0 deletions include/GafferImage/OpenImageIOReader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2012, John Haddon. All rights reserved.
// Copyright (c) 2012-2015, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERIMAGE_OPENIMAGEIOREADER_H
#define GAFFERIMAGE_OPENIMAGEIOREADER_H

#include "Gaffer/NumericPlug.h"

#include "GafferImage/ImageNode.h"

namespace Gaffer
{

IE_CORE_FORWARDDECLARE( StringPlug )

} // namespace Gaffer

namespace GafferImage
{

class OpenImageIOReader : public ImageNode
{

public :

OpenImageIOReader( const std::string &name=defaultName<OpenImageIOReader>() );
virtual ~OpenImageIOReader();

IE_CORE_DECLARERUNTIMETYPEDEXTENSION( GafferImage::OpenImageIOReader, OpenImageIOReaderTypeId, ImageNode );

enum MissingFrameMode
{
Error = 0,
Black,
Hold,
};

Gaffer::StringPlug *fileNamePlug();
const Gaffer::StringPlug *fileNamePlug() const;

/// Number of times the node has been refreshed.
Gaffer::IntPlug *refreshCountPlug();
const Gaffer::IntPlug *refreshCountPlug() const;

Gaffer::IntPlug *missingFrameModePlug();
const Gaffer::IntPlug *missingFrameModePlug() const;

Gaffer::IntVectorDataPlug *availableFramesPlug();
const Gaffer::IntVectorDataPlug *availableFramesPlug() const;

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

static size_t supportedExtensions( std::vector<std::string> &extensions );

/// Returns the maximum amount of memory in Mb to use for the cache.
static size_t getCacheMemoryLimit();
/// Sets the maximum amount of memory the cache may use in Mb.
static void setCacheMemoryLimit( size_t mb );

protected :

virtual void hash( const Gaffer::ValuePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void compute( Gaffer::ValuePlug *output, const Gaffer::Context *context ) const;

virtual void hashFormat( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashDataWindow( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashMetadata( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashChannelNames( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;
virtual void hashChannelData( const GafferImage::ImagePlug *output, const Gaffer::Context *context, IECore::MurmurHash &h ) const;

virtual GafferImage::Format computeFormat( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual Imath::Box2i computeDataWindow( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstCompoundObjectPtr computeMetadata( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstStringVectorDataPtr computeChannelNames( const Gaffer::Context *context, const ImagePlug *parent ) const;
virtual IECore::ConstFloatVectorDataPtr computeChannelData( const std::string &channelName, const Imath::V2i &tileOrigin, const Gaffer::Context *context, const ImagePlug *parent ) const;

private :

void hashFileName( const Gaffer::Context *context, IECore::MurmurHash &h ) const;

void plugSet( Gaffer::Plug *plug );

static size_t g_firstPlugIndex;

};

IE_CORE_DECLAREPTR( OpenImageIOReader )

} // namespace GafferImage

#endif // GAFFERIMAGE_OPENIMAGEIOREADER_H
1 change: 1 addition & 0 deletions include/GafferImage/TypeIds.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ enum TypeId
BlurTypeId = 110810,
ShapeTypeId = 110811,
TextTypeId = 110812,
OpenImageIOReaderTypeId = 110813,

LastTypeId = 110849
};
Expand Down
2 changes: 1 addition & 1 deletion include/GafferImageBindings/ImageReaderBinding.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2014, Image Engine Design Inc. All rights reserved.
// Copyright (c) 2014-2015, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
Expand Down
47 changes: 47 additions & 0 deletions include/GafferImageBindings/OpenColorIOTransformBinding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2015, Image Engine Design Inc. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above
// copyright notice, this list of conditions and the following
// disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided with
// the distribution.
//
// * Neither the name of John Haddon nor the names of
// any other contributors to this software may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////

#ifndef GAFFERIMAGEBINDINGS_OPENCOLORIOTRANSFORMBINDING_H
#define GAFFERIMAGEBINDINGS_OPENCOLORIOTRANSFORMBINDING_H

namespace GafferImageBindings
{

void bindOpenColorIOTransform();

} // namespace GafferImageBindings

#endif // GAFFERIMAGEBINDINGS_OPENCOLORIOTRANSFORMBINDING_H
Loading

0 comments on commit db2e27d

Please sign in to comment.