PageRenderTime 34ms CodeModel.GetById 10ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/AllocationTransform.cpp

http://github.com/imageworks/OpenColorIO
C++ | 182 lines | 120 code | 33 blank | 29 comment | 3 complexity | d5ed982e48ca11b9f35cd5930fbe71d9 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 "AllocationOp.h"
 36#include "OpBuilders.h"
 37
 38OCIO_NAMESPACE_ENTER
 39{
 40    AllocationTransformRcPtr AllocationTransform::Create()
 41    {
 42        return AllocationTransformRcPtr(new AllocationTransform(), &deleter);
 43    }
 44    
 45    void AllocationTransform::deleter(AllocationTransform* t)
 46    {
 47        delete t;
 48    }
 49    
 50    
 51    class AllocationTransform::Impl
 52    {
 53    public:
 54        TransformDirection dir_;
 55        Allocation allocation_;
 56        std::vector<float> vars_;
 57        
 58        Impl() :
 59            dir_(TRANSFORM_DIR_FORWARD),
 60            allocation_(ALLOCATION_UNIFORM)
 61        { }
 62        
 63        ~Impl()
 64        { }
 65        
 66        Impl& operator= (const Impl & rhs)
 67        {
 68            dir_ = rhs.dir_;
 69            allocation_ = rhs.allocation_;
 70            vars_ = rhs.vars_;
 71            return *this;
 72        }
 73    };
 74    
 75    ///////////////////////////////////////////////////////////////////////////
 76    
 77    
 78    AllocationTransform::AllocationTransform()
 79        : m_impl(new AllocationTransform::Impl)
 80    {
 81    }
 82    
 83    TransformRcPtr AllocationTransform::createEditableCopy() const
 84    {
 85        AllocationTransformRcPtr transform = AllocationTransform::Create();
 86        *(transform->m_impl) = *m_impl;
 87        return transform;
 88    }
 89    
 90    AllocationTransform::~AllocationTransform()
 91    {
 92        delete m_impl;
 93        m_impl = NULL;
 94    }
 95    
 96    AllocationTransform& AllocationTransform::operator= (const AllocationTransform & rhs)
 97    {
 98        *m_impl = *rhs.m_impl;
 99        return *this;
100    }
101    
102    TransformDirection AllocationTransform::getDirection() const
103    {
104        return getImpl()->dir_;
105    }
106    
107    void AllocationTransform::setDirection(TransformDirection dir)
108    {
109        getImpl()->dir_ = dir;
110    }
111    
112    
113    Allocation AllocationTransform::getAllocation() const
114    {
115        return getImpl()->allocation_;
116    }
117    
118    void AllocationTransform::setAllocation(Allocation allocation)
119    {
120        getImpl()->allocation_ = allocation;
121    }
122    
123    int AllocationTransform::getNumVars() const
124    {
125        return static_cast<int>(getImpl()->vars_.size());
126    }
127    
128    void AllocationTransform::getVars(float * vars) const
129    {
130        if(!getImpl()->vars_.empty())
131        {
132            memcpy(vars,
133                &getImpl()->vars_[0],
134                getImpl()->vars_.size()*sizeof(float));
135        }
136    }
137    
138    void AllocationTransform::setVars(int numvars, const float * vars)
139    {
140        getImpl()->vars_.resize(numvars);
141        
142        if(!getImpl()->vars_.empty())
143        {
144            memcpy(&getImpl()->vars_[0],
145                vars,
146                numvars*sizeof(float));
147        }
148    }
149    
150    std::ostream& operator<< (std::ostream& os, const AllocationTransform& t)
151    {
152        os << "<AllocationTransform ";
153        os << "direction=" << TransformDirectionToString(t.getDirection()) << ", ";
154        os << ">\n";
155        
156        return os;
157    }
158    
159    
160    ///////////////////////////////////////////////////////////////////////////
161    
162    
163    void BuildAllocationOps(OpRcPtrVec & ops,
164                      const Config& /*config*/,
165                      const AllocationTransform& allocationTransform,
166                      TransformDirection dir)
167    {
168        TransformDirection combinedDir = CombineTransformDirections(dir,
169                                                  allocationTransform.getDirection());
170        
171        AllocationData data;
172        data.allocation = allocationTransform.getAllocation();
173        data.vars.resize(allocationTransform.getNumVars());
174        if(!data.vars.empty())
175        {
176            allocationTransform.getVars(&data.vars[0]);
177        }
178        
179        CreateAllocationOps(ops, data, combinedDir);
180    }
181}
182OCIO_NAMESPACE_EXIT