PageRenderTime 25ms CodeModel.GetById 16ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/LogTransform.cpp

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