im2d_single.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. /*
  2. * Copyright (C) 2022 Rockchip Electronics Co., Ltd.
  3. * Authors:
  4. * Cerf Yu <cerf.yu@rock-chips.com>
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef _im2d_single_h_
  19. #define _im2d_single_h_
  20. #include "im2d_type.h"
  21. #ifdef __cplusplus
  22. /**
  23. * copy
  24. *
  25. * @param src
  26. * The input source image.
  27. * @param dst
  28. * The output destination image.
  29. * @param sync
  30. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  31. * @param release_fence_fd
  32. * When 'sync == 0', the fence_fd used to identify the current job state
  33. *
  34. * @returns success or else negative error code.
  35. */
  36. IM_API IM_STATUS imcopy(const rga_buffer_t src, rga_buffer_t dst, int sync = 1, int *release_fence_fd = NULL);
  37. /**
  38. * Resize
  39. *
  40. * @param src
  41. * The input source image.
  42. * @param dst
  43. * The output destination image.
  44. * @param fx
  45. * X-direction resize factor.
  46. * @param fy
  47. * X-direction resize factor.
  48. * @param interpolation
  49. * Interpolation formula(Only RGA1 support).
  50. * @param sync
  51. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  52. * @param release_fence_fd
  53. * When 'sync == 0', the fence_fd used to identify the current job state
  54. *
  55. * @returns success or else negative error code.
  56. */
  57. IM_API IM_STATUS imresize(const rga_buffer_t src, rga_buffer_t dst, double fx = 0, double fy = 0, int interpolation = 0, int sync = 1, int *release_fence_fd = NULL);
  58. /**
  59. * Crop
  60. *
  61. * @param src
  62. * The input source image.
  63. * @param dst
  64. * The output destination image.
  65. * @param rect
  66. * The rectangle on the source image that needs to be cropped.
  67. * @param sync
  68. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  69. * @param release_fence_fd
  70. * When 'sync == 0', the fence_fd used to identify the current job state
  71. *
  72. * @returns success or else negative error code.
  73. */
  74. IM_API IM_STATUS imcrop(const rga_buffer_t src, rga_buffer_t dst, im_rect rect, int sync = 1, int *release_fence_fd = NULL);
  75. /**
  76. * translate
  77. *
  78. * @param src
  79. * The input source image.
  80. * @param dst
  81. * The output destination image.
  82. * @param x
  83. * Output the coordinates of the starting point in the X-direction of the destination image.
  84. * @param y
  85. * Output the coordinates of the starting point in the Y-direction of the destination image.
  86. * @param sync
  87. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  88. * @param release_fence_fd
  89. * When 'sync == 0', the fence_fd used to identify the current job state
  90. *
  91. * @returns success or else negative error code.
  92. */
  93. IM_API IM_STATUS imtranslate(const rga_buffer_t src, rga_buffer_t dst, int x, int y, int sync = 1, int *release_fence_fd = NULL);
  94. /**
  95. * format convert
  96. *
  97. * @param src
  98. * The input source image.
  99. * @param dst
  100. * The output destination image.
  101. * @param sfmt
  102. * The source image format.
  103. * @param dfmt
  104. * The destination image format.
  105. * @param mode
  106. * color space mode:
  107. * IM_YUV_TO_RGB_BT601_LIMIT
  108. * IM_YUV_TO_RGB_BT601_FULL
  109. * IM_YUV_TO_RGB_BT709_LIMIT
  110. * IM_RGB_TO_YUV_BT601_FULL
  111. * IM_RGB_TO_YUV_BT601_LIMIT
  112. * IM_RGB_TO_YUV_BT709_LIMIT
  113. * @param sync
  114. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  115. * @param release_fence_fd
  116. * When 'sync == 0', the fence_fd used to identify the current job state
  117. *
  118. * @returns success or else negative error code.
  119. */
  120. IM_API IM_STATUS imcvtcolor(rga_buffer_t src, rga_buffer_t dst, int sfmt, int dfmt, int mode = IM_COLOR_SPACE_DEFAULT, int sync = 1, int *release_fence_fd = NULL);
  121. /**
  122. * rotation
  123. *
  124. * @param src
  125. * The input source image.
  126. * @param dst
  127. * The output destination image.
  128. * @param rotation
  129. * IM_HAL_TRANSFORM_ROT_90
  130. * IM_HAL_TRANSFORM_ROT_180
  131. * IM_HAL_TRANSFORM_ROT_270
  132. * @param sync
  133. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  134. * @param release_fence_fd
  135. * When 'sync == 0', the fence_fd used to identify the current job state
  136. *
  137. * @returns success or else negative error code.
  138. */
  139. IM_API IM_STATUS imrotate(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync = 1, int *release_fence_fd = NULL);
  140. /**
  141. * flip
  142. *
  143. * @param src
  144. * The input source image.
  145. * @param dst
  146. * The output destination image.
  147. * @param mode
  148. * IM_HAL_TRANSFORM_FLIP_H
  149. * IM_HAL_TRANSFORM_FLIP_V
  150. * @param sync
  151. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  152. * @param release_fence_fd
  153. * When 'sync == 0', the fence_fd used to identify the current job state
  154. *
  155. * @returns success or else negative error code.
  156. */
  157. IM_API IM_STATUS imflip(const rga_buffer_t src, rga_buffer_t dst, int mode, int sync = 1, int *release_fence_fd = NULL);
  158. /**
  159. * 2-channel blend (SRC + DST -> DST or SRCA + SRCB -> DST)
  160. *
  161. * @param fg_image
  162. * The foreground image.
  163. * @param bg_image
  164. * The background image, which is also the output destination image.
  165. * @param mode
  166. * Port-Duff mode:
  167. * IM_ALPHA_BLEND_SRC
  168. * IM_ALPHA_BLEND_DST
  169. * IM_ALPHA_BLEND_SRC_OVER
  170. * IM_ALPHA_BLEND_DST_OVER
  171. * @param sync
  172. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  173. * @param release_fence_fd
  174. * When 'sync == 0', the fence_fd used to identify the current job state
  175. *
  176. * @returns success or else negative error code.
  177. */
  178. IM_API IM_STATUS imblend(const rga_buffer_t fd_image, rga_buffer_t bg_image, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL);
  179. /**
  180. * 3-channel blend (SRC + DST -> DST or SRCA + SRCB -> DST)
  181. *
  182. * @param fg_image
  183. * The foreground image.
  184. * @param bg_image
  185. * The background image.
  186. * @param output_image
  187. * The output destination image.
  188. * @param mode
  189. * Port-Duff mode:
  190. * IM_ALPHA_BLEND_SRC
  191. * IM_ALPHA_BLEND_DST
  192. * IM_ALPHA_BLEND_SRC_OVER
  193. * IM_ALPHA_BLEND_DST_OVER
  194. * @param sync
  195. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  196. * @param release_fence_fd
  197. * When 'sync == 0', the fence_fd used to identify the current job state
  198. *
  199. * @returns success or else negative error code.
  200. */
  201. IM_API IM_STATUS imcomposite(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL);
  202. /**
  203. * color key
  204. *
  205. * @param fg_image
  206. * The foreground image.
  207. * @param bg_image
  208. * The background image, which is also the output destination image.
  209. * @param colorkey_range
  210. * The range of color key.
  211. * @param sync
  212. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  213. *
  214. * @returns success or else negative error code.
  215. */
  216. IM_API IM_STATUS imcolorkey(const rga_buffer_t src, rga_buffer_t dst, im_colorkey_range range, int mode = IM_ALPHA_COLORKEY_NORMAL, int sync = 1, int *release_fence_fd = NULL);
  217. /**
  218. * OSD
  219. *
  220. * @param osd
  221. * The osd text block.
  222. * @param dst
  223. * The background image.
  224. * @param osd_rect
  225. * The rectangle on the source image that needs to be OSD.
  226. * @param osd_config
  227. * osd mode configuration.
  228. * @param sync
  229. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  230. *
  231. * @returns success or else negative error code.
  232. */
  233. IM_API IM_STATUS imosd(const rga_buffer_t osd,const rga_buffer_t dst,
  234. const im_rect osd_rect, im_osd_t *osd_config,
  235. int sync = 1, int *release_fence_fd = NULL);
  236. /**
  237. * nn quantize
  238. *
  239. * @param src
  240. * The input source image.
  241. * @param dst
  242. * The output destination image.
  243. * @param nninfo
  244. * nn configuration
  245. * @param sync
  246. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  247. *
  248. * @returns success or else negative error code.
  249. */
  250. IM_API IM_STATUS imquantize(const rga_buffer_t src, rga_buffer_t dst, im_nn_t nn_info, int sync = 1, int *release_fence_fd = NULL);
  251. /**
  252. * ROP
  253. *
  254. * @param src
  255. * The input source image.
  256. * @param dst
  257. * The output destination image.
  258. * @param rop_code
  259. * The ROP opcode.
  260. * @param sync
  261. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  262. *
  263. * @returns success or else negative error code.
  264. */
  265. IM_API IM_STATUS imrop(const rga_buffer_t src, rga_buffer_t dst, int rop_code, int sync = 1, int *release_fence_fd = NULL);
  266. /**
  267. * fill/reset/draw
  268. *
  269. * @param dst
  270. * The output destination image.
  271. * @param rect
  272. * The rectangle on the source image that needs to be filled with color.
  273. * @param color
  274. * The fill color value.
  275. * @param sync
  276. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  277. *
  278. * @returns success or else negative error code.
  279. */
  280. IM_API IM_STATUS imfill(rga_buffer_t dst, im_rect rect, int color, int sync = 1, int *release_fence_fd = NULL);
  281. /**
  282. * fill array
  283. *
  284. * @param dst
  285. * The output destination image.
  286. * @param rect_array
  287. * The rectangle arrays on the source image that needs to be filled with color.
  288. * @param array_size
  289. * The size of rectangular area arrays.
  290. * @param color
  291. * The fill color value.
  292. * @param sync
  293. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  294. *
  295. * @returns success or else negative error code.
  296. */
  297. IM_API IM_STATUS imfillArray(rga_buffer_t dst, im_rect *rect_array, int array_size, uint32_t color, int sync = 1, int *release_fence_fd = NULL);
  298. /**
  299. * fill rectangle
  300. *
  301. * @param dst
  302. * The output destination image.
  303. * @param rect
  304. * The rectangle on the source image that needs to be filled with color.
  305. * @param color
  306. * The fill color value.
  307. * @param thickness
  308. * Thickness of lines that make up the rectangle. Negative values, like -1,
  309. * mean that the function has to draw a filled rectangle.
  310. * @param sync
  311. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  312. *
  313. * @returns success or else negative error code.
  314. */
  315. IM_API IM_STATUS imrectangle(rga_buffer_t dst, im_rect rect,
  316. uint32_t color, int thickness,
  317. int sync = 1, int *release_fence_fd = NULL);
  318. /**
  319. * fill rectangle array
  320. *
  321. * @param dst
  322. * The output destination image.
  323. * @param rect_array
  324. * The rectangle arrays on the source image that needs to be filled with color.
  325. * @param array_size
  326. * The size of rectangular area arrays.
  327. * @param color
  328. * The fill color value.
  329. * @param thickness
  330. * Thickness of lines that make up the rectangle. Negative values, like -1,
  331. * mean that the function has to draw a filled rectangle.
  332. * @param sync
  333. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  334. *
  335. * @returns success or else negative error code.
  336. */
  337. IM_API IM_STATUS imrectangleArray(rga_buffer_t dst, im_rect *rect_array, int array_size,
  338. uint32_t color, int thickness,
  339. int sync = 1, int *release_fence_fd = NULL);
  340. /**
  341. * MOSAIC
  342. *
  343. * @param image
  344. * The output destination image.
  345. * @param rect
  346. * The rectangle on the source image that needs to be mosaicked.
  347. * @param mosaic_mode
  348. * mosaic block width configuration:
  349. * IM_MOSAIC_8
  350. * IM_MOSAIC_16
  351. * IM_MOSAIC_32
  352. * IM_MOSAIC_64
  353. * IM_MOSAIC_128
  354. * @param sync
  355. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  356. *
  357. * @returns success or else negative error code.
  358. */
  359. IM_API IM_STATUS immosaic(const rga_buffer_t image, im_rect rect, int mosaic_mode, int sync = 1, int *release_fence_fd = NULL);
  360. /**
  361. * MOSAIC array
  362. *
  363. * @param image
  364. * The output destination image.
  365. * @param rect_array
  366. * The rectangle arrays on the source image that needs to be filled with color.
  367. * @param array_size
  368. * The size of rectangular area arrays.
  369. * @param mosaic_mode
  370. * mosaic block width configuration:
  371. * IM_MOSAIC_8
  372. * IM_MOSAIC_16
  373. * IM_MOSAIC_32
  374. * IM_MOSAIC_64
  375. * IM_MOSAIC_128
  376. * @param sync
  377. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  378. *
  379. * @returns success or else negative error code.
  380. */
  381. IM_API IM_STATUS immosaicArray(const rga_buffer_t image, im_rect *rect_array, int array_size, int mosaic_mode, int sync = 1, int *release_fence_fd = NULL);
  382. /**
  383. * palette
  384. *
  385. * @param src
  386. * The input source image.
  387. * @param dst
  388. * The output destination image.
  389. * @param lut
  390. * The LUT table.
  391. * @param sync
  392. * When 'sync == 1', wait for the operation to complete and return, otherwise return directly.
  393. *
  394. * @returns success or else negative error code.
  395. */
  396. IM_API IM_STATUS impalette(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t lut, int sync = 1, int *release_fence_fd = NULL);
  397. /**
  398. * process for single task mode
  399. *
  400. * @param src
  401. * The input source image and is also the foreground image in blend.
  402. * @param dst
  403. * The output destination image and is also the foreground image in blend.
  404. * @param pat
  405. * The foreground image, or a LUT table.
  406. * @param srect
  407. * The rectangle on the src channel image that needs to be processed.
  408. * @param drect
  409. * The rectangle on the dst channel image that needs to be processed.
  410. * @param prect
  411. * The rectangle on the pat channel image that needs to be processed.
  412. * @param opt
  413. * The image processing options configuration.
  414. * @param usage
  415. * The image processing usage.
  416. *
  417. * @returns success or else negative error code.
  418. */
  419. IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat,
  420. im_rect srect, im_rect drect, im_rect prect,
  421. int acquire_fence_fd, int *release_fence_fd,
  422. im_opt_t *opt_ptr, int usage);
  423. /**
  424. * make border
  425. *
  426. * @param src
  427. * The input source image.
  428. * @param dst
  429. * The output destination image.
  430. * @param top
  431. * the top pixels
  432. * @param bottom
  433. * the bottom pixels
  434. * @param left
  435. * the left pixels
  436. * @param right
  437. * the right pixels
  438. * @param border_type
  439. * Border type.
  440. * @param value
  441. * The pixel value at which the border is filled.
  442. *
  443. * @returns success or else negative error code.
  444. */
  445. IM_API IM_STATUS immakeBorder(rga_buffer_t src, rga_buffer_t dst,
  446. int top, int bottom, int left, int right,
  447. int border_type, int value = 0,
  448. int sync = 1, int acquir_fence_fd = -1, int *release_fence_fd = NULL);
  449. #endif /* #ifdef __cplusplus */
  450. IM_C_API IM_STATUS immosaic(const rga_buffer_t image, im_rect rect, int mosaic_mode, int sync);
  451. IM_C_API IM_STATUS imosd(const rga_buffer_t osd,const rga_buffer_t dst,
  452. const im_rect osd_rect, im_osd_t *osd_config, int sync);
  453. IM_C_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat,
  454. im_rect srect, im_rect drect, im_rect prect, int usage);
  455. /* Start: Symbols reserved for compatibility with macro functions */
  456. IM_C_API IM_STATUS imcopy_t(const rga_buffer_t src, rga_buffer_t dst, int sync);
  457. IM_C_API IM_STATUS imresize_t(const rga_buffer_t src, rga_buffer_t dst, double fx, double fy, int interpolation, int sync);
  458. IM_C_API IM_STATUS imcrop_t(const rga_buffer_t src, rga_buffer_t dst, im_rect rect, int sync);
  459. IM_C_API IM_STATUS imtranslate_t(const rga_buffer_t src, rga_buffer_t dst, int x, int y, int sync);
  460. IM_C_API IM_STATUS imcvtcolor_t(rga_buffer_t src, rga_buffer_t dst, int sfmt, int dfmt, int mode, int sync);
  461. IM_C_API IM_STATUS imrotate_t(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync);
  462. IM_C_API IM_STATUS imflip_t (const rga_buffer_t src, rga_buffer_t dst, int mode, int sync);
  463. IM_C_API IM_STATUS imblend_t(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode, int sync);
  464. IM_C_API IM_STATUS imcolorkey_t(const rga_buffer_t src, rga_buffer_t dst, im_colorkey_range range, int mode, int sync);
  465. IM_C_API IM_STATUS imquantize_t(const rga_buffer_t src, rga_buffer_t dst, im_nn_t nn_info, int sync);
  466. IM_C_API IM_STATUS imrop_t(const rga_buffer_t src, rga_buffer_t dst, int rop_code, int sync);
  467. IM_C_API IM_STATUS imfill_t(rga_buffer_t dst, im_rect rect, int color, int sync);
  468. IM_C_API IM_STATUS impalette_t(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t lut, int sync);
  469. /* End: Symbols reserved for compatibility with macro functions */
  470. #ifndef __cplusplus
  471. #define RGA_GET_MIN(n1, n2) ((n1) < (n2) ? (n1) : (n2))
  472. /**
  473. * copy
  474. *
  475. * @param src
  476. * @param dst
  477. * @param sync
  478. * wait until operation complete
  479. *
  480. * @returns success or else negative error code.
  481. */
  482. #define imcopy(src, dst, ...) \
  483. ({ \
  484. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  485. int __args[] = {__VA_ARGS__}; \
  486. int __argc = sizeof(__args)/sizeof(int); \
  487. if (__argc == 0) { \
  488. __ret = imcopy_t(src, dst, 1); \
  489. } else if (__argc == 1){ \
  490. __ret = imcopy_t(src, dst, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  491. } else { \
  492. __ret = IM_STATUS_INVALID_PARAM; \
  493. printf("invalid parameter\n"); \
  494. } \
  495. __ret; \
  496. })
  497. /**
  498. * Resize
  499. *
  500. * @param src
  501. * @param dst
  502. * @param fx
  503. * @param fy
  504. * @param interpolation
  505. * @param sync
  506. * wait until operation complete
  507. *
  508. * @returns success or else negative error code.
  509. */
  510. #define imresize(src, dst, ...) \
  511. ({ \
  512. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  513. double __args[] = {__VA_ARGS__}; \
  514. int __argc = sizeof(__args)/sizeof(double); \
  515. if (__argc == 0) { \
  516. __ret = imresize_t(src, dst, 0, 0, INTER_LINEAR, 1); \
  517. } else if (__argc == 2){ \
  518. __ret = imresize_t(src, dst, __args[RGA_GET_MIN(__argc, 0)], __args[RGA_GET_MIN(__argc, 1)], INTER_LINEAR, 1); \
  519. } else if (__argc == 3){ \
  520. __ret = imresize_t(src, dst, __args[RGA_GET_MIN(__argc, 0)], __args[RGA_GET_MIN(__argc, 1)], (int)__args[RGA_GET_MIN(__argc, 2)], 1); \
  521. } else if (__argc == 4){ \
  522. __ret = imresize_t(src, dst, __args[RGA_GET_MIN(__argc, 0)], __args[RGA_GET_MIN(__argc, 1)], (int)__args[RGA_GET_MIN(__argc, 2)], (int)__args[RGA_GET_MIN(__argc, 3)]); \
  523. } else { \
  524. __ret = IM_STATUS_INVALID_PARAM; \
  525. printf("invalid parameter\n"); \
  526. } \
  527. __ret; \
  528. })
  529. #define impyramid(src, dst, direction) \
  530. imresize_t(src, \
  531. dst, \
  532. direction == IM_UP_SCALE ? 0.5 : 2, \
  533. direction == IM_UP_SCALE ? 0.5 : 2, \
  534. INTER_LINEAR, 1)
  535. /**
  536. * format convert
  537. *
  538. * @param src
  539. * @param dst
  540. * @param sfmt
  541. * @param dfmt
  542. * @param mode
  543. * color space mode: IM_COLOR_SPACE_MODE
  544. * @param sync
  545. * wait until operation complete
  546. *
  547. * @returns success or else negative error code.
  548. */
  549. #define imcvtcolor(src, dst, sfmt, dfmt, ...) \
  550. ({ \
  551. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  552. int __args[] = {__VA_ARGS__}; \
  553. int __argc = sizeof(__args)/sizeof(int); \
  554. if (__argc == 0) { \
  555. __ret = imcvtcolor_t(src, dst, sfmt, dfmt, IM_COLOR_SPACE_DEFAULT, 1); \
  556. } else if (__argc == 1){ \
  557. __ret = imcvtcolor_t(src, dst, sfmt, dfmt, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \
  558. } else if (__argc == 2){ \
  559. __ret = imcvtcolor_t(src, dst, sfmt, dfmt, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \
  560. } else { \
  561. __ret = IM_STATUS_INVALID_PARAM; \
  562. printf("invalid parameter\n"); \
  563. } \
  564. __ret; \
  565. })
  566. /**
  567. * Crop
  568. *
  569. * @param src
  570. * @param dst
  571. * @param rect
  572. * @param sync
  573. * wait until operation complete
  574. *
  575. * @returns success or else negative error code.
  576. */
  577. #define imcrop(src, dst, rect, ...) \
  578. ({ \
  579. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  580. int __args[] = {__VA_ARGS__}; \
  581. int __argc = sizeof(__args)/sizeof(int); \
  582. if (__argc == 0) { \
  583. __ret = imcrop_t(src, dst, rect, 1); \
  584. } else if (__argc == 1){ \
  585. __ret = imcrop_t(src, dst, rect, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  586. } else { \
  587. __ret = IM_STATUS_INVALID_PARAM; \
  588. printf("invalid parameter\n"); \
  589. } \
  590. __ret; \
  591. })
  592. /**
  593. * translate
  594. *
  595. * @param src
  596. * @param dst
  597. * @param x
  598. * @param y
  599. * @param sync
  600. * wait until operation complete
  601. *
  602. * @returns success or else negative error code.
  603. */
  604. #define imtranslate(src, dst, x, y, ...) \
  605. ({ \
  606. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  607. int __args[] = {__VA_ARGS__}; \
  608. int __argc = sizeof(__args)/sizeof(int); \
  609. if (__argc == 0) { \
  610. __ret = imtranslate_t(src, dst, x, y, 1); \
  611. } else if (__argc == 1){ \
  612. __ret = imtranslate_t(src, dst, x, y, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  613. } else { \
  614. __ret = IM_STATUS_INVALID_PARAM; \
  615. printf("invalid parameter\n"); \
  616. } \
  617. __ret; \
  618. })
  619. /**
  620. * rotation
  621. *
  622. * @param src
  623. * @param dst
  624. * @param rotation
  625. * IM_HAL_TRANSFORM_ROT_90
  626. * IM_HAL_TRANSFORM_ROT_180
  627. * IM_HAL_TRANSFORM_ROT_270
  628. * @param sync
  629. * wait until operation complete
  630. *
  631. * @returns success or else negative error code.
  632. */
  633. #define imrotate(src, dst, rotation, ...) \
  634. ({ \
  635. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  636. int __args[] = {__VA_ARGS__}; \
  637. int __argc = sizeof(__args)/sizeof(int); \
  638. if (__argc == 0) { \
  639. __ret = imrotate_t(src, dst, rotation, 1); \
  640. } else if (__argc == 1){ \
  641. __ret = imrotate_t(src, dst, rotation, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  642. } else { \
  643. __ret = IM_STATUS_INVALID_PARAM; \
  644. printf("invalid parameter\n"); \
  645. } \
  646. __ret; \
  647. })
  648. /**
  649. * flip
  650. *
  651. * @param src
  652. * @param dst
  653. * @param mode
  654. * IM_HAL_TRANSFORM_FLIP_H
  655. * IM_HAL_TRANSFORM_FLIP_V
  656. * @param sync
  657. * wait until operation complete
  658. *
  659. * @returns success or else negative error code.
  660. */
  661. #define imflip(src, dst, mode, ...) \
  662. ({ \
  663. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  664. int __args[] = {__VA_ARGS__}; \
  665. int __argc = sizeof(__args)/sizeof(int); \
  666. if (__argc == 0) { \
  667. __ret = imflip_t(src, dst, mode, 1); \
  668. } else if (__argc == 1){ \
  669. __ret = imflip_t(src, dst, mode, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  670. } else { \
  671. __ret = IM_STATUS_INVALID_PARAM; \
  672. printf("invalid parameter\n"); \
  673. } \
  674. __ret; \
  675. })
  676. /**
  677. * blend (SRC + DST -> DST or SRCA + SRCB -> DST)
  678. *
  679. * @param srcA
  680. * @param srcB can be NULL.
  681. * @param dst
  682. * @param mode
  683. * IM_ALPHA_BLEND_MODE
  684. * @param sync
  685. * wait until operation complete
  686. *
  687. * @returns success or else negative error code.
  688. */
  689. #define imblend(srcA, dst, ...) \
  690. ({ \
  691. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  692. rga_buffer_t srcB; \
  693. memset(&srcB, 0x00, sizeof(rga_buffer_t)); \
  694. int __args[] = {__VA_ARGS__}; \
  695. int __argc = sizeof(__args)/sizeof(int); \
  696. if (__argc == 0) { \
  697. __ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \
  698. } else if (__argc == 1){ \
  699. __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \
  700. } else if (__argc == 2){ \
  701. __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \
  702. } else { \
  703. __ret = IM_STATUS_INVALID_PARAM; \
  704. printf("invalid parameter\n"); \
  705. } \
  706. __ret; \
  707. })
  708. #define imcomposite(srcA, srcB, dst, ...) \
  709. ({ \
  710. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  711. int __args[] = {__VA_ARGS__}; \
  712. int __argc = sizeof(__args)/sizeof(int); \
  713. if (__argc == 0) { \
  714. __ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \
  715. } else if (__argc == 1){ \
  716. __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \
  717. } else if (__argc == 2){ \
  718. __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \
  719. } else { \
  720. __ret = IM_STATUS_INVALID_PARAM; \
  721. printf("invalid parameter\n"); \
  722. } \
  723. __ret; \
  724. })
  725. /**
  726. * color key
  727. *
  728. * @param src
  729. * @param dst
  730. * @param colorkey_range
  731. * max color
  732. * min color
  733. * @param sync
  734. * wait until operation complete
  735. *
  736. * @returns success or else negative error code.
  737. */
  738. #define imcolorkey(src, dst, range, ...) \
  739. ({ \
  740. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  741. int __args[] = {__VA_ARGS__}; \
  742. int __argc = sizeof(__args)/sizeof(int); \
  743. if (__argc == 0) { \
  744. __ret = imcolorkey_t(src, dst, range, IM_ALPHA_COLORKEY_NORMAL, 1); \
  745. } else if (__argc == 1){ \
  746. __ret = imcolorkey_t(src, dst, range, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \
  747. } else if (__argc == 2){ \
  748. __ret = imcolorkey_t(src, dst, range, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \
  749. } else { \
  750. __ret = IM_STATUS_INVALID_PARAM; \
  751. printf("invalid parameter\n"); \
  752. } \
  753. __ret; \
  754. })
  755. /**
  756. * nn quantize
  757. *
  758. * @param src
  759. * @param dst
  760. * @param nninfo
  761. * @param sync
  762. * wait until operation complete
  763. *
  764. * @returns success or else negative error code.
  765. */
  766. #define imquantize(src, dst, nn_info, ...) \
  767. ({ \
  768. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  769. int __args[] = {__VA_ARGS__}; \
  770. int __argc = sizeof(__args)/sizeof(int); \
  771. if (__argc == 0) { \
  772. __ret = imquantize_t(src, dst, nn_info, 1); \
  773. } else if (__argc == 1){ \
  774. __ret = imquantize_t(src, dst, nn_info, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  775. } else { \
  776. __ret = IM_STATUS_INVALID_PARAM; \
  777. printf("invalid parameter\n"); \
  778. } \
  779. __ret; \
  780. })
  781. /**
  782. * ROP
  783. *
  784. * @param src
  785. * @param dst
  786. * @param rop_code
  787. * @param sync
  788. * wait until operation complete
  789. *
  790. * @returns success or else negative error code.
  791. */
  792. #define imrop(src, dst, rop_code, ...) \
  793. ({ \
  794. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  795. int __args[] = {__VA_ARGS__}; \
  796. int __argc = sizeof(__args)/sizeof(int); \
  797. if (__argc == 0) { \
  798. __ret = imrop_t(src, dst, rop_code, 1); \
  799. } else if (__argc == 1){ \
  800. __ret = imrop_t(src, dst, rop_code, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  801. } else { \
  802. __ret = IM_STATUS_INVALID_PARAM; \
  803. printf("invalid parameter\n"); \
  804. } \
  805. __ret; \
  806. })
  807. /**
  808. * fill/reset/draw
  809. *
  810. * @param src
  811. * @param dst
  812. * @param rect
  813. * @param color
  814. * @param sync
  815. * wait until operation complete
  816. *
  817. * @returns success or else negative error code.
  818. */
  819. #define imfill(buf, rect, color, ...) \
  820. ({ \
  821. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  822. int __args[] = {__VA_ARGS__}; \
  823. int __argc = sizeof(__args)/sizeof(int); \
  824. if (__argc == 0) { \
  825. __ret = imfill_t(buf, rect, color, 1); \
  826. } else if (__argc == 1){ \
  827. __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  828. } else { \
  829. __ret = IM_STATUS_INVALID_PARAM; \
  830. printf("invalid parameter\n"); \
  831. } \
  832. __ret; \
  833. })
  834. #define imreset(buf, rect, color, ...) \
  835. ({ \
  836. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  837. int __args[] = {__VA_ARGS__}; \
  838. int __argc = sizeof(__args)/sizeof(int); \
  839. if (__argc == 0) { \
  840. __ret = imfill_t(buf, rect, color, 1); \
  841. } else if (__argc == 1){ \
  842. __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  843. } else { \
  844. __ret = IM_STATUS_INVALID_PARAM; \
  845. printf("invalid parameter\n"); \
  846. } \
  847. __ret; \
  848. })
  849. #define imdraw(buf, rect, color, ...) \
  850. ({ \
  851. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  852. int __args[] = {__VA_ARGS__}; \
  853. int __argc = sizeof(__args)/sizeof(int); \
  854. if (__argc == 0) { \
  855. __ret = imfill_t(buf, rect, color, 1); \
  856. } else if (__argc == 1){ \
  857. __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  858. } else { \
  859. __ret = IM_STATUS_INVALID_PARAM; \
  860. printf("invalid parameter\n"); \
  861. } \
  862. __ret; \
  863. })
  864. /**
  865. * palette
  866. *
  867. * @param src
  868. * @param dst
  869. * @param lut
  870. * @param sync
  871. * wait until operation complete
  872. *
  873. * @returns success or else negative error code.
  874. */
  875. #define impalette(src, dst, lut, ...) \
  876. ({ \
  877. IM_STATUS __ret = IM_STATUS_SUCCESS; \
  878. int __args[] = {__VA_ARGS__}; \
  879. int __argc = sizeof(__args)/sizeof(int); \
  880. if (__argc == 0) { \
  881. __ret = impalette_t(src, dst, lut, 1); \
  882. } else if (__argc == 1){ \
  883. __ret = impalette_t(src, dst, lut, (int)__args[RGA_GET_MIN(__argc, 0)]); \
  884. } else { \
  885. __ret = IM_STATUS_INVALID_PARAM; \
  886. printf("invalid parameter\n"); \
  887. } \
  888. __ret; \
  889. })
  890. /* End define IM2D macro API */
  891. #endif
  892. #endif /* #ifndef _im2d_single_h_ */