1 /* 2 * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 * Authors: 4 * PutinLee <putin.lee@rock-chips.com> 5 * Cerf Yu <cerf.yu@rock-chips.com> 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 #ifndef _im2d_h_ 21 #define _im2d_h_ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #ifndef IM_API 28 #define IM_API /* define API export as needed */ 29 #endif 30 31 typedef enum { 32 /* Rotation */ 33 IM_HAL_TRANSFORM_ROT_90 = 1 << 0, 34 IM_HAL_TRANSFORM_ROT_180 = 1 << 1, 35 IM_HAL_TRANSFORM_ROT_270 = 1 << 2, 36 IM_HAL_TRANSFORM_FLIP_H = 1 << 3, 37 IM_HAL_TRANSFORM_FLIP_V = 1 << 4, 38 IM_HAL_TRANSFORM_FLIP_H_V = 1 << 5, 39 IM_HAL_TRANSFORM_MASK = 0x3f, 40 41 /* 42 * Blend 43 * Additional blend usage, can be used with both source and target configs. 44 * If none of the below is set, the default "SRC over DST" is applied. 45 */ 46 IM_ALPHA_BLEND_SRC_OVER = 1 << 6, /* Default, Porter-Duff "SRC over DST" */ 47 IM_ALPHA_BLEND_SRC = 1 << 7, /* Porter-Duff "SRC" */ 48 IM_ALPHA_BLEND_DST = 1 << 8, /* Porter-Duff "DST" */ 49 IM_ALPHA_BLEND_SRC_IN = 1 << 9, /* Porter-Duff "SRC in DST" */ 50 IM_ALPHA_BLEND_DST_IN = 1 << 10, /* Porter-Duff "DST in SRC" */ 51 IM_ALPHA_BLEND_SRC_OUT = 1 << 11, /* Porter-Duff "SRC out DST" */ 52 IM_ALPHA_BLEND_DST_OUT = 1 << 12, /* Porter-Duff "DST out SRC" */ 53 IM_ALPHA_BLEND_DST_OVER = 1 << 13, /* Porter-Duff "DST over SRC" */ 54 IM_ALPHA_BLEND_SRC_ATOP = 1 << 14, /* Porter-Duff "SRC ATOP" */ 55 IM_ALPHA_BLEND_DST_ATOP = 1 << 15, /* Porter-Duff "DST ATOP" */ 56 IM_ALPHA_BLEND_XOR = 1 << 16, /* Xor */ 57 IM_ALPHA_BLEND_MASK = 0x1ffc0, 58 59 IM_ALPHA_COLORKEY_NORMAL = 1 << 17, 60 IM_ALPHA_COLORKEY_INVERTED = 1 << 18, 61 IM_ALPHA_COLORKEY_MASK = 0x60000, 62 63 IM_SYNC = 1 << 19, 64 IM_ASYNC = 1 << 26, 65 IM_CROP = 1 << 20, /* Unused */ 66 IM_COLOR_FILL = 1 << 21, 67 IM_COLOR_PALETTE = 1 << 22, 68 IM_NN_QUANTIZE = 1 << 23, 69 IM_ROP = 1 << 24, 70 IM_ALPHA_BLEND_PRE_MUL = 1 << 25, 71 } IM_USAGE; 72 73 typedef enum { 74 IM_ROP_AND = 0x88, 75 IM_ROP_OR = 0xee, 76 IM_ROP_NOT_DST = 0x55, 77 IM_ROP_NOT_SRC = 0x33, 78 IM_ROP_XOR = 0xf6, 79 IM_ROP_NOT_XOR = 0xf9, 80 } IM_ROP_CODE; 81 82 typedef enum { 83 IM_RGA_SUPPORT_FORMAT_ERROR_INDEX = 0, 84 IM_RGA_SUPPORT_FORMAT_RGB_INDEX, 85 IM_RGA_SUPPORT_FORMAT_RGB_OTHER_INDEX, 86 IM_RGA_SUPPORT_FORMAT_BPP_INDEX, 87 IM_RGA_SUPPORT_FORMAT_YUV_8_INDEX, 88 IM_RGA_SUPPORT_FORMAT_YUV_10_INDEX, 89 IM_RGA_SUPPORT_FORMAT_YUYV_420_INDEX, 90 IM_RGA_SUPPORT_FORMAT_YUYV_422_INDEX, 91 IM_RGA_SUPPORT_FORMAT_YUV_400_INDEX, 92 IM_RGA_SUPPORT_FORMAT_Y4_INDEX, 93 IM_RGA_SUPPORT_FORMAT_MASK_INDEX, 94 } IM_RGA_SUPPORT_FORMAT_INDEX; 95 96 typedef enum { 97 IM_RGA_SUPPORT_FORMAT_ERROR = 1 << IM_RGA_SUPPORT_FORMAT_ERROR_INDEX, 98 IM_RGA_SUPPORT_FORMAT_RGB = 1 << IM_RGA_SUPPORT_FORMAT_RGB_INDEX, 99 IM_RGA_SUPPORT_FORMAT_RGB_OTHER = 1 << IM_RGA_SUPPORT_FORMAT_RGB_OTHER_INDEX, 100 IM_RGA_SUPPORT_FORMAT_BPP = 1 << IM_RGA_SUPPORT_FORMAT_BPP_INDEX, 101 IM_RGA_SUPPORT_FORMAT_YUV_8 = 1 << IM_RGA_SUPPORT_FORMAT_YUV_8_INDEX, 102 IM_RGA_SUPPORT_FORMAT_YUV_10 = 1 << IM_RGA_SUPPORT_FORMAT_YUV_10_INDEX, 103 IM_RGA_SUPPORT_FORMAT_YUYV_420 = 1 << IM_RGA_SUPPORT_FORMAT_YUYV_420_INDEX, 104 IM_RGA_SUPPORT_FORMAT_YUYV_422 = 1 << IM_RGA_SUPPORT_FORMAT_YUYV_422_INDEX, 105 IM_RGA_SUPPORT_FORMAT_YUV_400 = 1 << IM_RGA_SUPPORT_FORMAT_YUV_400_INDEX, 106 IM_RGA_SUPPORT_FORMAT_Y4 = 1 << IM_RGA_SUPPORT_FORMAT_Y4_INDEX, 107 IM_RGA_SUPPORT_FORMAT_MASK = ~((~(unsigned int)0x0 << IM_RGA_SUPPORT_FORMAT_MASK_INDEX) | 1), 108 } IM_RGA_SUPPORT_FORMAT; 109 110 typedef enum { 111 IM_RGA_SUPPORT_FEATURE_ERROR_INDEX = 0, 112 IM_RGA_SUPPORT_FEATURE_COLOR_FILL_INDEX, 113 IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE_INDEX, 114 IM_RGA_SUPPORT_FEATURE_ROP_INDEX, 115 IM_RGA_SUPPORT_FEATURE_QUANTIZE_INDEX, 116 IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC_INDEX, 117 IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC_INDEX, 118 IM_RGA_SUPPORT_FEATURE_MASK_INDEX, 119 } IM_RGA_SUPPORT_FEATURE_INDEX; 120 121 typedef enum { 122 IM_RGA_SUPPORT_FEATURE_ERROR = 1 << IM_RGA_SUPPORT_FEATURE_ERROR_INDEX, 123 IM_RGA_SUPPORT_FEATURE_COLOR_FILL = 1 << IM_RGA_SUPPORT_FEATURE_COLOR_FILL_INDEX, 124 IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE = 1 << IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE_INDEX, 125 IM_RGA_SUPPORT_FEATURE_ROP = 1 << IM_RGA_SUPPORT_FEATURE_ROP_INDEX, 126 IM_RGA_SUPPORT_FEATURE_QUANTIZE = 1 << IM_RGA_SUPPORT_FEATURE_QUANTIZE_INDEX, 127 IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC = 1 << IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC_INDEX, 128 IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC = 1 << IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC_INDEX, 129 IM_RGA_SUPPORT_FEATURE_MASK = ~((~(unsigned int)0x0 << IM_RGA_SUPPORT_FEATURE_MASK_INDEX) | 1), 130 } IM_RGA_SUPPORT_FEATURE; 131 132 /* Status codes, returned by any blit function */ 133 typedef enum { 134 IM_STATUS_NOERROR = 2, 135 IM_STATUS_SUCCESS = 1, 136 IM_STATUS_NOT_SUPPORTED = -1, 137 IM_STATUS_OUT_OF_MEMORY = -2, 138 IM_STATUS_INVALID_PARAM = -3, 139 IM_STATUS_ILLEGAL_PARAM = -4, 140 IM_STATUS_FAILED = 0, 141 } IM_STATUS; 142 143 /* Status codes, returned by any blit function */ 144 typedef enum { 145 IM_YUV_TO_RGB_BT601_LIMIT = 1 << 0, 146 IM_YUV_TO_RGB_BT601_FULL = 2 << 0, 147 IM_YUV_TO_RGB_BT709_LIMIT = 3 << 0, 148 IM_YUV_TO_RGB_MASK = 3 << 0, 149 IM_RGB_TO_YUV_BT601_FULL = 1 << 2, 150 IM_RGB_TO_YUV_BT601_LIMIT = 2 << 2, 151 IM_RGB_TO_YUV_BT709_LIMIT = 3 << 2, 152 IM_RGB_TO_YUV_MASK = 3 << 2, 153 IM_RGB_TO_Y4 = 1 << 4, 154 IM_RGB_TO_Y4_DITHER = 2 << 4, 155 IM_RGB_TO_Y1_DITHER = 3 << 4, 156 IM_Y4_MASK = 3 << 4, 157 IM_RGB_FULL = 1 << 8, 158 IM_RGB_CLIP = 2 << 8, 159 IM_YUV_BT601_LIMIT_RANGE = 3 << 8, 160 IM_YUV_BT601_FULL_RANGE = 4 << 8, 161 IM_YUV_BT709_LIMIT_RANGE = 5 << 8, 162 IM_YUV_BT709_FULL_RANGE = 6 << 8, 163 IM_FULL_CSC_MASK = 0xf << 8, 164 IM_COLOR_SPACE_DEFAULT = 0, 165 } IM_COLOR_SPACE_MODE; 166 167 typedef enum { 168 IM_UP_SCALE, 169 IM_DOWN_SCALE, 170 } IM_SCALE; 171 172 typedef enum { 173 INTER_NEAREST, 174 INTER_LINEAR, 175 INTER_CUBIC, 176 } IM_SCALE_MODE; 177 178 /* Get RGA basic information index */ 179 typedef enum { 180 RGA_VENDOR = 0, 181 RGA_VERSION, 182 RGA_MAX_INPUT, 183 RGA_MAX_OUTPUT, 184 RGA_SCALE_LIMIT, 185 RGA_INPUT_FORMAT, 186 RGA_OUTPUT_FORMAT, 187 RGA_FEATURE, 188 RGA_EXPECTED, 189 RGA_ALL, 190 } IM_INFORMATION; 191 192 /* rga version index */ 193 typedef enum { 194 RGA_V_ERR = 0x0, 195 RGA_1 = 0x1, 196 RGA_1_PLUS = 0x2, 197 RGA_2 = 0x3, 198 RGA_2_LITE0 = 0x4, 199 RGA_2_LITE1 = 0x5, 200 RGA_2_ENHANCE = 0x6, 201 } RGA_VERSION_NUM; 202 203 typedef struct { 204 RGA_VERSION_NUM version; 205 unsigned int input_resolution; 206 unsigned int output_resolution; 207 unsigned int scale_limit; 208 unsigned int performance; 209 unsigned int input_format; 210 unsigned int output_format; 211 unsigned int feature; 212 char reserved[28]; 213 } rga_info_table_entry; 214 215 /* Rectangle definition */ 216 typedef struct { 217 int x; /* upper-left x */ 218 int y; /* upper-left y */ 219 int width; /* width */ 220 int height; /* height */ 221 } im_rect; 222 223 typedef struct { 224 int max; /* The Maximum value of the color key */ 225 int min; /* The minimum value of the color key */ 226 } im_colorkey_range; 227 228 229 typedef struct im_nn { 230 int scale_r; /* scaling factor on R channal */ 231 int scale_g; /* scaling factor on G channal */ 232 int scale_b; /* scaling factor on B channal */ 233 int offset_r; /* offset on R channal */ 234 int offset_g; /* offset on G channal */ 235 int offset_b; /* offset on B channal */ 236 } im_nn_t; 237 238 /* im_info definition */ 239 typedef struct { 240 void* vir_addr; /* virtual address */ 241 void* phy_addr; /* physical address */ 242 int fd; /* shared fd */ 243 int width; /* width */ 244 int height; /* height */ 245 int wstride; /* wstride */ 246 int hstride; /* hstride */ 247 int format; /* format */ 248 int color_space_mode; /* color_space_mode */ 249 int color; /* color, used by color fill */ 250 int global_alpha; /* global_alpha */ 251 im_colorkey_range colorkey_range; /* range value of color key */ 252 im_nn_t nn; 253 int rop_code; 254 } rga_buffer_t; 255 256 /* 257 * @return error message string 258 */ 259 #define imStrError(...) \ 260 ( { \ 261 const char* err; \ 262 int args[] = {__VA_ARGS__}; \ 263 int argc = sizeof(args)/sizeof(int); \ 264 if (argc == 0) { \ 265 err = imStrError_t(IM_STATUS_INVALID_PARAM); \ 266 } else if (argc == 1) { \ 267 err = imStrError_t((IM_STATUS)args[0]); \ 268 } else { \ 269 err = ("Fatal error, imStrError() too many parameters\n"); \ 270 printf("Fatal error, imStrError() too many parameters\n"); \ 271 } \ 272 err; \ 273 }) 274 IM_API const char* imStrError_t(IM_STATUS status); 275 276 /* 277 * @return rga_buffer_t 278 */ 279 #define wrapbuffer_virtualaddr(vir_addr, width, height, format, ...) \ 280 do { \ 281 rga_buffer_t buffer; \ 282 int args[] = {__VA_ARGS__}; \ 283 int argc = sizeof(args)/sizeof(int); \ 284 if (argc == 0) { \ 285 buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, width, height, format); \ 286 } else if (argc == 2) { \ 287 buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, args[0], args[1], format); \ 288 } else { \ 289 printf("invalid parameter\n"); \ 290 } \ 291 buffer; \ 292 } while (0) 293 294 #define wrapbuffer_physicaladdr(phy_addr, width, height, format, ...) \ 295 do { \ 296 rga_buffer_t buffer; \ 297 int args[] = {__VA_ARGS__}; \ 298 int argc = sizeof(args)/sizeof(int); \ 299 if (argc == 0) { \ 300 buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, width, height, format); \ 301 } else if (argc == 2) { \ 302 buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, args[0], args[1], format); \ 303 } else { \ 304 printf("invalid parameter\n"); \ 305 } \ 306 buffer; \ 307 } while (0) 308 309 #define wrapbuffer_fd(fd, width, height, format, ...) \ 310 do { \ 311 rga_buffer_t buffer; \ 312 int args[] = {__VA_ARGS__}; \ 313 int argc = sizeof(args)/sizeof(int); \ 314 if (argc == 0) { \ 315 buffer = wrapbuffer_fd_t(fd, width, height, width, height, format); \ 316 } else if (argc == 2) { \ 317 buffer = wrapbuffer_fd_t(fd, width, height, args[0], args[1], format); \ 318 } else { \ 319 printf("invalid parameter\n"); \ 320 } \ 321 buffer; \ 322 } while (0) 323 324 IM_API rga_buffer_t wrapbuffer_virtualaddr_t(void* vir_addr, int width, int height, 325 int wstride, int hstride, int format); 326 IM_API rga_buffer_t wrapbuffer_physicaladdr_t(void* phy_addr, int width, int height, 327 int wstride, int hstride, int format); 328 IM_API rga_buffer_t wrapbuffer_fd_t(int fd, int width, int height, int wstride, int hstride, int format); 329 330 /* 331 * Get RGA basic information, supported resolution, supported format, etc. 332 * 333 * @param name 334 * RGA_VENDOR 335 * RGA_VERSION 336 * RGA_MAX_INPUT 337 * RGA_MAX_OUTPUT 338 * RGA_INPUT_FORMAT 339 * RGA_OUTPUT_FORMAT 340 * RGA_EXPECTED 341 * RGA_ALL 342 * 343 * @returns a usage describing properties of RGA. 344 */ 345 IM_API IM_STATUS rga_get_info(rga_info_table_entry *return_table); 346 347 /* 348 * Query RGA basic information, supported resolution, supported format, etc. 349 * 350 * @param name 351 * RGA_VENDOR 352 * RGA_VERSION 353 * RGA_MAX_INPUT 354 * RGA_MAX_OUTPUT 355 * RGA_INPUT_FORMAT 356 * RGA_OUTPUT_FORMAT 357 * RGA_EXPECTED 358 * RGA_ALL 359 * 360 * @returns a string describing properties of RGA. 361 */ 362 IM_API const char* querystring(int name); 363 364 /* 365 * check RGA basic information, supported resolution, supported format, etc. 366 * 367 * @param src 368 * @param dst 369 * @param src_rect 370 * @param dst_rect 371 * @param mode_usage 372 * 373 * @returns no error or else negative error code. 374 */ 375 #define imcheck(src, dst, src_rect, dst_rect, ...) \ 376 do { \ 377 IM_STATUS ret = IM_STATUS_NOERROR; \ 378 rga_buffer_t pat; \ 379 im_rect pat_rect; \ 380 int tmp = memset_s(&pat, 0, sizeof(rga_buffer_t), 0); \ 381 if (!tmp) { \ 382 printf("memset fail %d\n", tmp); \ 383 } \ 384 tmp = memset_s(&pat_rect, 0, sizeof(im_rect), 0); \ 385 if (!tmp) { \ 386 printf("memset fail %d\n", tmp); \ 387 } \ 388 int args[] = {__VA_ARGS__}; \ 389 int argc = sizeof(args)/sizeof(int); \ 390 if (argc == 0) { \ 391 ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, 0); \ 392 } else if (argc == 1) { \ 393 ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, args[0]); \ 394 } else { \ 395 ret = IM_STATUS_FAILED; \ 396 printf("check failed\n"); \ 397 } \ 398 ret; \ 399 } while (0) 400 #define imcheck_composite(src, dst, pat, src_rect, dst_rect, pat_rect, ...) \ 401 do { \ 402 IM_STATUS ret = IM_STATUS_NOERROR; \ 403 int args[] = {__VA_ARGS__}; \ 404 int argc = sizeof(args)/sizeof(int); \ 405 if (argc == 0) { \ 406 ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, 0); \ 407 } else if (argc == 1) { \ 408 ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, args[0]); \ 409 } else { \ 410 ret = IM_STATUS_FAILED; \ 411 printf("check failed\n"); \ 412 } \ 413 ret; \ 414 } while (0) 415 IM_API IM_STATUS imcheck_t(const rga_buffer_t src, const rga_buffer_t dst, const rga_buffer_t pat, 416 const im_rect src_rect, const im_rect dst_rect, 417 const im_rect pat_rect, const int mdoe_usage); 418 419 /* 420 * Resize 421 * 422 * @param src 423 * @param dst 424 * @param fx 425 * @param fy 426 * @param interpolation 427 * @param sync 428 * wait until operation complete 429 * 430 * @returns success or else negative error code. 431 */ 432 #define imresize(src, dst, ...) \ 433 do { \ 434 IM_STATUS ret = IM_STATUS_SUCCESS; \ 435 double args[] = {__VA_ARGS__}; \ 436 int argc = sizeof(args)/sizeof(double); \ 437 if (argc == 0) { \ 438 ret = imresize_t(src, dst, 0, 0, INTER_LINEAR, 1); \ 439 } else if (argc == 2) { \ 440 ret = imresize_t(src, dst, args[0], args[1], INTER_LINEAR, 1); \ 441 } else if (argc == 3) { \ 442 ret = imresize_t(src, dst, args[0], args[1], (int)args[2], 1); \ 443 } else if (argc == 4) { \ 444 ret = imresize_t(src, dst, args[0], args[1], (int)args[2], (int)args[3]); \ 445 } else { \ 446 ret = IM_STATUS_INVALID_PARAM; \ 447 printf("invalid parameter\n"); \ 448 } \ 449 ret; \ 450 } while (0) 451 452 #define impyramid(src, dst, direction) \ 453 imresize_t(src, \ 454 dst, \ 455 (direction) == IM_UP_SCALE ? (0.5) : (2), \ 456 (direction) == IM_UP_SCALE ? (0.5) : (2), \ 457 INTER_LINEAR, 1) 458 459 IM_API IM_STATUS imresize_t(const rga_buffer_t src, rga_buffer_t dst, double fx, 460 double fy, int interpolation, int sync); 461 462 /* 463 * Crop 464 * 465 * @param src 466 * @param dst 467 * @param rect 468 * @param sync 469 * wait until operation complete 470 * 471 * @returns success or else negative error code. 472 */ 473 #define imcrop(src, dst, rect, ...) \ 474 do { \ 475 IM_STATUS ret = IM_STATUS_SUCCESS; \ 476 int args[] = {__VA_ARGS__}; \ 477 int argc = sizeof(args)/sizeof(int); \ 478 if (argc == 0) { \ 479 ret = imcrop_t(src, dst, rect, 1); \ 480 } else if (argc == 1) { \ 481 ret = imcrop_t(src, dst, rect, args[0]); \ 482 } else { \ 483 ret = IM_STATUS_INVALID_PARAM; \ 484 printf("invalid parameter\n"); \ 485 } \ 486 ret; \ 487 } while (0) 488 489 IM_API IM_STATUS imcrop_t(const rga_buffer_t src, rga_buffer_t dst, im_rect rect, int sync); 490 491 /* 492 * rotation 493 * 494 * @param src 495 * @param dst 496 * @param rotation 497 * IM_HAL_TRANSFORM_ROT_90 498 * IM_HAL_TRANSFORM_ROT_180 499 * IM_HAL_TRANSFORM_ROT_270 500 * @param sync 501 * wait until operation complete 502 * 503 * @returns success or else negative error code. 504 */ 505 #define imrotate(src, dst, rotation, ...) \ 506 do { \ 507 IM_STATUS ret = IM_STATUS_SUCCESS; \ 508 int args[] = {__VA_ARGS__}; \ 509 int argc = sizeof(args)/sizeof(int); \ 510 if (argc == 0) { \ 511 ret = imrotate_t(src, dst, rotation, 1); \ 512 } else if (argc == 1) { \ 513 ret = imrotate_t(src, dst, rotation, args[0]); \ 514 } else { \ 515 ret = IM_STATUS_INVALID_PARAM; \ 516 printf("invalid parameter\n"); \ 517 } \ 518 ret; \ 519 } while (0) 520 521 IM_API IM_STATUS imrotate_t(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync); 522 523 /* 524 * flip 525 * 526 * @param src 527 * @param dst 528 * @param mode 529 * IM_HAL_TRANSFORM_FLIP_H 530 * IM_HAL_TRANSFORM_FLIP_V 531 * @param sync 532 * wait until operation complete 533 * 534 * @returns success or else negative error code. 535 */ 536 #define imflip(src, dst, mode, ...) \ 537 do { \ 538 IM_STATUS ret = IM_STATUS_SUCCESS; \ 539 int args[] = {__VA_ARGS__}; \ 540 int argc = sizeof(args)/sizeof(int); \ 541 if (argc == 0) { \ 542 ret = imflip_t(src, dst, mode, 1); \ 543 } else if (argc == 1) { \ 544 ret = imflip_t(src, dst, mode, args[0]); \ 545 } else { \ 546 ret = IM_STATUS_INVALID_PARAM; \ 547 printf("invalid parameter\n"); \ 548 } \ 549 ret; \ 550 } while (0) 551 552 IM_API IM_STATUS imflip_t (const rga_buffer_t src, rga_buffer_t dst, int mode, int sync); 553 554 /* 555 * fill/reset/draw 556 * 557 * @param src 558 * @param dst 559 * @param rect 560 * @param color 561 * @param sync 562 * wait until operation complete 563 * 564 * @returns success or else negative error code. 565 */ 566 #define imfill(buf, rect, color, ...) \ 567 ( { \ 568 IM_STATUS ret = IM_STATUS_SUCCESS; \ 569 int args[] = {__VA_ARGS__}; \ 570 int argc = sizeof(args)/sizeof(int); \ 571 if (argc == 0) { \ 572 ret = imfill_t(buf, rect, color, 1); \ 573 } else if (argc == 1) { \ 574 ret = imfill_t(buf, rect, color, args[0]); \ 575 } else { \ 576 ret = IM_STATUS_INVALID_PARAM; \ 577 printf("invalid parameter\n"); \ 578 } \ 579 ret; \ 580 }) 581 582 #define imreset(buf, rect, color, ...) \ 583 do { \ 584 IM_STATUS ret = IM_STATUS_SUCCESS; \ 585 int args[] = {__VA_ARGS__}; \ 586 int argc = sizeof(args)/sizeof(int); \ 587 if (argc == 0) { \ 588 ret = imfill_t(buf, rect, color, 1); \ 589 } else if (argc == 1) { \ 590 ret = imfill_t(buf, rect, color, args[0]); \ 591 } else { \ 592 ret = IM_STATUS_INVALID_PARAM; \ 593 printf("invalid parameter\n"); \ 594 } \ 595 ret; \ 596 } while (0) 597 598 #define imdraw(buf, rect, color, ...) \ 599 do { \ 600 IM_STATUS ret = IM_STATUS_SUCCESS; \ 601 int args[] = {__VA_ARGS__}; \ 602 int argc = sizeof(args)/sizeof(int); \ 603 if (argc == 0) { \ 604 ret = imfill_t(buf, rect, color, 1); \ 605 } else if (argc == 1) { \ 606 ret = imfill_t(buf, rect, color, args[0]); \ 607 } else { \ 608 ret = IM_STATUS_INVALID_PARAM; \ 609 printf("invalid parameter\n"); \ 610 } \ 611 ret; \ 612 } while (0) 613 IM_API IM_STATUS imfill_t(rga_buffer_t dst, im_rect rect, int color, int sync); 614 615 /* 616 * palette 617 * 618 * @param src 619 * @param dst 620 * @param lut 621 * @param sync 622 * wait until operation complete 623 * 624 * @returns success or else negative error code. 625 */ 626 #define impalette(src, dst, lut, ...) \ 627 do { \ 628 IM_STATUS ret = IM_STATUS_SUCCESS; \ 629 int args[] = {__VA_ARGS__}; \ 630 int argc = sizeof(args)/sizeof(int); \ 631 if (argc == 0) { \ 632 ret = impalette_t(src, dst, lut, 1); \ 633 } else if (argc == 1) { \ 634 ret = impalette_t(src, dst, lut, args[0]); \ 635 } else { \ 636 ret = IM_STATUS_INVALID_PARAM; \ 637 printf("invalid parameter\n"); \ 638 } \ 639 ret; \ 640 } while (0) 641 IM_API IM_STATUS impalette_t(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t lut, int sync); 642 643 /* 644 * translate 645 * 646 * @param src 647 * @param dst 648 * @param x 649 * @param y 650 * @param sync 651 * wait until operation complete 652 * 653 * @returns success or else negative error code. 654 */ 655 #define imtranslate(src, dst, x, y, ...) \ 656 do { \ 657 IM_STATUS ret = IM_STATUS_SUCCESS; \ 658 int args[] = {__VA_ARGS__}; \ 659 int argc = sizeof(args)/sizeof(int); \ 660 if (argc == 0) { \ 661 ret = imtranslate_t(src, dst, x, y, 1); \ 662 } else if (argc == 1) { \ 663 ret = imtranslate_t(src, dst, x, y, args[0]); \ 664 } else { \ 665 ret = IM_STATUS_INVALID_PARAM; \ 666 printf("invalid parameter\n"); \ 667 } \ 668 ret; \ 669 } while (0) 670 IM_API IM_STATUS imtranslate_t(const rga_buffer_t src, rga_buffer_t dst, int x, int y, int sync); 671 672 /* 673 * copy 674 * 675 * @param src 676 * @param dst 677 * @param sync 678 * wait until operation complete 679 * 680 * @returns success or else negative error code. 681 */ 682 #define imcopy(src, dst, ...) \ 683 ( { \ 684 IM_STATUS ret = IM_STATUS_SUCCESS; \ 685 int args[] = {__VA_ARGS__}; \ 686 int argc = sizeof(args)/sizeof(int); \ 687 if (argc == 0) { \ 688 ret = imcopy_t(src, dst, 1); \ 689 } else if (argc == 1) { \ 690 ret = imcopy_t(src, dst, args[0]); \ 691 } else { \ 692 ret = IM_STATUS_INVALID_PARAM; \ 693 printf("invalid parameter\n"); \ 694 } \ 695 ret; \ 696 }) 697 698 IM_API IM_STATUS imcopy_t(const rga_buffer_t src, rga_buffer_t dst, int sync); 699 700 /* 701 * blend (SRC + DST -> DST or SRCA + SRCB -> DST) 702 * 703 * @param srcA 704 * @param srcB can be NULL. 705 * @param dst 706 * @param mode 707 * IM_ALPHA_BLEND_MODE 708 * @param sync 709 * wait until operation complete 710 * 711 * @returns success or else negative error code. 712 */ 713 #define imblend(srcA, dst, ...) \ 714 do { \ 715 IM_STATUS ret = IM_STATUS_SUCCESS; \ 716 rga_buffer_t srcB; \ 717 int tmp = memset_s(&srcB, 0x00, sizeof(rga_buffer_t), 0x00,); \ 718 if (!tmp) { \ 719 printf("memset fail %d\n", tmp); \ 720 } \ 721 int args[] = {__VA_ARGS__}; \ 722 int argc = sizeof(args)/sizeof(int); \ 723 if (argc == 0) { \ 724 ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \ 725 } else if (argc == 1) { \ 726 ret = imblend_t(srcA, srcB, dst, args[0], 1); \ 727 } else if (argc == 2) { \ 728 ret = imblend_t(srcA, srcB, dst, args[0], args[1]); \ 729 } else { \ 730 ret = IM_STATUS_INVALID_PARAM; \ 731 printf("invalid parameter\n"); \ 732 } \ 733 ret; \ 734 } while (0) 735 #define imcomposite(srcA, srcB, dst, ...) \ 736 do { \ 737 IM_STATUS ret = IM_STATUS_SUCCESS; \ 738 int args[] = {__VA_ARGS__}; \ 739 int argc = sizeof(args)/sizeof(int); \ 740 if (argc == 0) { \ 741 ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \ 742 } else if (argc == 1) { \ 743 ret = imblend_t(srcA, srcB, dst, args[0], 1); \ 744 } else if (argc == 2) { \ 745 ret = imblend_t(srcA, srcB, dst, args[0], args[1]); \ 746 } else { \ 747 ret = IM_STATUS_INVALID_PARAM; \ 748 printf("invalid parameter\n"); \ 749 } \ 750 ret; \ 751 } while (0) 752 IM_API IM_STATUS imblend_t(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode, int sync); 753 754 /* 755 * color key 756 * 757 * @param src 758 * @param dst 759 * @param colorkey_range 760 * max color 761 * min color 762 * @param sync 763 * wait until operation complete 764 * 765 * @returns success or else negative error code. 766 */ 767 #define imcolorkey(src, dst, range, ...) \ 768 do { \ 769 IM_STATUS ret = IM_STATUS_SUCCESS; \ 770 int args[] = {__VA_ARGS__}; \ 771 int argc = sizeof(args)/sizeof(int); \ 772 if (argc == 0) { \ 773 ret = imcolorkey_t(src, dst, range, IM_ALPHA_COLORKEY_NORMAL, 1); \ 774 } else if (argc == 1) { \ 775 ret = imcolorkey_t(src, dst, range, args[0], 1); \ 776 } else if (argc == 2) { \ 777 ret = imcolorkey_t(src, dst, range, args[0], args[1]); \ 778 } else { \ 779 ret = IM_STATUS_INVALID_PARAM; \ 780 printf("invalid parameter\n"); \ 781 } \ 782 ret; \ 783 } while (0) 784 IM_API IM_STATUS imcolorkey_t(const rga_buffer_t src, rga_buffer_t dst, im_colorkey_range range, int mode, int sync); 785 786 /* 787 * format convert 788 * 789 * @param src 790 * @param dst 791 * @param sfmt 792 * @param dfmt 793 * @param mode 794 * color space mode: IM_COLOR_SPACE_MODE 795 * @param sync 796 * wait until operation complete 797 * 798 * @returns success or else negative error code. 799 */ 800 #define imcvtcolor(src, dst, sfmt, dfmt, ...) \ 801 do { \ 802 IM_STATUS ret = IM_STATUS_SUCCESS; \ 803 int args[] = {__VA_ARGS__}; \ 804 int argc = sizeof(args)/sizeof(int); \ 805 if (argc == 0) { \ 806 ret = imcvtcolor_t(src, dst, sfmt, dfmt, IM_COLOR_SPACE_DEFAULT, 1); \ 807 } else if (argc == 1) { \ 808 ret = imcvtcolor_t(src, dst, sfmt, dfmt, args[0], 1); \ 809 } else if (argc == 2) { \ 810 ret = imcvtcolor_t(src, dst, sfmt, dfmt, args[0], args[1]); \ 811 } else { \ 812 ret = IM_STATUS_INVALID_PARAM; \ 813 printf("invalid parameter\n"); \ 814 } \ 815 ret; \ 816 } while (0) 817 818 IM_API IM_STATUS imcvtcolor_t(rga_buffer_t src, rga_buffer_t dst, int sfmt, int dfmt, int mode, int sync); 819 820 /* 821 * nn quantize 822 * 823 * @param src 824 * @param dst 825 * @param nninfo 826 * @param sync 827 * wait until operation complete 828 * 829 * @returns success or else negative error code. 830 */ 831 #define imquantize(src, dst, nn_info, ...) \ 832 do { \ 833 IM_STATUS ret = IM_STATUS_SUCCESS; \ 834 int args[] = {__VA_ARGS__}; \ 835 int argc = sizeof(args)/sizeof(int); \ 836 if (argc == 0) { \ 837 ret = imquantize_t(src, dst, nn_info, 1); \ 838 } else if (argc == 1) { \ 839 ret = imquantize_t(src, dst, nn_info, args[0]); \ 840 } else { \ 841 ret = IM_STATUS_INVALID_PARAM; \ 842 printf("invalid parameter\n"); \ 843 } \ 844 ret; \ 845 } while (0) 846 847 IM_API IM_STATUS imquantize_t(const rga_buffer_t src, rga_buffer_t dst, im_nn_t nn_info, int sync); 848 849 /* 850 * ROP 851 * 852 * @param src 853 * @param dst 854 * @param rop_code 855 * @param sync 856 * wait until operation complete 857 * 858 * @returns success or else negative error code. 859 */ 860 #define imrop(src, dst, rop_code, ...) \ 861 do { \ 862 IM_STATUS ret = IM_STATUS_SUCCESS; \ 863 int args[] = {__VA_ARGS__}; \ 864 int argc = sizeof(args)/sizeof(int); \ 865 if (argc == 0) { \ 866 ret = imrop_t(src, dst, rop_code, 1); \ 867 } else if (argc == 1) { \ 868 ret = imrop_t(src, dst, rop_code, args[0]); \ 869 } else { \ 870 ret = IM_STATUS_INVALID_PARAM; \ 871 printf("invalid parameter\n"); \ 872 } \ 873 ret; \ 874 } while (0) 875 IM_API IM_STATUS imrop_t(const rga_buffer_t src, rga_buffer_t dst, int rop_code, int sync); 876 877 /* 878 * process 879 * 880 * @param src 881 * @param dst 882 * @param usage 883 * @param ... 884 * wait until operation complete 885 * 886 * @returns success or else negative error code. 887 */ 888 IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 889 im_rect srect, im_rect drect, im_rect prect, int usage); 890 891 /* 892 * block until all execution is complete 893 * 894 * @returns success or else negative error code. 895 */ 896 IM_API IM_STATUS imsync(void); 897 898 #ifdef __cplusplus 899 } 900 #endif 901 #endif /* _im2d_h_ */ 902 903