PageRenderTime 29ms CodeModel.GetById 10ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/ExponentTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 151 lines | 94 code | 28 blank | 29 comment | 3 complexity | d7a0c4ebad8ea16d7bcbb3020a9756e9 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 <cstring>
 30
 31#include <OpenColorIO/OpenColorIO.h>
 32
 33#include "ExponentOps.h"
 34#include "OpBuilders.h"
 35
 36
 37OCIO_NAMESPACE_ENTER
 38{
 39    ExponentTransformRcPtr ExponentTransform::Create()
 40    {
 41        return ExponentTransformRcPtr(new ExponentTransform(), &deleter);
 42    }
 43    
 44    void ExponentTransform::deleter(ExponentTransform* t)
 45    {
 46        delete t;
 47    }
 48    
 49    
 50    class ExponentTransform::Impl
 51    {
 52    public:
 53        TransformDirection dir_;
 54        float value_[4];
 55        
 56        Impl() :
 57            dir_(TRANSFORM_DIR_FORWARD)
 58        {
 59            for(int i=0; i<4; ++i)
 60            {
 61                value_[i] = 1.0f;
 62            }
 63        }
 64        
 65        ~Impl()
 66        { }
 67        
 68        Impl& operator= (const Impl & rhs)
 69        {
 70            dir_ = rhs.dir_;
 71            memcpy(value_, rhs.value_, 4*sizeof(float));
 72            return *this;
 73        }
 74    };
 75    
 76    ///////////////////////////////////////////////////////////////////////////
 77    
 78    
 79    
 80    ExponentTransform::ExponentTransform()
 81        : m_impl(new ExponentTransform::Impl)
 82    {
 83    }
 84    
 85    TransformRcPtr ExponentTransform::createEditableCopy() const
 86    {
 87        ExponentTransformRcPtr transform = ExponentTransform::Create();
 88        *(transform->m_impl) = *m_impl;
 89        return transform;
 90    }
 91    
 92    ExponentTransform::~ExponentTransform()
 93    {
 94        delete m_impl;
 95        m_impl = NULL;
 96    }
 97    
 98    ExponentTransform& ExponentTransform::operator= (const ExponentTransform & rhs)
 99    {
100        *m_impl = *rhs.m_impl;
101        return *this;
102    }
103    
104    TransformDirection ExponentTransform::getDirection() const
105    {
106        return getImpl()->dir_;
107    }
108    
109    void ExponentTransform::setDirection(TransformDirection dir)
110    {
111        getImpl()->dir_ = dir;
112    }
113    
114    void ExponentTransform::setValue(const float * vec4)
115    {
116        if(vec4) memcpy(getImpl()->value_, vec4, 4*sizeof(float));
117    }
118    
119    void ExponentTransform::getValue(float * vec4) const
120    {
121        if(vec4) memcpy(vec4, getImpl()->value_, 4*sizeof(float));
122    }
123    
124    std::ostream& operator<< (std::ostream& os, const ExponentTransform& t)
125    {
126        os << "<ExponentTransform ";
127        os << "direction=" << TransformDirectionToString(t.getDirection()) << ", ";
128        os << ">\n";
129        return os;
130    }
131    
132    
133    ///////////////////////////////////////////////////////////////////////////////////////////////////////
134    
135    void BuildExponentOps(OpRcPtrVec & ops,
136                          const Config& /*config*/,
137                          const ExponentTransform & transform,
138                          TransformDirection dir)
139    {
140        TransformDirection combinedDir = CombineTransformDirections(dir,
141            transform.getDirection());
142        
143        float vec4[4];
144        transform.getValue(vec4);
145        
146        CreateExponentOp(ops,
147                         vec4,
148                         combinedDir);
149    }
150}
151OCIO_NAMESPACE_EXIT