PageRenderTime 41ms CodeModel.GetById 2ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/Transform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 175 lines | 137 code | 10 blank | 28 comment | 39 complexity | 11b137541cc3bb53e498d74d1f3e120b MD5 | raw file
  1/*
  2Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
  3All Rights Reserved.
  4
  5Redistribution and use in source and binary forms, with or without
  6modification, are permitted provided that the following conditions are
  7met:
  8* Redistributions of source code must retain the above copyright
  9  notice, this list of conditions and the following disclaimer.
 10* Redistributions in binary form must reproduce the above copyright
 11  notice, this list of conditions and the following disclaimer in the
 12  documentation and/or other materials provided with the distribution.
 13* Neither the name of Sony Pictures Imageworks nor the names of its
 14  contributors may be used to endorse or promote products derived from
 15  this software without specific prior written permission.
 16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 17"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 18LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 19A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 20OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 21SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 22LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 23DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 24THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 26OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27*/
 28
 29#include <OpenColorIO/OpenColorIO.h>
 30
 31#include "FileTransform.h"
 32#include "OpBuilders.h"
 33#include "Processor.h"
 34
 35#include <sstream>
 36
 37OCIO_NAMESPACE_ENTER
 38{
 39    Transform::~Transform()
 40    { }
 41    
 42    
 43    void BuildOps(OpRcPtrVec & ops,
 44                  const Config & config,
 45                  const ConstContextRcPtr & context,
 46                  const ConstTransformRcPtr & transform,
 47                  TransformDirection dir)
 48    {
 49        // A null transform is valid, and corresponds to a no-op.
 50        if(!transform)
 51            return;
 52        
 53        if(ConstAllocationTransformRcPtr allocationTransform = \
 54            DynamicPtrCast<const AllocationTransform>(transform))
 55        {
 56            BuildAllocationOps(ops, config, *allocationTransform, dir);
 57        }
 58        else if(ConstCDLTransformRcPtr cdlTransform = \
 59            DynamicPtrCast<const CDLTransform>(transform))
 60        {
 61            BuildCDLOps(ops, config, *cdlTransform, dir);
 62        }
 63        else if(ConstColorSpaceTransformRcPtr colorSpaceTransform = \
 64            DynamicPtrCast<const ColorSpaceTransform>(transform))
 65        {
 66            BuildColorSpaceOps(ops, config, context, *colorSpaceTransform, dir);
 67        }
 68        else if(ConstDisplayTransformRcPtr displayTransform = \
 69            DynamicPtrCast<const DisplayTransform>(transform))
 70        {
 71            BuildDisplayOps(ops, config, context, *displayTransform, dir);
 72        }
 73        else if(ConstExponentTransformRcPtr exponentTransform = \
 74            DynamicPtrCast<const ExponentTransform>(transform))
 75        {
 76            BuildExponentOps(ops, config, *exponentTransform, dir);
 77        }
 78        else if(ConstFileTransformRcPtr fileTransform = \
 79            DynamicPtrCast<const FileTransform>(transform))
 80        {
 81            BuildFileOps(ops, config, context, *fileTransform, dir);
 82        }
 83        else if(ConstGroupTransformRcPtr groupTransform = \
 84            DynamicPtrCast<const GroupTransform>(transform))
 85        {
 86            BuildGroupOps(ops, config, context, *groupTransform, dir);
 87        }
 88        else if(ConstLogTransformRcPtr logTransform = \
 89            DynamicPtrCast<const LogTransform>(transform))
 90        {
 91            BuildLogOps(ops, config, *logTransform, dir);
 92        }
 93        else if(ConstLookTransformRcPtr lookTransform = \
 94            DynamicPtrCast<const LookTransform>(transform))
 95        {
 96            BuildLookOps(ops, config, context, *lookTransform, dir);
 97        }
 98        else if(ConstMatrixTransformRcPtr matrixTransform = \
 99            DynamicPtrCast<const MatrixTransform>(transform))
100        {
101            BuildMatrixOps(ops, config, *matrixTransform, dir);
102        }
103        else if(ConstTruelightTransformRcPtr truelightTransform = \
104            DynamicPtrCast<const TruelightTransform>(transform))
105        {
106            BuildTruelightOps(ops, config, *truelightTransform, dir);
107        }
108        else
109        {
110            std::ostringstream os;
111            os << "Unknown transform type for Op Creation.";
112            throw Exception(os.str().c_str());
113        }
114    }
115    
116    std::ostream& operator<< (std::ostream & os, const Transform & transform)
117    {
118        const Transform* t = &transform;
119        
120        if(const AllocationTransform * allocationTransform = \
121            dynamic_cast<const AllocationTransform*>(t))
122        {
123            os << *allocationTransform;
124        }
125        else if(const CDLTransform * cdlTransform = \
126            dynamic_cast<const CDLTransform*>(t))
127        {
128            os << *cdlTransform;
129        }
130        else if(const ColorSpaceTransform * colorSpaceTransform = \
131            dynamic_cast<const ColorSpaceTransform*>(t))
132        {
133            os << *colorSpaceTransform;
134        }
135        else if(const DisplayTransform * displayTransform = \
136            dynamic_cast<const DisplayTransform*>(t))
137        {
138            os << *displayTransform;
139        }
140        else if(const ExponentTransform * exponentTransform = \
141            dynamic_cast<const ExponentTransform*>(t))
142        {
143            os << *exponentTransform;
144        }
145        else if(const FileTransform * fileTransform = \
146            dynamic_cast<const FileTransform*>(t))
147        {
148            os << *fileTransform;
149        }
150        else if(const GroupTransform * groupTransform = \
151            dynamic_cast<const GroupTransform*>(t))
152        {
153            os << *groupTransform;
154        }
155        else if(const MatrixTransform * matrixTransform = \
156            dynamic_cast<const MatrixTransform*>(t))
157        {
158            os << *matrixTransform;
159        }
160        else if(const TruelightTransform * truelightTransform = \
161            dynamic_cast<const TruelightTransform*>(t))
162        {
163            os << *truelightTransform;
164        }
165        else
166        {
167            std::ostringstream error;
168            os << "Unknown transform type for serialization.";
169            throw Exception(error.str().c_str());
170        }
171        
172        return os;
173    }
174}
175OCIO_NAMESPACE_EXIT