-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
122 lines (95 loc) · 3.51 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/time.h>
#include "../../libs/libge2d/include/ge2d_port.h"
#include "../../libs/libge2d/include/aml_ge2d.h"
#include "../../libs/libge2d/include/ge2d_com.h"
#include "../../libs/bmp/include/bmp.h"
int main(void) {
int ret = 0;
int64_t start, end;
int src_width = 1920;
int src_height = 1080;
int src_format = PIXEL_FORMAT_RGBA_8888;
int dst_width = 1920;
int dst_height = 1080;
int dst_format = PIXEL_FORMAT_RGBA_8888;
int op = AML_GE2D_STRETCHBLIT;
aml_ge2d_t amlge2d;
/* Prepare the struct for GE2D operation info*/
memset(&amlge2d, 0x0, sizeof(aml_ge2d_t));
memset(&(amlge2d.ge2dinfo.src_info[0]), 0, sizeof(buffer_info_t));
memset(&(amlge2d.ge2dinfo.src_info[1]), 0, sizeof(buffer_info_t));
memset(&(amlge2d.ge2dinfo.dst_info), 0, sizeof(buffer_info_t));
/* Initialize GE2D */
amlge2d.ge2dinfo.src_info[0].memtype = GE2D_CANVAS_ALLOC;
amlge2d.ge2dinfo.src_info[0].mem_alloc_type = AML_GE2D_MEM_DMABUF;
amlge2d.ge2dinfo.src_info[0].canvas_w = src_width;
amlge2d.ge2dinfo.src_info[0].canvas_h = src_height;
amlge2d.ge2dinfo.src_info[0].format = src_format;
amlge2d.ge2dinfo.src_info[0].plane_number = 4;
amlge2d.ge2dinfo.dst_info.memtype = GE2D_CANVAS_ALLOC;
amlge2d.ge2dinfo.dst_info.mem_alloc_type = AML_GE2D_MEM_DMABUF;
amlge2d.ge2dinfo.dst_info.canvas_w = dst_width;
amlge2d.ge2dinfo.dst_info.canvas_h = dst_height;
amlge2d.ge2dinfo.dst_info.format = dst_format;
amlge2d.ge2dinfo.dst_info.plane_number = 4;
amlge2d.ge2dinfo.offset = 0;
amlge2d.ge2dinfo.ge2d_op = op;
amlge2d.ge2dinfo.blend_mode = BLEND_MODE_PREMULTIPLIED;
printf("Init aml ge2d\n");
ret = aml_ge2d_init(&amlge2d);
if (ret < 0)
return ge2d_fail;
ret = aml_ge2d_mem_alloc(&amlge2d);
if (ret < 0)
goto exit;
sync_src_dmabuf_to_device(&amlge2d.ge2dinfo, 0);
if (amlge2d.src_size[0] == 0)
return 0;
ret = bmp_read(amlge2d.ge2dinfo.src_info[0].vaddr[0], "./input_rgba.bmp");
if (ret < 0)
goto exit;
/* Configure for the copy operation */
amlge2d.ge2dinfo.src_info[0].rect.x = 0;
amlge2d.ge2dinfo.src_info[0].rect.y = 0;
amlge2d.ge2dinfo.src_info[0].rect.w = src_width;
amlge2d.ge2dinfo.src_info[0].rect.h = src_height;
amlge2d.ge2dinfo.dst_info.rect.x = 0;
amlge2d.ge2dinfo.dst_info.rect.y = 0;
amlge2d.ge2dinfo.dst_info.rect.w = dst_width;
amlge2d.ge2dinfo.dst_info.rect.h = dst_height;
amlge2d.ge2dinfo.dst_info.rotation = GE2D_ROTATION_0;
amlge2d.ge2dinfo.src_info[0].layer_mode = LAYER_MODE_PREMULTIPLIED;
amlge2d.ge2dinfo.src_info[0].plane_alpha = 0xff;
start = get_cur_us();
ret = aml_ge2d_process(&amlge2d.ge2dinfo);
end = get_cur_us();
/* Check operation success */
if (ret < 0) {
printf("dmabuf err\n");
}
else {
printf("dmabuf success\n");
printf("exec time: %ld us\n", end - start);
}
sync_dst_dmabuf_to_cpu(&amlge2d.ge2dinfo);
/* Write output image */
bmp_write(amlge2d.ge2dinfo.dst_info.vaddr[0], "./output.bmp", dst_width, dst_height);
/* Clean up memory objects */
exit:
if (amlge2d.src_data[0]) {
free(amlge2d.src_data[0]);
amlge2d.src_data[0] = NULL;
}
if (amlge2d.dst_data[0]) {
free(amlge2d.dst_data[0]);
amlge2d.dst_data[0] = NULL;
}
aml_ge2d_mem_free(&amlge2d);
aml_ge2d_exit(&amlge2d);
return (0);
}