/src/core/Lut3DOp.h

http://github.com/imageworks/OpenColorIO · C Header · 114 lines · 49 code · 25 blank · 40 comment · 0 complexity · f83975f30ef4d78960b7ebdea8e3641e 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_LUT3DOP_H
  28. #define INCLUDED_OCIO_LUT3DOP_H
  29. #include <OpenColorIO/OpenColorIO.h>
  30. #include "Mutex.h"
  31. #include "Op.h"
  32. #include <vector>
  33. OCIO_NAMESPACE_ENTER
  34. {
  35. // TODO: turn into a class instead of a struct?
  36. struct Lut3D;
  37. typedef OCIO_SHARED_PTR<Lut3D> Lut3DRcPtr;
  38. struct Lut3D
  39. {
  40. static Lut3DRcPtr Create();
  41. float from_min[3];
  42. float from_max[3];
  43. int size[3];
  44. typedef std::vector<float> fv_t;
  45. fv_t lut;
  46. std::string getCacheID() const;
  47. private:
  48. Lut3D();
  49. mutable std::string m_cacheID;
  50. mutable Mutex m_cacheidMutex;
  51. };
  52. // RGB channel ordering.
  53. // Pixels ordered in such a way that the blue coordinate changes fastest,
  54. // then the green coordinate, and finally, the red coordinate changes slowest
  55. inline int GetLut3DIndex_B(int indexR, int indexG, int indexB,
  56. int sizeR, int sizeG, int /*sizeB*/)
  57. {
  58. return 3 * (indexR + sizeR * (indexG + sizeG * indexB));
  59. }
  60. // RGB channel ordering.
  61. // Pixels ordered in such a way that the red coordinate changes fastest,
  62. // then the green coordinate, and finally, the blue coordinate changes slowest
  63. inline int GetLut3DIndex_R(int indexR, int indexG, int indexB,
  64. int /*sizeR*/, int sizeG, int sizeB)
  65. {
  66. return 3 * (indexB + sizeB * (indexG + sizeG * indexR));
  67. }
  68. // What is the preferred order for the lut3d?
  69. // I.e., are the first two entries change along
  70. // the blue direction, or the red direction?
  71. // OpenGL expects 'red'
  72. enum Lut3DOrder
  73. {
  74. LUT3DORDER_FAST_RED = 0,
  75. LUT3DORDER_FAST_BLUE
  76. };
  77. void GenerateIdentityLut3D(float* img, int edgeLen, int numChannels,
  78. Lut3DOrder lut3DOrder);
  79. // Essentially the cube root, but will throw an exception if the
  80. // cuberoot is not exact.
  81. int Get3DLutEdgeLenFromNumPixels(int numPixels);
  82. void CreateLut3DOp(OpRcPtrVec & ops,
  83. Lut3DRcPtr lut,
  84. Interpolation interpolation,
  85. TransformDirection direction);
  86. }
  87. OCIO_NAMESPACE_EXIT
  88. #endif