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 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/types.h>
24 #include <math.h>
25 #include <fcntl.h>
26 #include <memory.h>
27 #include <unistd.h>
28 #include <sys/time.h>
29
30 #ifdef ANDROID
31 #include <ui/GraphicBuffer.h>
32 #endif
33
34 #include "im2d.hpp"
35 #include "RockchipRga.h"
36 #include "RgaUtils.h"
37 #include "args.h"
38
39 #define ERROR -1
40
41 /********** SrcInfo set **********/
42 #define SRC_WIDTH 1280
43 #define SRC_HEIGHT 720
44
45 #ifdef ANDROID
46 #define SRC_FORMAT HAL_PIXEL_FORMAT_RGBA_8888
47 #endif
48 #ifdef LINUX
49 #define SRC_FORMAT RK_FORMAT_RGBA_8888
50 #endif
51 /********** DstInfo set **********/
52 #define DST_WIDTH 1280
53 #define DST_HEIGHT 720
54
55 #ifdef ANDROID
56 #define DST_FORMAT HAL_PIXEL_FORMAT_RGBA_8888
57 #endif
58 #ifdef LINUX
59 #define DST_FORMAT RK_FORMAT_RGBA_8888
60 #endif
61
62 struct timeval start, end;
63 long usec1;
64
65 #ifdef ANDROID
66 enum {
67 FILL_BUFF = 0,
68 EMPTY_BUFF = 1
69 };
70
71 /*
72 * In order to be compatible with different android versions,
73 * some gralloc usage is defined here.
74 * The correct usage should be to refer to the corresponding header file:
75 * Android 12 and above: #include "hardware/gralloc_rockchip.h"
76 * Android 11 and below: #include "hardware/gralloc.h"
77 */
78 #define GRALLOC_USAGE_PRIVATE_11 (1ULL << 56)
79 #define RK_GRALLOC_USAGE_WITHIN_4G GRALLOC_USAGE_PRIVATE_11
80 #define RK_GRALLOC_USAGE_RGA_ACCESS RK_GRALLOC_USAGE_WITHIN_4G
81
GraphicBuffer_Init(int width,int height,int format)82 sp<GraphicBuffer> GraphicBuffer_Init(int width, int height,int format) {
83 uint64_t usage = 0;
84
85 /* cacheable */
86 // usage |= GRALLOC_USAGE_SW_READ_OFTEN;
87 usage |= RK_GRALLOC_USAGE_WITHIN_4G;
88
89 sp<GraphicBuffer> gb(new GraphicBuffer(width, height, format, 0, usage));
90
91 if (gb->initCheck()) {
92 printf("GraphicBuffer check error : %s\n",strerror(errno));
93 return NULL;
94 } else
95 printf("GraphicBuffer check %s \n","ok");
96
97 return gb;
98 }
99
100 /********** write data to buffer or init buffer**********/
GraphicBuffer_Fill(sp<GraphicBuffer> gb,int flag,int index)101 int GraphicBuffer_Fill(sp<GraphicBuffer> gb, int flag, int index) {
102 int ret;
103 char* buf = NULL;
104 ret = gb->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)&buf);
105
106 if (ret) {
107 printf("lock buffer error : %s\n",strerror(errno));
108 return ERROR;
109 } else
110 printf("lock buffer %s \n","ok");
111
112 if(flag)
113 memset(buf,0x00,gb->getPixelFormat()*gb->getWidth()*gb->getHeight());
114 else {
115 ret = get_buf_from_file(buf, gb->getPixelFormat(), gb->getWidth(), gb->getHeight(), index);
116 if (!ret)
117 printf("open file %s \n", "ok");
118 else {
119 printf ("open file %s \n", "fault");
120 return ERROR;
121 }
122 }
123
124 ret = gb->unlock();
125 if (ret) {
126 printf("unlock buffer error : %s\n",strerror(errno));
127 return ERROR;
128 } else
129 printf("unlock buffer %s \n","ok");
130
131 return 0;
132 }
133
134 #if USE_AHARDWAREBUFFER
AHardwareBuffer_Init(int width,int height,int format,AHardwareBuffer ** outBuffer)135 int AHardwareBuffer_Init(int width, int height, int format, AHardwareBuffer** outBuffer) {
136 sp<GraphicBuffer> gbuffer;
137 gbuffer = GraphicBuffer_Init(width, height, format);
138 if(gbuffer == NULL) {
139 return ERROR;
140 }
141
142 *outBuffer = reinterpret_cast<AHardwareBuffer*>(gbuffer.get());
143 // Ensure the buffer doesn't get destroyed when the sp<> goes away.
144 AHardwareBuffer_acquire(*outBuffer);
145 printf("AHardwareBuffer init ok!\n");
146 return 0;
147 }
148
AHardwareBuffer_Fill(AHardwareBuffer ** buffer,int flag,int index)149 int AHardwareBuffer_Fill(AHardwareBuffer** buffer, int flag, int index) {
150 sp<GraphicBuffer> gbuffer;
151
152 gbuffer = reinterpret_cast<GraphicBuffer*>(*buffer);
153
154 if(ERROR == GraphicBuffer_Fill(gbuffer, flag, index)) {
155 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
156 return ERROR;
157 }
158
159 *buffer = reinterpret_cast<AHardwareBuffer*>(gbuffer.get());
160 // Ensure the buffer doesn't get destroyed when the sp<> goes away.
161
162 AHardwareBuffer_acquire(*buffer);
163 printf("AHardwareBuffer %s ok!\n", flag==0?"fill":"empty");
164 return 0;
165 }
166
AHardwareBuffer_Deinit(AHardwareBuffer * buffer)167 void AHardwareBuffer_Deinit(AHardwareBuffer* buffer) {
168 AHardwareBuffer_release(buffer);
169 }
170
171 #endif
172 #endif
173
main(int argc,char * argv[])174 int main(int argc, char* argv[]) {
175 int ret = 0, while_time = 0;
176 int parm_data[MODE_MAX] = {0};
177
178 int COLOR;
179 IM_USAGE ROTATE;
180 IM_USAGE FLIP;
181
182 int MODE;
183 IM_INFORMATION IM_INFO;
184 IM_STATUS STATUS;
185
186 im_rect src_rect;
187 im_rect dst_rect;
188 rga_buffer_t src;
189 rga_buffer_t dst;
190 rga_buffer_handle_t src_handle;
191 rga_buffer_handle_t dst_handle;
192
193 #ifdef ANDROID
194 #if USE_AHARDWAREBUFFER
195 AHardwareBuffer* src_buf = nullptr;
196 AHardwareBuffer* dst_buf = nullptr;
197 #else
198 sp<GraphicBuffer> src_buf;
199 sp<GraphicBuffer> dst_buf;
200 #endif
201 #endif
202
203 #ifdef LINUX
204 char* src_buf = NULL;
205 char* dst_buf = NULL;
206 #endif
207
208 memset(&src_rect, 0, sizeof(src_rect));
209 memset(&dst_rect, 0, sizeof(dst_rect));
210 memset(&src, 0, sizeof(src));
211 memset(&dst, 0, sizeof(dst));
212
213 MODE = readArguments(argc, argv, parm_data);
214 if (MODE & WHILE_FLAG) {
215 /* Remove flag of MODE_WHILE. */
216 MODE &= ~WHILE_FLAG;
217
218 while_time = parm_data[MODE_WHILE];
219 }
220 printf("MODE = %x\n", MODE);
221 if(MODE_NONE == MODE) {
222 printf("%s, Unknow RGA mode\n", __FUNCTION__);
223 return ERROR;
224 }
225
226 /********** Get parameters **********/
227 if(MODE != MODE_QUERYSTRING) {
228 #ifdef ANDROID
229 #if USE_AHARDWAREBUFFER
230 if(ERROR == AHardwareBuffer_Init(SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT, &src_buf)) {
231 printf("AHardwareBuffer init error!\n");
232 return ERROR;
233 }
234 if(ERROR == AHardwareBuffer_Init(DST_WIDTH, DST_HEIGHT, DST_FORMAT, &dst_buf)) {
235 printf("AHardwareBuffer init error!\n");
236 return ERROR;
237 }
238
239 if(ERROR == AHardwareBuffer_Fill(&src_buf, FILL_BUFF, 0)) {
240 printf("%s, write AHardwareBuffer error!\n", __FUNCTION__);
241 return -1;
242 }
243 if(MODE == MODE_BLEND || MODE == MODE_FILL) {
244 if(ERROR == AHardwareBuffer_Fill(&dst_buf, FILL_BUFF, 1)) {
245 printf("%s, write AHardwareBuffer error!\n", __FUNCTION__);
246 return ERROR;
247 }
248 } else {
249 if(ERROR == AHardwareBuffer_Fill(&dst_buf, EMPTY_BUFF, 1)) {
250 printf("%s, write AHardwareBuffer error!\n", __FUNCTION__);
251 return ERROR;
252 }
253 }
254
255 src_handle = importbuffer_AHardwareBuffer(src_buf);
256 if (src_handle <= 0) {
257 printf("Failed to import AHardwareBuffer for src channel!\n");
258 return ERROR;
259 }
260 dst_handle = importbuffer_AHardwareBuffer(dst_buf);
261 if (dst_handle <= 0) {
262 printf("Failed to import AHardwareBuffer for dst channel!\n");
263 return ERROR;
264 }
265 #else
266 src_buf = GraphicBuffer_Init(SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
267 dst_buf = GraphicBuffer_Init(DST_WIDTH, DST_HEIGHT, DST_FORMAT);
268 if (src_buf == NULL || dst_buf == NULL) {
269 printf("GraphicBuff init error!\n");
270 return ERROR;
271 }
272
273 if(ERROR == GraphicBuffer_Fill(src_buf, FILL_BUFF, 0)) {
274 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
275 return -1;
276 }
277 if(MODE == MODE_BLEND || MODE == MODE_FILL) {
278 if(ERROR == GraphicBuffer_Fill(dst_buf, FILL_BUFF, 1)) {
279 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
280 return ERROR;
281 }
282 } else {
283 if(ERROR == GraphicBuffer_Fill(dst_buf, EMPTY_BUFF, 1)) {
284 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
285 return ERROR;
286 }
287 }
288
289 src_handle = importbuffer_GraphicBuffer(src_buf);
290 if (src_handle <= 0) {
291 printf("Failed to import GraphicBuffer for src channel!\n");
292 return ERROR;
293 }
294 dst_handle = importbuffer_GraphicBuffer(dst_buf);
295 if (dst_handle <= 0) {
296 printf("Failed to import GraphicBuffer for dst channel!\n");
297 return ERROR;
298 }
299 #endif
300 #elif LINUX
301 src_buf = (char*)malloc(SRC_WIDTH*SRC_HEIGHT*get_bpp_from_format(SRC_FORMAT));
302 dst_buf = (char*)malloc(DST_WIDTH*DST_HEIGHT*get_bpp_from_format(DST_FORMAT));
303
304 ret = get_buf_from_file(src_buf, SRC_FORMAT, SRC_WIDTH, SRC_HEIGHT, 0);
305 if (!ret)
306 printf("open file\n");
307 else
308 printf ("can not open file\n");
309
310 if(MODE == MODE_BLEND || MODE == MODE_FILL) {
311 ret = get_buf_from_file(dst_buf, DST_FORMAT, DST_WIDTH, DST_HEIGHT, 1);
312 if (!ret)
313 printf("open file\n");
314 else
315 printf ("can not open file\n");
316 } else {
317 memset(dst_buf,0x00,DST_WIDTH*DST_HEIGHT*get_bpp_from_format(DST_FORMAT));
318 }
319
320 src_handle = importbuffer_virtualaddr(src_buf, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
321 if (src_handle <= 0) {
322 printf("Failed to import virtualaddr for src channel!\n");
323 return ERROR;
324 }
325 dst_handle = importbuffer_virtualaddr(dst_buf, DST_WIDTH, DST_HEIGHT, DST_FORMAT);
326 if (dst_handle <= 0) {
327 printf("Failed to import virtualaddr for dst channel!\n");
328 return ERROR;
329 }
330 #endif
331
332 src = wrapbuffer_handle(src_handle, SRC_WIDTH, SRC_HEIGHT, SRC_FORMAT);
333 dst = wrapbuffer_handle(dst_handle, DST_WIDTH, DST_HEIGHT, DST_FORMAT);
334 if(src.width == 0 || dst.width == 0) {
335 printf("%s, %s", __FUNCTION__, imStrError());
336 return ERROR;
337 }
338 }
339
340 do {
341 if (while_time) {
342 static int while_num = 1;
343 printf("This is %d time in the loop\n", while_num);
344
345 while_num++;
346 while_time--;
347 }
348 /********** Execution function according to mode **********/
349 switch(MODE) {
350 case MODE_QUERYSTRING :
351
352 IM_INFO = (IM_INFORMATION)parm_data[MODE_QUERYSTRING];
353 printf("\n%s\n", querystring(IM_INFO));
354
355 break;
356
357 case MODE_COPY : //rgaImDemo --copy
358
359 ret = imcheck(src, dst, src_rect, dst_rect);
360 if (IM_STATUS_NOERROR != ret) {
361 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
362 return -1;
363 }
364 gettimeofday(&start, NULL);
365
366 STATUS = imcopy(src, dst);
367
368 gettimeofday(&end, NULL);
369 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
370 printf("copying .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
371
372 break;
373
374 case MODE_RESIZE : //rgaImDemo --resize=up/down
375 releasebuffer_handle(dst_handle);
376 dst_handle = -1;
377
378 switch(parm_data[MODE_RESIZE]) {
379 case IM_UP_SCALE :
380 #ifdef ANDROID
381 #if USE_AHARDWAREBUFFER
382 if(ERROR == AHardwareBuffer_Init(1920, 1080, DST_FORMAT, &dst_buf)) {
383 printf("AHardwareBuffer init error!\n");
384 return ERROR;
385 }
386
387 if(ERROR == AHardwareBuffer_Fill(&dst_buf, EMPTY_BUFF, 0)) {
388 printf("%s, write AHardwareBuffer error!\n", __FUNCTION__);
389 return ERROR;
390 }
391
392 dst_handle = importbuffer_AHardwareBuffer(dst_buf);
393 if (dst_handle <= 0) {
394 printf("Failed to import AHardwareBuffer for dst channel!\n");
395 return ERROR;
396 }
397 #else
398 dst_buf = GraphicBuffer_Init(1920, 1080, DST_FORMAT);
399 if (dst_buf == NULL) {
400 printf("dst GraphicBuff init error!\n");
401 return ERROR;
402 }
403 if(ERROR == GraphicBuffer_Fill(dst_buf, EMPTY_BUFF, 1)) {
404 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
405 return ERROR;
406 }
407
408 dst_handle = importbuffer_GraphicBuffer(dst_buf);
409 if (dst_handle <= 0) {
410 printf("Failed to import GraphicBuffer for dst channel!\n");
411 return ERROR;
412 }
413 #endif
414 #elif LINUX
415 if (dst_buf != NULL) {
416 free(dst_buf);
417 dst_buf = NULL;
418 }
419 dst_buf = (char*)malloc(1920*1080*get_bpp_from_format(DST_FORMAT));
420
421 memset(dst_buf,0x00,1920*1080*get_bpp_from_format(DST_FORMAT));
422
423 dst_handle = importbuffer_virtualaddr(dst_buf, 1920, 1080, DST_FORMAT);
424 if (dst_handle <= 0) {
425 printf("Failed to import virtualaddr for dst channel!\n");
426 return ERROR;
427 }
428 #endif
429 dst = wrapbuffer_handle(dst_handle, 1920, 1080, DST_FORMAT);
430 if(dst.width == 0) {
431 printf("%s, %s\n", __FUNCTION__, imStrError());
432 return ERROR;
433 }
434
435 break;
436 case IM_DOWN_SCALE :
437
438 #ifdef ANDROID
439 #if USE_AHARDWAREBUFFER
440 if(ERROR == AHardwareBuffer_Init(720, 480, DST_FORMAT, &dst_buf)) {
441 printf("AHardwareBuffer init error!\n");
442 return ERROR;
443 }
444
445 if(ERROR == AHardwareBuffer_Fill(&dst_buf, EMPTY_BUFF, 0)) {
446 printf("%s, write AHardwareBuffer error!\n", __FUNCTION__);
447 return ERROR;
448 }
449
450 dst_handle = importbuffer_AHardwareBuffer(dst_buf);
451 if (dst_handle <= 0) {
452 printf("Failed to import AHardwareBuffer for dst channel!\n");
453 return ERROR;
454 }
455 #else
456 dst_buf = GraphicBuffer_Init(720, 480, DST_FORMAT);
457 if (dst_buf == NULL) {
458 printf("dst GraphicBuff init error!\n");
459 return ERROR;
460 }
461 if(ERROR == GraphicBuffer_Fill(dst_buf, EMPTY_BUFF, 1)) {
462 printf("%s, write Graphicbuffer error!\n", __FUNCTION__);
463 return ERROR;
464 }
465
466 dst_handle = importbuffer_GraphicBuffer(dst_buf);
467 if (dst_handle <= 0) {
468 printf("Failed to import GraphicBuffer for dst channel!\n");
469 return ERROR;
470 }
471 #endif
472 #elif LINUX
473 if (dst_buf != NULL) {
474 free(dst_buf);
475 dst_buf = NULL;
476 }
477 dst_buf = (char*)malloc(720*480*get_bpp_from_format(DST_FORMAT));
478
479 memset(dst_buf,0x00,720*480*get_bpp_from_format(DST_FORMAT));
480
481 dst_handle = importbuffer_virtualaddr(dst_buf, 720, 480, DST_FORMAT);
482 if (dst_handle <= 0) {
483 printf("Failed to import virtualaddr for dst channel!\n");
484 return ERROR;
485 }
486 #endif
487 dst = wrapbuffer_handle(dst_handle, 720, 480, DST_FORMAT);
488 if(dst.width == 0) {
489 printf("%s, %s\n", __FUNCTION__, imStrError());
490 return ERROR;
491 }
492 break;
493 }
494
495 ret = imcheck(src, dst, src_rect, dst_rect);
496 if (IM_STATUS_NOERROR != ret) {
497 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
498 return -1;
499 }
500
501 gettimeofday(&start, NULL);
502
503 STATUS = imresize(src, dst);
504
505 gettimeofday(&end, NULL);
506 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
507 printf("resizing .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
508
509 break;
510
511 case MODE_CROP : //rgaImDemo --crop
512
513 src_rect.x = 100;
514 src_rect.y = 100;
515 src_rect.width = 300;
516 src_rect.height = 300;
517
518 ret = imcheck(src, dst, src_rect, dst_rect, IM_CROP);
519 if (IM_STATUS_NOERROR != ret) {
520 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
521 return -1;
522 }
523
524 gettimeofday(&start, NULL);
525
526 STATUS = imcrop(src, dst, src_rect);
527
528 gettimeofday(&end, NULL);
529 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
530 printf("cropping .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
531
532 break;
533
534 case MODE_ROTATE : //rgaImDemo --rotate=90/180/270
535
536 ROTATE = (IM_USAGE)parm_data[MODE_ROTATE];
537
538 if (IM_HAL_TRANSFORM_ROT_90 == ROTATE || IM_HAL_TRANSFORM_ROT_270 == ROTATE) {
539 dst.width = src.height;
540 dst.height = src.width;
541 dst.wstride = src.hstride;
542 dst.hstride = src.wstride;
543 }
544
545 ret = imcheck(src, dst, src_rect, dst_rect, ROTATE);
546 if (IM_STATUS_NOERROR != ret) {
547 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
548 return -1;
549 }
550
551 gettimeofday(&start, NULL);
552
553 STATUS = imrotate(src, dst, ROTATE);
554
555 gettimeofday(&end, NULL);
556 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
557 printf("rotating .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
558
559 break;
560
561 case MODE_FLIP : //rgaImDemo --flip=H/V
562
563 FLIP = (IM_USAGE)parm_data[MODE_FLIP];
564
565 ret = imcheck(src, dst, src_rect, dst_rect);
566 if (IM_STATUS_NOERROR != ret) {
567 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
568 return -1;
569 }
570
571 gettimeofday(&start, NULL);
572
573 STATUS = imflip(src, dst, FLIP);
574
575 gettimeofday(&end, NULL);
576 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
577 printf("flipping .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
578
579 break;
580
581 case MODE_TRANSLATE : //rgaImDemo --translate
582
583 src_rect.x = 300;
584 src_rect.y = 300;
585
586 ret = imcheck(src, dst, src_rect, dst_rect);
587 if (IM_STATUS_NOERROR != ret) {
588 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
589 return -1;
590 }
591
592 gettimeofday(&start, NULL);
593
594 STATUS = imtranslate(src, dst, src_rect.x, src_rect.y);
595
596 gettimeofday(&end, NULL);
597 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
598 printf("translating .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
599
600 break;
601
602 case MODE_BLEND : //rgaImDemo --blend
603
604 ret = imcheck(src, dst, src_rect, dst_rect);
605 if (IM_STATUS_NOERROR != ret) {
606 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
607 return -1;
608 }
609
610 gettimeofday(&start, NULL);
611
612 STATUS = imblend(src, dst);
613
614 gettimeofday(&end, NULL);
615 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
616 printf("blending .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
617
618 break;
619
620 case MODE_CVTCOLOR : //rgaImDemo --cvtcolor
621
622 #ifdef ANDROID
623 src.format = HAL_PIXEL_FORMAT_RGBA_8888;
624 dst.format = HAL_PIXEL_FORMAT_YCrCb_NV12;
625 #endif
626 #ifdef LINUX
627 src.format = RK_FORMAT_RGBA_8888;
628 dst.format = RK_FORMAT_YCbCr_420_SP;
629 #endif
630
631 ret = imcheck(src, dst, src_rect, dst_rect);
632 if (IM_STATUS_NOERROR != ret) {
633 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
634 return -1;
635 }
636
637 gettimeofday(&start, NULL);
638
639 STATUS = imcvtcolor(src, dst, src.format, dst.format);
640
641 gettimeofday(&end, NULL);
642 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
643 printf("cvtcolor .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
644
645 break;
646
647 case MODE_FILL : //rgaImDemo --fill=blue/green/red
648
649 COLOR = parm_data[MODE_FILL];
650
651 dst_rect.x = 100;
652 dst_rect.y = 100;
653 dst_rect.width = 300;
654 dst_rect.height = 300;
655
656 ret = imcheck(src, dst, src_rect, dst_rect, IM_COLOR_FILL);
657 if (IM_STATUS_NOERROR != ret) {
658 printf("%d, check error! %s\n", __LINE__, imStrError((IM_STATUS)ret));
659 return -1;
660 }
661
662 gettimeofday(&start, NULL);
663
664 STATUS = imfill(dst, dst_rect, COLOR);
665
666 gettimeofday(&end, NULL);
667 usec1 = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
668 printf("filling .... cost time %ld us, %s\n", usec1, imStrError(STATUS));
669
670 break;
671
672 case MODE_NONE :
673
674 printf("%s, Unknown mode\n", __FUNCTION__);
675
676 break;
677
678 default :
679
680 printf("%s, Invalid mode\n", __FUNCTION__);
681
682 break;
683 }
684
685 if (while_time) {
686 /* 200ms */
687 usleep(200000);
688 }
689 }while(while_time);
690
691 /********** release rga buffer handle **********/
692 releasebuffer_handle(src_handle);
693 releasebuffer_handle(dst_handle);
694
695 /********** output buf data to file **********/
696 #ifdef ANDROID
697 char* outbuf = NULL;
698 #if USE_AHARDWAREBUFFER
699 sp<GraphicBuffer> gbuffer = reinterpret_cast<GraphicBuffer*>(dst_buf);
700 if (gbuffer != NULL) {
701 ret = gbuffer->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&outbuf);
702 if (ret != 0) {
703 printf("%s, %d, lock buffer failed!\n", __FUNCTION__, __LINE__);
704 return -1;
705 }
706 output_buf_data_to_file(outbuf, dst.format, dst.wstride, dst.hstride, 0);
707 ret = gbuffer->unlock();
708 if (ret != 0) {
709 printf("%s, %d, unlock buffer failed!\n", __FUNCTION__, __LINE__);
710 return -1;
711 }
712 }
713
714 AHardwareBuffer_Deinit(src_buf);
715 AHardwareBuffer_Deinit(dst_buf);
716 #else
717 if (dst_buf != NULL) {
718 ret = dst_buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN, (void**)&outbuf);
719 if (ret != 0) {
720 printf("%s, %d, lock buffer failed!\n", __FUNCTION__, __LINE__);
721 return -1;
722 }
723 output_buf_data_to_file(outbuf, dst.format, dst.wstride, dst.hstride, 0);
724 ret = dst_buf->unlock();
725 if (ret != 0) {
726 printf("%s, %d, unlock buffer failed!\n", __FUNCTION__, __LINE__);
727 return -1;
728 }
729 }
730 #endif
731 #endif
732
733 #ifdef LINUX
734 if (src_buf != NULL) {
735 free(src_buf);
736 src_buf = NULL;
737 }
738
739 if (dst_buf != NULL) {
740 output_buf_data_to_file(dst_buf, dst.format, dst.wstride, dst.hstride, 0);
741 free(dst_buf);
742 dst_buf = NULL;
743 }
744 #endif
745
746 return 0;
747 }
748
749