ImfDeepImageChannel.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_DEEP_IMAGE_CHANNEL_H
  6. #define INCLUDED_IMF_DEEP_IMAGE_CHANNEL_H
  7. //----------------------------------------------------------------------------
  8. //
  9. // class DeepImageChannel,
  10. // template class TypedDeepImageChannel<T>
  11. //
  12. // For an explanation of images, levels and channels,
  13. // see the comments in header file Image.h.
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "ImfUtilExport.h"
  17. #include "ImfNamespace.h"
  18. #include "ImfImageChannel.h"
  19. #include "ImfSampleCountChannel.h"
  20. #include "ImfImageLevel.h"
  21. #include "ImfDeepFrameBuffer.h"
  22. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  23. class DeepImageLevel;
  24. class SampleCountChannel;
  25. //
  26. // Image channels:
  27. //
  28. // A TypedDeepImageChannel<T> holds the pixel data for a single channel
  29. // of one level of a deep image. Each pixel in the channel contains an
  30. // array of n samples of type T, where T is either half, float or
  31. // unsigned int, and n is stored in a separate sample count channel.
  32. // Sample storage is allocated only for pixels within the data window
  33. // of the level.
  34. //
  35. class IMFUTIL_EXPORT_TYPE DeepImageChannel: public ImageChannel
  36. {
  37. public:
  38. //
  39. // Construct an OpenEXR frame buffer slice for this channel.
  40. // This function is needed reading an image from an OpenEXR
  41. // file and for saving an image in an OpenEXR file.
  42. //
  43. virtual DeepSlice slice () const = 0;
  44. //
  45. // Access to the image level to which this channel belongs.
  46. //
  47. IMFUTIL_EXPORT DeepImageLevel & deepLevel();
  48. IMFUTIL_EXPORT const DeepImageLevel & deepLevel() const;
  49. //
  50. // Access to the sample count channel for this deep channel.
  51. //
  52. IMFUTIL_EXPORT SampleCountChannel & sampleCounts();
  53. IMFUTIL_EXPORT const SampleCountChannel & sampleCounts() const;
  54. protected:
  55. friend class DeepImageLevel;
  56. IMFUTIL_EXPORT DeepImageChannel (DeepImageLevel &level, bool pLinear);
  57. IMFUTIL_EXPORT virtual ~DeepImageChannel();
  58. DeepImageChannel (const DeepImageChannel& other) = delete;
  59. DeepImageChannel& operator = (const DeepImageChannel& other) = delete;
  60. DeepImageChannel (DeepImageChannel&& other) = delete;
  61. DeepImageChannel& operator = (DeepImageChannel&& other) = delete;
  62. virtual void setSamplesToZero
  63. (size_t i,
  64. unsigned int oldNumSamples,
  65. unsigned int newNumSamples) = 0;
  66. virtual void moveSampleList
  67. (size_t i,
  68. unsigned int oldNumSamples,
  69. unsigned int newNumSamples,
  70. size_t newSampleListPosition) = 0;
  71. virtual void moveSamplesToNewBuffer
  72. (const unsigned int * oldNumSamples,
  73. const unsigned int * newNumSamples,
  74. const size_t * newSampleListPositions) = 0;
  75. virtual void initializeSampleLists () = 0;
  76. IMFUTIL_EXPORT virtual void resize ();
  77. virtual void resetBasePointer () = 0;
  78. };
  79. template <class T>
  80. class IMFUTIL_EXPORT_TEMPLATE_TYPE TypedDeepImageChannel: public DeepImageChannel
  81. {
  82. public:
  83. //
  84. // The OpenEXR pixel type of this channel (HALF, FLOAT or UINT).
  85. //
  86. virtual PixelType pixelType () const;
  87. //
  88. // Construct an OpenEXR frame buffer slice for this channel.
  89. // This function is needed reading an image from an OpenEXR
  90. // file and for saving an image in an OpenEXR file.
  91. //
  92. virtual DeepSlice slice () const;
  93. //
  94. // Access to the pixel at pixel space location (x, y), without bounds
  95. // checking. Accessing a location outside the data window of the image
  96. // level results in undefined behavior.
  97. //
  98. // The pixel contains a pointer to an array of samples to type T. The
  99. // number of samples in this array is sampleCounts().at(x,y).
  100. //
  101. T * operator () (int x, int y);
  102. const T * operator () (int x, int y) const;
  103. //
  104. // Access to the pixel at pixel space location (x, y), with bounds
  105. // checking. Accessing a location outside the data window of the
  106. // image level throws an Iex::ArgExc exception.
  107. //
  108. T * at (int x, int y);
  109. const T * at (int x, int y) const;
  110. //
  111. // Faster access to all pixels in a single horizontal row of the
  112. // channel. Access is not bounds checked; accessing out of bounds
  113. // rows or pixels results in undefined behavior.
  114. //
  115. // Rows are numbered from 0 to pixelsPerColumn()-1, and each row
  116. // contains pixelsPerRow() values. The number of samples in
  117. // row(r)[i] is sampleCounts().row(r)[i].
  118. //
  119. T * const * row (int r);
  120. const T * const * row (int r) const;
  121. private:
  122. friend class DeepImageLevel;
  123. IMFUTIL_HIDDEN
  124. TypedDeepImageChannel (DeepImageLevel &level, bool pLinear);
  125. IMFUTIL_HIDDEN
  126. virtual ~TypedDeepImageChannel ();
  127. TypedDeepImageChannel (const TypedDeepImageChannel& other) = delete;
  128. TypedDeepImageChannel& operator = (const TypedDeepImageChannel& other) = delete;
  129. TypedDeepImageChannel (TypedDeepImageChannel&& other) = delete;
  130. TypedDeepImageChannel& operator = (TypedDeepImageChannel&& other) = delete;
  131. IMFUTIL_HIDDEN
  132. virtual void setSamplesToZero
  133. (size_t i,
  134. unsigned int oldNumSamples,
  135. unsigned int newNumSamples);
  136. IMFUTIL_HIDDEN
  137. virtual void moveSampleList
  138. (size_t i,
  139. unsigned int oldNumSamples,
  140. unsigned int newNumSamples,
  141. size_t newSampleListPosition);
  142. IMFUTIL_HIDDEN
  143. virtual void moveSamplesToNewBuffer
  144. (const unsigned int * oldNumSamples,
  145. const unsigned int * newNumSamples,
  146. const size_t * newSampleListPositions);
  147. IMFUTIL_HIDDEN
  148. virtual void initializeSampleLists ();
  149. IMFUTIL_HIDDEN
  150. virtual void resize ();
  151. IMFUTIL_HIDDEN
  152. virtual void resetBasePointer ();
  153. T ** _sampleListPointers; // Array of pointers to per-pixel
  154. //sample lists
  155. T ** _base; // Base pointer for faster access
  156. // to entries in _sampleListPointers
  157. T * _sampleBuffer; // Contiguous memory block that
  158. // contains all sample lists for
  159. // this channel
  160. };
  161. //
  162. // Channel typedefs for the pixel data types supported by OpenEXR.
  163. //
  164. typedef TypedDeepImageChannel<half> DeepHalfChannel;
  165. typedef TypedDeepImageChannel<float> DeepFloatChannel;
  166. typedef TypedDeepImageChannel<unsigned int> DeepUIntChannel;
  167. //-----------------------------------------------------------------------------
  168. // Implementation of templates and inline functions
  169. //-----------------------------------------------------------------------------
  170. template <class T>
  171. inline T *
  172. TypedDeepImageChannel<T>::operator () (int x, int y)
  173. {
  174. return _base[y * pixelsPerRow() + x];
  175. }
  176. template <class T>
  177. inline const T *
  178. TypedDeepImageChannel<T>::operator () (int x, int y) const
  179. {
  180. return _base[y * pixelsPerRow() + x];
  181. }
  182. template <class T>
  183. inline T *
  184. TypedDeepImageChannel<T>::at (int x, int y)
  185. {
  186. boundsCheck (x, y);
  187. return _base[y * pixelsPerRow() + x];
  188. }
  189. template <class T>
  190. inline const T *
  191. TypedDeepImageChannel<T>::at (int x, int y) const
  192. {
  193. boundsCheck (x, y);
  194. return _base[y * pixelsPerRow() + x];
  195. }
  196. template <class T>
  197. inline T * const *
  198. TypedDeepImageChannel<T>::row (int r)
  199. {
  200. return _base + r * pixelsPerRow();
  201. }
  202. template <class T>
  203. inline const T * const *
  204. TypedDeepImageChannel<T>::row (int r) const
  205. {
  206. return _base + r * pixelsPerRow();
  207. }
  208. #ifndef COMPILING_IMF_DEEP_IMAGE_CHANNEL
  209. extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedDeepImageChannel<half>;
  210. extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedDeepImageChannel<float>;
  211. extern template class IMFUTIL_EXPORT_EXTERN_TEMPLATE TypedDeepImageChannel<unsigned int>;
  212. #endif
  213. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  214. #endif