vx_khr_tiling.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * Copyright (c) 2012-2017 The Khronos Group Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _VX_KHR_TILING_H_
  17. #define _VX_KHR_TILING_H_
  18. /*!
  19. * \file
  20. * \brief The Khronos Extension for User Tiling Functions.
  21. *
  22. * \defgroup group_tiling Extension: User Tiling API
  23. * \brief The Khronos Extension for User Tiling Functions.
  24. */
  25. #define OPENVX_KHR_TILING "vx_khr_tiling"
  26. #if defined(OPENVX_TILING_1_0)
  27. #undef OPENVX_TILING_1_1
  28. #endif
  29. #include <VX/vx.h>
  30. /* For vx_kernel_input_validate_f and vx_kernel_output_validate_f: */
  31. #include <VX/vx_compatibility.h>
  32. /*! \def VX_RESTRICT
  33. * \brief A platform wrapper for the restrict keyword.
  34. * \ingroup group_tiling
  35. */
  36. #if defined(_WIN32)
  37. #define VX_RESTRICT
  38. #else
  39. #if defined(__cplusplus) || defined(ANDROID)
  40. #define VX_RESTRICT __restrict
  41. #else
  42. #define VX_RESTRICT restrict
  43. #endif
  44. #endif
  45. /*! \brief The User Tiling Function tile block size declaration.
  46. * \details The author of a User Tiling Kernel will use this structure to define
  47. * the dimensionality of the tile block.
  48. * \ingroup group_tiling
  49. */
  50. typedef struct _vx_tile_block_size_t {
  51. vx_int32 width; /*!< \brief Tile block width in pixels. */
  52. vx_int32 height; /*!< \brief Tile block height in pixels. */
  53. } vx_tile_block_size_t;
  54. /*! \brief The User Tiling Function Neighborhood declaration.
  55. * \details The author of a User Tiling Kernel will use this structure to define
  56. * the neighborhood surrounding the tile block.
  57. * \ingroup group_tiling
  58. */
  59. typedef struct _vx_neighborhood_size_t {
  60. vx_int32 left; /*!< \brief Left of the tile block. */
  61. vx_int32 right; /*!< \brief Right of the tile block. */
  62. vx_int32 top; /*!< \brief Top of the tile block. */
  63. vx_int32 bottom; /*!< \brief Bottom of the tile block. */
  64. } vx_neighborhood_size_t;
  65. /*! \brief A structure which describes the tile's parent image.
  66. * \ingroup group_tiling
  67. */
  68. typedef struct _vx_image_description_t {
  69. vx_uint32 width; /*!< \brief Width of the image */
  70. vx_uint32 height; /*!< \brief Height of the image */
  71. vx_df_image format; /*!< \brief The <tt>\ref vx_df_image_e</tt> of the image */
  72. vx_uint32 planes; /*!< \brief The number of planes in the image */
  73. vx_enum range; /*!< \brief The <tt>\ref vx_channel_range_e</tt> enumeration. */
  74. vx_enum space; /*!< \brief The <tt>\ref vx_color_space_e</tt> enumeration. */
  75. } vx_image_description_t;
  76. /*! \brief The maximum number of planes in a tiled image.
  77. * \ingroup group_tiling
  78. */
  79. #define VX_MAX_TILING_PLANES (4)
  80. /*! \brief The tile structure declaration.
  81. * \ingroup group_tiling
  82. */
  83. typedef struct _vx_tile_t {
  84. /*! \brief The array of pointers to the tile's image plane. */
  85. vx_uint8 * VX_RESTRICT base[VX_MAX_TILING_PLANES];
  86. /*! \brief The top left X pixel index within the width dimension of the image. */
  87. vx_uint32 tile_x;
  88. /*! \brief The top left Y pixel index within the height dimension of the image. */
  89. vx_uint32 tile_y;
  90. /*! \brief The array of addressing structure to describe each plane. */
  91. vx_imagepatch_addressing_t addr[VX_MAX_TILING_PLANES];
  92. /*! \brief The output block size structure. */
  93. vx_tile_block_size_t tile_block;
  94. /*! \brief The neighborhood definition. */
  95. vx_neighborhood_size_t neighborhood;
  96. /*! \brief The description and attributes of the image. */
  97. vx_image_description_t image;
  98. } vx_tile_t;
  99. #ifndef VX_TILE_ATTRIBUTES_DEFINITIONS
  100. /*!
  101. * \brief The full height of the tile's parent image in pixels.
  102. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  103. * \ingroup group_tiling
  104. */
  105. #define vxImageHeight(ptile) ((ptile))->image.height)
  106. /*!
  107. * \brief The full width of the tile's parent image in pixels.
  108. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  109. * \ingroup group_tiling
  110. */
  111. #define vxImageWidth(ptile) ((ptile))->image.width)
  112. /*!
  113. * \brief The offset between the left edge of the image and the left edge of the tile, in pixels.
  114. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  115. * \ingroup group_tiling
  116. */
  117. #define vxTileX(ptile) ((ptile)->tile_x)
  118. /*!
  119. * \brief The offset between the top edge of the image and the top edge of the tile, in pixels.
  120. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  121. * \ingroup group_tiling
  122. */
  123. #define vxTileY(ptile) ((ptile)->tile_y)
  124. /*!
  125. * \brief The width of the tile in pixels.
  126. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  127. * \param [in] index The plane index.
  128. * \ingroup group_tiling
  129. */
  130. #define vxTileWidth(ptile, index) ((ptile)->addr[index].dim_x)
  131. /*!
  132. * \brief The height of the tile in pixels.
  133. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  134. * \param [in] index The plane index.
  135. * \ingroup group_tiling
  136. */
  137. #define vxTileHeight(ptile, index) ((ptile)->addr[index].dim_y)
  138. /*!
  139. * \brief The tile block height.
  140. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  141. * \ingroup group_tiling
  142. */
  143. #define vxTileBlockHeight(ptile) ((ptile)->tile_block.height)
  144. /*!
  145. * \brief The tile block width.
  146. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  147. * \ingroup group_tiling
  148. */
  149. #define vxTileBlockWidth(ptile) ((ptile)->tile_block.width)
  150. /*!
  151. * \brief The simple wrapper to access each image's neighborhood -X value.
  152. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  153. * \ingroup group_tiling
  154. */
  155. #define vxNeighborhoodLeft(ptile) ((ptile)->neighborhood.left)
  156. /*!
  157. * \brief The simple wrapper to access each image's neighborhood +X value.
  158. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  159. * \ingroup group_tiling
  160. */
  161. #define vxNeighborhoodRight(ptile) ((ptile)->neighborhood.right)
  162. /*!
  163. * \brief The simple wrapper to access each image's neighborhood -Y value.
  164. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  165. * \ingroup group_tiling
  166. */
  167. #define vxNeighborhoodTop(ptile) ((ptile)->neighborhood.top)
  168. /*!
  169. * \brief The simple wrapper to access each image's neighborhood +Y value.
  170. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  171. * \ingroup group_tiling
  172. */
  173. #define vxNeighborhoodBottom(ptile) ((ptile)->neighborhood.bottom)
  174. #if 0
  175. /*!
  176. * \brief The simple wrapper to access each image's stride X value.
  177. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  178. * \ingroup group_tiling
  179. */
  180. #define vxStrideSizeX(ptile, index) ((ptile)->addr[index].stride_x)
  181. /*!
  182. * \brief The simple wrapper to access each image's stride Y value.
  183. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  184. * \ingroup group_tiling
  185. */
  186. #define vxStrideSizeY(ptile, index) ((ptile)->addr[index].stride_y)
  187. /*!
  188. * \brief The simple wrapper to access each image's step X value.
  189. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  190. * \ingroup group_tiling
  191. */
  192. #define vxStepSizeX(ptile, index) ((ptile)->addr[index].step_x)
  193. /*!
  194. * \brief The simple wrapper to access each image's step Y value.
  195. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  196. * \ingroup group_tiling
  197. */
  198. #define vxStepSizeY(ptile, index) ((ptile)->addr[index].step_y)
  199. #endif
  200. #endif
  201. /*! \brief The User Kernel Tiling Attributes.
  202. * \ingroup group_tiling
  203. */
  204. enum vx_kernel_attribute_tiling_e {
  205. /*! \brief This allows a tiling mode kernel to set its input neighborhood. */
  206. VX_KERNEL_INPUT_NEIGHBORHOOD = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x7,
  207. /*! \brief This allows a tiling mode kernel to set its output tile block size. */
  208. VX_KERNEL_OUTPUT_TILE_BLOCK_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x8,
  209. /*! \brief This allows the author to set the border mode on the tiling kernel. */
  210. VX_KERNEL_BORDER = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0x9,
  211. /*! \brief This determines the per tile memory allocation. */
  212. VX_KERNEL_TILE_MEMORY_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0xA,
  213. #if defined(OPENVX_TILING_1_1)
  214. /*! \brief This allows a tiling mode kernel to set its input tile block size. */
  215. VX_KERNEL_INPUT_TILE_BLOCK_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0xB,
  216. /*! \brief This allows a tiling mode kernel to set its output neighborhood. */
  217. VX_KERNEL_OUTPUT_NEIGHBORHOOD = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_KERNEL) + 0xC,
  218. #endif
  219. };
  220. /*! \brief The User Node Tiling Attributes.
  221. * \note These are largely unusable by the tiling function, as it doesn't give you the node reference!
  222. * \ingroup group_tiling
  223. */
  224. enum vx_node_attribute_tiling_e {
  225. /*! \brief This allows a tiling mode node to get its input neighborhood. */
  226. VX_NODE_INPUT_NEIGHBORHOOD = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0xB,
  227. /*! \brief This allows a tiling mode node to get its output tile block size. */
  228. VX_NODE_OUTPUT_TILE_BLOCK_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0xC,
  229. /*! \brief This is the size of the tile local memory area. */
  230. VX_NODE_TILE_MEMORY_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0xD,
  231. #if defined(OPENVX_TILING_1_1)
  232. /*! \brief This allows a tiling mode node to get its input tile block size. */
  233. VX_NODE_INPUT_TILE_BLOCK_SIZE = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0xE,
  234. /*! \brief This allows a tiling mode node to get its output neighborhood. */
  235. VX_NODE_OUTPUT_NEIGHBORHOOD = VX_ATTRIBUTE_BASE(VX_ID_KHRONOS, VX_TYPE_NODE) + 0xF,
  236. #endif
  237. };
  238. /*! \brief The tiling border mode extensions
  239. * \ingroup group_tiling
  240. */
  241. enum vx_border_tiling_e {
  242. /*! \brief This value indicates that the author of the tiling kernel wrote
  243. * code to handle border conditions into the kernel itself. If this mode
  244. * is set, it can not be overriden by a call to the \ref vxSetNodeAttribute
  245. * with \ref VX_NODE_BORDER.
  246. */
  247. VX_BORDER_MODE_SELF = VX_ENUM_BASE(VX_ID_KHRONOS, VX_ENUM_BORDER) + 0x3,
  248. };
  249. /*! \typedef vx_tiling_kernel_f
  250. * \brief Tiling Kernel function typedef for User Tiling Kernels.
  251. * \note Tiles may come in any dimension and are not guaranteed to be delivered in
  252. * any particular order.
  253. * \param [in] parameters The array abstract pointers to parameters.
  254. * \param [in] tile_memory The local tile memory pointer if requested, otherwise NULL.
  255. * \param [in] tile_memory_size The size of the local tile memory, if not requested, 0.
  256. * \ingroup group_tiling
  257. */
  258. #ifdef __cplusplus
  259. typedef void (*vx_tiling_kernel_f)(void * VX_RESTRICT parameters[],
  260. void * VX_RESTRICT tile_memory,
  261. vx_size tile_memory_size);
  262. #else
  263. typedef void (*vx_tiling_kernel_f)(void * VX_RESTRICT parameters[VX_RESTRICT],
  264. void * VX_RESTRICT tile_memory,
  265. vx_size tile_memory_size);
  266. #endif
  267. #ifndef VX_IMAGE_PIXEL_DEFINITION
  268. /*! \def vxImageOffset
  269. * \brief Computes the offset within an image.
  270. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  271. * \param [in] i The plane index.
  272. * \param [in] x The Width Coordinates.
  273. * \param [in] y The Height Coordinates.
  274. * \param [in] ox The X offset.
  275. * \param [in] oy The Y offset.
  276. * \ingroup group_tiling
  277. */
  278. #define vxImageOffset(ptile, i, x, y, ox, oy) \
  279. ((ptile)->addr[i].stride_y * (vx_int32)(((vx_int32)((oy)+(y)) * (vx_int32)(ptile)->addr[i].scale_y)/(vx_int32)VX_SCALE_UNITY)) + \
  280. ((ptile)->addr[i].stride_x * (vx_int32)(((vx_int32)((ox)+(x)) * (vx_int32)(ptile)->addr[i].scale_x)/(vx_int32)VX_SCALE_UNITY))
  281. /*! \def vxImagePixel
  282. * \brief Accesses an image pixel as a type-cast indexed pointer dereference.
  283. * \param [in] type The type of the image pixel. Example values are <tt>\ref vx_uint8</tt>, <tt>\ref vx_uint16</tt>, <tt>\ref vx_uint32</tt>, etc.
  284. * \param [in] ptile The pointer to the \ref vx_tile_t structure.
  285. * \param [in] i The plane index.
  286. * \param [in] x The Center Pixel in Width Coordinates.
  287. * \param [in] y The Center Pixel in Height Coordinates.
  288. * \param [in] ox The X offset.
  289. * \param [in] oy The Y offset.
  290. * \ingroup group_tiling
  291. */
  292. #define vxImagePixel(type, ptile, i, x, y, ox, oy) \
  293. *((type *)(&((vx_uint8 *)(ptile)->base[i])[vxImageOffset(ptile, i, x, y, ox, oy)]))
  294. #endif
  295. #ifdef __cplusplus
  296. extern "C" {
  297. #endif
  298. /*! \brief Allows a user to add a tile-able kernel to the OpenVX system.
  299. * \param [in] context The handle to the implementation context.
  300. * \param [in] name The string to be used to match the kernel.
  301. * \param [in] enumeration The enumerated value of the kernel to be used by clients.
  302. * \param [in] flexible_func_ptr The process-local flexible function pointer to be invoked.
  303. * \param [in] fast_func_ptr The process-local fast function pointer to be invoked.
  304. * \param [in] num_params The number of parameters for this kernel.
  305. * \param [in] input The pointer to a function which will validate the
  306. * input parameters to this kernel.
  307. * \param [in] output The pointer to a function which will validate the
  308. * output parameters to this kernel.
  309. * \note Tiling Kernels do not have access to any of the normal node attributes listed
  310. * in \ref vx_node_attribute_e.
  311. * \post Call <tt>\ref vxAddParameterToKernel</tt> for as many parameters as the function has,
  312. * then call <tt>\ref vxFinalizeKernel</tt>.
  313. * \retval 0 Indicates that an error occurred when adding the kernel.
  314. * Note that the fast or flexible formula, but not both, can be NULL.
  315. * \ingroup group_tiling
  316. */
  317. VX_API_ENTRY vx_kernel VX_API_CALL vxAddTilingKernel(vx_context context,
  318. vx_char name[VX_MAX_KERNEL_NAME],
  319. vx_enum enumeration,
  320. vx_tiling_kernel_f flexible_func_ptr,
  321. vx_tiling_kernel_f fast_func_ptr,
  322. vx_uint32 num_params,
  323. vx_kernel_input_validate_f input,
  324. vx_kernel_output_validate_f output);
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. #endif