pointerArithmetic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libimage - An image library
  4. * See file License for license information.
  5. */
  6. #ifndef HELP_IPP_H
  7. #define HELP_IPP_H
  8. #include "core/image/ippwrapper.h"
  9. #include "core/image/CoordT.h"
  10. namespace NICE {
  11. /**
  12. * Shift an IPP pointer in an image.
  13. * Get a new pointer that points to the pixel at location (\c x, \c y)
  14. * @param pointer Original pointer to the image data
  15. * @param x The X-coordinate of the pixel to point to
  16. * @param y The Y-coordinate of the pixel to point to
  17. * @param stepsize IPP stepsize associated with \c pointer
  18. * @return A pointer pointing to the pixel (\c x, \c y)
  19. */
  20. template <class T>
  21. inline const T* pointerToPixel1(const T* pointer, int x, int y, int stepsize) {
  22. return (T*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(T));
  23. }
  24. /**
  25. * Shift an IPP pointer in an image.
  26. * @copydoc pointerToPixel1()
  27. */
  28. template <class T>
  29. inline T* pointerToPixel1(T* pointer, int x, int y, int stepsize) {
  30. return (T*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(T));
  31. }
  32. /**
  33. * Shift an IPP pointer in a three channel image.
  34. * @copydoc pointerToPixel1()
  35. */
  36. template <class T>
  37. inline const T* pointerToPixel3(const T* pointer, int x, int y, int stepsize) {
  38. return (T*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(T) * 3);
  39. }
  40. /**
  41. * Shift an IPP pointer in a three channel image.
  42. * @copydoc pointerToPixel1()
  43. */
  44. template <class T>
  45. inline T* pointerToPixel3(T* pointer, int x, int y, int stepsize) {
  46. return (T*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(T) * 3);
  47. }
  48. /**
  49. * Shift an IPP pointer in an image.
  50. * Get a new pointer that points to the pixel at location (\c 0, \c y)
  51. * @param pointer Original pointer to the image data
  52. * @param y The Y-coordinate of the pixel to point to
  53. * @param stepsize IPP stepsize associated with \c pointer
  54. * @return A pointer pointing to the pixel (\c 0, \c y)
  55. */
  56. template <class T>
  57. inline const T* pointerToPixelY(const T* pointer, int y, int stepsize) {
  58. return (T*) (((Ipp8u*) pointer) + y * stepsize);
  59. }
  60. /**
  61. * Shift an IPP pointer in an image.
  62. * @copydoc pointerToPixel()
  63. */
  64. template <class T>
  65. inline T* pointerToPixelY(T* pointer, int y, int stepsize) {
  66. return (T*) (((Ipp8u*) pointer) + y * stepsize);
  67. }
  68. /**
  69. * Shift an IPP pointer in an image.
  70. * Get a new pointer that points to the pixel at location \c coord
  71. * @param pointer Original pointer to the image data
  72. * @param coord coordinate of the pixel to point to
  73. * @param stepsize IPP stepsize associated with \c pointer
  74. * @return A pointer pointing to the pixel \c coord
  75. */
  76. template <class T>
  77. inline const T* pointerToPixel1(const T* pointer, const Coord &coord, int stepsize) {
  78. return (T*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(T));
  79. }
  80. /**
  81. * Shift an IPP pointer in an image.
  82. * Get a new pointer that points to the pixel at location \c coord
  83. * @param pointer Original pointer to the image data
  84. * @param coord coordinate of the pixel to point to
  85. * @param stepsize IPP stepsize associated with \c pointer
  86. * @return A pointer pointing to the pixel \c coord
  87. */
  88. template <class T>
  89. inline T* pointerToPixel1(T* pointer, const Coord &coord, int stepsize) {
  90. return (T*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(T));
  91. }
  92. /**
  93. * Shift an IPP pointer in a three channel image.
  94. * Get a new pointer that points to the pixel at location \c coord
  95. * @param pointer Original pointer to the image data
  96. * @param coord coordinate of the pixel to point to
  97. * @param stepsize IPP stepsize associated with \c pointer
  98. * @return A pointer pointing to the pixel \c coord
  99. */
  100. template <class T>
  101. inline const T* pointerToPixel3(const T* pointer, const Coord &coord, int stepsize) {
  102. return (T*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(T) * 3);
  103. }
  104. /**
  105. * Shift an IPP pointer in a three channel image.
  106. * Get a new pointer that points to the pixel at location \c coord
  107. * @param pointer Original pointer to the image data
  108. * @param coord coordinate of the pixel to point to
  109. * @param stepsize IPP stepsize associated with \c pointer
  110. * @return A pointer pointing to the pixel \c coord
  111. */
  112. template <class T>
  113. inline T* pointerToPixel3(T* pointer, const Coord &coord, int stepsize) {
  114. return (T*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(T) * 3);
  115. }
  116. /**
  117. * Shift an IPP pointer in an image.
  118. * Get a new pointer that points to the pixel at location (\c x, \c y)
  119. * @param pointer Original pointer to the image data
  120. * @param x The X-coordinate of the pixel to point to
  121. * @param y The Y-coordinate of the pixel to point to
  122. * @param rowStepsize IPP (row) stepsize associated with \c pointer
  123. * @param columnStepsize stepsize between colmuns associated with \c pointer
  124. * @return A pointer pointing to the pixel (\c x, \c y)
  125. */
  126. template <class T>
  127. inline const T* pointerToPixelEx(const T* pointer, int x, int y, int rowStepsize, int columnStepsize) {
  128. return (T*) (((Ipp8u*) pointer) + y * rowStepsize + x * columnStepsize);
  129. }
  130. /**
  131. * Shift an IPP pointer in an image.
  132. * @copydoc pointerToPixel1()
  133. */
  134. template <class T>
  135. inline T* pointerToPixelEx(T* pointer, int x, int y, int rowStepsize, int columnStepsize) {
  136. return (T*) (((Ipp8u*) pointer) + y * rowStepsize + x * columnStepsize);
  137. }
  138. /**
  139. * Shift an IPP pointer in an image.
  140. * Get a new pointer that points to the pixel at location (\c x, \c y)
  141. * @param pointer Original pointer to the image data
  142. * @param x The X-coordinate of the pixel to point to
  143. * @param y The Y-coordinate of the pixel to point to
  144. * @param stepsize IPP stepsize associated with \c pointer
  145. * @return A pointer pointing to the pixel (\c x, \c y)
  146. */
  147. inline const Ipp8u* helpIppiShiftPointer_8u_C1(const Ipp8u* pointer, const int x, const int y,
  148. int stepsize) {
  149. return pointer + y * stepsize + x;
  150. }
  151. /**
  152. * Shift an IPP pointer in an image.
  153. * @copydoc helpIppiShiftPointer_8u_C1()
  154. */
  155. inline Ipp8u* helpIppiShiftPointer_8u_C1(Ipp8u* pointer, const int x, const int y,
  156. int stepsize) {
  157. return pointer + y * stepsize + x;
  158. }
  159. /**
  160. * Shift an IPP pointer in an image.
  161. * @copydoc helpIppiShiftPointer_8u_C1()
  162. */
  163. inline const Ipp8u* helpIppiShiftPointer_8u_C3(const Ipp8u* pointer, const int x, const int y,
  164. int stepsize) {
  165. return pointer + y * stepsize + x * 3;
  166. }
  167. /**
  168. * Shift an IPP pointer in an image.
  169. * @copydoc helpIppiShiftPointer_8u_C1()
  170. */
  171. inline Ipp8u* helpIppiShiftPointer_8u_C3(Ipp8u* pointer, const int x, const int y,
  172. int stepsize) {
  173. return pointer + y * stepsize + x * 3;
  174. }
  175. /**
  176. * Shift an IPP pointer in an image.
  177. * @copydoc helpIppiShiftPointer_8u_C1()
  178. */
  179. inline const Ipp16s* helpIppiShiftPointer_16s_C1(const Ipp16s* pointer, const int x, const int y,
  180. int stepsize) {
  181. return (Ipp16s*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp16s));
  182. }
  183. /**
  184. * Shift an IPP pointer in an image.
  185. * @copydoc helpIppiShiftPointer_8u_C1()
  186. */
  187. inline Ipp16s* helpIppiShiftPointer_16s_C1(Ipp16s* pointer, const int x, const int y,
  188. int stepsize) {
  189. return (Ipp16s*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp16s));
  190. }
  191. /**
  192. * Shift an IPP pointer in an image.
  193. * @copydoc helpIppiShiftPointer_8u_C1()
  194. */
  195. inline const Ipp32f* helpIppiShiftPointer_32f_C1(const Ipp32f* pointer, const int x, const int y,
  196. int stepsize) {
  197. return (Ipp32f*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp32f));
  198. }
  199. /**
  200. * Shift an IPP pointer in an image.
  201. * @copydoc helpIppiShiftPointer_8u_C1()
  202. */
  203. inline Ipp32f* helpIppiShiftPointer_32f_C1(Ipp32f* pointer, const int x, const int y,
  204. int stepsize) {
  205. return (Ipp32f*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp32f));
  206. }
  207. /**
  208. * Shift an IPP pointer in an image.
  209. * @copydoc helpIppiShiftPointer_8u_C1()
  210. */
  211. inline const Ipp64f* helpIppiShiftPointer_64f_C1(const Ipp64f* pointer, const int x, const int y,
  212. int stepsize) {
  213. return (Ipp64f*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp64f));
  214. }
  215. /**
  216. * Shift an IPP pointer in an image.
  217. * @copydoc helpIppiShiftPointer_8u_C1()
  218. */
  219. inline Ipp64f* helpIppiShiftPointer_64f_C1(Ipp64f* pointer, const int x, const int y,
  220. int stepsize) {
  221. return (Ipp64f*) (((Ipp8u*) pointer) + y * stepsize + x * sizeof(Ipp64f));
  222. }
  223. /**
  224. * Shift an IPP pointer in an image.
  225. * @param pointer Original pointer to the image data
  226. * @param coord coordinate of the pixel to point to
  227. * @param stepsize IPP stepsize associated with \c pointer
  228. * @return pointer pointing to the pixel \c coord
  229. */
  230. inline const Ipp8u* helpIppiShiftPointer_8u_C1(const Ipp8u* pointer, const Coord &coord,
  231. int stepsize) {
  232. return pointer + coord.y * stepsize + coord.x;
  233. }
  234. /**
  235. * Shift an IPP pointer in an image.
  236. * @param pointer Original pointer to the image data
  237. * @param coord coordinate of the pixel to point to
  238. * @param stepsize IPP stepsize associated with \c pointer
  239. * @return pointer pointing to the pixel \c coord
  240. */
  241. inline Ipp8u* helpIppiShiftPointer_8u_C1(Ipp8u* pointer, const Coord &coord,
  242. int stepsize) {
  243. return pointer + coord.y * stepsize + coord.x;
  244. }
  245. /**
  246. * Shift an IPP pointer in an image.
  247. * @param pointer Original pointer to the image data
  248. * @param coord coordinate of the pixel to point to
  249. * @param stepsize IPP stepsize associated with \c pointer
  250. * @return pointer pointing to the pixel \c coord
  251. */
  252. inline const Ipp8u* helpIppiShiftPointer_8u_C3(const Ipp8u* pointer, const Coord &coord,
  253. int stepsize) {
  254. return pointer + coord.y * stepsize + coord.x * 3;
  255. }
  256. /**
  257. * Shift an IPP pointer in an image.
  258. * @param pointer Original pointer to the image data
  259. * @param coord coordinate of the pixel to point to
  260. * @param stepsize IPP stepsize associated with \c pointer
  261. * @return pointer pointing to the pixel \c coord
  262. */
  263. inline Ipp8u* helpIppiShiftPointer_8u_C3(Ipp8u* pointer, const Coord &coord,
  264. int stepsize) {
  265. return pointer + coord.y * stepsize + coord.x * 3;
  266. }
  267. /**
  268. * Shift an IPP pointer in an image.
  269. * @param pointer Original pointer to the image data
  270. * @param coord coordinate of the pixel to point to
  271. * @param stepsize IPP stepsize associated with \c pointer
  272. * @return pointer pointing to the pixel \c coord
  273. */
  274. inline const Ipp16s* helpIppiShiftPointer_16s_C1(const Ipp16s* pointer, const Coord &coord,
  275. int stepsize) {
  276. return (Ipp16s*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp16s));
  277. }
  278. /**
  279. * Shift an IPP pointer in an image.
  280. * @param pointer Original pointer to the image data
  281. * @param coord coordinate of the pixel to point to
  282. * @param stepsize IPP stepsize associated with \c pointer
  283. * @return pointer pointing to the pixel \c coord
  284. */
  285. inline Ipp16s* helpIppiShiftPointer_16s_C1(Ipp16s* pointer, const Coord &coord,
  286. int stepsize) {
  287. return (Ipp16s*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp16s));
  288. }
  289. /**
  290. * Shift an IPP pointer in an image.
  291. * @param pointer Original pointer to the image data
  292. * @param coord coordinate of the pixel to point to
  293. * @param stepsize IPP stepsize associated with \c pointer
  294. * @return pointer pointing to the pixel \c coord
  295. */
  296. inline const Ipp32f* helpIppiShiftPointer_32f_C1(const Ipp32f* pointer, const Coord &coord,
  297. int stepsize) {
  298. return (Ipp32f*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp32f));
  299. }
  300. /**
  301. * Shift an IPP pointer in an image.
  302. * @param pointer Original pointer to the image data
  303. * @param coord coordinate of the pixel to point to
  304. * @param stepsize IPP stepsize associated with \c pointer
  305. * @return pointer pointing to the pixel \c coord
  306. */
  307. inline Ipp32f* helpIppiShiftPointer_32f_C1(Ipp32f* pointer, const Coord &coord,
  308. int stepsize) {
  309. return (Ipp32f*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp32f));
  310. }
  311. /**
  312. * Shift an IPP pointer in an image.
  313. * @param pointer Original pointer to the image data
  314. * @param coord coordinate of the pixel to point to
  315. * @param stepsize IPP stepsize associated with \c pointer
  316. * @return pointer pointing to the pixel \c coord
  317. */
  318. inline const Ipp64f* helpIppiShiftPointer_64f_C1(const Ipp64f* pointer, const Coord &coord,
  319. int stepsize) {
  320. return (Ipp64f*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp64f));
  321. }
  322. /**
  323. * Shift an IPP pointer in an image.
  324. * @param pointer Original pointer to the image data
  325. * @param coord coordinate of the pixel to point to
  326. * @param stepsize IPP stepsize associated with \c pointer
  327. * @return pointer pointing to the pixel \c coord
  328. */
  329. inline Ipp64f* helpIppiShiftPointer_64f_C1(Ipp64f* pointer, const Coord &coord,
  330. int stepsize) {
  331. return (Ipp64f*) (((Ipp8u*) pointer) + coord.y * stepsize + coord.x * sizeof(Ipp64f));
  332. }
  333. } // namespace
  334. #endif