PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/Lut3DOp.h

http://github.com/imageworks/OpenColorIO
C++ Header | 114 lines | 49 code | 25 blank | 40 comment | 0 complexity | f83975f30ef4d78960b7ebdea8e3641e 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
 30#ifndef INCLUDED_OCIO_LUT3DOP_H
 31#define INCLUDED_OCIO_LUT3DOP_H
 32
 33#include <OpenColorIO/OpenColorIO.h>
 34
 35#include "Mutex.h"
 36#include "Op.h"
 37
 38#include <vector>
 39
 40OCIO_NAMESPACE_ENTER
 41{
 42    // TODO: turn into a class instead of a struct?
 43    
 44    struct Lut3D;
 45    typedef OCIO_SHARED_PTR<Lut3D> Lut3DRcPtr;
 46    
 47    struct Lut3D
 48    {
 49        static Lut3DRcPtr Create();
 50        
 51        float from_min[3];
 52        float from_max[3];
 53        int size[3];
 54        
 55        typedef std::vector<float> fv_t;
 56        fv_t lut;
 57        
 58        std::string getCacheID() const;
 59        
 60    private:
 61        Lut3D();
 62        mutable std::string m_cacheID;
 63        mutable Mutex m_cacheidMutex;
 64    };
 65    
 66    // RGB channel ordering.
 67    // Pixels ordered in such a way that the blue coordinate changes fastest,
 68    // then the green coordinate, and finally, the red coordinate changes slowest
 69    
 70    inline int GetLut3DIndex_B(int indexR, int indexG, int indexB,
 71                               int sizeR,  int sizeG,  int /*sizeB*/)
 72    {
 73        return 3 * (indexR + sizeR * (indexG + sizeG * indexB));
 74    }
 75    
 76    
 77    // RGB channel ordering.
 78    // Pixels ordered in such a way that the red coordinate changes fastest,
 79    // then the green coordinate, and finally, the blue coordinate changes slowest
 80    
 81    inline int GetLut3DIndex_R(int indexR, int indexG, int indexB,
 82                               int /*sizeR*/,  int sizeG,  int sizeB)
 83    {
 84        return 3 * (indexB + sizeB * (indexG + sizeG * indexR));
 85    }
 86    
 87    // What is the preferred order for the lut3d?
 88    // I.e., are the first two entries change along
 89    // the blue direction, or the red direction?
 90    // OpenGL expects 'red'
 91    
 92    enum Lut3DOrder
 93    {
 94        LUT3DORDER_FAST_RED = 0,
 95        LUT3DORDER_FAST_BLUE
 96    };
 97    
 98    void GenerateIdentityLut3D(float* img, int edgeLen, int numChannels,
 99                               Lut3DOrder lut3DOrder);
100    
101    // Essentially the cube root, but will throw an exception if the
102    // cuberoot is not exact.
103    int Get3DLutEdgeLenFromNumPixels(int numPixels);
104    
105    
106    
107    void CreateLut3DOp(OpRcPtrVec & ops,
108                       Lut3DRcPtr lut,
109                       Interpolation interpolation,
110                       TransformDirection direction);
111}
112OCIO_NAMESPACE_EXIT
113
114#endif