/src/core/LogTransform.cpp

http://github.com/imageworks/OpenColorIO · C++ · 157 lines · 97 code · 30 blank · 30 comment · 0 complexity · 418e5b504b2ed1693a4341435744ebf5 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 <sstream>
  29. #include <vector>
  30. #include <OpenColorIO/OpenColorIO.h>
  31. #include "LogOps.h"
  32. #include "OpBuilders.h"
  33. OCIO_NAMESPACE_ENTER
  34. {
  35. LogTransformRcPtr LogTransform::Create()
  36. {
  37. return LogTransformRcPtr(new LogTransform(), &deleter);
  38. }
  39. void LogTransform::deleter(LogTransform* t)
  40. {
  41. delete t;
  42. }
  43. class LogTransform::Impl
  44. {
  45. public:
  46. TransformDirection dir_;
  47. float base_;
  48. Impl() :
  49. dir_(TRANSFORM_DIR_FORWARD),
  50. base_(2.0)
  51. { }
  52. ~Impl()
  53. { }
  54. Impl& operator= (const Impl & rhs)
  55. {
  56. dir_ = rhs.dir_;
  57. base_ = rhs.base_;
  58. return *this;
  59. }
  60. };
  61. ///////////////////////////////////////////////////////////////////////////
  62. LogTransform::LogTransform()
  63. : m_impl(new LogTransform::Impl)
  64. {
  65. }
  66. TransformRcPtr LogTransform::createEditableCopy() const
  67. {
  68. LogTransformRcPtr transform = LogTransform::Create();
  69. *(transform->m_impl) = *m_impl;
  70. return transform;
  71. }
  72. LogTransform::~LogTransform()
  73. {
  74. delete m_impl;
  75. m_impl = NULL;
  76. }
  77. LogTransform& LogTransform::operator= (const LogTransform & rhs)
  78. {
  79. *m_impl = *rhs.m_impl;
  80. return *this;
  81. }
  82. TransformDirection LogTransform::getDirection() const
  83. {
  84. return getImpl()->dir_;
  85. }
  86. void LogTransform::setDirection(TransformDirection dir)
  87. {
  88. getImpl()->dir_ = dir;
  89. }
  90. float LogTransform::getBase() const
  91. {
  92. return getImpl()->base_;
  93. }
  94. void LogTransform::setBase(float val)
  95. {
  96. getImpl()->base_ = val;
  97. }
  98. std::ostream& operator<< (std::ostream& os, const LogTransform& t)
  99. {
  100. os << "<LogTransform ";
  101. os << "base=" << t.getBase() << ", ";
  102. os << "direction=" << TransformDirectionToString(t.getDirection()) << ", ";
  103. os << ">\n";
  104. return os;
  105. }
  106. ///////////////////////////////////////////////////////////////////////////
  107. void BuildLogOps(OpRcPtrVec & ops,
  108. const Config& /*config*/,
  109. const LogTransform& transform,
  110. TransformDirection dir)
  111. {
  112. TransformDirection combinedDir = CombineTransformDirections(dir,
  113. transform.getDirection());
  114. float basescalar = transform.getBase();
  115. float base[3] = { basescalar, basescalar, basescalar };
  116. float k[3] = { 1.0f, 1.0f, 1.0f };
  117. float m[3] = { 1.0f, 1.0f, 1.0f };
  118. float b[3] = { 0.0f, 0.0f, 0.0f };
  119. float kb[3] = { 0.0f, 0.0f, 0.0f };
  120. // output = k * log(mx+b, base) + kb
  121. CreateLogOp(ops,
  122. k, m, b, base, kb,
  123. combinedDir);
  124. }
  125. }
  126. OCIO_NAMESPACE_EXIT