/src/core/Op.h

http://github.com/imageworks/OpenColorIO · C Header · 136 lines · 52 code · 34 blank · 50 comment · 0 complexity · 4f2e8435cc86e6def7fa04f76bc8bfc9 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_OP_H
  28. #define INCLUDED_OCIO_OP_H
  29. #include <OpenColorIO/OpenColorIO.h>
  30. #include <sstream>
  31. #include <vector>
  32. OCIO_NAMESPACE_ENTER
  33. {
  34. struct AllocationData
  35. {
  36. Allocation allocation;
  37. std::vector<float> vars;
  38. AllocationData():
  39. allocation(ALLOCATION_UNIFORM)
  40. {};
  41. std::string getCacheID() const;
  42. };
  43. std::ostream& operator<< (std::ostream&, const AllocationData&);
  44. class Op;
  45. typedef OCIO_SHARED_PTR<Op> OpRcPtr;
  46. typedef std::vector<OpRcPtr> OpRcPtrVec;
  47. std::string SerializeOpVec(const OpRcPtrVec & ops, int indent=0);
  48. bool IsOpVecNoOp(const OpRcPtrVec & ops);
  49. void FinalizeOpVec(OpRcPtrVec & opVec, bool optimize=true);
  50. void OptimizeOpVec(OpRcPtrVec & result);
  51. class Op
  52. {
  53. public:
  54. virtual ~Op();
  55. virtual OpRcPtr clone() const = 0;
  56. //! Something short, and printable.
  57. // The type of stuff you'd want to see in debugging.
  58. virtual std::string getInfo() const = 0;
  59. //! This should yield a string of not unreasonable length.
  60. //! It can only be called after finalize()
  61. virtual std::string getCacheID() const = 0;
  62. //! Is the processing a noop? I.e, does apply do nothing.
  63. //! (Even no-ops may define Allocation though.)
  64. //! This must be implmented in a manner where its valid to call
  65. //! *prior* to finalize. (Optimizers may make use of it)
  66. virtual bool isNoOp() const = 0;
  67. virtual bool isSameType(const OpRcPtr & op) const = 0;
  68. virtual bool isInverse(const OpRcPtr & op) const = 0;
  69. virtual bool canCombineWith(const OpRcPtr & op) const;
  70. // Return a vector of result ops, which correspond to
  71. // THIS combinedWith secondOp.
  72. //
  73. // If the result is a noOp, it is valid for the resulting opsVec
  74. // to be empty.
  75. virtual void combineWith(OpRcPtrVec & ops, const OpRcPtr & secondOp) const;
  76. virtual bool hasChannelCrosstalk() const = 0;
  77. virtual void dumpMetadata(ProcessorMetadataRcPtr & /*metadata*/) const
  78. { }
  79. // This is called a single time after construction.
  80. // Final pre-processing and safety checks should happen here,
  81. // rather than in the constructor.
  82. virtual void finalize() = 0;
  83. // Render the specified pixels.
  84. //
  85. // This must be safe to call in a multi-threaded context.
  86. // Ops that have mutable data internally, or rely on external
  87. // caching, must thus be appropriately mutexed.
  88. virtual void apply(float* rgbaBuffer, long numPixels) const = 0;
  89. //! Does this op support gpu shader text generation
  90. virtual bool supportsGpuShader() const = 0;
  91. // TODO: If temp variables are ever needed, also pass tempvar prefix.
  92. virtual void writeGpuShader(std::ostream & shader,
  93. const std::string & pixelName,
  94. const GpuShaderDesc & shaderDesc) const = 0;
  95. private:
  96. Op& operator= (const Op &);
  97. };
  98. std::ostream& operator<< (std::ostream&, const Op&);
  99. }
  100. OCIO_NAMESPACE_EXIT
  101. #endif