/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. /*
  2. Copyright (c) 2003-2010 Sony Pictures Imageworks Inc., et al.
  3. All Rights Reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. * Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. * Neither the name of Sony Pictures Imageworks nor the names of its
  13. contributors may be used to endorse or promote products derived from
  14. this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef INCLUDED_OCIO_FILETRANSFORM_H
  28. #define INCLUDED_OCIO_FILETRANSFORM_H
  29. #include <map>
  30. #include <OpenColorIO/OpenColorIO.h>
  31. #include "Op.h"
  32. #include "Processor.h"
  33. OCIO_NAMESPACE_ENTER
  34. {
  35. void ClearFileTransformCaches();
  36. class CachedFile
  37. {
  38. public:
  39. CachedFile() {};
  40. virtual ~CachedFile() {};
  41. };
  42. typedef OCIO_SHARED_PTR<CachedFile> CachedFileRcPtr;
  43. const int FORMAT_CAPABILITY_NONE = 0;
  44. const int FORMAT_CAPABILITY_READ = 1;
  45. const int FORMAT_CAPABILITY_WRITE = 2;
  46. const int FORMAT_CAPABILITY_ALL = (FORMAT_CAPABILITY_READ | FORMAT_CAPABILITY_WRITE);
  47. struct FormatInfo
  48. {
  49. std::string name; // name must be globally unique
  50. std::string extension; // extension does not need to be unique
  51. int capabilities;
  52. FormatInfo():
  53. capabilities(FORMAT_CAPABILITY_NONE)
  54. { }
  55. };
  56. typedef std::vector<FormatInfo> FormatInfoVec;
  57. class FileFormat
  58. {
  59. public:
  60. virtual ~FileFormat();
  61. virtual void GetFormatInfo(FormatInfoVec & formatInfoVec) const = 0;
  62. virtual CachedFileRcPtr Read(std::istream & istream) const = 0;
  63. virtual void Write(const Baker & baker,
  64. const std::string & formatName,
  65. std::ostream & ostream) const;
  66. virtual void BuildFileOps(OpRcPtrVec & ops,
  67. const Config & config,
  68. const ConstContextRcPtr & context,
  69. CachedFileRcPtr cachedFile,
  70. const FileTransform & fileTransform,
  71. TransformDirection dir) const = 0;
  72. // For logging purposes
  73. std::string getName() const;
  74. private:
  75. FileFormat& operator= (const FileFormat &);
  76. };
  77. typedef std::map<std::string, FileFormat*> FileFormatMap;
  78. typedef std::vector<FileFormat*> FileFormatVector;
  79. // TODO: This interface is ugly. What private API is actually appropriate?
  80. // Maybe, instead of exposing the raw formats, we wrap it?
  81. // FileCachePair GetFile(const std::string & filepath) and all
  82. // lookups will move internal
  83. class FormatRegistry
  84. {
  85. public:
  86. static FormatRegistry & GetInstance();
  87. // TODO: Make these return a vector of possible formats
  88. FileFormat* getFileFormatByName(const std::string & name) const;
  89. FileFormat* getFileFormatForExtension(const std::string & extension) const;
  90. int getNumRawFormats() const;
  91. FileFormat* getRawFormatByIndex(int index) const;
  92. int getNumFormats(int capability) const;
  93. const char * getFormatNameByIndex(int capability, int index) const;
  94. const char * getFormatExtensionByIndex(int capability, int index) const;
  95. private:
  96. FormatRegistry();
  97. ~FormatRegistry();
  98. void registerFileFormat(FileFormat* format);
  99. FileFormatMap m_formatsByName;
  100. FileFormatMap m_formatsByExtension;
  101. FileFormatVector m_rawFormats;
  102. typedef std::vector<std::string> StringVec;
  103. StringVec m_readFormatNames;
  104. StringVec m_readFormatExtensions;
  105. StringVec m_writeFormatNames;
  106. StringVec m_writeFormatExtensions;
  107. };
  108. // Registry Builders
  109. FileFormat * CreateFileFormat3DL();
  110. FileFormat * CreateFileFormatCCC();
  111. FileFormat * CreateFileFormatCC();
  112. FileFormat * CreateFileFormatCSP();
  113. FileFormat * CreateFileFormatHDL();
  114. FileFormat * CreateFileFormatIridasItx();
  115. FileFormat * CreateFileFormatIridasCube();
  116. FileFormat * CreateFileFormatIridasLook();
  117. FileFormat * CreateFileFormatPandora();
  118. FileFormat * CreateFileFormatSpi1D();
  119. FileFormat * CreateFileFormatSpi3D();
  120. FileFormat * CreateFileFormatSpiMtx();
  121. FileFormat * CreateFileFormatTruelight();
  122. FileFormat * CreateFileFormatVF();
  123. }
  124. OCIO_NAMESPACE_EXIT
  125. #endif