/src/core/Transform.cpp

http://github.com/imageworks/OpenColorIO · C++ · 175 lines · 137 code · 10 blank · 28 comment · 39 complexity · 11b137541cc3bb53e498d74d1f3e120b 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. #include <OpenColorIO/OpenColorIO.h>
  28. #include "FileTransform.h"
  29. #include "OpBuilders.h"
  30. #include "Processor.h"
  31. #include <sstream>
  32. OCIO_NAMESPACE_ENTER
  33. {
  34. Transform::~Transform()
  35. { }
  36. void BuildOps(OpRcPtrVec & ops,
  37. const Config & config,
  38. const ConstContextRcPtr & context,
  39. const ConstTransformRcPtr & transform,
  40. TransformDirection dir)
  41. {
  42. // A null transform is valid, and corresponds to a no-op.
  43. if(!transform)
  44. return;
  45. if(ConstAllocationTransformRcPtr allocationTransform = \
  46. DynamicPtrCast<const AllocationTransform>(transform))
  47. {
  48. BuildAllocationOps(ops, config, *allocationTransform, dir);
  49. }
  50. else if(ConstCDLTransformRcPtr cdlTransform = \
  51. DynamicPtrCast<const CDLTransform>(transform))
  52. {
  53. BuildCDLOps(ops, config, *cdlTransform, dir);
  54. }
  55. else if(ConstColorSpaceTransformRcPtr colorSpaceTransform = \
  56. DynamicPtrCast<const ColorSpaceTransform>(transform))
  57. {
  58. BuildColorSpaceOps(ops, config, context, *colorSpaceTransform, dir);
  59. }
  60. else if(ConstDisplayTransformRcPtr displayTransform = \
  61. DynamicPtrCast<const DisplayTransform>(transform))
  62. {
  63. BuildDisplayOps(ops, config, context, *displayTransform, dir);
  64. }
  65. else if(ConstExponentTransformRcPtr exponentTransform = \
  66. DynamicPtrCast<const ExponentTransform>(transform))
  67. {
  68. BuildExponentOps(ops, config, *exponentTransform, dir);
  69. }
  70. else if(ConstFileTransformRcPtr fileTransform = \
  71. DynamicPtrCast<const FileTransform>(transform))
  72. {
  73. BuildFileOps(ops, config, context, *fileTransform, dir);
  74. }
  75. else if(ConstGroupTransformRcPtr groupTransform = \
  76. DynamicPtrCast<const GroupTransform>(transform))
  77. {
  78. BuildGroupOps(ops, config, context, *groupTransform, dir);
  79. }
  80. else if(ConstLogTransformRcPtr logTransform = \
  81. DynamicPtrCast<const LogTransform>(transform))
  82. {
  83. BuildLogOps(ops, config, *logTransform, dir);
  84. }
  85. else if(ConstLookTransformRcPtr lookTransform = \
  86. DynamicPtrCast<const LookTransform>(transform))
  87. {
  88. BuildLookOps(ops, config, context, *lookTransform, dir);
  89. }
  90. else if(ConstMatrixTransformRcPtr matrixTransform = \
  91. DynamicPtrCast<const MatrixTransform>(transform))
  92. {
  93. BuildMatrixOps(ops, config, *matrixTransform, dir);
  94. }
  95. else if(ConstTruelightTransformRcPtr truelightTransform = \
  96. DynamicPtrCast<const TruelightTransform>(transform))
  97. {
  98. BuildTruelightOps(ops, config, *truelightTransform, dir);
  99. }
  100. else
  101. {
  102. std::ostringstream os;
  103. os << "Unknown transform type for Op Creation.";
  104. throw Exception(os.str().c_str());
  105. }
  106. }
  107. std::ostream& operator<< (std::ostream & os, const Transform & transform)
  108. {
  109. const Transform* t = &transform;
  110. if(const AllocationTransform * allocationTransform = \
  111. dynamic_cast<const AllocationTransform*>(t))
  112. {
  113. os << *allocationTransform;
  114. }
  115. else if(const CDLTransform * cdlTransform = \
  116. dynamic_cast<const CDLTransform*>(t))
  117. {
  118. os << *cdlTransform;
  119. }
  120. else if(const ColorSpaceTransform * colorSpaceTransform = \
  121. dynamic_cast<const ColorSpaceTransform*>(t))
  122. {
  123. os << *colorSpaceTransform;
  124. }
  125. else if(const DisplayTransform * displayTransform = \
  126. dynamic_cast<const DisplayTransform*>(t))
  127. {
  128. os << *displayTransform;
  129. }
  130. else if(const ExponentTransform * exponentTransform = \
  131. dynamic_cast<const ExponentTransform*>(t))
  132. {
  133. os << *exponentTransform;
  134. }
  135. else if(const FileTransform * fileTransform = \
  136. dynamic_cast<const FileTransform*>(t))
  137. {
  138. os << *fileTransform;
  139. }
  140. else if(const GroupTransform * groupTransform = \
  141. dynamic_cast<const GroupTransform*>(t))
  142. {
  143. os << *groupTransform;
  144. }
  145. else if(const MatrixTransform * matrixTransform = \
  146. dynamic_cast<const MatrixTransform*>(t))
  147. {
  148. os << *matrixTransform;
  149. }
  150. else if(const TruelightTransform * truelightTransform = \
  151. dynamic_cast<const TruelightTransform*>(t))
  152. {
  153. os << *truelightTransform;
  154. }
  155. else
  156. {
  157. std::ostringstream error;
  158. os << "Unknown transform type for serialization.";
  159. throw Exception(error.str().c_str());
  160. }
  161. return os;
  162. }
  163. }
  164. OCIO_NAMESPACE_EXIT