BayerAverageMap.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /*
  2. * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are 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 NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @file
  30. * <b>Libargus Extension: Bayer Average Map API</b>
  31. *
  32. * @b Description: This file defines the BayerAverageMap extension.
  33. */
  34. #ifndef _ARGUS_EXT_BAYER_AVERAGE_MAP_H
  35. #define _ARGUS_EXT_BAYER_AVERAGE_MAP_H
  36. namespace Argus
  37. {
  38. /**
  39. * Generates local averages of a capture's raw Bayer data. These averages are generated for
  40. * a number of small rectangles, called bins, that are evenly distributed across the image.
  41. * These averages may be calculated before optical clipping to the output bit depth occurs, thus
  42. * the working range of this averaging may extend beyond the optical range of the output pixels;
  43. * this allows the averages to remain steady while the sensor freely modifies its optical range.
  44. *
  45. * Any pixel values outside of the working range are clipped with respect to this averaging.
  46. * Specifically, the API excludes them from the average calculation and increments
  47. * the clipped pixel counter for the containing region.
  48. * @see Ext::IBayerAverageMap::getClipCounts()
  49. *
  50. * This extension introduces two new interfaces:
  51. * - Ext::IBayerAverageMapSettings enables average map generation in a capture Request.
  52. * - Ext::IBayerAverageMap exposes the average map values from the CaptureMetadata.
  53. *
  54. * @defgroup ArgusExtBayerAverageMap Ext::BayerAverageMap
  55. * @ingroup ArgusExtensions
  56. */
  57. DEFINE_UUID(ExtensionName, EXT_BAYER_AVERAGE_MAP, 12c3de20,64c5,11e6,bdf4,08,00,20,0c,9a,66);
  58. namespace Ext
  59. {
  60. /**
  61. * @class IBayerAverageMapSettings
  62. *
  63. * Interface to Bayer average map settings.
  64. *
  65. * @ingroup ArgusRequest ArgusExtBayerAverageMap
  66. */
  67. DEFINE_UUID(InterfaceID, IID_BAYER_AVERAGE_MAP_SETTINGS, 12c3de21,64c5,11e6,bdf4,08,00,20,0c,9a,66);
  68. class IBayerAverageMapSettings : public Interface
  69. {
  70. public:
  71. static const InterfaceID& id() { return IID_BAYER_AVERAGE_MAP_SETTINGS; }
  72. /**
  73. * Enables or disables Bayer average map generation. When enabled, CaptureMetadata
  74. * returned by completed captures will expose the IBayerAverageMap interface.
  75. *
  76. * @param[in] enable whether or not Bayer average map generation is enabled.
  77. */
  78. virtual void setBayerAverageMapEnable(bool enable) = 0;
  79. /**
  80. * @returns whether or not Bayer average map generation is enabled.
  81. */
  82. virtual bool getBayerAverageMapEnable() const = 0;
  83. protected:
  84. ~IBayerAverageMapSettings() {}
  85. };
  86. /**
  87. * @class IBayerAverageMap
  88. *
  89. * Interface to Bayer average map metadata.
  90. *
  91. * The Bayer average map provides local averages of the capture's raw pixels for a number
  92. * of small rectangular regions, called bins, that are evenly distributed across the image.
  93. * Each average is a floating-point value that is nomalized such that [0.0, 1.0] maps to the
  94. * full optical range of the output pixels, but values outside this range may be included in
  95. * the averages so long as they are within the working range of the average calculation.
  96. * For pixels that have values outside the working range, the API excludes such pixels from the
  97. * average calculation and increments the clipped pixel counter for the containing region.
  98. * @see IBayerAverageMap::getWorkingRange()
  99. * @see IBayerAverageMap::getClipCounts()
  100. *
  101. * The size and layout of the bins used to calculate the averages are determined by the Argus
  102. * implementation and are illustrated in the following diagram. The bin size and interval are
  103. * constant across the image, and are positioned such that the generated averages cover the
  104. * majority of the full image. All dimensions are given in pixels.
  105. *
  106. * @code
  107. * start.x interval.width
  108. * _______ _________________
  109. * | | | |
  110. * _ ________________________________________________________
  111. * | | |
  112. * start.y | | |
  113. * |_ | _____ _____ _____ | _
  114. * | | | | | | | | |
  115. * | | 0,0 | | 1,0 | | 2,0 | | |
  116. * | |_____| |_____| |_____| | |
  117. * | | | interval.height
  118. * | | |
  119. * | | |
  120. * | _____ _____ _____ | _|
  121. * | | | | | | | |
  122. * | | 0,1 | | 1,1 | | 2,1 | |
  123. * | |_____| |_____| |_____| |
  124. * | |
  125. * | |
  126. * | |
  127. * | _____ _____ _____ | _
  128. * | | | | | | | | |
  129. * | | 0,2 | | 1,2 | | 2,2 | | | size.height
  130. * | |_____| |_____| |_____| | _|
  131. * | |
  132. * | |
  133. * |________________________________________________________|
  134. *
  135. * |_____|
  136. *
  137. * size.width
  138. * @endcode
  139. *
  140. * @ingroup ArgusCaptureMetadata ArgusExtBayerAverageMap
  141. */
  142. DEFINE_UUID(InterfaceID, IID_BAYER_AVERAGE_MAP, 12c3de22,64c5,11e6,bdf4,08,00,20,0c,9a,66);
  143. class IBayerAverageMap : public Interface
  144. {
  145. public:
  146. static const InterfaceID& id() { return IID_BAYER_AVERAGE_MAP; }
  147. /**
  148. * Returns the starting location of the first bin, in pixels, where the
  149. * location is relative to the top-left corner of the image.
  150. */
  151. virtual Point2D<uint32_t> getBinStart() const = 0;
  152. /**
  153. * Returns the size of each bin, in pixels.
  154. */
  155. virtual Size2D<uint32_t> getBinSize() const = 0;
  156. /**
  157. * Returns the number of bins in both the horizontal (width) and vertical (height) directions.
  158. * This size is equivalent to the array dimensions for the output from
  159. * IBayerAverageMap::getAverages() or IBayerAverageMap::getClipCounts().
  160. */
  161. virtual Size2D<uint32_t> getBinCount() const = 0;
  162. /**
  163. * Returns the bin intervals for both the x and y axis. These intervals are defined as the
  164. * number of pixels between the first pixel of a bin and that of the immediate next bin.
  165. */
  166. virtual Size2D<uint32_t> getBinInterval() const = 0;
  167. /**
  168. * Returns the working range of the averaging calculation. The working range is defined as
  169. * the range of values that are included in the average calculation (e.g. not clipped),
  170. * and may extend beyond the normalized [0.0, 1.0] range of the optical output. For example,
  171. * if the working range is [-0.5, 1.5], this means that values in [-0.5, 0) and (1, 1.5] will
  172. * still be included in the average calculation despite being clipped to [0.0, 1.0] in the
  173. * output pixels. Any pixels outside this working range are excluded from average calculation
  174. * and will increment the clip count.
  175. * @see IBayerAverageMap::getClipCounts()
  176. *
  177. * @note When the bit depth available for averaging is equal to the optical bit depth of
  178. * the output, the working range will be less than the full [0.0, 1.0] optical range. For
  179. * example, when 10 bits of data are available, the raw output pixels in [0u, 1023u] will
  180. * map to [0.0, 1.0]; however, the values of 0 and 1023 will be considered clipped for the
  181. * sake of average calculation, and so the working range would be [1/1023.0, 1022/1023.0].
  182. */
  183. virtual Range<float> getWorkingRange() const = 0;
  184. /**
  185. * Returns the average values for all bins. These values are normalized such that
  186. * [0.0, 1.0] maps to the optical range of the output, but the range of possible values
  187. * is determined by the working range. For input pixels that have values outside the
  188. * working range, the API excludes such pixels from the average calculation and
  189. * increments the clipped pixel counter for the containing region.
  190. * @see IBayerAverageMap::getWorkingRange()
  191. * @see IBayerAverageMap::getClipCounts()
  192. *
  193. * @param[out] averages The output array to store the averages for all bins. This
  194. * 2-dimensional array is sized as returned by IBayerAverageMap::getBinCount(),
  195. * where each array element is a floating point BayerTuple containing the R,
  196. * G_EVEN, G_ODD, and B averages for that bin.
  197. */
  198. virtual Status getAverages(Array2D< BayerTuple<float> >* averages) const = 0;
  199. /**
  200. * Returns the clipped pixel counts for all bins. This is the number of pixels in the bin
  201. * whose value exceeds the working range and have been excluded from average calculation.
  202. * @see IBayerAverageMap::getWorkingRange()
  203. *
  204. * @param[out] clipCounts The output array to store the clip counts for all bins. This
  205. * 2-dimensional array is sized as returned by
  206. * Ext::IBayerAverageMap::getBinCount(), where each array element is an uint32_t
  207. * BayerTuple containing the R, G_EVEN, G_ODD, and B clip counts for that bin.
  208. */
  209. virtual Status getClipCounts(Array2D< BayerTuple<uint32_t> >* clipCounts) const = 0;
  210. protected:
  211. ~IBayerAverageMap() {}
  212. };
  213. } // namespace Ext
  214. } // namespace Argus
  215. #endif // _ARGUS_EXT_BAYER_AVERAGE_MAP_H