/src/core/Lut1DOp.h

http://github.com/imageworks/OpenColorIO · C Header · 107 lines · 43 code · 21 blank · 43 comment · 0 complexity · ccde4dd2090df4e1b2d35334ad695973 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_LUT1DOP_H
  28. #define INCLUDED_OCIO_LUT1DOP_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. enum ErrorType
  37. {
  38. ERROR_ABSOLUTE = 1,
  39. ERROR_RELATIVE
  40. };
  41. struct Lut1D;
  42. typedef OCIO_SHARED_PTR<Lut1D> Lut1DRcPtr;
  43. struct Lut1D
  44. {
  45. static Lut1DRcPtr Create();
  46. // This will compute the cacheid, and also
  47. // determine if the lut is a no-op.
  48. // If this lut is being read in from float ASCII text
  49. // a value of 1e-5 is preferable.
  50. // If this lut is being read in from integer ASCII
  51. // representation, the value will depend on the LSB
  52. // at the specified integer precision.
  53. // Example: reading 10-bit ints? Use 2/1023.0
  54. // If you dont want to do the noop computation,
  55. // specify a 0.0 tolerance.
  56. //
  57. // TODO: Instead of having each user compute the error
  58. // individually, maybe they should specify the original file bitdepth?
  59. // (with appropriate precision tokens?)
  60. float maxerror;
  61. ErrorType errortype;
  62. float from_min[3];
  63. float from_max[3];
  64. typedef std::vector<float> fv_t;
  65. fv_t luts[3];
  66. std::string getCacheID() const;
  67. bool isNoOp() const;
  68. void unfinalize();
  69. private:
  70. Lut1D();
  71. mutable std::string m_cacheID;
  72. mutable bool m_isNoOp;
  73. mutable Mutex m_mutex;
  74. void finalize() const;
  75. };
  76. typedef OCIO_SHARED_PTR<Lut1D> Lut1DRcPtr;
  77. // This generates an identity 1d lut, from 0.0 to 1.0
  78. void GenerateIdentityLut1D(float* img, int numElements, int numChannels);
  79. void CreateLut1DOp(OpRcPtrVec & ops,
  80. const Lut1DRcPtr & lut,
  81. Interpolation interpolation,
  82. TransformDirection direction);
  83. }
  84. OCIO_NAMESPACE_EXIT
  85. #endif