PageRenderTime 77ms CodeModel.GetById 65ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/src/core/AllocationOp.cpp

http://github.com/imageworks/OpenColorIO
C++ | 128 lines | 84 code | 15 blank | 29 comment | 16 complexity | 80fc5543c02a03b9b2342c748a9365ff 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 "AllocationOp.h"
 30#include "LogOps.h"
 31#include "MatrixOps.h"
 32#include "Op.h"
 33
 34#include <OpenColorIO/OpenColorIO.h>
 35
 36OCIO_NAMESPACE_ENTER
 37{
 38
 39    void CreateAllocationOps(OpRcPtrVec & ops,
 40                             const AllocationData & data,
 41                             TransformDirection dir)
 42    {
 43        if(data.allocation == ALLOCATION_UNIFORM)
 44        {
 45            float oldmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
 46            float oldmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
 47            float newmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
 48            float newmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
 49            
 50            if(data.vars.size() >= 2)
 51            {
 52                for(int i=0; i<3; ++i)
 53                {
 54                    oldmin[i] = data.vars[0];
 55                    oldmax[i] = data.vars[1];
 56                }
 57            }
 58            
 59            CreateFitOp(ops,
 60                        oldmin, oldmax,
 61                        newmin, newmax,
 62                        dir);
 63        }
 64        else if(data.allocation == ALLOCATION_LG2)
 65        {
 66            float oldmin[4] = { -10.0f, -10.0f, -10.0f, 0.0f };
 67            float oldmax[4] = { 6.0f, 6.0f, 6.0f, 1.0f };
 68            float newmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
 69            float newmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
 70            
 71            if(data.vars.size() >= 2)
 72            {
 73                for(int i=0; i<3; ++i)
 74                {
 75                    oldmin[i] = data.vars[0];
 76                    oldmax[i] = data.vars[1];
 77                }
 78            }
 79            
 80            
 81            // Log Settings
 82            // output = k * log(mx+b, base) + kb
 83            
 84            float k[3] = { 1.0f, 1.0f, 1.0f };
 85            float m[3] = { 1.0f, 1.0f, 1.0f };
 86            float b[3] = { 0.0f, 0.0f, 0.0f };
 87            float base[3] = { 2.0f, 2.0f, 2.0f };
 88            float kb[3] = { 0.0f, 0.0f, 0.0f };
 89            
 90            if(data.vars.size() >= 3)
 91            {
 92                for(int i=0; i<3; ++i)
 93                {
 94                    b[i] = data.vars[2];
 95                }
 96            }
 97            
 98            if(dir == TRANSFORM_DIR_FORWARD)
 99            {
100                CreateLogOp(ops, k, m, b, base, kb, dir);
101                
102                CreateFitOp(ops,
103                            oldmin, oldmax,
104                            newmin, newmax,
105                            dir);
106            }
107            else if(dir == TRANSFORM_DIR_INVERSE)
108            {
109                CreateFitOp(ops,
110                            oldmin, oldmax,
111                            newmin, newmax,
112                            dir);
113                
114                CreateLogOp(ops, k, m, b, base, kb, dir);
115            }
116            else
117            {
118                throw Exception("Cannot BuildAllocationOps, unspecified transform direction.");
119            }
120        }
121        else
122        {
123            throw Exception("Unsupported Allocation Type.");
124        }
125    }
126    
127}
128OCIO_NAMESPACE_EXIT