1 /* 2 Copyright (c) 2003-2012 Sony Pictures Imageworks Inc., et al. 3 All Rights Reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are 7 met: 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. 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 30 #ifndef _OPENCOLORIO_AE_CONTEXT_H_ 31 #define _OPENCOLORIO_AE_CONTEXT_H_ 32 33 #include <string> 34 #include <vector> 35 36 #include "OpenColorIO_AE.h" 37 #include "OpenColorIO_AE_GL.h" 38 39 #include <OpenColorIO/OpenColorIO.h> 40 namespace OCIO = OCIO_NAMESPACE; 41 42 43 44 // yeah, this probably could/should go in a seperate file 45 class Path 46 { 47 public: 48 Path(const std::string &path, const std::string &dir); 49 Path(const Path &path); ~Path()50 ~Path() {} 51 52 std::string full_path() const; 53 std::string relative_path(bool force) const; 54 55 bool exists() const; 56 57 private: 58 std::string _path; 59 std::string _dir; 60 61 typedef enum { 62 TYPE_UNKNOWN = 0, 63 TYPE_MAC, 64 TYPE_WIN 65 } PathType; 66 67 static PathType path_type(const std::string &path); 68 static bool is_relative(const std::string &path); 69 static std::string convert_delimiters(const std::string &path); 70 static std::vector<std::string> components(const std::string &path); 71 }; 72 73 74 class OpenColorIO_AE_Context 75 { 76 public: 77 OpenColorIO_AE_Context(const std::string &path, OCIO_Source source); 78 OpenColorIO_AE_Context(const ArbitraryData *arb_data, const std::string &dir); 79 ~OpenColorIO_AE_Context(); 80 81 bool Verify(const ArbitraryData *arb_data, const std::string &dir); 82 83 void setupConvert(const char *input, const char *output); 84 void setupDisplay(const char *input, const char *device, const char *transform); 85 void setupLUT(bool invert, OCIO_Interp interpolation); 86 87 typedef std::vector<std::string> SpaceVec; 88 getAction()89 OCIO_Action getAction() const { return _action; } getInput()90 const std::string & getInput() const { return _input; } getOutput()91 const std::string & getOutput() const { return _output; } getDevice()92 const std::string & getDevice() const { return _device; } getTransform()93 const std::string & getTransform() const { return _transform; } 94 const SpaceVec & getInputs(bool fullPath=false) const { return fullPath ? _inputsFullPath : _inputs; } getDevices()95 const SpaceVec & getDevices() const { return _devices; } getTransforms()96 const SpaceVec & getTransforms() const { return _transforms; } 97 config()98 OCIO::ConstConfigRcPtr config() const { return _config; } processor()99 OCIO::ConstProcessorRcPtr processor() const { return _processor; } 100 101 bool ExportLUT(const std::string &path, const std::string &display_icc_path); 102 103 bool ProcessWorldGL(PF_EffectWorld *float_world); 104 105 private: 106 std::string _path; 107 OCIO_Source _source; 108 std::string _config_name; 109 110 OCIO_Action _action; 111 112 std::string _input; 113 std::string _output; 114 std::string _device; 115 std::string _transform; 116 SpaceVec _inputs; 117 SpaceVec _inputsFullPath; 118 SpaceVec _devices; 119 SpaceVec _transforms; 120 121 bool _invert; 122 OCIO_Interp _interpolation; 123 124 125 OCIO::ConstConfigRcPtr _config; 126 OCIO::ConstProcessorRcPtr _processor; 127 128 129 bool _gl_init; 130 131 GLuint _fragShader; 132 GLuint _program; 133 134 GLuint _imageTexID; 135 136 GLuint _lut3dTexID; 137 std::vector<float> _lut3d; 138 std::string _lut3dcacheid; 139 std::string _shadercacheid; 140 141 std::string _inputColorSpace; 142 std::string _display; 143 std::string _transformName; 144 145 146 GLuint _renderBuffer; 147 int _bufferWidth; 148 int _bufferHeight; 149 150 void InitOCIOGL(); 151 void UpdateOCIOGLState(); 152 }; 153 154 155 #endif // _OPENCOLORIO_AE_CONTEXT_H_