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