/src/core/ExponentTransform.cpp

http://github.com/imageworks/OpenColorIO · C++ · 151 lines · 94 code · 28 blank · 29 comment · 3 complexity · d7a0c4ebad8ea16d7bcbb3020a9756e9 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 <cstring>
  28. #include <OpenColorIO/OpenColorIO.h>
  29. #include "ExponentOps.h"
  30. #include "OpBuilders.h"
  31. OCIO_NAMESPACE_ENTER
  32. {
  33. ExponentTransformRcPtr ExponentTransform::Create()
  34. {
  35. return ExponentTransformRcPtr(new ExponentTransform(), &deleter);
  36. }
  37. void ExponentTransform::deleter(ExponentTransform* t)
  38. {
  39. delete t;
  40. }
  41. class ExponentTransform::Impl
  42. {
  43. public:
  44. TransformDirection dir_;
  45. float value_[4];
  46. Impl() :
  47. dir_(TRANSFORM_DIR_FORWARD)
  48. {
  49. for(int i=0; i<4; ++i)
  50. {
  51. value_[i] = 1.0f;
  52. }
  53. }
  54. ~Impl()
  55. { }
  56. Impl& operator= (const Impl & rhs)
  57. {
  58. dir_ = rhs.dir_;
  59. memcpy(value_, rhs.value_, 4*sizeof(float));
  60. return *this;
  61. }
  62. };
  63. ///////////////////////////////////////////////////////////////////////////
  64. ExponentTransform::ExponentTransform()
  65. : m_impl(new ExponentTransform::Impl)
  66. {
  67. }
  68. TransformRcPtr ExponentTransform::createEditableCopy() const
  69. {
  70. ExponentTransformRcPtr transform = ExponentTransform::Create();
  71. *(transform->m_impl) = *m_impl;
  72. return transform;
  73. }
  74. ExponentTransform::~ExponentTransform()
  75. {
  76. delete m_impl;
  77. m_impl = NULL;
  78. }
  79. ExponentTransform& ExponentTransform::operator= (const ExponentTransform & rhs)
  80. {
  81. *m_impl = *rhs.m_impl;
  82. return *this;
  83. }
  84. TransformDirection ExponentTransform::getDirection() const
  85. {
  86. return getImpl()->dir_;
  87. }
  88. void ExponentTransform::setDirection(TransformDirection dir)
  89. {
  90. getImpl()->dir_ = dir;
  91. }
  92. void ExponentTransform::setValue(const float * vec4)
  93. {
  94. if(vec4) memcpy(getImpl()->value_, vec4, 4*sizeof(float));
  95. }
  96. void ExponentTransform::getValue(float * vec4) const
  97. {
  98. if(vec4) memcpy(vec4, getImpl()->value_, 4*sizeof(float));
  99. }
  100. std::ostream& operator<< (std::ostream& os, const ExponentTransform& t)
  101. {
  102. os << "<ExponentTransform ";
  103. os << "direction=" << TransformDirectionToString(t.getDirection()) << ", ";
  104. os << ">\n";
  105. return os;
  106. }
  107. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  108. void BuildExponentOps(OpRcPtrVec & ops,
  109. const Config& /*config*/,
  110. const ExponentTransform & transform,
  111. TransformDirection dir)
  112. {
  113. TransformDirection combinedDir = CombineTransformDirections(dir,
  114. transform.getDirection());
  115. float vec4[4];
  116. transform.getValue(vec4);
  117. CreateExponentOp(ops,
  118. vec4,
  119. combinedDir);
  120. }
  121. }
  122. OCIO_NAMESPACE_EXIT