From 18b33b1749599e716f0a148a28a07cf41efb8588 Mon Sep 17 00:00:00 2001 From: lucien fostier Date: Thu, 6 Apr 2017 23:38:10 -0700 Subject: [PATCH] ImageWriter: Added metadata node to inject colorspace name --- include/GafferImage/ImageWriter.h | 7 +++++ python/GafferImageUI/ImageWriterUI.py | 12 ++++++++ src/GafferImage/ImageWriter.cpp | 42 +++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/include/GafferImage/ImageWriter.h b/include/GafferImage/ImageWriter.h index 5341502d8c7..8be34725773 100644 --- a/include/GafferImage/ImageWriter.h +++ b/include/GafferImage/ImageWriter.h @@ -55,6 +55,7 @@ namespace GafferImage { IE_CORE_FORWARDDECLARE( ColorSpace ) +IE_CORE_FORWARDDECLARE( ImageMetadata ) IE_CORE_FORWARDDECLARE( ImagePlug ) class ImageWriter : public GafferDispatch::TaskNode @@ -88,6 +89,9 @@ class ImageWriter : public GafferDispatch::TaskNode Gaffer::StringPlug *colorSpacePlug(); const Gaffer::StringPlug *colorSpacePlug() const; + Gaffer::StringPlug *colorSpaceMetadataNamePlug(); + const Gaffer::StringPlug *colorSpaceMetadataNamePlug() const; + Gaffer::ValuePlug *fileFormatSettingsPlug( const std::string &fileFormat ); const Gaffer::ValuePlug *fileFormatSettingsPlug( const std::string &fileFormat ) const; @@ -105,6 +109,9 @@ class ImageWriter : public GafferDispatch::TaskNode ColorSpace *colorSpace(); const ColorSpace *colorSpace() const; + ImageMetadata *meta(); + const ImageMetadata *meta() const; + Gaffer::Expression *expression(); const Gaffer::Expression *expression() const; diff --git a/python/GafferImageUI/ImageWriterUI.py b/python/GafferImageUI/ImageWriterUI.py index ff74c91e285..3b95486daa8 100644 --- a/python/GafferImageUI/ImageWriterUI.py +++ b/python/GafferImageUI/ImageWriterUI.py @@ -120,6 +120,18 @@ def __colorSpacePresetValues( plug ) : ], + "colorSpaceMetadataName" : [ + + "description", + """ + Name of the metadata used to store the output image colorspace. + """, + + "layout:section", "ColorSpaceMetadata", + "layout:index", -4, + + ], + "out" : [ "description", diff --git a/src/GafferImage/ImageWriter.cpp b/src/GafferImage/ImageWriter.cpp index 30b606604ce..98bf71084cd 100644 --- a/src/GafferImage/ImageWriter.cpp +++ b/src/GafferImage/ImageWriter.cpp @@ -63,6 +63,7 @@ OIIO_NAMESPACE_USING #include "GafferImage/ImagePlug.h" #include "GafferImage/OpenImageIOAlgo.h" #include "GafferImage/ColorSpace.h" +#include "GafferImage/ImageMetadata.h" using namespace std; using namespace Imath; @@ -721,7 +722,13 @@ ImageWriter::ImageWriter( const std::string &name ) ExpressionPtr expression = new Expression( "__expression" ); addChild( expression ); + ImageMetadataPtr imageMetadata = new ImageMetadata( "__metaData" ); + addChild( imageMetadata ); + imageMetadata->inPlug()->setInput( colorSpace->outPlug() ); + //imageMetadata->metadataPlug()->addOptionalMember( "gaffer:colorspace", new StringPlug() , "colorSpace" ); + addChild( new StringPlug( "colorSpace" ) ); + addChild( new StringPlug( "colorSpaceMetadataName" ) ); addChild( new ImagePlug( "out", Plug::Out, Plug::Default & ~Plug::Serialisable ) ); outPlug()->setInput( inPlug() ); @@ -845,25 +852,44 @@ const Expression *ImageWriter::expression() const return getChild( g_firstPlugIndex+4 ); } +GafferImage::ImageMetadata *ImageWriter::meta() +{ + return getChild( g_firstPlugIndex+5 ); +} + +const GafferImage::ImageMetadata *ImageWriter::meta() const +{ + return getChild( g_firstPlugIndex+5 ); +} Gaffer::StringPlug *ImageWriter::colorSpacePlug() { - return getChild( g_firstPlugIndex+5 ); + return getChild( g_firstPlugIndex+6 ); } const Gaffer::StringPlug *ImageWriter::colorSpacePlug() const { - return getChild( g_firstPlugIndex+5 ); + return getChild( g_firstPlugIndex+6 ); +} + +Gaffer::StringPlug *ImageWriter::colorSpaceMetadataNamePlug() +{ + return getChild( g_firstPlugIndex+7 ); +} + +const Gaffer::StringPlug *ImageWriter::colorSpaceMetadataNamePlug() const +{ + return getChild( g_firstPlugIndex+7 ); } GafferImage::ImagePlug *ImageWriter::outPlug() { - return getChild( g_firstPlugIndex+6 ); + return getChild( g_firstPlugIndex+8 ); } const GafferImage::ImagePlug *ImageWriter::outPlug() const { - return getChild( g_firstPlugIndex+6 ); + return getChild( g_firstPlugIndex+8 ); } Gaffer::ValuePlug *ImageWriter::fileFormatSettingsPlug( const std::string &fileFormat ) @@ -978,6 +1004,10 @@ void ImageWriter::execute() const // and then probably removing it again on the way back into C++. That would mean that the ImageWriter is deleted before it's even constructed. Expression *e = const_cast( expression() ); e->setExpression( string( "parent[\"__colorSpace\"][\"outputSpace\"] = context.get(\"gaffer:colorspace\", \"\") " ), string( "python" ) ); + + ImageMetadata *m = const_cast( meta() ); + m->metadataPlug()->addOptionalMember( "gaffer:colorspace", new StringPlug() , "colorSpace" ); + if( !inPlug()->getInput() ) { throw IECore::Exception( "No input image." ); @@ -1081,13 +1111,13 @@ void ImageWriter::execute() const if ( spec.tile_width == 0 ) { FlatScanlineWriter flatScanlineWriter( out, fileName, processDataWindow, imageFormat ); - ImageAlgo::parallelGatherTiles( colorSpace()->outPlug(), spec.channelnames, processor, flatScanlineWriter, processDataWindow, ImageAlgo::TopToBottom ); + ImageAlgo::parallelGatherTiles( meta()->outPlug(), spec.channelnames, processor, flatScanlineWriter, processDataWindow, ImageAlgo::TopToBottom ); flatScanlineWriter.finish(); } else { FlatTileWriter flatTileWriter( out, fileName, processDataWindow, imageFormat ); - ImageAlgo::parallelGatherTiles( colorSpace()->outPlug(), spec.channelnames, processor, flatTileWriter, processDataWindow, ImageAlgo::TopToBottom ); + ImageAlgo::parallelGatherTiles( meta()->outPlug(), spec.channelnames, processor, flatTileWriter, processDataWindow, ImageAlgo::TopToBottom ); flatTileWriter.finish(); }