PageRenderTime 46ms CodeModel.GetById 29ms app.highlight 11ms RepoModel.GetById 4ms app.codeStats 0ms

/src/core/FileTransform.h

http://github.com/imageworks/OpenColorIO
C++ Header | 156 lines | 92 code | 30 blank | 34 comment | 0 complexity | 18e85738e11bfcde344fd94e681bafcb 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_FILETRANSFORM_H
 31#define INCLUDED_OCIO_FILETRANSFORM_H
 32
 33#include <map>
 34
 35#include <OpenColorIO/OpenColorIO.h>
 36
 37#include "Op.h"
 38#include "Processor.h"
 39
 40OCIO_NAMESPACE_ENTER
 41{
 42    void ClearFileTransformCaches();
 43    
 44    class CachedFile
 45    {
 46    public:
 47        CachedFile() {};
 48        virtual ~CachedFile() {};
 49    };
 50    
 51    typedef OCIO_SHARED_PTR<CachedFile> CachedFileRcPtr;
 52    
 53    const int FORMAT_CAPABILITY_NONE = 0;
 54    const int FORMAT_CAPABILITY_READ = 1;
 55    const int FORMAT_CAPABILITY_WRITE = 2;
 56    const int FORMAT_CAPABILITY_ALL = (FORMAT_CAPABILITY_READ | FORMAT_CAPABILITY_WRITE);
 57    
 58    struct FormatInfo
 59    {
 60        std::string name;       // name must be globally unique
 61        std::string extension;  // extension does not need to be unique
 62        int capabilities;
 63        
 64        FormatInfo():
 65            capabilities(FORMAT_CAPABILITY_NONE)
 66        { }
 67    };
 68    
 69    typedef std::vector<FormatInfo> FormatInfoVec;
 70    
 71    class FileFormat
 72    {
 73    public:
 74        virtual ~FileFormat();
 75        
 76        virtual void GetFormatInfo(FormatInfoVec & formatInfoVec) const = 0;
 77        
 78        virtual CachedFileRcPtr Read(std::istream & istream) const = 0;
 79        
 80        virtual void Write(const Baker & baker,
 81                           const std::string & formatName,
 82                           std::ostream & ostream) const;
 83        
 84        virtual void BuildFileOps(OpRcPtrVec & ops,
 85                                  const Config & config,
 86                                  const ConstContextRcPtr & context,
 87                                  CachedFileRcPtr cachedFile,
 88                                  const FileTransform & fileTransform,
 89                                  TransformDirection dir) const = 0;
 90        
 91        // For logging purposes
 92        std::string getName() const;
 93    private:
 94        FileFormat& operator= (const FileFormat &);
 95    };
 96    
 97    typedef std::map<std::string, FileFormat*> FileFormatMap;
 98    typedef std::vector<FileFormat*> FileFormatVector;
 99    
100    // TODO: This interface is ugly. What private API is actually appropriate?
101    // Maybe, instead of exposing the raw formats, we wrap it?
102    // FileCachePair GetFile(const std::string & filepath) and all
103    // lookups will move internal
104    
105    class FormatRegistry
106    {
107    public:
108        static FormatRegistry & GetInstance();
109        
110        // TODO: Make these return a vector of possible formats
111        FileFormat* getFileFormatByName(const std::string & name) const;
112        FileFormat* getFileFormatForExtension(const std::string & extension) const;
113        
114        int getNumRawFormats() const;
115        FileFormat* getRawFormatByIndex(int index) const;
116        
117        int getNumFormats(int capability) const;
118        const char * getFormatNameByIndex(int capability, int index) const;
119        const char * getFormatExtensionByIndex(int capability, int index) const;
120    private:
121        FormatRegistry();
122        ~FormatRegistry();
123        
124        void registerFileFormat(FileFormat* format);
125        
126        FileFormatMap m_formatsByName;
127        FileFormatMap m_formatsByExtension;
128        FileFormatVector m_rawFormats;
129        
130        typedef std::vector<std::string> StringVec;
131        StringVec m_readFormatNames;
132        StringVec m_readFormatExtensions;
133        StringVec m_writeFormatNames;
134        StringVec m_writeFormatExtensions;
135    };
136    
137    // Registry Builders
138    FileFormat * CreateFileFormat3DL();
139    FileFormat * CreateFileFormatCCC();
140    FileFormat * CreateFileFormatCC();
141    FileFormat * CreateFileFormatCSP();
142    FileFormat * CreateFileFormatHDL();
143    FileFormat * CreateFileFormatIridasItx();
144    FileFormat * CreateFileFormatIridasCube();
145    FileFormat * CreateFileFormatIridasLook();
146    FileFormat * CreateFileFormatPandora();
147    FileFormat * CreateFileFormatSpi1D();
148    FileFormat * CreateFileFormatSpi3D();
149    FileFormat * CreateFileFormatSpiMtx();
150    FileFormat * CreateFileFormatTruelight();
151    FileFormat * CreateFileFormatVF();
152    
153}
154OCIO_NAMESPACE_EXIT
155
156#endif