PageRenderTime 32ms CodeModel.GetById 17ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/core/Op.h

http://github.com/imageworks/OpenColorIO
C Header | 136 lines | 52 code | 34 blank | 50 comment | 0 complexity | 4f2e8435cc86e6def7fa04f76bc8bfc9 MD5 | raw file
Possible License(s): BSD-3-Clause
  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_OP_H
 31#define INCLUDED_OCIO_OP_H
 32
 33#include <OpenColorIO/OpenColorIO.h>
 34
 35#include <sstream>
 36#include <vector>
 37
 38OCIO_NAMESPACE_ENTER
 39{
 40    struct AllocationData
 41    {
 42        Allocation allocation;
 43        std::vector<float> vars;
 44        
 45        AllocationData():
 46            allocation(ALLOCATION_UNIFORM)
 47            {};
 48        
 49        std::string getCacheID() const;
 50    };
 51    
 52    std::ostream& operator<< (std::ostream&, const AllocationData&);
 53    
 54    class Op;
 55    typedef OCIO_SHARED_PTR<Op> OpRcPtr;
 56    typedef std::vector<OpRcPtr> OpRcPtrVec;
 57    
 58    std::string SerializeOpVec(const OpRcPtrVec & ops, int indent=0);
 59    bool IsOpVecNoOp(const OpRcPtrVec & ops);
 60    
 61    void FinalizeOpVec(OpRcPtrVec & opVec, bool optimize=true);
 62    
 63    void OptimizeOpVec(OpRcPtrVec & result);
 64    
 65    class Op
 66    {
 67        public:
 68            virtual ~Op();
 69            
 70            virtual OpRcPtr clone() const = 0;
 71            
 72            //! Something short, and printable.
 73            //  The type of stuff you'd want to see in debugging.
 74            virtual std::string getInfo() const = 0;
 75            
 76            //! This should yield a string of not unreasonable length.
 77            //! It can only be called after finalize()
 78            virtual std::string getCacheID() const = 0;
 79            
 80            //! Is the processing a noop? I.e, does apply do nothing.
 81            //! (Even no-ops may define Allocation though.)
 82            //! This must be implmented in a manner where its valid to call
 83            //! *prior* to finalize. (Optimizers may make use of it)
 84            virtual bool isNoOp() const = 0;
 85            
 86            virtual bool isSameType(const OpRcPtr & op) const = 0;
 87            
 88            virtual bool isInverse(const OpRcPtr & op) const = 0;
 89            
 90            virtual bool canCombineWith(const OpRcPtr & op) const;
 91            
 92            // Return a vector of result ops, which correspond to
 93            // THIS combinedWith secondOp.
 94            //
 95            // If the result is a noOp, it is valid for the resulting opsVec
 96            // to be empty.
 97            
 98            virtual void combineWith(OpRcPtrVec & ops, const OpRcPtr & secondOp) const;
 99            
100            virtual bool hasChannelCrosstalk() const = 0;
101            
102            virtual void dumpMetadata(ProcessorMetadataRcPtr & /*metadata*/) const
103            { }
104            
105            // This is called a single time after construction.
106            // Final pre-processing and safety checks should happen here,
107            // rather than in the constructor.
108            
109            virtual void finalize() = 0;
110            
111            // Render the specified pixels.
112            //
113            // This must be safe to call in a multi-threaded context.
114            // Ops that have mutable data internally, or rely on external
115            // caching, must thus be appropriately mutexed.
116            
117            virtual void apply(float* rgbaBuffer, long numPixels) const = 0;
118            
119            
120            //! Does this op support gpu shader text generation
121            virtual bool supportsGpuShader() const = 0;
122            
123            // TODO: If temp variables are ever needed, also pass tempvar prefix.
124            virtual void writeGpuShader(std::ostream & shader,
125                                        const std::string & pixelName,
126                                        const GpuShaderDesc & shaderDesc) const = 0;
127            
128        private:
129            Op& operator= (const Op &);
130    };
131    
132    std::ostream& operator<< (std::ostream&, const Op&);
133}
134OCIO_NAMESPACE_EXIT
135
136#endif