/src/core/Processor.h

http://github.com/imageworks/OpenColorIO · C Header · 132 lines · 57 code · 29 blank · 46 comment · 0 complexity · ff6cc3d7cafcb0f619ad1f8bb76d54a1 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_PROCESSOR_H
  28. #define INCLUDED_OCIO_PROCESSOR_H
  29. #include <sstream>
  30. #include <OpenColorIO/OpenColorIO.h>
  31. #include "Mutex.h"
  32. #include "Op.h"
  33. #include "PrivateTypes.h"
  34. OCIO_NAMESPACE_ENTER
  35. {
  36. class Processor::Impl
  37. {
  38. private:
  39. ProcessorMetadataRcPtr m_metadata;
  40. OpRcPtrVec m_cpuOps;
  41. // These 3 op vecs represent the 3 stages in our gpu pipe.
  42. // 1) preprocess shader text
  43. // 2) 3d lut process lookup
  44. // 3) postprocess shader text
  45. OpRcPtrVec m_gpuOpsHwPreProcess;
  46. OpRcPtrVec m_gpuOpsCpuLatticeProcess;
  47. OpRcPtrVec m_gpuOpsHwPostProcess;
  48. mutable std::string m_cpuCacheID;
  49. // Cache the last last queried value,
  50. // for the specified shader description
  51. mutable std::string m_lastShaderDesc;
  52. mutable std::string m_shader;
  53. mutable std::string m_shaderCacheID;
  54. mutable std::vector<float> m_lut3D;
  55. mutable std::string m_lut3DCacheID;
  56. mutable Mutex m_resultsCacheMutex;
  57. public:
  58. Impl();
  59. ~Impl();
  60. bool isNoOp() const;
  61. bool hasChannelCrosstalk() const;
  62. ConstProcessorMetadataRcPtr getMetadata() const;
  63. void apply(ImageDesc& img) const;
  64. void applyRGB(float * pixel) const;
  65. void applyRGBA(float * pixel) const;
  66. const char * getCpuCacheID() const;
  67. const char * getGpuShaderText(const GpuShaderDesc & gpuDesc) const;
  68. const char * getGpuShaderTextCacheID(const GpuShaderDesc & shaderDesc) const;
  69. void getGpuLut3D(float* lut3d, const GpuShaderDesc & shaderDesc) const;
  70. const char * getGpuLut3DCacheID(const GpuShaderDesc & shaderDesc) const;
  71. ////////////////////////////////////////////
  72. //
  73. // Builder functions, Not exposed
  74. void addColorSpaceConversion(const Config & config,
  75. const ConstContextRcPtr & context,
  76. const ConstColorSpaceRcPtr & srcColorSpace,
  77. const ConstColorSpaceRcPtr & dstColorSpace);
  78. void addTransform(const Config & config,
  79. const ConstContextRcPtr & context,
  80. const ConstTransformRcPtr& transform,
  81. TransformDirection direction);
  82. void finalize();
  83. void calcGpuShaderText(std::ostream & shader,
  84. const GpuShaderDesc & shaderDesc) const;
  85. };
  86. // TODO: Move these!
  87. // TODO: Its not ideal that buildops requires a config to be passed around
  88. // but the only alternative is to make build ops a function on it?
  89. // and even if it were, what about the build calls it dispatches to...
  90. // TODO: all of the build op functions shouldnt take a LocalProcessor class
  91. // Instead, they should take an abstract interface class that defines
  92. // registerOp(OpRcPtr op), annotateColorSpace, finalizeOps, etc.
  93. // of which LocalProcessor happens to be one example.
  94. // Then the only location in the codebase that knows of LocalProcessor is
  95. // in Config.cpp, which creates one.
  96. void BuildOps(OpRcPtrVec & ops,
  97. const Config & config,
  98. const ConstTransformRcPtr & transform,
  99. TransformDirection dir);
  100. }
  101. OCIO_NAMESPACE_EXIT
  102. #endif