/src/core/AllocationOp.cpp

http://github.com/imageworks/OpenColorIO · C++ · 128 lines · 84 code · 15 blank · 29 comment · 16 complexity · 80fc5543c02a03b9b2342c748a9365ff 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 "AllocationOp.h"
  28. #include "LogOps.h"
  29. #include "MatrixOps.h"
  30. #include "Op.h"
  31. #include <OpenColorIO/OpenColorIO.h>
  32. OCIO_NAMESPACE_ENTER
  33. {
  34. void CreateAllocationOps(OpRcPtrVec & ops,
  35. const AllocationData & data,
  36. TransformDirection dir)
  37. {
  38. if(data.allocation == ALLOCATION_UNIFORM)
  39. {
  40. float oldmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  41. float oldmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  42. float newmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  43. float newmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  44. if(data.vars.size() >= 2)
  45. {
  46. for(int i=0; i<3; ++i)
  47. {
  48. oldmin[i] = data.vars[0];
  49. oldmax[i] = data.vars[1];
  50. }
  51. }
  52. CreateFitOp(ops,
  53. oldmin, oldmax,
  54. newmin, newmax,
  55. dir);
  56. }
  57. else if(data.allocation == ALLOCATION_LG2)
  58. {
  59. float oldmin[4] = { -10.0f, -10.0f, -10.0f, 0.0f };
  60. float oldmax[4] = { 6.0f, 6.0f, 6.0f, 1.0f };
  61. float newmin[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  62. float newmax[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  63. if(data.vars.size() >= 2)
  64. {
  65. for(int i=0; i<3; ++i)
  66. {
  67. oldmin[i] = data.vars[0];
  68. oldmax[i] = data.vars[1];
  69. }
  70. }
  71. // Log Settings
  72. // output = k * log(mx+b, base) + kb
  73. float k[3] = { 1.0f, 1.0f, 1.0f };
  74. float m[3] = { 1.0f, 1.0f, 1.0f };
  75. float b[3] = { 0.0f, 0.0f, 0.0f };
  76. float base[3] = { 2.0f, 2.0f, 2.0f };
  77. float kb[3] = { 0.0f, 0.0f, 0.0f };
  78. if(data.vars.size() >= 3)
  79. {
  80. for(int i=0; i<3; ++i)
  81. {
  82. b[i] = data.vars[2];
  83. }
  84. }
  85. if(dir == TRANSFORM_DIR_FORWARD)
  86. {
  87. CreateLogOp(ops, k, m, b, base, kb, dir);
  88. CreateFitOp(ops,
  89. oldmin, oldmax,
  90. newmin, newmax,
  91. dir);
  92. }
  93. else if(dir == TRANSFORM_DIR_INVERSE)
  94. {
  95. CreateFitOp(ops,
  96. oldmin, oldmax,
  97. newmin, newmax,
  98. dir);
  99. CreateLogOp(ops, k, m, b, base, kb, dir);
  100. }
  101. else
  102. {
  103. throw Exception("Cannot BuildAllocationOps, unspecified transform direction.");
  104. }
  105. }
  106. else
  107. {
  108. throw Exception("Unsupported Allocation Type.");
  109. }
  110. }
  111. }
  112. OCIO_NAMESPACE_EXIT