├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── build-linux_RK3588.sh ├── include ├── 3rdparty │ ├── rga │ │ └── RK3588 │ │ │ ├── include │ │ │ ├── GrallocOps.h │ │ │ ├── RgaApi.h │ │ │ ├── RgaMutex.h │ │ │ ├── RgaSingleton.h │ │ │ ├── RgaUtils.h │ │ │ ├── RockchipRga.h │ │ │ ├── drmrga.h │ │ │ ├── im2d.h │ │ │ ├── im2d.hpp │ │ │ ├── im2d_hardware.h │ │ │ ├── im2d_type.h │ │ │ ├── im2d_version.h │ │ │ └── rga.h │ │ │ └── lib │ │ │ └── Linux │ │ │ └── aarch64 │ │ │ └── librga.so │ ├── rk_mpi_mmz │ │ ├── include │ │ │ └── rk_mpi_mmz.h │ │ ├── lib │ │ │ └── Linux │ │ │ │ └── aarch64 │ │ │ │ └── libmpimmz.so │ │ └── readme.txt │ └── stb │ │ ├── stb_image.h │ │ ├── stb_image_resize.h │ │ └── stb_image_write.h ├── CameraParams.h ├── MvCameraControl.h ├── MvErrorDefine.h ├── MvISPErrorDefine.h ├── PixelType.h ├── ThreadPool.hpp ├── drm_func.h ├── librknn_api.so ├── librknnrt.so ├── postprocess.h ├── rga_func.h ├── rknnPool.hpp └── rknn_api.h ├── lib ├── libFormatConversion.so ├── libMVGigEVisionSDK.so ├── libMVGigEVisionSDK.so.3.2.2.1 ├── libMVRender.so ├── libMediaProcess.so ├── libMvCameraControl.so ├── libMvCameraControl.so.3.2.2.1 ├── libMvUsb3vTL.so └── libMvUsb3vTL.so.3.2.2.1 ├── model ├── RK3588 │ └── yolov5s_relu_tk2_RK3588_i8.rknn └── coco_80_labels_list.txt ├── performance.sh └── src ├── main.cc └── postprocess.cc /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.dylib 16 | *.dll 17 | 18 | # Fortran module files 19 | *.mod 20 | *.smod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | 33 | *.mp4 34 | /build 35 | /install -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | project(rknn_yolov5_demo) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_CXX_FLAGS "-pthread") 8 | 9 | # skip 3rd-party lib dependencies 10 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--allow-shlib-undefined") 11 | 12 | # install target and libraries 13 | set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/rknn_yolov5_demo_${CMAKE_SYSTEM_NAME}) 14 | 15 | set(CMAKE_SKIP_INSTALL_RPATH FALSE) 16 | set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) 17 | set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") 18 | 19 | # rknn api 20 | set(RKNN_API_PATH ${CMAKE_SOURCE_DIR}/../../runtime/RK3588/${CMAKE_SYSTEM_NAME}/librknn_api) 21 | set(LIB_ARCH aarch64) 22 | set(RKNN_RT_LIB ${CMAKE_SOURCE_DIR}/include/librknnrt.so) 23 | include_directories(${RKNN_API_PATH}/include) 24 | include_directories(${CMAKE_SOURCE_DIR}/include/3rdparty) 25 | 26 | # opencv 27 | find_package(OpenCV REQUIRED) 28 | 29 | #rga 30 | set(RGA_PATH ${CMAKE_SOURCE_DIR}/include/3rdparty/rga/RK3588) 31 | set(LIB_ARCH aarch64) 32 | set(RGA_LIB ${RGA_PATH}/lib/Linux/${LIB_ARCH}/librga.so) 33 | include_directories( ${RGA_PATH}/include) 34 | set(CMAKE_INSTALL_RPATH "lib") 35 | 36 | # MVS 37 | include_directories( ${CMAKE_SOURCE_DIR}/include) 38 | link_directories(${CMAKE_SOURCE_DIR}/lib) 39 | set(MVS_LIB ${CMAKE_SOURCE_DIR}/lib/MvCameraControl.so) 40 | 41 | 42 | # rknn_yolov5_demo 43 | include_directories( ${CMAKE_SOURCE_DIR}/include) 44 | 45 | add_executable(rknn_yolov5_demo 46 | src/main.cc 47 | src/postprocess.cc 48 | ) 49 | 50 | target_link_libraries(rknn_yolov5_demo 51 | ${RKNN_RT_LIB} 52 | ${RGA_LIB} 53 | ${OpenCV_LIBS} 54 | MvCameraControl 55 | ) 56 | 57 | 58 | # install target and libraries 59 | set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/install/rknn_yolov5_demo_${CMAKE_SYSTEM_NAME}) 60 | install(TARGETS rknn_yolov5_demo DESTINATION ./) 61 | install(PROGRAMS ${RKNN_RT_LIB} DESTINATION lib) 62 | install(PROGRAMS ${RGA_LIB} DESTINATION lib) 63 | install(DIRECTORY model DESTINATION ./) 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | * 此仓库为c++实现, 实时目标检测使用yolov5网络,目标检测代码改自:https://github.com/leafqycc/rknn-cpp-Multithreading 3 | * 所用摄像头为海康hikvision千兆以太网口工业相机 MV-CA020-10GM:200万像素 CMOS 黑白 GigE 4 | 5 | # 更新说明 6 | * 无 7 | 8 | # 使用说明 9 | ### 演示 10 | * 系统需安装有**OpenCV** **海康工业相机SDK** 11 | * 可切换至root用户运行performance.sh定频提高性能和稳定性 12 | * 编译完成后进入install运行命令./rknn_yolov5_demo **模型所在路径** 13 | 14 | ### 部署应用 15 | * 修改include/rknnPool.hpp中的rknn_lite类 16 | * 修改inclue/rknnPool.hpp中的rknnPool类的构造函数 17 | 18 | # 多线程模型帧率测试 19 | * 使用performance.sh进行CPU/NPU定频尽量减少误差 20 | * 测试模型来源: 21 | * [yolov5s_relu_tk2_RK3588_i8.rknn](https://github.com/airockchip/rknn_model_zoo/tree/main/models) 22 | 23 | 24 | # Acknowledgements 25 | * https://github.com/rockchip-linux/rknpu2 26 | * https://github.com/senlinzhan/dpool 27 | * https://github.com/ultralytics/yolov5 28 | * https://github.com/airockchip/rknn_model_zoo 29 | * https://github.com/rockchip-linux/rknn-toolkit2 30 | -------------------------------------------------------------------------------- /build-linux_RK3588.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | # TARGET_SOC="rk3588" 4 | GCC_COMPILER=aarch64-linux-gnu 5 | 6 | export LD_LIBRARY_PATH=${TOOL_CHAIN}/lib64:$LD_LIBRARY_PATH 7 | export CC=${GCC_COMPILER}-gcc 8 | export CXX=${GCC_COMPILER}-g++ 9 | 10 | ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd ) 11 | 12 | # build 13 | BUILD_DIR=${ROOT_PWD}/build/build_linux_aarch64 14 | 15 | if [ ! -d "${BUILD_DIR}" ]; then 16 | mkdir -p ${BUILD_DIR} 17 | fi 18 | 19 | cd ${BUILD_DIR} 20 | cmake ../.. -DCMAKE_SYSTEM_NAME=Linux 21 | make -j8 22 | make install 23 | cd - 24 | 25 | # 运行demo 26 | # cd install/rknn_yolov5_demo_Linux/ && ./rknn_yolov5_demo ./model/RK3588/yolov5s_relu_tk2_RK3588_i8.rknn 0 27 | cd install/rknn_yolov5_demo_Linux/ && ./rknn_yolov5_demo ./model/RK3588/yolov5s_relu_tk2_RK3588_i8.rknn 28 | 29 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/GrallocOps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _rk_graphic_buffer_h_ 20 | #define _rk_graphic_buffer_h_ 21 | 22 | #ifdef ANDROID 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | #include "drmrga.h" 49 | #include "rga.h" 50 | 51 | // ------------------------------------------------------------------------------- 52 | int RkRgaGetHandleFd(buffer_handle_t handle, int *fd); 53 | int RkRgaGetHandleAttributes(buffer_handle_t handle, 54 | std::vector *attrs); 55 | int RkRgaGetHandleMapAddress(buffer_handle_t handle, 56 | void **buf); 57 | #endif //Android 58 | 59 | #endif //_rk_graphic_buffer_h_ 60 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/RgaApi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 _rockchip_rga_c_h_ 19 | #define _rockchip_rga_c_h_ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | #include "drmrga.h" 34 | #include "rga.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C"{ 38 | #endif 39 | 40 | /* 41 | * Compatible with the old version of C interface.The new 42 | * version of the C interface no longer requires users to 43 | * initialize rga, so RgaInit and RgaDeInit are just for 44 | * compatibility with the old C interface, so please do 45 | * not use ctx, because it is usually a NULL. 46 | */ 47 | #define RgaInit(ctx) ({ \ 48 | int ret = 0; \ 49 | ret = c_RkRgaInit(); \ 50 | c_RkRgaGetContext(ctx); \ 51 | ret;\ 52 | }) 53 | #define RgaDeInit(ctx) { \ 54 | (void)ctx; /* unused */ \ 55 | c_RkRgaDeInit(); \ 56 | } 57 | #define RgaBlit(...) c_RkRgaBlit(__VA_ARGS__) 58 | #define RgaCollorFill(...) c_RkRgaColorFill(__VA_ARGS__) 59 | #define RgaFlush() c_RkRgaFlush() 60 | 61 | int c_RkRgaInit(); 62 | void c_RkRgaDeInit(); 63 | void c_RkRgaGetContext(void **ctx); 64 | int c_RkRgaBlit(rga_info_t *src, rga_info_t *dst, rga_info_t *src1); 65 | int c_RkRgaColorFill(rga_info_t *dst); 66 | int c_RkRgaFlush(); 67 | 68 | #ifndef ANDROID /* linux */ 69 | int c_RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp); 70 | int c_RkRgaGetAllocBufferCache(bo_t *bo_info, int width, int height, int bpp); 71 | int c_RkRgaGetMmap(bo_t *bo_info); 72 | int c_RkRgaUnmap(bo_t *bo_info); 73 | int c_RkRgaFree(bo_t *bo_info); 74 | int c_RkRgaGetBufferFd(bo_t *bo_info, int *fd); 75 | #endif /* #ifndef ANDROID */ 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* #ifndef _rockchip_rga_c_h_ */ 82 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/RgaMutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 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 | 19 | 20 | #ifndef _LIBS_RGA_MUTEX_H 21 | #define _LIBS_RGA_MUTEX_H 22 | 23 | #ifndef ANDROID 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | 31 | // Enable thread safety attributes only with clang. 32 | // The attributes can be safely erased when compiling with other compilers. 33 | #if defined(__clang__) && (!defined(SWIG)) 34 | #define THREAD_ANNOTATION_ATTRIBUTE__(x) __attribute__((x)) 35 | #else 36 | #define THREAD_ANNOTATION_ATTRIBUTE__(x) // no-op 37 | #endif 38 | 39 | #define CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(capability(x)) 40 | 41 | #define SCOPED_CAPABILITY THREAD_ANNOTATION_ATTRIBUTE__(scoped_lockable) 42 | 43 | #define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x)) 44 | 45 | #define PT_GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(pt_guarded_by(x)) 46 | 47 | #define ACQUIRED_BEFORE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_before(__VA_ARGS__)) 48 | 49 | #define ACQUIRED_AFTER(...) THREAD_ANNOTATION_ATTRIBUTE__(acquired_after(__VA_ARGS__)) 50 | 51 | #define REQUIRES(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__)) 52 | 53 | #define REQUIRES_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_shared_capability(__VA_ARGS__)) 54 | 55 | #define ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_capability(__VA_ARGS__)) 56 | 57 | #define ACQUIRE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(acquire_shared_capability(__VA_ARGS__)) 58 | 59 | #define RELEASE(...) THREAD_ANNOTATION_ATTRIBUTE__(release_capability(__VA_ARGS__)) 60 | 61 | #define RELEASE_SHARED(...) THREAD_ANNOTATION_ATTRIBUTE__(release_shared_capability(__VA_ARGS__)) 62 | 63 | #define TRY_ACQUIRE(...) THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_capability(__VA_ARGS__)) 64 | 65 | #define TRY_ACQUIRE_SHARED(...) \ 66 | THREAD_ANNOTATION_ATTRIBUTE__(try_acquire_shared_capability(__VA_ARGS__)) 67 | 68 | #define EXCLUDES(...) THREAD_ANNOTATION_ATTRIBUTE__(locks_excluded(__VA_ARGS__)) 69 | 70 | #define ASSERT_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_capability(x)) 71 | 72 | #define ASSERT_SHARED_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(assert_shared_capability(x)) 73 | 74 | #define RETURN_CAPABILITY(x) THREAD_ANNOTATION_ATTRIBUTE__(lock_returned(x)) 75 | 76 | #define NO_THREAD_SAFETY_ANALYSIS THREAD_ANNOTATION_ATTRIBUTE__(no_thread_safety_analysis) 77 | 78 | class Condition; 79 | 80 | /* 81 | * NOTE: This class is for code that builds on Win32. Its usage is 82 | * deprecated for code which doesn't build for Win32. New code which 83 | * doesn't build for Win32 should use std::mutex and std::lock_guard instead. 84 | * 85 | * Simple mutex class. The implementation is system-dependent. 86 | * 87 | * The mutex must be unlocked by the thread that locked it. They are not 88 | * recursive, i.e. the same thread can't lock it multiple times. 89 | */ 90 | class CAPABILITY("mutex") Mutex { 91 | public: 92 | enum { 93 | PRIVATE = 0, 94 | SHARED = 1 95 | }; 96 | 97 | Mutex(); 98 | explicit Mutex(const char* name); 99 | explicit Mutex(int type, const char* name = nullptr); 100 | ~Mutex(); 101 | 102 | // lock or unlock the mutex 103 | int32_t lock() ACQUIRE(); 104 | void unlock() RELEASE(); 105 | 106 | // lock if possible; returns 0 on success, error otherwise 107 | int32_t tryLock() TRY_ACQUIRE(0); 108 | 109 | int32_t timedLock(int64_t timeoutNs) TRY_ACQUIRE(0); 110 | 111 | // Manages the mutex automatically. It'll be locked when Autolock is 112 | // constructed and released when Autolock goes out of scope. 113 | class SCOPED_CAPABILITY Autolock { 114 | public: 115 | inline explicit Autolock(Mutex& mutex) ACQUIRE(mutex) : mLock(mutex) { 116 | mLock.lock(); 117 | } 118 | inline explicit Autolock(Mutex* mutex) ACQUIRE(mutex) : mLock(*mutex) { 119 | mLock.lock(); 120 | } 121 | inline ~Autolock() RELEASE() { 122 | mLock.unlock(); 123 | } 124 | 125 | private: 126 | Mutex& mLock; 127 | // Cannot be copied or moved - declarations only 128 | Autolock(const Autolock&); 129 | Autolock& operator=(const Autolock&); 130 | }; 131 | 132 | private: 133 | friend class Condition; 134 | 135 | // A mutex cannot be copied 136 | Mutex(const Mutex&); 137 | Mutex& operator=(const Mutex&); 138 | 139 | pthread_mutex_t mMutex; 140 | }; 141 | 142 | // --------------------------------------------------------------------------- 143 | inline Mutex::Mutex() { 144 | pthread_mutex_init(&mMutex, nullptr); 145 | } 146 | inline Mutex::Mutex(__attribute__((unused)) const char* name) { 147 | pthread_mutex_init(&mMutex, nullptr); 148 | } 149 | inline Mutex::Mutex(int type, __attribute__((unused)) const char* name) { 150 | if (type == SHARED) { 151 | pthread_mutexattr_t attr; 152 | pthread_mutexattr_init(&attr); 153 | pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED); 154 | pthread_mutex_init(&mMutex, &attr); 155 | pthread_mutexattr_destroy(&attr); 156 | } else { 157 | pthread_mutex_init(&mMutex, nullptr); 158 | } 159 | } 160 | inline Mutex::~Mutex() { 161 | pthread_mutex_destroy(&mMutex); 162 | } 163 | inline int32_t Mutex::lock() { 164 | return -pthread_mutex_lock(&mMutex); 165 | } 166 | inline void Mutex::unlock() { 167 | pthread_mutex_unlock(&mMutex); 168 | } 169 | inline int32_t Mutex::tryLock() { 170 | return -pthread_mutex_trylock(&mMutex); 171 | } 172 | inline int32_t Mutex::timedLock(int64_t timeoutNs) { 173 | timespec now; 174 | clock_gettime(CLOCK_REALTIME, &now); 175 | timeoutNs += now.tv_sec*1000000000 + now.tv_nsec; 176 | const struct timespec ts = { 177 | /* .tv_sec = */ static_cast(timeoutNs / 1000000000), 178 | /* .tv_nsec = */ static_cast(timeoutNs % 1000000000), 179 | }; 180 | return -pthread_mutex_timedlock(&mMutex, &ts); 181 | } 182 | 183 | // --------------------------------------------------------------------------- 184 | 185 | /* 186 | * Automatic mutex. Declare one of these at the top of a function. 187 | * When the function returns, it will go out of scope, and release the 188 | * mutex. 189 | */ 190 | 191 | typedef Mutex::Autolock AutoMutex; 192 | #endif // __ANDROID_VNDK__ 193 | #endif // _LIBS_RGA_MUTEX_H 194 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/RgaSingleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _LIBS_RGA_SINGLETON_H 20 | #define _LIBS_RGA_SINGLETON_H 21 | 22 | #ifndef ANDROID 23 | #include "RgaMutex.h" 24 | 25 | #if defined(__clang__) 26 | #pragma clang diagnostic push 27 | #pragma clang diagnostic ignored "-Wundefined-var-template" 28 | #endif 29 | 30 | template 31 | class Singleton { 32 | public: 33 | static TYPE& getInstance() { 34 | Mutex::Autolock _l(sLock); 35 | TYPE* instance = sInstance; 36 | if (instance == nullptr) { 37 | instance = new TYPE(); 38 | sInstance = instance; 39 | } 40 | return *instance; 41 | } 42 | 43 | static bool hasInstance() { 44 | Mutex::Autolock _l(sLock); 45 | return sInstance != nullptr; 46 | } 47 | 48 | protected: 49 | ~Singleton() { } 50 | Singleton() { } 51 | 52 | private: 53 | Singleton(const Singleton&); 54 | Singleton& operator = (const Singleton&); 55 | static Mutex sLock; 56 | static TYPE* sInstance; 57 | }; 58 | 59 | #if defined(__clang__) 60 | #pragma clang diagnostic pop 61 | #endif 62 | 63 | #define RGA_SINGLETON_STATIC_INSTANCE(TYPE) \ 64 | template<> ::Mutex \ 65 | (::Singleton< TYPE >::sLock)(::Mutex::PRIVATE); \ 66 | template<> TYPE* ::Singleton< TYPE >::sInstance(nullptr); /* NOLINT */ \ 67 | template class ::Singleton< TYPE >; 68 | 69 | #endif //ANDROID 70 | #endif //_LIBS_RGA_SINGLETON_H 71 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/RgaUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _rga_utils_h_ 20 | #define _rga_utils_h_ 21 | 22 | // ------------------------------------------------------------------------------- 23 | float get_bpp_from_format(int format); 24 | int get_perPixel_stride_from_format(int format); 25 | int get_buf_from_file(void *buf, int f, int sw, int sh, int index); 26 | int output_buf_data_to_file(void *buf, int f, int sw, int sh, int index); 27 | const char *translate_format_str(int format); 28 | int get_buf_from_file_FBC(void *buf, int f, int sw, int sh, int index); 29 | int output_buf_data_to_file_FBC(void *buf, int f, int sw, int sh, int index); 30 | #endif 31 | 32 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/RockchipRga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _rockchip_rga_h_ 20 | #define _rockchip_rga_h_ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "drmrga.h" 34 | #include "GrallocOps.h" 35 | #include "RgaUtils.h" 36 | #include "rga.h" 37 | 38 | ////////////////////////////////////////////////////////////////////////////////// 39 | #ifndef ANDROID 40 | #include "RgaSingleton.h" 41 | #endif 42 | 43 | #ifdef ANDROID 44 | #include 45 | #include 46 | #include 47 | 48 | namespace android { 49 | #endif 50 | 51 | class RockchipRga :public Singleton { 52 | public: 53 | 54 | static inline RockchipRga& get() { 55 | return getInstance(); 56 | } 57 | 58 | int RkRgaInit(); 59 | void RkRgaDeInit(); 60 | void RkRgaGetContext(void **ctx); 61 | #ifndef ANDROID /* LINUX */ 62 | int RkRgaAllocBuffer(int drm_fd /* input */, bo_t *bo_info, 63 | int width, int height, int bpp, int flags); 64 | int RkRgaFreeBuffer(int drm_fd /* input */, bo_t *bo_info); 65 | int RkRgaGetAllocBuffer(bo_t *bo_info, int width, int height, int bpp); 66 | int RkRgaGetAllocBufferExt(bo_t *bo_info, int width, int height, int bpp, int flags); 67 | int RkRgaGetAllocBufferCache(bo_t *bo_info, int width, int height, int bpp); 68 | int RkRgaGetMmap(bo_t *bo_info); 69 | int RkRgaUnmap(bo_t *bo_info); 70 | int RkRgaFree(bo_t *bo_info); 71 | int RkRgaGetBufferFd(bo_t *bo_info, int *fd); 72 | #else 73 | int RkRgaGetBufferFd(buffer_handle_t handle, int *fd); 74 | int RkRgaGetHandleMapCpuAddress(buffer_handle_t handle, void **buf); 75 | #endif 76 | int RkRgaBlit(rga_info *src, rga_info *dst, rga_info *src1); 77 | int RkRgaCollorFill(rga_info *dst); 78 | int RkRgaCollorPalette(rga_info *src, rga_info *dst, rga_info *lut); 79 | int RkRgaFlush(); 80 | 81 | 82 | void RkRgaSetLogOnceFlag(int log) { 83 | mLogOnce = log; 84 | } 85 | void RkRgaSetAlwaysLogFlag(bool log) { 86 | mLogAlways = log; 87 | } 88 | void RkRgaLogOutRgaReq(struct rga_req rgaReg); 89 | int RkRgaLogOutUserPara(rga_info *rgaInfo); 90 | inline bool RkRgaIsReady() { 91 | return mSupportRga; 92 | } 93 | 94 | RockchipRga(); 95 | ~RockchipRga(); 96 | private: 97 | bool mSupportRga; 98 | int mLogOnce; 99 | int mLogAlways; 100 | void * mContext; 101 | 102 | friend class Singleton; 103 | }; 104 | 105 | #ifdef ANDROID 106 | }; // namespace android 107 | #endif 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/drmrga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _rk_drm_rga_ 20 | #define _rk_drm_rga_ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "rga.h" 27 | 28 | #ifdef ANDROID 29 | #define DRMRGA_HARDWARE_MODULE_ID "librga" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef ANDROID_12 37 | #include 38 | #endif 39 | 40 | #endif 41 | 42 | #ifndef ANDROID /* LINUX */ 43 | /* flip source image horizontally (around the vertical axis) */ 44 | #define HAL_TRANSFORM_FLIP_H 0x01 45 | /* flip source image vertically (around the horizontal axis)*/ 46 | #define HAL_TRANSFORM_FLIP_V 0x02 47 | /* rotate source image 90 degrees clockwise */ 48 | #define HAL_TRANSFORM_ROT_90 0x04 49 | /* rotate source image 180 degrees */ 50 | #define HAL_TRANSFORM_ROT_180 0x03 51 | /* rotate source image 270 degrees clockwise */ 52 | #define HAL_TRANSFORM_ROT_270 0x07 53 | #endif 54 | 55 | #define HAL_TRANSFORM_FLIP_H_V 0x08 56 | 57 | /*****************************************************************************/ 58 | 59 | /* for compatibility */ 60 | #define DRM_RGA_MODULE_API_VERSION HWC_MODULE_API_VERSION_0_1 61 | #define DRM_RGA_DEVICE_API_VERSION HWC_DEVICE_API_VERSION_0_1 62 | #define DRM_RGA_API_VERSION HWC_DEVICE_API_VERSION 63 | 64 | #define DRM_RGA_TRANSFORM_ROT_MASK 0x0000000F 65 | #define DRM_RGA_TRANSFORM_ROT_0 0x00000000 66 | #define DRM_RGA_TRANSFORM_ROT_90 HAL_TRANSFORM_ROT_90 67 | #define DRM_RGA_TRANSFORM_ROT_180 HAL_TRANSFORM_ROT_180 68 | #define DRM_RGA_TRANSFORM_ROT_270 HAL_TRANSFORM_ROT_270 69 | 70 | #define DRM_RGA_TRANSFORM_FLIP_MASK 0x00000003 71 | #define DRM_RGA_TRANSFORM_FLIP_H HAL_TRANSFORM_FLIP_H 72 | #define DRM_RGA_TRANSFORM_FLIP_V HAL_TRANSFORM_FLIP_V 73 | 74 | enum { 75 | AWIDTH = 0, 76 | AHEIGHT, 77 | ASTRIDE, 78 | AFORMAT, 79 | ASIZE, 80 | ATYPE, 81 | }; 82 | /*****************************************************************************/ 83 | 84 | #ifndef ANDROID 85 | /* memory type definitions. */ 86 | enum drm_rockchip_gem_mem_type { 87 | /* Physically Continuous memory and used as default. */ 88 | ROCKCHIP_BO_CONTIG = 1 << 0, 89 | /* cachable mapping. */ 90 | ROCKCHIP_BO_CACHABLE = 1 << 1, 91 | /* write-combine mapping. */ 92 | ROCKCHIP_BO_WC = 1 << 2, 93 | ROCKCHIP_BO_SECURE = 1 << 3, 94 | ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | 95 | ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE 96 | }; 97 | 98 | typedef struct bo { 99 | int fd; 100 | void *ptr; 101 | size_t size; 102 | size_t offset; 103 | size_t pitch; 104 | unsigned handle; 105 | } bo_t; 106 | #endif 107 | 108 | /* 109 | @value size: user not need care about.For avoid read/write out of memory 110 | */ 111 | typedef struct rga_rect { 112 | int xoffset; 113 | int yoffset; 114 | int width; 115 | int height; 116 | int wstride; 117 | int hstride; 118 | int format; 119 | int size; 120 | } rga_rect_t; 121 | 122 | typedef struct rga_nn { 123 | int nn_flag; 124 | int scale_r; 125 | int scale_g; 126 | int scale_b; 127 | int offset_r; 128 | int offset_g; 129 | int offset_b; 130 | } rga_nn_t; 131 | 132 | typedef struct rga_dither { 133 | int enable; 134 | int mode; 135 | int lut0_l; 136 | int lut0_h; 137 | int lut1_l; 138 | int lut1_h; 139 | } rga_dither_t; 140 | 141 | /* 142 | @value fd: use fd to share memory, it can be ion shard fd,and dma fd. 143 | @value virAddr:userspace address 144 | @value phyAddr:use phy address 145 | @value hnd: use buffer_handle_t 146 | */ 147 | typedef struct rga_info { 148 | int fd; 149 | void *virAddr; 150 | void *phyAddr; 151 | #ifndef ANDROID /* LINUX */ 152 | unsigned hnd; 153 | #else /* Android */ 154 | buffer_handle_t hnd; 155 | #endif 156 | int format; 157 | rga_rect_t rect; 158 | unsigned int blend; 159 | int bufferSize; 160 | int rotation; 161 | int color; 162 | int testLog; 163 | int mmuFlag; 164 | int colorkey_en; 165 | int colorkey_mode; 166 | int colorkey_max; 167 | int colorkey_min; 168 | int scale_mode; 169 | int color_space_mode; 170 | int sync_mode; 171 | rga_nn_t nn; 172 | rga_dither_t dither; 173 | int rop_code; 174 | int rd_mode; 175 | unsigned short is_10b_compact; 176 | unsigned short is_10b_endian; 177 | 178 | int in_fence_fd; 179 | int out_fence_fd; 180 | 181 | int core; 182 | int priority; 183 | 184 | unsigned short enable; 185 | 186 | int handle; 187 | 188 | struct rga_mosaic_info mosaic_info; 189 | 190 | struct rga_osd_info osd_info; 191 | 192 | struct rga_pre_intr_info pre_intr; 193 | 194 | int mpi_mode; 195 | int ctx_id; 196 | 197 | char reserve[402]; 198 | } rga_info_t; 199 | 200 | 201 | typedef struct drm_rga { 202 | rga_rect_t src; 203 | rga_rect_t dst; 204 | } drm_rga_t; 205 | 206 | /* 207 | @fun rga_set_rect:For use to set the rects esayly 208 | 209 | @param rect:The rect user want to set,like setting the src rect: 210 | drm_rga_t rects; 211 | rga_set_rect(rects.src,0,0,1920,1080,1920,NV12); 212 | mean to set the src rect to the value. 213 | */ 214 | static inline int rga_set_rect(rga_rect_t *rect, 215 | int x, int y, int w, int h, int sw, int sh, int f) { 216 | if (!rect) 217 | return -EINVAL; 218 | 219 | rect->xoffset = x; 220 | rect->yoffset = y; 221 | rect->width = w; 222 | rect->height = h; 223 | rect->wstride = sw; 224 | rect->hstride = sh; 225 | rect->format = f; 226 | 227 | return 0; 228 | } 229 | 230 | #ifndef ANDROID /* LINUX */ 231 | static inline void rga_set_rotation(rga_info_t *info, int angle) { 232 | if (angle == 90) 233 | info->rotation = HAL_TRANSFORM_ROT_90; 234 | else if (angle == 180) 235 | info->rotation = HAL_TRANSFORM_ROT_180; 236 | else if (angle == 270) 237 | info->rotation = HAL_TRANSFORM_ROT_270; 238 | } 239 | #endif 240 | /*****************************************************************************/ 241 | 242 | #endif 243 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/im2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 5 | * Cerf Yu 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 | #include "im2d_version.h" 28 | #include "im2d_type.h" 29 | 30 | #ifndef IM_API 31 | #define IM_API /* define API export as needed */ 32 | #endif 33 | 34 | #define RGA_GET_MIN(n1, n2) ((n1) < (n2) ? (n1) : (n2)) 35 | 36 | /* 37 | * @return error message string 38 | */ 39 | #define imStrError(...) \ 40 | ({ \ 41 | const char* im2d_api_err; \ 42 | int __args[] = {__VA_ARGS__}; \ 43 | int __argc = sizeof(__args)/sizeof(int); \ 44 | if (__argc == 0) { \ 45 | im2d_api_err = imStrError_t(IM_STATUS_INVALID_PARAM); \ 46 | } else if (__argc == 1){ \ 47 | im2d_api_err = imStrError_t((IM_STATUS)__args[0]); \ 48 | } else { \ 49 | im2d_api_err = ("Fatal error, imStrError() too many parameters\n"); \ 50 | printf("Fatal error, imStrError() too many parameters\n"); \ 51 | } \ 52 | im2d_api_err; \ 53 | }) 54 | IM_API const char* imStrError_t(IM_STATUS status); 55 | 56 | /* 57 | * Import external buffers into RGA driver. 58 | * 59 | * @param fd/va/pa 60 | * Select dma_fd/virtual_address/physical_address by buffer type 61 | * @param param 62 | * Configure buffer parameters 63 | * 64 | * @return rga_buffer_handle_t 65 | */ 66 | IM_API rga_buffer_handle_t importbuffer_fd(int fd, im_handle_param_t *param); 67 | IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, im_handle_param_t *param); 68 | IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, im_handle_param_t *param); 69 | 70 | /* 71 | * Import external buffers into RGA driver. 72 | * 73 | * @param handle 74 | * rga buffer handle 75 | * 76 | * @return success or else negative error code. 77 | */ 78 | IM_API IM_STATUS releasebuffer_handle(rga_buffer_handle_t handle); 79 | 80 | /* 81 | * Wrap image Parameters. 82 | * 83 | * @param handle 84 | * RGA buffer handle. 85 | * @param width 86 | * Width of image manipulation area. 87 | * @param height 88 | * Height of image manipulation area. 89 | * @param wstride 90 | * Width pixel stride, default (width = wstride). 91 | * @param hstride 92 | * Height pixel stride, default (height = hstride). 93 | * @param format 94 | * Image format. 95 | * 96 | * @return rga_buffer_t 97 | */ 98 | #define wrapbuffer_handle(handle, width, height, format, ...) \ 99 | ({ \ 100 | rga_buffer_t im2d_api_buffer; \ 101 | int __args[] = {__VA_ARGS__}; \ 102 | int __argc = sizeof(__args)/sizeof(int); \ 103 | if (__argc == 0) { \ 104 | im2d_api_buffer = wrapbuffer_handle_t(handle, width, height, width, height, format); \ 105 | } else if (__argc == 2){ \ 106 | im2d_api_buffer = wrapbuffer_handle_t(handle, width, height, __args[0], __args[1], format); \ 107 | } else { \ 108 | printf("invalid parameter\n"); \ 109 | } \ 110 | im2d_api_buffer; \ 111 | }) 112 | IM_API rga_buffer_t wrapbuffer_handle_t(rga_buffer_handle_t handle, int width, int height, int wstride, int hstride, int format); 113 | 114 | /* For legarcy. */ 115 | #define wrapbuffer_virtualaddr(vir_addr, width, height, format, ...) \ 116 | ({ \ 117 | rga_buffer_t im2d_api_buffer; \ 118 | int __args[] = {__VA_ARGS__}; \ 119 | int __argc = sizeof(__args)/sizeof(int); \ 120 | if (__argc == 0) { \ 121 | im2d_api_buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, width, height, format); \ 122 | } else if (__argc == 2){ \ 123 | im2d_api_buffer = wrapbuffer_virtualaddr_t(vir_addr, width, height, __args[0], __args[1], format); \ 124 | } else { \ 125 | printf("invalid parameter\n"); \ 126 | } \ 127 | im2d_api_buffer; \ 128 | }) 129 | 130 | #define wrapbuffer_physicaladdr(phy_addr, width, height, format, ...) \ 131 | ({ \ 132 | rga_buffer_t im2d_api_buffer; \ 133 | int __args[] = {__VA_ARGS__}; \ 134 | int __argc = sizeof(__args)/sizeof(int); \ 135 | if (__argc == 0) { \ 136 | im2d_api_buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, width, height, format); \ 137 | } else if (__argc == 2){ \ 138 | im2d_api_buffer = wrapbuffer_physicaladdr_t(phy_addr, width, height, __args[0], __args[1], format); \ 139 | } else { \ 140 | printf("invalid parameter\n"); \ 141 | } \ 142 | im2d_api_buffer; \ 143 | }) 144 | 145 | #define wrapbuffer_fd(fd, width, height, format, ...) \ 146 | ({ \ 147 | rga_buffer_t im2d_api_buffer; \ 148 | int __args[] = {__VA_ARGS__}; \ 149 | int __argc = sizeof(__args)/sizeof(int); \ 150 | if (__argc == 0) { \ 151 | im2d_api_buffer = wrapbuffer_fd_t(fd, width, height, width, height, format); \ 152 | } else if (__argc == 2){ \ 153 | im2d_api_buffer = wrapbuffer_fd_t(fd, width, height, __args[0], __args[1], format); \ 154 | } else { \ 155 | printf("invalid parameter\n"); \ 156 | } \ 157 | im2d_api_buffer; \ 158 | }) 159 | IM_API rga_buffer_t wrapbuffer_virtualaddr_t(void* vir_addr, int width, int height, int wstride, int hstride, int format); 160 | IM_API rga_buffer_t wrapbuffer_physicaladdr_t(void* phy_addr, int width, int height, int wstride, int hstride, int format); 161 | IM_API rga_buffer_t wrapbuffer_fd_t(int fd, int width, int height, int wstride, int hstride, int format); 162 | 163 | /* 164 | * Query RGA basic information, supported resolution, supported format, etc. 165 | * 166 | * @param name 167 | * RGA_VENDOR 168 | * RGA_VERSION 169 | * RGA_MAX_INPUT 170 | * RGA_MAX_OUTPUT 171 | * RGA_INPUT_FORMAT 172 | * RGA_OUTPUT_FORMAT 173 | * RGA_EXPECTED 174 | * RGA_ALL 175 | * 176 | * @returns a string describing properties of RGA. 177 | */ 178 | IM_API const char* querystring(int name); 179 | 180 | /* 181 | * check RGA basic information, supported resolution, supported format, etc. 182 | * 183 | * @param src 184 | * @param dst 185 | * @param src_rect 186 | * @param dst_rect 187 | * @param mode_usage 188 | * 189 | * @returns no error or else negative error code. 190 | */ 191 | #define imcheck(src, dst, src_rect, dst_rect, ...) \ 192 | ({ \ 193 | IM_STATUS __ret = IM_STATUS_NOERROR; \ 194 | rga_buffer_t __pat; \ 195 | im_rect __pat_rect; \ 196 | memset(&__pat, 0, sizeof(rga_buffer_t)); \ 197 | memset(&__pat_rect, 0, sizeof(im_rect)); \ 198 | int __args[] = {__VA_ARGS__}; \ 199 | int __argc = sizeof(__args)/sizeof(int); \ 200 | if (__argc == 0) { \ 201 | rga_check_perpare((rga_buffer_t *)(&src), (rga_buffer_t *)(&dst), (rga_buffer_t *)(&__pat), \ 202 | (im_rect *)(&src_rect), (im_rect *)(&dst_rect), (im_rect *)(&__pat_rect), 0); \ 203 | __ret = imcheck_t(src, dst, __pat, src_rect, dst_rect, __pat_rect, 0); \ 204 | } else if (__argc == 1){ \ 205 | rga_check_perpare((rga_buffer_t *)(&src), (rga_buffer_t *)(&dst), (rga_buffer_t *)(&__pat), \ 206 | (im_rect *)(&src_rect), (im_rect *)(&dst_rect), (im_rect *)(&__pat_rect), __args[0]); \ 207 | __ret = imcheck_t(src, dst, __pat, src_rect, dst_rect, __pat_rect, __args[0]); \ 208 | } else { \ 209 | __ret = IM_STATUS_FAILED; \ 210 | printf("check failed\n"); \ 211 | } \ 212 | __ret; \ 213 | }) 214 | #define imcheck_composite(src, dst, pat, src_rect, dst_rect, pat_rect, ...) \ 215 | ({ \ 216 | IM_STATUS __ret = IM_STATUS_NOERROR; \ 217 | int __args[] = {__VA_ARGS__}; \ 218 | int __argc = sizeof(__args)/sizeof(int); \ 219 | if (__argc == 0) { \ 220 | rga_check_perpare((rga_buffer_t *)(&src), (rga_buffer_t *)(&dst), (rga_buffer_t *)(&pat), \ 221 | (im_rect *)(&src_rect), (im_rect *)(&dst_rect), (im_rect *)(&pat_rect), 0); \ 222 | __ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, 0); \ 223 | } else if (__argc == 1){ \ 224 | rga_check_perpare((rga_buffer_t *)(&src), (rga_buffer_t *)(&dst), (rga_buffer_t *)(&pat), \ 225 | (im_rect *)(&src_rect), (im_rect *)(&dst_rect), (im_rect *)(&pat_rect), __args[0]); \ 226 | __ret = imcheck_t(src, dst, pat, src_rect, dst_rect, pat_rect, __args[0]); \ 227 | } else { \ 228 | __ret = IM_STATUS_FAILED; \ 229 | printf("check failed\n"); \ 230 | } \ 231 | __ret; \ 232 | }) 233 | IM_API void rga_check_perpare(rga_buffer_t *src, rga_buffer_t *dst, rga_buffer_t *pat, 234 | im_rect *src_rect, im_rect *dst_rect, im_rect *pat_rect, int mode_usage); 235 | IM_API IM_STATUS imcheck_t(const rga_buffer_t src, const rga_buffer_t dst, const rga_buffer_t pat, 236 | const im_rect src_rect, const im_rect dst_rect, const im_rect pat_rect, const int mode_usage); 237 | 238 | /* 239 | * Resize 240 | * 241 | * @param src 242 | * @param dst 243 | * @param fx 244 | * @param fy 245 | * @param interpolation 246 | * @param sync 247 | * wait until operation complete 248 | * 249 | * @returns success or else negative error code. 250 | */ 251 | #define imresize(src, dst, ...) \ 252 | ({ \ 253 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 254 | double __args[] = {__VA_ARGS__}; \ 255 | int __argc = sizeof(__args)/sizeof(double); \ 256 | if (__argc == 0) { \ 257 | __ret = imresize_t(src, dst, 0, 0, INTER_LINEAR, 1); \ 258 | } else if (__argc == 2){ \ 259 | __ret = imresize_t(src, dst, __args[RGA_GET_MIN(__argc, 0)], __args[RGA_GET_MIN(__argc, 1)], INTER_LINEAR, 1); \ 260 | } else if (__argc == 3){ \ 261 | __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); \ 262 | } else if (__argc == 4){ \ 263 | __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)]); \ 264 | } else { \ 265 | __ret = IM_STATUS_INVALID_PARAM; \ 266 | printf("invalid parameter\n"); \ 267 | } \ 268 | __ret; \ 269 | }) 270 | 271 | #define impyramid(src, dst, direction) \ 272 | imresize_t(src, \ 273 | dst, \ 274 | direction == IM_UP_SCALE ? 0.5 : 2, \ 275 | direction == IM_UP_SCALE ? 0.5 : 2, \ 276 | INTER_LINEAR, 1) 277 | 278 | IM_API IM_STATUS imresize_t(const rga_buffer_t src, rga_buffer_t dst, double fx, double fy, int interpolation, int sync); 279 | 280 | /* 281 | * Crop 282 | * 283 | * @param src 284 | * @param dst 285 | * @param rect 286 | * @param sync 287 | * wait until operation complete 288 | * 289 | * @returns success or else negative error code. 290 | */ 291 | #define imcrop(src, dst, rect, ...) \ 292 | ({ \ 293 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 294 | int __args[] = {__VA_ARGS__}; \ 295 | int __argc = sizeof(__args)/sizeof(int); \ 296 | if (__argc == 0) { \ 297 | __ret = imcrop_t(src, dst, rect, 1); \ 298 | } else if (__argc == 1){ \ 299 | __ret = imcrop_t(src, dst, rect, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 300 | } else { \ 301 | __ret = IM_STATUS_INVALID_PARAM; \ 302 | printf("invalid parameter\n"); \ 303 | } \ 304 | __ret; \ 305 | }) 306 | 307 | IM_API IM_STATUS imcrop_t(const rga_buffer_t src, rga_buffer_t dst, im_rect rect, int sync); 308 | 309 | /* 310 | * rotation 311 | * 312 | * @param src 313 | * @param dst 314 | * @param rotation 315 | * IM_HAL_TRANSFORM_ROT_90 316 | * IM_HAL_TRANSFORM_ROT_180 317 | * IM_HAL_TRANSFORM_ROT_270 318 | * @param sync 319 | * wait until operation complete 320 | * 321 | * @returns success or else negative error code. 322 | */ 323 | #define imrotate(src, dst, rotation, ...) \ 324 | ({ \ 325 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 326 | int __args[] = {__VA_ARGS__}; \ 327 | int __argc = sizeof(__args)/sizeof(int); \ 328 | if (__argc == 0) { \ 329 | __ret = imrotate_t(src, dst, rotation, 1); \ 330 | } else if (__argc == 1){ \ 331 | __ret = imrotate_t(src, dst, rotation, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 332 | } else { \ 333 | __ret = IM_STATUS_INVALID_PARAM; \ 334 | printf("invalid parameter\n"); \ 335 | } \ 336 | __ret; \ 337 | }) 338 | 339 | IM_API IM_STATUS imrotate_t(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync); 340 | 341 | /* 342 | * flip 343 | * 344 | * @param src 345 | * @param dst 346 | * @param mode 347 | * IM_HAL_TRANSFORM_FLIP_H 348 | * IM_HAL_TRANSFORM_FLIP_V 349 | * @param sync 350 | * wait until operation complete 351 | * 352 | * @returns success or else negative error code. 353 | */ 354 | #define imflip(src, dst, mode, ...) \ 355 | ({ \ 356 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 357 | int __args[] = {__VA_ARGS__}; \ 358 | int __argc = sizeof(__args)/sizeof(int); \ 359 | if (__argc == 0) { \ 360 | __ret = imflip_t(src, dst, mode, 1); \ 361 | } else if (__argc == 1){ \ 362 | __ret = imflip_t(src, dst, mode, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 363 | } else { \ 364 | __ret = IM_STATUS_INVALID_PARAM; \ 365 | printf("invalid parameter\n"); \ 366 | } \ 367 | __ret; \ 368 | }) 369 | 370 | IM_API IM_STATUS imflip_t (const rga_buffer_t src, rga_buffer_t dst, int mode, int sync); 371 | 372 | /* 373 | * fill/reset/draw 374 | * 375 | * @param src 376 | * @param dst 377 | * @param rect 378 | * @param color 379 | * @param sync 380 | * wait until operation complete 381 | * 382 | * @returns success or else negative error code. 383 | */ 384 | #define imfill(buf, rect, color, ...) \ 385 | ({ \ 386 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 387 | int __args[] = {__VA_ARGS__}; \ 388 | int __argc = sizeof(__args)/sizeof(int); \ 389 | if (__argc == 0) { \ 390 | __ret = imfill_t(buf, rect, color, 1); \ 391 | } else if (__argc == 1){ \ 392 | __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 393 | } else { \ 394 | __ret = IM_STATUS_INVALID_PARAM; \ 395 | printf("invalid parameter\n"); \ 396 | } \ 397 | __ret; \ 398 | }) 399 | 400 | #define imreset(buf, rect, color, ...) \ 401 | ({ \ 402 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 403 | int __args[] = {__VA_ARGS__}; \ 404 | int __argc = sizeof(__args)/sizeof(int); \ 405 | if (__argc == 0) { \ 406 | __ret = imfill_t(buf, rect, color, 1); \ 407 | } else if (__argc == 1){ \ 408 | __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 409 | } else { \ 410 | __ret = IM_STATUS_INVALID_PARAM; \ 411 | printf("invalid parameter\n"); \ 412 | } \ 413 | __ret; \ 414 | }) 415 | 416 | #define imdraw(buf, rect, color, ...) \ 417 | ({ \ 418 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 419 | int __args[] = {__VA_ARGS__}; \ 420 | int __argc = sizeof(__args)/sizeof(int); \ 421 | if (__argc == 0) { \ 422 | __ret = imfill_t(buf, rect, color, 1); \ 423 | } else if (__argc == 1){ \ 424 | __ret = imfill_t(buf, rect, color, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 425 | } else { \ 426 | __ret = IM_STATUS_INVALID_PARAM; \ 427 | printf("invalid parameter\n"); \ 428 | } \ 429 | __ret; \ 430 | }) 431 | IM_API IM_STATUS imfill_t(rga_buffer_t dst, im_rect rect, int color, int sync); 432 | 433 | /* 434 | * palette 435 | * 436 | * @param src 437 | * @param dst 438 | * @param lut 439 | * @param sync 440 | * wait until operation complete 441 | * 442 | * @returns success or else negative error code. 443 | */ 444 | #define impalette(src, dst, lut, ...) \ 445 | ({ \ 446 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 447 | int __args[] = {__VA_ARGS__}; \ 448 | int __argc = sizeof(__args)/sizeof(int); \ 449 | if (__argc == 0) { \ 450 | __ret = impalette_t(src, dst, lut, 1); \ 451 | } else if (__argc == 1){ \ 452 | __ret = impalette_t(src, dst, lut, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 453 | } else { \ 454 | __ret = IM_STATUS_INVALID_PARAM; \ 455 | printf("invalid parameter\n"); \ 456 | } \ 457 | __ret; \ 458 | }) 459 | IM_API IM_STATUS impalette_t(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t lut, int sync); 460 | 461 | /* 462 | * translate 463 | * 464 | * @param src 465 | * @param dst 466 | * @param x 467 | * @param y 468 | * @param sync 469 | * wait until operation complete 470 | * 471 | * @returns success or else negative error code. 472 | */ 473 | #define imtranslate(src, dst, x, y, ...) \ 474 | ({ \ 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 = imtranslate_t(src, dst, x, y, 1); \ 480 | } else if (__argc == 1){ \ 481 | __ret = imtranslate_t(src, dst, x, y, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 482 | } else { \ 483 | __ret = IM_STATUS_INVALID_PARAM; \ 484 | printf("invalid parameter\n"); \ 485 | } \ 486 | __ret; \ 487 | }) 488 | IM_API IM_STATUS imtranslate_t(const rga_buffer_t src, rga_buffer_t dst, int x, int y, int sync); 489 | 490 | /* 491 | * copy 492 | * 493 | * @param src 494 | * @param dst 495 | * @param sync 496 | * wait until operation complete 497 | * 498 | * @returns success or else negative error code. 499 | */ 500 | #define imcopy(src, dst, ...) \ 501 | ({ \ 502 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 503 | int __args[] = {__VA_ARGS__}; \ 504 | int __argc = sizeof(__args)/sizeof(int); \ 505 | if (__argc == 0) { \ 506 | __ret = imcopy_t(src, dst, 1); \ 507 | } else if (__argc == 1){ \ 508 | __ret = imcopy_t(src, dst, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 509 | } else { \ 510 | __ret = IM_STATUS_INVALID_PARAM; \ 511 | printf("invalid parameter\n"); \ 512 | } \ 513 | __ret; \ 514 | }) 515 | 516 | IM_API IM_STATUS imcopy_t(const rga_buffer_t src, rga_buffer_t dst, int sync); 517 | 518 | /* 519 | * blend (SRC + DST -> DST or SRCA + SRCB -> DST) 520 | * 521 | * @param srcA 522 | * @param srcB can be NULL. 523 | * @param dst 524 | * @param mode 525 | * IM_ALPHA_BLEND_MODE 526 | * @param sync 527 | * wait until operation complete 528 | * 529 | * @returns success or else negative error code. 530 | */ 531 | #define imblend(srcA, dst, ...) \ 532 | ({ \ 533 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 534 | rga_buffer_t srcB; \ 535 | memset(&srcB, 0x00, sizeof(rga_buffer_t)); \ 536 | int __args[] = {__VA_ARGS__}; \ 537 | int __argc = sizeof(__args)/sizeof(int); \ 538 | if (__argc == 0) { \ 539 | __ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \ 540 | } else if (__argc == 1){ \ 541 | __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \ 542 | } else if (__argc == 2){ \ 543 | __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \ 544 | } else { \ 545 | __ret = IM_STATUS_INVALID_PARAM; \ 546 | printf("invalid parameter\n"); \ 547 | } \ 548 | __ret; \ 549 | }) 550 | #define imcomposite(srcA, srcB, dst, ...) \ 551 | ({ \ 552 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 553 | int __args[] = {__VA_ARGS__}; \ 554 | int __argc = sizeof(__args)/sizeof(int); \ 555 | if (__argc == 0) { \ 556 | __ret = imblend_t(srcA, srcB, dst, IM_ALPHA_BLEND_SRC_OVER, 1); \ 557 | } else if (__argc == 1){ \ 558 | __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \ 559 | } else if (__argc == 2){ \ 560 | __ret = imblend_t(srcA, srcB, dst, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \ 561 | } else { \ 562 | __ret = IM_STATUS_INVALID_PARAM; \ 563 | printf("invalid parameter\n"); \ 564 | } \ 565 | __ret; \ 566 | }) 567 | IM_API IM_STATUS imblend_t(const rga_buffer_t srcA, const rga_buffer_t srcB, rga_buffer_t dst, int mode, int sync); 568 | 569 | /* 570 | * color key 571 | * 572 | * @param src 573 | * @param dst 574 | * @param colorkey_range 575 | * max color 576 | * min color 577 | * @param sync 578 | * wait until operation complete 579 | * 580 | * @returns success or else negative error code. 581 | */ 582 | #define imcolorkey(src, dst, range, ...) \ 583 | ({ \ 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 = imcolorkey_t(src, dst, range, IM_ALPHA_COLORKEY_NORMAL, 1); \ 589 | } else if (__argc == 1){ \ 590 | __ret = imcolorkey_t(src, dst, range, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \ 591 | } else if (__argc == 2){ \ 592 | __ret = imcolorkey_t(src, dst, range, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \ 593 | } else { \ 594 | __ret = IM_STATUS_INVALID_PARAM; \ 595 | printf("invalid parameter\n"); \ 596 | } \ 597 | __ret; \ 598 | }) 599 | IM_API IM_STATUS imcolorkey_t(const rga_buffer_t src, rga_buffer_t dst, im_colorkey_range range, int mode, int sync); 600 | 601 | /* 602 | * format convert 603 | * 604 | * @param src 605 | * @param dst 606 | * @param sfmt 607 | * @param dfmt 608 | * @param mode 609 | * color space mode: IM_COLOR_SPACE_MODE 610 | * @param sync 611 | * wait until operation complete 612 | * 613 | * @returns success or else negative error code. 614 | */ 615 | #define imcvtcolor(src, dst, sfmt, dfmt, ...) \ 616 | ({ \ 617 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 618 | int __args[] = {__VA_ARGS__}; \ 619 | int __argc = sizeof(__args)/sizeof(int); \ 620 | if (__argc == 0) { \ 621 | __ret = imcvtcolor_t(src, dst, sfmt, dfmt, IM_COLOR_SPACE_DEFAULT, 1); \ 622 | } else if (__argc == 1){ \ 623 | __ret = imcvtcolor_t(src, dst, sfmt, dfmt, (int)__args[RGA_GET_MIN(__argc, 0)], 1); \ 624 | } else if (__argc == 2){ \ 625 | __ret = imcvtcolor_t(src, dst, sfmt, dfmt, (int)__args[RGA_GET_MIN(__argc, 0)], (int)__args[RGA_GET_MIN(__argc, 1)]); \ 626 | } else { \ 627 | __ret = IM_STATUS_INVALID_PARAM; \ 628 | printf("invalid parameter\n"); \ 629 | } \ 630 | __ret; \ 631 | }) 632 | 633 | IM_API IM_STATUS imcvtcolor_t(rga_buffer_t src, rga_buffer_t dst, int sfmt, int dfmt, int mode, int sync); 634 | 635 | /* 636 | * nn quantize 637 | * 638 | * @param src 639 | * @param dst 640 | * @param nninfo 641 | * @param sync 642 | * wait until operation complete 643 | * 644 | * @returns success or else negative error code. 645 | */ 646 | #define imquantize(src, dst, nn_info, ...) \ 647 | ({ \ 648 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 649 | int __args[] = {__VA_ARGS__}; \ 650 | int __argc = sizeof(__args)/sizeof(int); \ 651 | if (__argc == 0) { \ 652 | __ret = imquantize_t(src, dst, nn_info, 1); \ 653 | } else if (__argc == 1){ \ 654 | __ret = imquantize_t(src, dst, nn_info, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 655 | } else { \ 656 | __ret = IM_STATUS_INVALID_PARAM; \ 657 | printf("invalid parameter\n"); \ 658 | } \ 659 | __ret; \ 660 | }) 661 | 662 | IM_API IM_STATUS imquantize_t(const rga_buffer_t src, rga_buffer_t dst, im_nn_t nn_info, int sync); 663 | 664 | /* 665 | * ROP 666 | * 667 | * @param src 668 | * @param dst 669 | * @param rop_code 670 | * @param sync 671 | * wait until operation complete 672 | * 673 | * @returns success or else negative error code. 674 | */ 675 | #define imrop(src, dst, rop_code, ...) \ 676 | ({ \ 677 | IM_STATUS __ret = IM_STATUS_SUCCESS; \ 678 | int __args[] = {__VA_ARGS__}; \ 679 | int __argc = sizeof(__args)/sizeof(int); \ 680 | if (__argc == 0) { \ 681 | __ret = imrop_t(src, dst, rop_code, 1); \ 682 | } else if (__argc == 1){ \ 683 | __ret = imrop_t(src, dst, rop_code, (int)__args[RGA_GET_MIN(__argc, 0)]); \ 684 | } else { \ 685 | __ret = IM_STATUS_INVALID_PARAM; \ 686 | printf("invalid parameter\n"); \ 687 | } \ 688 | __ret; \ 689 | }) 690 | IM_API IM_STATUS imrop_t(const rga_buffer_t src, rga_buffer_t dst, int rop_code, int sync); 691 | 692 | /* 693 | * MOSAIC 694 | * 695 | * @param src 696 | * @param dst 697 | * @param mosaic_mode 698 | * @param sync 699 | * wait until operation complete 700 | * 701 | * @returns success or else negative error code. 702 | */ 703 | IM_API IM_STATUS immosaic(const rga_buffer_t image, im_rect rect, int mosaic_mode, int sync); 704 | 705 | /* 706 | * OSD 707 | * 708 | * @param osd 709 | * osd block 710 | * @param dst 711 | * background image 712 | * @param osd_rect 713 | * @param osd_config 714 | * osd mode config 715 | * @param sync 716 | * wait until operation complete 717 | * 718 | * @returns success or else negative error code. 719 | */ 720 | IM_API IM_STATUS imosd(const rga_buffer_t osd,const rga_buffer_t dst, 721 | const im_rect osd_rect, im_osd_t *osd_config, int sync); 722 | 723 | /* 724 | * process 725 | * 726 | * @param src 727 | * @param dst 728 | * @param usage 729 | * @param ... 730 | * wait until operation complete 731 | * 732 | * @returns success or else negative error code. 733 | */ 734 | IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 735 | im_rect srect, im_rect drect, im_rect prect, int usage); 736 | 737 | /* 738 | * block until all execution is complete 739 | * 740 | * @returns success or else negative error code. 741 | */ 742 | IM_API IM_STATUS imsync(int out_fence_fd); 743 | 744 | /* 745 | * config 746 | * 747 | * @param name 748 | * enum IM_CONFIG_NAME 749 | * @param value 750 | * 751 | * @returns success or else negative error code. 752 | */ 753 | IM_API IM_STATUS imconfig(IM_CONFIG_NAME name, uint64_t value); 754 | 755 | IM_API im_ctx_id_t imbegin(uint32_t flags); 756 | 757 | IM_API IM_STATUS imcancel(im_ctx_id_t id); 758 | 759 | #ifdef __cplusplus 760 | } 761 | #endif 762 | #endif /* _im2d_h_ */ 763 | 764 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/im2d.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * PutinLee 5 | * Cerf Yu 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 | #ifndef _im2d_hpp_ 20 | #define _im2d_hpp_ 21 | 22 | #include "im2d.h" 23 | #include "RgaUtils.h" 24 | 25 | #ifdef ANDROID 26 | 27 | #include 28 | 29 | using namespace android; 30 | #endif 31 | 32 | /* 33 | * Import external buffers into RGA driver. 34 | * 35 | * @param fd/va/pa 36 | * Select dma_fd/virtual_address/physical_address by buffer type 37 | * @param size 38 | * Describes the size of the image buffer 39 | * 40 | * @return rga_buffer_handle_t 41 | */ 42 | IM_API rga_buffer_handle_t importbuffer_fd(int fd, int size); 43 | IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int size); 44 | IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int size); 45 | 46 | /* 47 | * Import external buffers into RGA driver. 48 | * 49 | * @param fd/va/pa 50 | * Select dma_fd/virtual_address/physical_address by buffer type 51 | * @param width 52 | * Describes the pixel width stride of the image buffer 53 | * @param height 54 | * Describes the pixel height stride of the image buffer 55 | * @param format 56 | * Describes the pixel format of the image buffer 57 | * 58 | * @return rga_buffer_handle_t 59 | */ 60 | IM_API rga_buffer_handle_t importbuffer_fd(int fd, int width, int height, int format); 61 | IM_API rga_buffer_handle_t importbuffer_virtualaddr(void *va, int width, int height, int format); 62 | IM_API rga_buffer_handle_t importbuffer_physicaladdr(uint64_t pa, int width, int height, int format); 63 | 64 | #undef wrapbuffer_handle 65 | IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle, 66 | int width, int height, 67 | int wstride, int hstride, 68 | int format); 69 | IM_API rga_buffer_t wrapbuffer_handle(rga_buffer_handle_t handle, 70 | int width, int height, 71 | int format); 72 | 73 | #if ANDROID 74 | IM_API rga_buffer_handle_t importbuffer_GraphicBuffer_handle(buffer_handle_t hnd); 75 | IM_API rga_buffer_handle_t importbuffer_GraphicBuffer(sp buf); 76 | 77 | IM_API rga_buffer_t wrapbuffer_handle(buffer_handle_t hnd); 78 | IM_API rga_buffer_t wrapbuffer_GraphicBuffer(sp buf); 79 | 80 | #if USE_AHARDWAREBUFFER 81 | #include 82 | IM_API rga_buffer_handle_t importbuffer_AHardwareBuffer(AHardwareBuffer *buf); 83 | IM_API rga_buffer_t wrapbuffer_AHardwareBuffer(AHardwareBuffer *buf); 84 | 85 | #endif /* USE_AHARDWAREBUFFER */ 86 | #endif /* ANDROID */ 87 | 88 | /* 89 | * Resize 90 | * 91 | * @param src 92 | * @param dst 93 | * @param fx 94 | * @param fy 95 | * @param interpolation 96 | * @param sync 97 | * wait until operation complete 98 | * 99 | * @returns success or else negative error code. 100 | */ 101 | #undef imresize 102 | 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); 103 | 104 | /* 105 | * Crop 106 | * 107 | * @param src 108 | * @param dst 109 | * @param rect 110 | * @param sync 111 | * wait until operation complete 112 | * 113 | * @returns success or else negative error code. 114 | */ 115 | #undef imcrop 116 | 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); 117 | 118 | /* 119 | * rotation 120 | * 121 | * @param src 122 | * @param dst 123 | * @param rotation 124 | * IM_HAL_TRANSFORM_ROT_90 125 | * IM_HAL_TRANSFORM_ROT_180 126 | * IM_HAL_TRANSFORM_ROT_270 127 | * @param sync 128 | * wait until operation complete 129 | * 130 | * @returns success or else negative error code. 131 | */ 132 | #undef imrotate 133 | IM_API IM_STATUS imrotate(const rga_buffer_t src, rga_buffer_t dst, int rotation, int sync = 1, int *release_fence_fd = NULL); 134 | 135 | /* 136 | * flip 137 | * 138 | * @param src 139 | * @param dst 140 | * @param mode 141 | * IM_HAL_TRANSFORM_FLIP_H 142 | * IM_HAL_TRANSFORM_FLIP_V 143 | * @param sync 144 | * wait until operation complete 145 | * 146 | * @returns success or else negative error code. 147 | */ 148 | #undef imflip 149 | IM_API IM_STATUS imflip(const rga_buffer_t src, rga_buffer_t dst, int mode, int sync = 1, int *release_fence_fd = NULL); 150 | 151 | /* 152 | * fill/reset/draw 153 | * 154 | * @param src 155 | * @param dst 156 | * @param rect 157 | * @param color 158 | * @param sync 159 | * wait until operation complete 160 | * 161 | * @returns success or else negative error code. 162 | */ 163 | #undef imfill 164 | IM_API IM_STATUS imfill(rga_buffer_t dst, im_rect rect, int color, int sync = 1, int *release_fence_fd = NULL); 165 | 166 | /* 167 | * palette 168 | * 169 | * @param src 170 | * @param dst 171 | * @param lut 172 | * @param sync 173 | * wait until operation complete 174 | * 175 | * @returns success or else negative error code. 176 | */ 177 | #undef impalette 178 | 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); 179 | 180 | /* 181 | * translate 182 | * 183 | * @param src 184 | * @param dst 185 | * @param x 186 | * @param y 187 | * @param sync 188 | * wait until operation complete 189 | * 190 | * @returns success or else negative error code. 191 | */ 192 | #undef imtranslate 193 | 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); 194 | 195 | /* 196 | * copy 197 | * 198 | * @param src 199 | * @param dst 200 | * @param sync 201 | * wait until operation complete 202 | * 203 | * @returns success or else negative error code. 204 | */ 205 | #undef imcopy 206 | IM_API IM_STATUS imcopy(const rga_buffer_t src, rga_buffer_t dst, int sync = 1, int *release_fence_fd = NULL); 207 | 208 | /* 209 | * blend (SRC + DST -> DST or SRCA + SRCB -> DST) 210 | * 211 | * @param srcA 212 | * @param srcB can be NULL. 213 | * @param dst 214 | * @param mode 215 | * IM_ALPHA_BLEND_MODE 216 | * @param sync 217 | * wait until operation complete 218 | * 219 | * @returns success or else negative error code. 220 | */ 221 | #undef imblend 222 | IM_API IM_STATUS imblend(const rga_buffer_t src, rga_buffer_t dst, int mode = IM_ALPHA_BLEND_SRC_OVER, int sync = 1, int *release_fence_fd = NULL); 223 | #undef imcomposite 224 | 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); 225 | 226 | /* 227 | * color key 228 | * 229 | * @param src 230 | * @param dst 231 | * @param colorkey_range 232 | * max color 233 | * min color 234 | * @param sync 235 | * wait until operation complete 236 | * 237 | * @returns success or else negative error code. 238 | */ 239 | #undef imcolorkey 240 | 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); 241 | 242 | /* 243 | * format convert 244 | * 245 | * @param src 246 | * @param dst 247 | * @param sfmt 248 | * @param dfmt 249 | * @param mode 250 | * color space mode: IM_COLOR_SPACE_MODE 251 | * @param sync 252 | * wait until operation complete 253 | * 254 | * @returns success or else negative error code. 255 | */ 256 | #undef imcvtcolor 257 | 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); 258 | 259 | /* 260 | * nn quantize 261 | * 262 | * @param src 263 | * @param dst 264 | * @param nninfo 265 | * @param sync 266 | * wait until operation complete 267 | * 268 | * @returns success or else negative error code. 269 | */ 270 | #undef imquantize 271 | 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); 272 | 273 | /* 274 | * ROP 275 | * 276 | * @param src 277 | * @param dst 278 | * @param rop_code 279 | * @param sync 280 | * wait until operation complete 281 | * 282 | * @returns success or else negative error code. 283 | */ 284 | #undef imrop 285 | 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); 286 | 287 | /* 288 | * MOSAIC 289 | * 290 | * @param src 291 | * @param dst 292 | * @param mosaic_mode 293 | * @param sync 294 | * wait until operation complete 295 | * 296 | * @returns success or else negative error code. 297 | */ 298 | IM_API IM_STATUS immosaic(const rga_buffer_t image, im_rect rect, int mosaic_mode, int sync = 1, int *release_fence_fd = NULL); 299 | 300 | /* 301 | * OSD 302 | * 303 | * @param osd 304 | * osd block 305 | * @param dst 306 | * background image 307 | * @param osd_rect 308 | * @param osd_config 309 | * osd mode config 310 | * @param sync 311 | * wait until operation complete 312 | * 313 | * @returns success or else negative error code. 314 | */ 315 | IM_API IM_STATUS imosd(const rga_buffer_t osd,const rga_buffer_t dst, 316 | const im_rect osd_rect, im_osd_t *osd_config, 317 | int sync = 1, int *release_fence_fd = NULL); 318 | 319 | /* 320 | * process 321 | * 322 | * @param src 323 | * @param dst 324 | * @param pat 325 | * @param srect 326 | * @param drect 327 | * @param prect 328 | * @param acquire_fence_fd 329 | * @param release_fence_fd 330 | * @param opt 331 | * @param usage 332 | * 333 | * @returns success or else negative error code. 334 | */ 335 | IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 336 | im_rect srect, im_rect drect, im_rect prect, 337 | int acquire_fence_fd, int *release_fence_fd, im_opt_t *opt_ptr, int usage); 338 | IM_API IM_STATUS improcess(rga_buffer_t src, rga_buffer_t dst, rga_buffer_t pat, 339 | im_rect srect, im_rect drect, im_rect prect, 340 | int acquire_fence_fd, int *release_fence_fd, im_opt_t *opt, int usage, im_ctx_id_t ctx_id); 341 | 342 | #endif /* _im2d_hpp_ */ 343 | 344 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/im2d_hardware.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Cerf Yu 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 | 19 | #ifndef _RGA_IM2D_HARDWARE_H_ 20 | #define _RGA_IM2D_HARDWARE_H_ 21 | 22 | #include "rga.h" 23 | 24 | typedef enum { 25 | IM_RGA_HW_VERSION_RGA_V_ERR_INDEX = 0x0, 26 | IM_RGA_HW_VERSION_RGA_1_INDEX, 27 | IM_RGA_HW_VERSION_RGA_1_PLUS_INDEX, 28 | IM_RGA_HW_VERSION_RGA_2_INDEX, 29 | IM_RGA_HW_VERSION_RGA_2_LITE0_INDEX, 30 | IM_RGA_HW_VERSION_RGA_2_LITE1_INDEX, 31 | IM_RGA_HW_VERSION_RGA_2_ENHANCE_INDEX, 32 | IM_RGA_HW_VERSION_RGA_3_INDEX, 33 | IM_RGA_HW_VERSION_MASK_INDEX, 34 | } IM_RGA_HW_VERSION_INDEX; 35 | 36 | typedef enum { 37 | IM_RGA_HW_VERSION_RGA_V_ERR = 1 << IM_RGA_HW_VERSION_RGA_V_ERR_INDEX, 38 | IM_RGA_HW_VERSION_RGA_1 = 1 << IM_RGA_HW_VERSION_RGA_1_INDEX, 39 | IM_RGA_HW_VERSION_RGA_1_PLUS = 1 << IM_RGA_HW_VERSION_RGA_1_PLUS_INDEX, 40 | IM_RGA_HW_VERSION_RGA_2 = 1 << IM_RGA_HW_VERSION_RGA_2_INDEX, 41 | IM_RGA_HW_VERSION_RGA_2_LITE0 = 1 << IM_RGA_HW_VERSION_RGA_2_LITE0_INDEX, 42 | IM_RGA_HW_VERSION_RGA_2_LITE1 = 1 << IM_RGA_HW_VERSION_RGA_2_LITE1_INDEX, 43 | IM_RGA_HW_VERSION_RGA_2_ENHANCE = 1 << IM_RGA_HW_VERSION_RGA_2_ENHANCE_INDEX, 44 | IM_RGA_HW_VERSION_RGA_3 = 1 << IM_RGA_HW_VERSION_RGA_3_INDEX, 45 | IM_RGA_HW_VERSION_MASK = ~((~(unsigned int)0x0 << IM_RGA_HW_VERSION_MASK_INDEX) | 1), 46 | }IM_RGA_HW_VERSION; 47 | 48 | typedef enum { 49 | IM_RGA_SUPPORT_FORMAT_ERROR_INDEX = 0, 50 | IM_RGA_SUPPORT_FORMAT_RGB_INDEX, 51 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER_INDEX, 52 | IM_RGA_SUPPORT_FORMAT_BPP_INDEX, 53 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT_INDEX, 54 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT_INDEX, 55 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT_INDEX, 56 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_10_BIT_INDEX, 57 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT_INDEX, 58 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT_INDEX, 59 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT_INDEX, 60 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_10_BIT_INDEX, 61 | IM_RGA_SUPPORT_FORMAT_YUYV_420_INDEX, 62 | IM_RGA_SUPPORT_FORMAT_YUYV_422_INDEX, 63 | IM_RGA_SUPPORT_FORMAT_YUV_400_INDEX, 64 | IM_RGA_SUPPORT_FORMAT_Y4_INDEX, 65 | IM_RGA_SUPPORT_FORMAT_RGBA2BPP_INDEX, 66 | IM_RGA_SUPPORT_FORMAT_MASK_INDEX, 67 | } IM_RGA_SUPPORT_FORMAT_INDEX; 68 | 69 | typedef enum { 70 | IM_RGA_SUPPORT_FORMAT_ERROR = 1 << IM_RGA_SUPPORT_FORMAT_ERROR_INDEX, 71 | IM_RGA_SUPPORT_FORMAT_RGB = 1 << IM_RGA_SUPPORT_FORMAT_RGB_INDEX, 72 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER = 1 << IM_RGA_SUPPORT_FORMAT_RGB_OTHER_INDEX, 73 | IM_RGA_SUPPORT_FORMAT_BPP = 1 << IM_RGA_SUPPORT_FORMAT_BPP_INDEX, 74 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT_INDEX, 75 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT_INDEX, 76 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT_INDEX, 77 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_10_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_10_BIT_INDEX, 78 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT_INDEX, 79 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT_INDEX, 80 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT_INDEX, 81 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_10_BIT = 1 << IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_10_BIT_INDEX, 82 | IM_RGA_SUPPORT_FORMAT_YUYV_420 = 1 << IM_RGA_SUPPORT_FORMAT_YUYV_420_INDEX, 83 | IM_RGA_SUPPORT_FORMAT_YUYV_422 = 1 << IM_RGA_SUPPORT_FORMAT_YUYV_422_INDEX, 84 | IM_RGA_SUPPORT_FORMAT_YUV_400 = 1 << IM_RGA_SUPPORT_FORMAT_YUV_400_INDEX, 85 | IM_RGA_SUPPORT_FORMAT_Y4 = 1 << IM_RGA_SUPPORT_FORMAT_Y4_INDEX, 86 | IM_RGA_SUPPORT_FORMAT_RGBA2BPP = 1 << IM_RGA_SUPPORT_FORMAT_RGBA2BPP_INDEX, 87 | IM_RGA_SUPPORT_FORMAT_MASK = ~((~(unsigned int)0x0 << IM_RGA_SUPPORT_FORMAT_MASK_INDEX) | 1), 88 | } IM_RGA_SUPPORT_FORMAT; 89 | 90 | typedef enum { 91 | IM_RGA_SUPPORT_FEATURE_ERROR_INDEX = 0, 92 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL_INDEX, 93 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE_INDEX, 94 | IM_RGA_SUPPORT_FEATURE_ROP_INDEX, 95 | IM_RGA_SUPPORT_FEATURE_QUANTIZE_INDEX, 96 | IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC_INDEX, 97 | IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC_INDEX, 98 | IM_RGA_SUPPORT_FEATURE_FBC_INDEX, 99 | IM_RGA_SUPPORT_FEATURE_BLEND_YUV_INDEX, 100 | IM_RGA_SUPPORT_FEATURE_BT2020_INDEX, 101 | IM_RGA_SUPPORT_FEATURE_MOSAIC_INDEX, 102 | IM_RGA_SUPPORT_FEATURE_OSD_INDEX, 103 | IM_RGA_SUPPORT_FEATURE_PRE_INTR_INDEX, 104 | IM_RGA_SUPPORT_FEATURE_MASK_INDEX, 105 | } IM_RGA_SUPPORT_FEATURE_INDEX; 106 | 107 | typedef enum { 108 | IM_RGA_SUPPORT_FEATURE_ERROR = 1 << IM_RGA_SUPPORT_FEATURE_ERROR_INDEX, 109 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL = 1 << IM_RGA_SUPPORT_FEATURE_COLOR_FILL_INDEX, 110 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE = 1 << IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE_INDEX, 111 | IM_RGA_SUPPORT_FEATURE_ROP = 1 << IM_RGA_SUPPORT_FEATURE_ROP_INDEX, 112 | IM_RGA_SUPPORT_FEATURE_QUANTIZE = 1 << IM_RGA_SUPPORT_FEATURE_QUANTIZE_INDEX, 113 | IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC = 1 << IM_RGA_SUPPORT_FEATURE_SRC1_R2Y_CSC_INDEX, 114 | IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC = 1 << IM_RGA_SUPPORT_FEATURE_DST_FULL_CSC_INDEX, 115 | IM_RGA_SUPPORT_FEATURE_FBC = 1 << IM_RGA_SUPPORT_FEATURE_FBC_INDEX, 116 | IM_RGA_SUPPORT_FEATURE_BLEND_YUV = 1 << IM_RGA_SUPPORT_FEATURE_BLEND_YUV_INDEX, 117 | IM_RGA_SUPPORT_FEATURE_BT2020 = 1 << IM_RGA_SUPPORT_FEATURE_BT2020_INDEX, 118 | IM_RGA_SUPPORT_FEATURE_MOSAIC = 1 << IM_RGA_SUPPORT_FEATURE_MOSAIC_INDEX, 119 | IM_RGA_SUPPORT_FEATURE_OSD = 1 << IM_RGA_SUPPORT_FEATURE_OSD_INDEX, 120 | IM_RGA_SUPPORT_FEATURE_PRE_INTR = 1 << IM_RGA_SUPPORT_FEATURE_PRE_INTR_INDEX, 121 | IM_RGA_SUPPORT_FEATURE_MASK = ~((~(unsigned int)0x0 << IM_RGA_SUPPORT_FEATURE_MASK_INDEX) | 1), 122 | } IM_RGA_SUPPORT_FEATURE; 123 | 124 | typedef struct { 125 | unsigned int version; 126 | unsigned int input_resolution; 127 | unsigned int output_resolution; 128 | unsigned int byte_stride; 129 | unsigned int scale_limit; 130 | unsigned int performance; 131 | unsigned int input_format; 132 | unsigned int output_format; 133 | unsigned int feature; 134 | char reserved[24]; 135 | } rga_info_table_entry; 136 | 137 | typedef struct { 138 | struct rga_version_t user; 139 | struct rga_version_t driver; 140 | } rga_dirver_bind_table_entry; 141 | 142 | const rga_info_table_entry hw_info_table[] = { 143 | { IM_RGA_HW_VERSION_RGA_V_ERR , 0, 0, 0, 0, 0, 0, 0, 0, {0} }, 144 | { IM_RGA_HW_VERSION_RGA_1 , 8192, 2048, 4, 8, 1, 145 | /* input format */ 146 | IM_RGA_SUPPORT_FORMAT_RGB | 147 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 148 | IM_RGA_SUPPORT_FORMAT_BPP | 149 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 150 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 151 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 152 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 153 | /* output format */ 154 | IM_RGA_SUPPORT_FORMAT_RGB | 155 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 156 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 157 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 158 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 159 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 160 | /* feature */ 161 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 162 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE | 163 | IM_RGA_SUPPORT_FEATURE_ROP, 164 | /* reserved */ 165 | {0} }, 166 | { IM_RGA_HW_VERSION_RGA_1_PLUS , 8192, 2048, 4, 8, 1, 167 | /* input format */ 168 | IM_RGA_SUPPORT_FORMAT_RGB | 169 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 170 | IM_RGA_SUPPORT_FORMAT_BPP | 171 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 172 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 173 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 174 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 175 | /* output format */ 176 | IM_RGA_SUPPORT_FORMAT_RGB | 177 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 178 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 179 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 180 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 181 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 182 | /* feature */ 183 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 184 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE, 185 | /* reserved */ 186 | {0} }, 187 | { IM_RGA_HW_VERSION_RGA_2 , 8192, 4096, 4, 16, 2, 188 | /* input format */ 189 | IM_RGA_SUPPORT_FORMAT_RGB | 190 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 191 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 192 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 193 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 194 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 195 | /* output format */ 196 | IM_RGA_SUPPORT_FORMAT_RGB | 197 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 198 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 199 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 200 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 201 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 202 | /* feature */ 203 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 204 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE | 205 | IM_RGA_SUPPORT_FEATURE_ROP, 206 | /* reserved */ 207 | {0} }, 208 | { IM_RGA_HW_VERSION_RGA_2_LITE0 , 8192, 4096, 4, 8, 2, 209 | /* input format */ 210 | IM_RGA_SUPPORT_FORMAT_RGB | 211 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 212 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 213 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 214 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 215 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 216 | /* output format */ 217 | IM_RGA_SUPPORT_FORMAT_RGB | 218 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 219 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 220 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 221 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 222 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 223 | /* feature */ 224 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 225 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE | 226 | IM_RGA_SUPPORT_FEATURE_ROP, 227 | /* reserved */ 228 | {0} }, 229 | { IM_RGA_HW_VERSION_RGA_2_LITE1 , 8192, 4096, 4, 8, 2, 230 | /* input format */ 231 | IM_RGA_SUPPORT_FORMAT_RGB | 232 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 233 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 234 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 235 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 236 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT | 237 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT | 238 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_10_BIT | 239 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT | 240 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_10_BIT, 241 | /* output format */ 242 | IM_RGA_SUPPORT_FORMAT_RGB | 243 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 244 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 245 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 246 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 247 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT, 248 | /* feature */ 249 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 250 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE, 251 | /* reserved */ 252 | {0} }, 253 | { IM_RGA_HW_VERSION_RGA_2_ENHANCE , 8192, 4096, 4, 16, 2, 254 | /* input format */ 255 | IM_RGA_SUPPORT_FORMAT_RGB | 256 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 257 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 258 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 259 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 260 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT | 261 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT | 262 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_10_BIT | 263 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT | 264 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_10_BIT, 265 | /* output format */ 266 | IM_RGA_SUPPORT_FORMAT_RGB | 267 | IM_RGA_SUPPORT_FORMAT_RGB_OTHER | 268 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 269 | IM_RGA_SUPPORT_FORMAT_YUV_420_PLANNER_8_BIT | 270 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 271 | IM_RGA_SUPPORT_FORMAT_YUV_422_PLANNER_8_BIT | 272 | IM_RGA_SUPPORT_FORMAT_YUYV_420 | 273 | IM_RGA_SUPPORT_FORMAT_YUYV_422, 274 | /* feature */ 275 | IM_RGA_SUPPORT_FEATURE_COLOR_FILL | 276 | IM_RGA_SUPPORT_FEATURE_COLOR_PALETTE | 277 | IM_RGA_SUPPORT_FEATURE_ROP, 278 | /* reserved */ 279 | {0} }, 280 | { IM_RGA_HW_VERSION_RGA_3 , 8176, 8128, 16, 8, 4, 281 | /* input format */ 282 | IM_RGA_SUPPORT_FORMAT_RGB | 283 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 284 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 285 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT | 286 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT | 287 | IM_RGA_SUPPORT_FORMAT_YUYV_422, 288 | /* output format */ 289 | IM_RGA_SUPPORT_FORMAT_RGB | 290 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_8_BIT | 291 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_8_BIT | 292 | IM_RGA_SUPPORT_FORMAT_YUV_420_SEMI_PLANNER_10_BIT | 293 | IM_RGA_SUPPORT_FORMAT_YUV_422_SEMI_PLANNER_10_BIT | 294 | IM_RGA_SUPPORT_FORMAT_YUYV_422, 295 | /* feature */ 296 | IM_RGA_SUPPORT_FEATURE_FBC | 297 | IM_RGA_SUPPORT_FEATURE_BLEND_YUV | 298 | IM_RGA_SUPPORT_FEATURE_BT2020, 299 | /* reserved */ 300 | {0} }, 301 | }; 302 | 303 | /* The range of the version is [min, max), that is version >= min, version < max. */ 304 | const rga_dirver_bind_table_entry driver_bind_table[] = { 305 | { { 0, 0, 0, "0.0.0" }, {0, 0, 0, "0.0.0" } }, 306 | { { 1, 0, 3, "1.0.3" }, {0, 0, 0, "0.0.0" } }, 307 | { { 1, 6, 0, "1.6.0" }, {1, 1, 5, "1.1.5" } }, 308 | { { 1, 7, 2, "1.7.2" }, {1, 2, 0, "1.2.0" } }, 309 | { { 1, 7, 3, "1.7.3" }, {1, 2, 4, "1.2.4" } }, 310 | }; 311 | 312 | #endif 313 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/im2d_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Cerf Yu 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 | 19 | #ifndef _RGA_IM2D_TYPE_H_ 20 | #define _RGA_IM2D_TYPE_H_ 21 | 22 | #include 23 | 24 | typedef enum { 25 | /* Rotation */ 26 | IM_HAL_TRANSFORM_ROT_90 = 1 << 0, 27 | IM_HAL_TRANSFORM_ROT_180 = 1 << 1, 28 | IM_HAL_TRANSFORM_ROT_270 = 1 << 2, 29 | IM_HAL_TRANSFORM_FLIP_H = 1 << 3, 30 | IM_HAL_TRANSFORM_FLIP_V = 1 << 4, 31 | IM_HAL_TRANSFORM_FLIP_H_V = 1 << 5, 32 | IM_HAL_TRANSFORM_MASK = 0x3f, 33 | 34 | /* 35 | * Blend 36 | * Additional blend usage, can be used with both source and target configs. 37 | * If none of the below is set, the default "SRC over DST" is applied. 38 | */ 39 | IM_ALPHA_BLEND_SRC_OVER = 1 << 6, /* Default, Porter-Duff "SRC over DST" */ 40 | IM_ALPHA_BLEND_SRC = 1 << 7, /* Porter-Duff "SRC" */ 41 | IM_ALPHA_BLEND_DST = 1 << 8, /* Porter-Duff "DST" */ 42 | IM_ALPHA_BLEND_SRC_IN = 1 << 9, /* Porter-Duff "SRC in DST" */ 43 | IM_ALPHA_BLEND_DST_IN = 1 << 10, /* Porter-Duff "DST in SRC" */ 44 | IM_ALPHA_BLEND_SRC_OUT = 1 << 11, /* Porter-Duff "SRC out DST" */ 45 | IM_ALPHA_BLEND_DST_OUT = 1 << 12, /* Porter-Duff "DST out SRC" */ 46 | IM_ALPHA_BLEND_DST_OVER = 1 << 13, /* Porter-Duff "DST over SRC" */ 47 | IM_ALPHA_BLEND_SRC_ATOP = 1 << 14, /* Porter-Duff "SRC ATOP" */ 48 | IM_ALPHA_BLEND_DST_ATOP = 1 << 15, /* Porter-Duff "DST ATOP" */ 49 | IM_ALPHA_BLEND_XOR = 1 << 16, /* Xor */ 50 | IM_ALPHA_BLEND_MASK = 0x1ffc0, 51 | 52 | IM_ALPHA_COLORKEY_NORMAL = 1 << 17, 53 | IM_ALPHA_COLORKEY_INVERTED = 1 << 18, 54 | IM_ALPHA_COLORKEY_MASK = 0x60000, 55 | 56 | IM_SYNC = 1 << 19, 57 | IM_CROP = 1 << 20, /* Unused */ 58 | IM_COLOR_FILL = 1 << 21, 59 | IM_COLOR_PALETTE = 1 << 22, 60 | IM_NN_QUANTIZE = 1 << 23, 61 | IM_ROP = 1 << 24, 62 | IM_ALPHA_BLEND_PRE_MUL = 1 << 25, 63 | IM_ASYNC = 1 << 26, 64 | IM_MOSAIC = 1 << 27, 65 | IM_OSD = 1 << 28, 66 | IM_PRE_INTR = 1 << 29, 67 | } IM_USAGE; 68 | 69 | typedef enum { 70 | IM_RASTER_MODE = 1 << 0, 71 | IM_FBC_MODE = 1 << 1, 72 | IM_TILE_MODE = 1 << 2, 73 | } IM_RD_MODE; 74 | 75 | typedef enum { 76 | IM_SCHEDULER_RGA3_CORE0 = 1 << 0, 77 | IM_SCHEDULER_RGA3_CORE1 = 1 << 1, 78 | IM_SCHEDULER_RGA2_CORE0 = 1 << 2, 79 | IM_SCHEDULER_RGA3_DEFAULT = IM_SCHEDULER_RGA3_CORE0, 80 | IM_SCHEDULER_RGA2_DEFAULT = IM_SCHEDULER_RGA2_CORE0, 81 | IM_SCHEDULER_MASK = 0x7, 82 | IM_SCHEDULER_DEFAULT = 0, 83 | } IM_SCHEDULER_CORE; 84 | 85 | typedef enum { 86 | IM_ROP_AND = 0x88, 87 | IM_ROP_OR = 0xee, 88 | IM_ROP_NOT_DST = 0x55, 89 | IM_ROP_NOT_SRC = 0x33, 90 | IM_ROP_XOR = 0xf6, 91 | IM_ROP_NOT_XOR = 0xf9, 92 | } IM_ROP_CODE; 93 | 94 | typedef enum { 95 | IM_MOSAIC_8 = 0x0, 96 | IM_MOSAIC_16 = 0x1, 97 | IM_MOSAIC_32 = 0x2, 98 | IM_MOSAIC_64 = 0x3, 99 | IM_MOSAIC_128 = 0x4, 100 | } IM_MOSAIC_MODE; 101 | 102 | /* Status codes, returned by any blit function */ 103 | typedef enum { 104 | IM_YUV_TO_RGB_BT601_LIMIT = 1 << 0, 105 | IM_YUV_TO_RGB_BT601_FULL = 2 << 0, 106 | IM_YUV_TO_RGB_BT709_LIMIT = 3 << 0, 107 | IM_YUV_TO_RGB_MASK = 3 << 0, 108 | IM_RGB_TO_YUV_BT601_FULL = 1 << 2, 109 | IM_RGB_TO_YUV_BT601_LIMIT = 2 << 2, 110 | IM_RGB_TO_YUV_BT709_LIMIT = 3 << 2, 111 | IM_RGB_TO_YUV_MASK = 3 << 2, 112 | IM_RGB_TO_Y4 = 1 << 4, 113 | IM_RGB_TO_Y4_DITHER = 2 << 4, 114 | IM_RGB_TO_Y1_DITHER = 3 << 4, 115 | IM_Y4_MASK = 3 << 4, 116 | IM_RGB_FULL = 1 << 8, 117 | IM_RGB_CLIP = 2 << 8, 118 | IM_YUV_BT601_LIMIT_RANGE = 3 << 8, 119 | IM_YUV_BT601_FULL_RANGE = 4 << 8, 120 | IM_YUV_BT709_LIMIT_RANGE = 5 << 8, 121 | IM_YUV_BT709_FULL_RANGE = 6 << 8, 122 | IM_FULL_CSC_MASK = 0xf << 8, 123 | IM_COLOR_SPACE_DEFAULT = 0, 124 | } IM_COLOR_SPACE_MODE; 125 | 126 | typedef enum { 127 | IM_UP_SCALE, 128 | IM_DOWN_SCALE, 129 | } IM_SCALE; 130 | 131 | typedef enum { 132 | INTER_NEAREST, 133 | INTER_LINEAR, 134 | INTER_CUBIC, 135 | } IM_SCALE_MODE; 136 | 137 | typedef enum { 138 | IM_CONFIG_SCHEDULER_CORE, 139 | IM_CONFIG_PRIORITY, 140 | IM_CONFIG_CHECK, 141 | } IM_CONFIG_NAME; 142 | 143 | typedef enum { 144 | IM_OSD_MODE_STATISTICS = 0x1 << 0, 145 | IM_OSD_MODE_AUTO_INVERT = 0x1 << 1, 146 | } IM_OSD_MODE; 147 | 148 | typedef enum { 149 | IM_OSD_INVERT_CHANNEL_NONE = 0x0, 150 | IM_OSD_INVERT_CHANNEL_Y_G = 0x1 << 0, 151 | IM_OSD_INVERT_CHANNEL_C_RB = 0x1 << 1, 152 | IM_OSD_INVERT_CHANNEL_ALPHA = 0x1 << 2, 153 | IM_OSD_INVERT_CHANNEL_COLOR = IM_OSD_INVERT_CHANNEL_Y_G | 154 | IM_OSD_INVERT_CHANNEL_C_RB, 155 | IM_OSD_INVERT_CHANNEL_BOTH = IM_OSD_INVERT_CHANNEL_COLOR | 156 | IM_OSD_INVERT_CHANNEL_ALPHA, 157 | } IM_OSD_INVERT_CHANNEL; 158 | 159 | typedef enum { 160 | IM_OSD_FLAGS_INTERNAL = 0, 161 | IM_OSD_FLAGS_EXTERNAL, 162 | } IM_OSD_FLAGS_MODE; 163 | 164 | typedef enum { 165 | IM_OSD_INVERT_USE_FACTOR, 166 | IM_OSD_INVERT_USE_SWAP, 167 | } IM_OSD_INVERT_MODE; 168 | 169 | typedef enum { 170 | IM_OSD_BACKGROUND_DEFAULT_BRIGHT = 0, 171 | IM_OSD_BACKGROUND_DEFAULT_DARK, 172 | } IM_OSD_BACKGROUND_DEFAULT; 173 | 174 | typedef enum { 175 | IM_OSD_BLOCK_MODE_NORMAL = 0, 176 | IM_OSD_BLOCK_MODE_DIFFERENT, 177 | } IM_OSD_BLOCK_WIDTH_MODE; 178 | 179 | typedef enum { 180 | IM_OSD_MODE_HORIZONTAL, 181 | IM_OSD_MODE_VERTICAL, 182 | } IM_OSD_DIRECTION; 183 | 184 | typedef enum { 185 | IM_OSD_COLOR_PIXEL, 186 | IM_OSD_COLOR_EXTERNAL, 187 | } IM_OSD_COLOR_MODE; 188 | 189 | typedef enum { 190 | IM_INTR_READ_INTR = 1 << 0, 191 | IM_INTR_READ_HOLD = 1 << 1, 192 | IM_INTR_WRITE_INTR = 1 << 2, 193 | } IM_PRE_INTR_FLAGS; 194 | 195 | typedef enum { 196 | IM_CONTEXT_NONE = 0x0, 197 | IM_CONTEXT_SRC_FIX_ENABLE = 0x1 << 0, // Enable kernel to modify the image parameters of the channel. 198 | IM_CONTEXT_SRC_CACHE_INFO = 0x1 << 1, // It will replace the parameters in ctx with the modified parameters. 199 | IM_CONTEXT_SRC1_FIX_ENABLE = 0x1 << 2, 200 | IM_CONTEXT_SRC1_CACHE_INFO = 0x1 << 3, 201 | IM_CONTEXT_DST_FIX_ENABLE = 0x1 << 4, 202 | IM_CONTEXT_DST_CACHE_INFO = 0x1 << 5, 203 | } IM_CONTEXT_FLAGS; 204 | 205 | /* Get RGA basic information index */ 206 | typedef enum { 207 | RGA_VENDOR = 0, 208 | RGA_VERSION, 209 | RGA_MAX_INPUT, 210 | RGA_MAX_OUTPUT, 211 | RGA_BYTE_STRIDE, 212 | RGA_SCALE_LIMIT, 213 | RGA_INPUT_FORMAT, 214 | RGA_OUTPUT_FORMAT, 215 | RGA_FEATURE, 216 | RGA_EXPECTED, 217 | RGA_ALL, 218 | } IM_INFORMATION; 219 | 220 | /* Status codes, returned by any blit function */ 221 | typedef enum { 222 | IM_STATUS_NOERROR = 2, 223 | IM_STATUS_SUCCESS = 1, 224 | IM_STATUS_NOT_SUPPORTED = -1, 225 | IM_STATUS_OUT_OF_MEMORY = -2, 226 | IM_STATUS_INVALID_PARAM = -3, 227 | IM_STATUS_ILLEGAL_PARAM = -4, 228 | IM_STATUS_ERROR_VERSION = -5, 229 | IM_STATUS_FAILED = 0, 230 | } IM_STATUS; 231 | 232 | typedef uint32_t im_api_version_t; 233 | typedef uint32_t im_ctx_id_t; 234 | typedef uint32_t rga_buffer_handle_t; 235 | 236 | /* Rectangle definition */ 237 | typedef struct { 238 | int x; /* upper-left x */ 239 | int y; /* upper-left y */ 240 | int width; /* width */ 241 | int height; /* height */ 242 | } im_rect; 243 | 244 | typedef struct { 245 | int max; /* The Maximum value of the color key */ 246 | int min; /* The minimum value of the color key */ 247 | } im_colorkey_range; 248 | 249 | 250 | typedef struct im_nn { 251 | int scale_r; /* scaling factor on R channal */ 252 | int scale_g; /* scaling factor on G channal */ 253 | int scale_b; /* scaling factor on B channal */ 254 | int offset_r; /* offset on R channal */ 255 | int offset_g; /* offset on G channal */ 256 | int offset_b; /* offset on B channal */ 257 | } im_nn_t; 258 | 259 | /* im_info definition */ 260 | typedef struct { 261 | void* vir_addr; /* virtual address */ 262 | void* phy_addr; /* physical address */ 263 | int fd; /* shared fd */ 264 | 265 | int width; /* width */ 266 | int height; /* height */ 267 | int wstride; /* wstride */ 268 | int hstride; /* hstride */ 269 | int format; /* format */ 270 | 271 | int color_space_mode; /* color_space_mode */ 272 | int global_alpha; /* global_alpha */ 273 | int rd_mode; 274 | 275 | /* legarcy */ 276 | int color; /* color, used by color fill */ 277 | im_colorkey_range colorkey_range; /* range value of color key */ 278 | im_nn_t nn; 279 | int rop_code; 280 | 281 | rga_buffer_handle_t handle; /* buffer handle */ 282 | } rga_buffer_t; 283 | 284 | typedef struct im_color { 285 | union { 286 | struct { 287 | uint8_t red; 288 | uint8_t green; 289 | uint8_t blue; 290 | uint8_t alpha; 291 | }; 292 | uint32_t value; 293 | }; 294 | } im_color_t; 295 | 296 | typedef struct im_osd_invert_factor { 297 | uint8_t alpha_max; 298 | uint8_t alpha_min; 299 | uint8_t yg_max; 300 | uint8_t yg_min; 301 | uint8_t crb_max; 302 | uint8_t crb_min; 303 | } im_osd_invert_factor_t; 304 | 305 | typedef struct im_osd_bpp2 { 306 | uint8_t ac_swap; // ac swap flag 307 | // 0: CA 308 | // 1: AC 309 | uint8_t endian_swap; // rgba2bpp endian swap 310 | // 0: Big endian 311 | // 1: Little endian 312 | im_color_t color0; 313 | im_color_t color1; 314 | } im_osd_bpp2_t; 315 | 316 | typedef struct im_osd_block { 317 | int width_mode; // normal or different 318 | // IM_OSD_BLOCK_MODE_NORMAL 319 | // IM_OSD_BLOCK_MODE_DIFFERENT 320 | union { 321 | int width; // normal_mode block width 322 | int width_index; // different_mode block width index in RAM 323 | }; 324 | 325 | int block_count; // block count 326 | 327 | int background_config; // background config is bright or dark 328 | // IM_OSD_BACKGROUND_DEFAULT_BRIGHT 329 | // IM_OSD_BACKGROUND_DEFAULT_DARK 330 | 331 | int direction; // osd block direction 332 | // IM_OSD_MODE_HORIZONTAL 333 | // IM_OSD_MODE_VERTICAL 334 | 335 | int color_mode; // using src1 color or config color 336 | // IM_OSD_COLOR_PIXEL 337 | // IM_OSD_COLOR_EXTERNAL 338 | im_color_t normal_color; // config color: normal 339 | im_color_t invert_color; // config color: invert 340 | } im_osd_block_t; 341 | 342 | typedef struct im_osd_invert { 343 | int invert_channel; // invert channel config: 344 | // IM_OSD_INVERT_CHANNEL_NONE 345 | // IM_OSD_INVERT_CHANNEL_Y_G 346 | // IM_OSD_INVERT_CHANNEL_C_RB 347 | // IM_OSD_INVERT_CHANNEL_ALPHA 348 | // IM_OSD_INVERT_CHANNEL_COLOR 349 | // IM_OSD_INVERT_CHANNEL_BOTH 350 | int flags_mode; // use external or inertnal RAM invert flags 351 | // IM_OSD_FLAGS_EXTERNAL 352 | // IM_OSD_FLAGS_INTERNAL 353 | int flags_index; // flags index when using internal RAM invert flags 354 | 355 | uint64_t invert_flags; // external invert flags 356 | uint64_t current_flags; // current flags 357 | 358 | int invert_mode; // invert use swap or factor 359 | // IM_OSD_INVERT_USE_FACTOR 360 | // IM_OSD_INVERT_USE_SWAP 361 | im_osd_invert_factor_t factor; 362 | 363 | int threash; 364 | } im_osd_invert_t; 365 | 366 | typedef struct im_osd { 367 | int osd_mode; // osd mode: statistics or auto_invert 368 | // IM_OSD_MODE_STATISTICS 369 | // IM_OSD_MODE_AUTO_INVERT 370 | im_osd_block_t block_parm; // osd block info config 371 | 372 | im_osd_invert_t invert_config; 373 | 374 | im_osd_bpp2_t bpp2_info; 375 | } im_osd_t; 376 | 377 | typedef struct im_intr_config { 378 | uint32_t flags; 379 | 380 | int read_threshold; 381 | int write_start; 382 | int write_step; 383 | } im_intr_config_t; 384 | 385 | typedef struct im_opt { 386 | im_api_version_t version; 387 | 388 | int color; /* color, used by color fill */ 389 | im_colorkey_range colorkey_range; /* range value of color key */ 390 | im_nn_t nn; 391 | int rop_code; 392 | 393 | int priority; 394 | int core; 395 | 396 | int mosaic_mode; 397 | 398 | im_osd_t osd_config; 399 | 400 | im_intr_config_t intr_config; 401 | 402 | char reserve[128]; 403 | } im_opt_t; 404 | 405 | typedef struct im_context { 406 | int priority; 407 | IM_SCHEDULER_CORE core; 408 | int check_mode; 409 | } im_context_t; 410 | 411 | typedef struct im_handle_param { 412 | uint32_t width; 413 | uint32_t height; 414 | uint32_t format; 415 | }im_handle_param_t; 416 | 417 | #endif /* _RGA_IM2D_TYPE_H_ */ 418 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/im2d_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Cerf Yu 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 | 19 | #ifndef _RGA_IM2D_VERSION_H_ 20 | #define _RGA_IM2D_VERSION_H_ 21 | 22 | #define RGA_VERSION_STR_HELPER(x) #x 23 | #define RGA_VERSION_STR(x) RGA_VERSION_STR_HELPER(x) 24 | 25 | /* RGA im2d api verison */ 26 | #define RGA_API_MAJOR_VERSION 1 27 | #define RGA_API_MINOR_VERSION 8 28 | #define RGA_API_REVISION_VERSION 0 29 | #define RGA_API_BUILD_VERSION 0 30 | 31 | #define RGA_API_VERSION \ 32 | RGA_VERSION_STR(RGA_API_MAJOR_VERSION) "." \ 33 | RGA_VERSION_STR(RGA_API_MINOR_VERSION) "." \ 34 | RGA_VERSION_STR(RGA_API_REVISION_VERSION) "_[" \ 35 | RGA_VERSION_STR(RGA_API_BUILD_VERSION) "]" 36 | #define RGA_API_FULL_VERSION "rga_api version " RGA_API_VERSION 37 | 38 | #define RGA_SET_CURRENT_API_VERISON (\ 39 | (RGA_API_MAJOR_VERSION & 0xff) << 24 | \ 40 | (RGA_API_MINOR_VERSION & 0xff) << 16 | \ 41 | (RGA_API_REVISION_VERSION & 0xff) << 8 | \ 42 | (RGA_API_BUILD_VERSION & 0xff)\ 43 | ) 44 | 45 | #endif /* _RGA_IM2D_VERSION_H_ */ 46 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/include/rga.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016 Rockchip Electronics Co., Ltd. 3 | * Authors: 4 | * Zhiqin Wei 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 | 19 | #ifndef _RGA_DRIVER_H_ 20 | #define _RGA_DRIVER_H_ 21 | 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | /* Use 'r' as magic number */ 31 | #define RGA_IOC_MAGIC 'r' 32 | #define RGA_IOW(nr, type) _IOW(RGA_IOC_MAGIC, nr, type) 33 | #define RGA_IOR(nr, type) _IOR(RGA_IOC_MAGIC, nr, type) 34 | #define RGA_IOWR(nr, type) _IOWR(RGA_IOC_MAGIC, nr, type) 35 | 36 | #define RGA_IOC_GET_DRVIER_VERSION RGA_IOR(0x1, struct rga_version_t) 37 | #define RGA_IOC_GET_HW_VERSION RGA_IOR(0x2, struct rga_hw_versions_t) 38 | #define RGA_IOC_IMPORT_BUFFER RGA_IOWR(0x3, struct rga_buffer_pool) 39 | #define RGA_IOC_RELEASE_BUFFER RGA_IOW(0x4, struct rga_buffer_pool) 40 | #define RGA_START_CONFIG RGA_IOR(0x5, uint32_t) 41 | #define RGA_END_CONFIG RGA_IOWR(0x6, struct rga_user_ctx_t) 42 | #define RGA_CMD_CONFIG RGA_IOWR(0x7, struct rga_user_ctx_t) 43 | #define RGA_CANCEL_CONFIG RGA_IOWR(0x8, uint32_t) 44 | 45 | #define RGA_BLIT_SYNC 0x5017 46 | #define RGA_BLIT_ASYNC 0x5018 47 | #define RGA_FLUSH 0x5019 48 | #define RGA_GET_RESULT 0x501a 49 | #define RGA_GET_VERSION 0x501b 50 | 51 | #define RGA2_BLIT_SYNC 0x6017 52 | #define RGA2_BLIT_ASYNC 0x6018 53 | #define RGA2_FLUSH 0x6019 54 | #define RGA2_GET_RESULT 0x601a 55 | #define RGA2_GET_VERSION 0x601b 56 | 57 | #define RGA_REG_CTRL_LEN 0x8 /* 8 */ 58 | #define RGA_REG_CMD_LEN 0x1c /* 28 */ 59 | #define RGA_CMD_BUF_SIZE 0x700 /* 16*28*4 */ 60 | 61 | #ifndef ENABLE 62 | #define ENABLE 1 63 | #endif 64 | 65 | #ifndef DISABLE 66 | #define DISABLE 0 67 | #endif 68 | 69 | enum rga_memory_type { 70 | RGA_DMA_BUFFER = 0, 71 | RGA_VIRTUAL_ADDRESS, 72 | RGA_PHYSICAL_ADDRESS 73 | }; 74 | 75 | /* RGA process mode enum */ 76 | enum { 77 | bitblt_mode = 0x0, 78 | color_palette_mode = 0x1, 79 | color_fill_mode = 0x2, 80 | line_point_drawing_mode = 0x3, 81 | blur_sharp_filter_mode = 0x4, 82 | pre_scaling_mode = 0x5, 83 | update_palette_table_mode = 0x6, 84 | update_patten_buff_mode = 0x7, 85 | }; 86 | 87 | 88 | enum { 89 | rop_enable_mask = 0x2, 90 | dither_enable_mask = 0x8, 91 | fading_enable_mask = 0x10, 92 | PD_enbale_mask = 0x20, 93 | }; 94 | 95 | enum { 96 | yuv2rgb_mode0 = 0x0, /* BT.601 MPEG */ 97 | yuv2rgb_mode1 = 0x1, /* BT.601 JPEG */ 98 | yuv2rgb_mode2 = 0x2, /* BT.709 */ 99 | 100 | rgb2yuv_601_full = 0x1 << 8, 101 | rgb2yuv_709_full = 0x2 << 8, 102 | yuv2yuv_601_limit_2_709_limit = 0x3 << 8, 103 | yuv2yuv_601_limit_2_709_full = 0x4 << 8, 104 | yuv2yuv_709_limit_2_601_limit = 0x5 << 8, 105 | yuv2yuv_709_limit_2_601_full = 0x6 << 8, //not support 106 | yuv2yuv_601_full_2_709_limit = 0x7 << 8, 107 | yuv2yuv_601_full_2_709_full = 0x8 << 8, //not support 108 | yuv2yuv_709_full_2_601_limit = 0x9 << 8, //not support 109 | yuv2yuv_709_full_2_601_full = 0xa << 8, //not support 110 | full_csc_mask = 0xf00, 111 | }; 112 | 113 | /* RGA rotate mode */ 114 | enum { 115 | rotate_mode0 = 0x0, /* no rotate */ 116 | rotate_mode1 = 0x1, /* rotate */ 117 | rotate_mode2 = 0x2, /* x_mirror */ 118 | rotate_mode3 = 0x3, /* y_mirror */ 119 | }; 120 | 121 | enum { 122 | color_palette_mode0 = 0x0, /* 1K */ 123 | color_palette_mode1 = 0x1, /* 2K */ 124 | color_palette_mode2 = 0x2, /* 4K */ 125 | color_palette_mode3 = 0x3, /* 8K */ 126 | }; 127 | 128 | enum { 129 | BB_BYPASS = 0x0, /* no rotate */ 130 | BB_ROTATE = 0x1, /* rotate */ 131 | BB_X_MIRROR = 0x2, /* x_mirror */ 132 | BB_Y_MIRROR = 0x3 /* y_mirror */ 133 | }; 134 | 135 | enum { 136 | nearby = 0x0, /* no rotate */ 137 | bilinear = 0x1, /* rotate */ 138 | bicubic = 0x2, /* x_mirror */ 139 | }; 140 | 141 | #define RGA_SCHED_PRIORITY_DEFAULT 0 142 | #define RGA_SCHED_PRIORITY_MAX 6 143 | 144 | enum { 145 | RGA3_SCHEDULER_CORE0 = 1 << 0, 146 | RGA3_SCHEDULER_CORE1 = 1 << 1, 147 | RGA2_SCHEDULER_CORE0 = 1 << 2, 148 | }; 149 | 150 | /* 151 | // Alpha Red Green Blue 152 | { 4, 32, {{32,24, 8, 0, 16, 8, 24,16 }}, GGL_RGBA }, // RK_FORMAT_RGBA_8888 153 | { 4, 24, {{ 0, 0, 8, 0, 16, 8, 24,16 }}, GGL_RGB }, // RK_FORMAT_RGBX_8888 154 | { 3, 24, {{ 0, 0, 8, 0, 16, 8, 24,16 }}, GGL_RGB }, // RK_FORMAT_RGB_888 155 | { 4, 32, {{32,24, 24,16, 16, 8, 8, 0 }}, GGL_BGRA }, // RK_FORMAT_BGRA_8888 156 | { 2, 16, {{ 0, 0, 16,11, 11, 5, 5, 0 }}, GGL_RGB }, // RK_FORMAT_RGB_565 157 | { 2, 16, {{ 1, 0, 16,11, 11, 6, 6, 1 }}, GGL_RGBA }, // RK_FORMAT_RGBA_5551 158 | { 2, 16, {{ 4, 0, 16,12, 12, 8, 8, 4 }}, GGL_RGBA }, // RK_FORMAT_RGBA_4444 159 | { 3, 24, {{ 0, 0, 24,16, 16, 8, 8, 0 }}, GGL_BGR }, // RK_FORMAT_BGB_888 160 | 161 | */ 162 | /* In order to be compatible with RK_FORMAT_XX and HAL_PIXEL_FORMAT_XX, 163 | * RK_FORMAT_XX is shifted to the left by 8 bits to distinguish. */ 164 | typedef enum _Rga_SURF_FORMAT { 165 | RK_FORMAT_RGBA_8888 = 0x0 << 8, 166 | RK_FORMAT_RGBX_8888 = 0x1 << 8, 167 | RK_FORMAT_RGB_888 = 0x2 << 8, 168 | RK_FORMAT_BGRA_8888 = 0x3 << 8, 169 | RK_FORMAT_RGB_565 = 0x4 << 8, 170 | RK_FORMAT_RGBA_5551 = 0x5 << 8, 171 | RK_FORMAT_RGBA_4444 = 0x6 << 8, 172 | RK_FORMAT_BGR_888 = 0x7 << 8, 173 | 174 | RK_FORMAT_YCbCr_422_SP = 0x8 << 8, 175 | RK_FORMAT_YCbCr_422_P = 0x9 << 8, 176 | RK_FORMAT_YCbCr_420_SP = 0xa << 8, 177 | RK_FORMAT_YCbCr_420_P = 0xb << 8, 178 | 179 | RK_FORMAT_YCrCb_422_SP = 0xc << 8, 180 | RK_FORMAT_YCrCb_422_P = 0xd << 8, 181 | RK_FORMAT_YCrCb_420_SP = 0xe << 8, 182 | RK_FORMAT_YCrCb_420_P = 0xf << 8, 183 | 184 | RK_FORMAT_BPP1 = 0x10 << 8, 185 | RK_FORMAT_BPP2 = 0x11 << 8, 186 | RK_FORMAT_BPP4 = 0x12 << 8, 187 | RK_FORMAT_BPP8 = 0x13 << 8, 188 | 189 | RK_FORMAT_Y4 = 0x14 << 8, 190 | RK_FORMAT_YCbCr_400 = 0x15 << 8, 191 | 192 | RK_FORMAT_BGRX_8888 = 0x16 << 8, 193 | 194 | RK_FORMAT_YVYU_422 = 0x18 << 8, 195 | RK_FORMAT_YVYU_420 = 0x19 << 8, 196 | RK_FORMAT_VYUY_422 = 0x1a << 8, 197 | RK_FORMAT_VYUY_420 = 0x1b << 8, 198 | RK_FORMAT_YUYV_422 = 0x1c << 8, 199 | RK_FORMAT_YUYV_420 = 0x1d << 8, 200 | RK_FORMAT_UYVY_422 = 0x1e << 8, 201 | RK_FORMAT_UYVY_420 = 0x1f << 8, 202 | 203 | RK_FORMAT_YCbCr_420_SP_10B = 0x20 << 8, 204 | RK_FORMAT_YCrCb_420_SP_10B = 0x21 << 8, 205 | RK_FORMAT_YCbCr_422_SP_10B = 0x22 << 8, 206 | RK_FORMAT_YCrCb_422_SP_10B = 0x23 << 8, 207 | /* For compatibility with misspellings */ 208 | RK_FORMAT_YCbCr_422_10b_SP = RK_FORMAT_YCbCr_422_SP_10B, 209 | RK_FORMAT_YCrCb_422_10b_SP = RK_FORMAT_YCrCb_422_SP_10B, 210 | 211 | RK_FORMAT_BGR_565 = 0x24 << 8, 212 | RK_FORMAT_BGRA_5551 = 0x25 << 8, 213 | RK_FORMAT_BGRA_4444 = 0x26 << 8, 214 | 215 | RK_FORMAT_ARGB_8888 = 0x28 << 8, 216 | RK_FORMAT_XRGB_8888 = 0x29 << 8, 217 | RK_FORMAT_ARGB_5551 = 0x2a << 8, 218 | RK_FORMAT_ARGB_4444 = 0x2b << 8, 219 | RK_FORMAT_ABGR_8888 = 0x2c << 8, 220 | RK_FORMAT_XBGR_8888 = 0x2d << 8, 221 | RK_FORMAT_ABGR_5551 = 0x2e << 8, 222 | RK_FORMAT_ABGR_4444 = 0x2f << 8, 223 | 224 | RK_FORMAT_RGBA2BPP = 0x30 << 8, 225 | 226 | RK_FORMAT_UNKNOWN = 0x100 << 8, 227 | } RgaSURF_FORMAT; 228 | 229 | /* RGA3 rd_mode */ 230 | enum 231 | { 232 | raster_mode = 0x1 << 0, 233 | fbc_mode = 0x1 << 1, 234 | tile_mode = 0x1 << 2, 235 | }; 236 | 237 | typedef struct rga_img_info_t { 238 | uint64_t yrgb_addr; /* yrgb mem addr */ 239 | uint64_t uv_addr; /* cb/cr mem addr */ 240 | uint64_t v_addr; /* cr mem addr */ 241 | 242 | uint32_t format; //definition by RK_FORMAT 243 | uint16_t act_w; 244 | uint16_t act_h; 245 | uint16_t x_offset; 246 | uint16_t y_offset; 247 | 248 | uint16_t vir_w; 249 | uint16_t vir_h; 250 | 251 | uint16_t endian_mode; //for BPP 252 | uint16_t alpha_swap; 253 | 254 | //used by RGA3 255 | uint16_t rotate_mode; 256 | uint16_t rd_mode; 257 | 258 | uint16_t is_10b_compact; 259 | uint16_t is_10b_endian; 260 | 261 | uint16_t enable; 262 | } 263 | rga_img_info_t; 264 | 265 | typedef struct POINT { 266 | uint16_t x; 267 | uint16_t y; 268 | } 269 | POINT; 270 | 271 | typedef struct RECT { 272 | uint16_t xmin; 273 | uint16_t xmax; // width - 1 274 | uint16_t ymin; 275 | uint16_t ymax; // height - 1 276 | } RECT; 277 | 278 | typedef struct MMU { 279 | uint8_t mmu_en; 280 | uint64_t base_addr; 281 | uint32_t mmu_flag; /* [0] mmu enable [1] src_flush [2] dst_flush [3] CMD_flush [4~5] page size*/ 282 | } MMU; 283 | 284 | typedef struct COLOR_FILL { 285 | int16_t gr_x_a; 286 | int16_t gr_y_a; 287 | int16_t gr_x_b; 288 | int16_t gr_y_b; 289 | int16_t gr_x_g; 290 | int16_t gr_y_g; 291 | int16_t gr_x_r; 292 | int16_t gr_y_r; 293 | //u8 cp_gr_saturation; 294 | } 295 | COLOR_FILL; 296 | 297 | typedef struct FADING { 298 | uint8_t b; 299 | uint8_t g; 300 | uint8_t r; 301 | uint8_t res; 302 | } 303 | FADING; 304 | 305 | typedef struct line_draw_t { 306 | POINT start_point; /* LineDraw_start_point */ 307 | POINT end_point; /* LineDraw_end_point */ 308 | uint32_t color; /* LineDraw_color */ 309 | uint32_t flag; /* (enum) LineDrawing mode sel */ 310 | uint32_t line_width; /* range 1~16 */ 311 | } 312 | line_draw_t; 313 | 314 | /* color space convert coefficient. */ 315 | typedef struct csc_coe_t { 316 | int16_t r_v; 317 | int16_t g_y; 318 | int16_t b_u; 319 | int32_t off; 320 | } csc_coe_t; 321 | 322 | typedef struct full_csc_t { 323 | uint8_t flag; 324 | csc_coe_t coe_y; 325 | csc_coe_t coe_u; 326 | csc_coe_t coe_v; 327 | } full_csc_t; 328 | 329 | struct rga_mosaic_info { 330 | uint8_t enable; 331 | uint8_t mode; 332 | }; 333 | 334 | struct rga_pre_intr_info { 335 | uint8_t enable; 336 | 337 | uint8_t read_intr_en; 338 | uint8_t write_intr_en; 339 | uint8_t read_hold_en; 340 | uint32_t read_threshold; 341 | uint32_t write_start; 342 | uint32_t write_step; 343 | }; 344 | 345 | /* MAX(min, (max - channel_value)) */ 346 | struct rga_osd_invert_factor { 347 | uint8_t alpha_max; 348 | uint8_t alpha_min; 349 | uint8_t yg_max; 350 | uint8_t yg_min; 351 | uint8_t crb_max; 352 | uint8_t crb_min; 353 | }; 354 | 355 | struct rga_color { 356 | union { 357 | struct { 358 | uint8_t red; 359 | uint8_t green; 360 | uint8_t blue; 361 | uint8_t alpha; 362 | }; 363 | uint32_t value; 364 | }; 365 | }; 366 | 367 | struct rga_osd_bpp2 { 368 | uint8_t ac_swap; // ac swap flag 369 | // 0: CA 370 | // 1: AC 371 | uint8_t endian_swap; // rgba2bpp endian swap 372 | // 0: Big endian 373 | // 1: Little endian 374 | struct rga_color color0; 375 | struct rga_color color1; 376 | }; 377 | 378 | struct rga_osd_mode_ctrl { 379 | uint8_t mode; // OSD cal mode: 380 | // 0b'1: statistics mode 381 | // 1b'1: auto inversion overlap mode 382 | uint8_t direction_mode; // horizontal or vertical 383 | // 0: horizontal 384 | // 1: vertical 385 | uint8_t width_mode; // using @fix_width or LUT width 386 | // 0: fix width 387 | // 1: LUT width 388 | uint16_t block_fix_width; // OSD block fixed width 389 | // real width = (fix_width + 1) * 2 390 | uint8_t block_num; // OSD block num 391 | uint16_t flags_index; // auto invert flags index 392 | 393 | /* invertion config */ 394 | uint8_t color_mode; // selete color 395 | // 0: src1 color 396 | // 1: config data color 397 | uint8_t invert_flags_mode; // invert flag selete 398 | // 0: use RAM flag 399 | // 1: usr last result 400 | uint8_t default_color_sel; // default color mode 401 | // 0: default is bright 402 | // 1: default is dark 403 | uint8_t invert_enable; // invert channel enable 404 | // 1 << 0: aplha enable 405 | // 1 << 1: Y/G disable 406 | // 1 << 2: C/RB disable 407 | uint8_t invert_mode; // invert cal mode 408 | // 0: normal(max-data) 409 | // 1: swap 410 | uint8_t invert_thresh; // if luma > thresh, osd_flag to be 1 411 | uint8_t unfix_index; // OSD width config index 412 | }; 413 | 414 | struct rga_osd_info { 415 | uint8_t enable; 416 | 417 | struct rga_osd_mode_ctrl mode_ctrl; 418 | struct rga_osd_invert_factor cal_factor; 419 | struct rga_osd_bpp2 bpp2_info; 420 | 421 | union { 422 | struct { 423 | uint32_t last_flags1; 424 | uint32_t last_flags0; 425 | }; 426 | uint64_t last_flags; 427 | }; 428 | 429 | union { 430 | struct { 431 | uint32_t cur_flags1; 432 | uint32_t cur_flags0; 433 | }; 434 | uint64_t cur_flags; 435 | }; 436 | }; 437 | 438 | #define RGA_VERSION_SIZE 16 439 | #define RGA_HW_SIZE 5 440 | 441 | struct rga_version_t { 442 | uint32_t major; 443 | uint32_t minor; 444 | uint32_t revision; 445 | uint8_t str[RGA_VERSION_SIZE]; 446 | }; 447 | 448 | struct rga_hw_versions_t { 449 | struct rga_version_t version[RGA_HW_SIZE]; 450 | uint32_t size; 451 | }; 452 | 453 | struct rga_memory_parm { 454 | uint32_t width; 455 | uint32_t height; 456 | uint32_t format; 457 | 458 | uint32_t size; 459 | }; 460 | 461 | struct rga_external_buffer { 462 | uint64_t memory; 463 | uint32_t type; 464 | 465 | uint32_t handle; 466 | struct rga_memory_parm memory_info; 467 | 468 | uint8_t reserve[252]; 469 | }; 470 | 471 | struct rga_buffer_pool { 472 | uint64_t buffers; 473 | uint32_t size; 474 | }; 475 | 476 | struct rga_req { 477 | uint8_t render_mode; /* (enum) process mode sel */ 478 | 479 | rga_img_info_t src; /* src image info */ 480 | rga_img_info_t dst; /* dst image info */ 481 | rga_img_info_t pat; /* patten image info */ 482 | 483 | uint64_t rop_mask_addr; /* rop4 mask addr */ 484 | uint64_t LUT_addr; /* LUT addr */ 485 | 486 | RECT clip; /* dst clip window default value is dst_vir */ 487 | /* value from [0, w-1] / [0, h-1]*/ 488 | 489 | int32_t sina; /* dst angle default value 0 16.16 scan from table */ 490 | int32_t cosa; /* dst angle default value 0 16.16 scan from table */ 491 | 492 | uint16_t alpha_rop_flag; /* alpha rop process flag */ 493 | /* ([0] = 1 alpha_rop_enable) */ 494 | /* ([1] = 1 rop enable) */ 495 | /* ([2] = 1 fading_enable) */ 496 | /* ([3] = 1 PD_enable) */ 497 | /* ([4] = 1 alpha cal_mode_sel) */ 498 | /* ([5] = 1 dither_enable) */ 499 | /* ([6] = 1 gradient fill mode sel) */ 500 | /* ([7] = 1 AA_enable) */ 501 | /* ([8] = 1 nn_quantize) */ 502 | /* ([9] = 1 Real color mode) */ 503 | 504 | uint8_t scale_mode; /* 0 nearst / 1 bilnear / 2 bicubic */ 505 | 506 | uint32_t color_key_max; /* color key max */ 507 | uint32_t color_key_min; /* color key min */ 508 | 509 | uint32_t fg_color; /* foreground color */ 510 | uint32_t bg_color; /* background color */ 511 | 512 | COLOR_FILL gr_color; /* color fill use gradient */ 513 | 514 | line_draw_t line_draw_info; 515 | 516 | FADING fading; 517 | 518 | uint8_t PD_mode; /* porter duff alpha mode sel */ 519 | 520 | uint8_t alpha_global_value; /* global alpha value */ 521 | 522 | uint16_t rop_code; /* rop2/3/4 code scan from rop code table*/ 523 | 524 | uint8_t bsfilter_flag; /* [2] 0 blur 1 sharp / [1:0] filter_type*/ 525 | 526 | uint8_t palette_mode; /* (enum) color palatte 0/1bpp, 1/2bpp 2/4bpp 3/8bpp*/ 527 | 528 | uint8_t yuv2rgb_mode; /* (enum) BT.601 MPEG / BT.601 JPEG / BT.709 */ 529 | 530 | uint8_t endian_mode; /* 0/big endian 1/little endian*/ 531 | 532 | uint8_t rotate_mode; /* (enum) rotate mode */ 533 | /* 0x0, no rotate */ 534 | /* 0x1, rotate */ 535 | /* 0x2, x_mirror */ 536 | /* 0x3, y_mirror */ 537 | 538 | uint8_t color_fill_mode; /* 0 solid color / 1 patten color */ 539 | 540 | MMU mmu_info; /* mmu information */ 541 | 542 | uint8_t alpha_rop_mode; /* ([0~1] alpha mode) */ 543 | /* ([2~3] rop mode) */ 544 | /* ([4] zero mode en) */ 545 | /* ([5] dst alpha mode) (RGA1) */ 546 | 547 | uint8_t src_trans_mode; 548 | 549 | uint8_t dither_mode; 550 | 551 | full_csc_t full_csc; /* full color space convert */ 552 | 553 | int32_t in_fence_fd; 554 | uint8_t core; 555 | uint8_t priority; 556 | int32_t out_fence_fd; 557 | 558 | uint8_t handle_flag; 559 | 560 | /* RGA2 1106 add */ 561 | struct rga_mosaic_info mosaic_info; 562 | 563 | uint8_t uvhds_mode; 564 | uint8_t uvvds_mode; 565 | 566 | struct rga_osd_info osd_info; 567 | 568 | struct rga_pre_intr_info pre_intr_info; 569 | 570 | uint8_t reservr[59]; 571 | }; 572 | 573 | struct rga_user_ctx_t { 574 | uint64_t cmd_ptr; 575 | uint32_t cmd_num; 576 | uint32_t id; 577 | uint32_t sync_mode; 578 | uint32_t out_fence_fd; 579 | 580 | uint32_t mpi_config_flags; 581 | 582 | uint8_t reservr[124]; 583 | }; 584 | 585 | #ifdef __cplusplus 586 | } 587 | #endif 588 | 589 | #endif /*_RK29_IPP_DRIVER_H_*/ 590 | -------------------------------------------------------------------------------- /include/3rdparty/rga/RK3588/lib/Linux/aarch64/librga.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/include/3rdparty/rga/RK3588/lib/Linux/aarch64/librga.so -------------------------------------------------------------------------------- /include/3rdparty/rk_mpi_mmz/include/rk_mpi_mmz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Rockchip Electronics Co. LTD 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | #ifndef __RK_MPI_MMZ_H__ 19 | #define __RK_MPI_MMZ_H__ 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | #if __cplusplus 25 | extern "C" { 26 | #endif 27 | #endif /* End of #ifdef __cplusplus */ 28 | 29 | typedef void* MB_BLK; 30 | typedef int RK_S32; 31 | typedef uint32_t RK_U32; 32 | typedef uint64_t RK_U64; 33 | typedef void RK_VOID; 34 | 35 | #define RK_MMZ_ALLOC_TYPE_IOMMU 0x00000000 36 | #define RK_MMZ_ALLOC_TYPE_CMA 0x00000001 37 | 38 | #define RK_MMZ_ALLOC_CACHEABLE 0x00000000 39 | #define RK_MMZ_ALLOC_UNCACHEABLE 0x00000010 40 | 41 | #define RK_MMZ_SYNC_READONLY 0x00000000 42 | #define RK_MMZ_SYNC_WRITEONLY 0x00000001 43 | #define RK_MMZ_SYNC_RW 0x00000002 44 | 45 | /* 46 | 申请buffer 47 | pBlk 返回分配的buffer信息 48 | u32Len 申请buffer的大小 49 | u32Flags 申请buffer类型 50 | 成功 返回0 51 | 失败 返回负值 52 | */ 53 | RK_S32 RK_MPI_MMZ_Alloc(MB_BLK *pBlk, RK_U32 u32Len, RK_U32 u32Flags); 54 | 55 | /* 56 | 释放buffer 57 | */ 58 | RK_S32 RK_MPI_MMZ_Free(MB_BLK mb); 59 | 60 | /* 61 | 获取物理地址 62 | 对于物理连续内存,返回其物理地址 63 | 对于非物理连续内存,返回-1 64 | */ 65 | RK_U64 RK_MPI_MMZ_Handle2PhysAddr(MB_BLK mb); 66 | 67 | /* 68 | 获取用户空间虚拟地址 69 | 失败返回NULL 70 | */ 71 | RK_VOID *RK_MPI_MMZ_Handle2VirAddr(MB_BLK mb); 72 | 73 | /* 74 | 获取buffer的fd 75 | 失败返回-1 76 | */ 77 | RK_S32 RK_MPI_MMZ_Handle2Fd(MB_BLK mb); 78 | 79 | /* 80 | 获取buffer大小 81 | 失败返回 (RK_U64)-1 82 | */ 83 | RK_U64 RK_MPI_MMZ_GetSize(MB_BLK mb); 84 | 85 | /* 86 | 通过fd查找到对应的buffer 87 | 成功 返回mb 88 | 失败 返回NULL 89 | */ 90 | MB_BLK RK_MPI_MMZ_Fd2Handle(RK_S32 fd); 91 | 92 | /* 93 | 通过vaddr查找到对应的buffer 94 | 成功 返回mb 95 | 失败 返回NULL 96 | */ 97 | MB_BLK RK_MPI_MMZ_VirAddr2Handle(RK_VOID *pstVirAddr); 98 | 99 | /* 100 | 通过paddr查找到对应的buffer 101 | 成功 返回mb 102 | 失败 返回NULL 103 | */ 104 | MB_BLK RK_MPI_MMZ_PhyAddr2Handle(RK_U64 paddr); 105 | 106 | /* 107 | 查询buffer是否cacheable 108 | 是 返回1 109 | 否 返回0 110 | 不确定 返回-1 111 | */ 112 | RK_S32 RK_MPI_MMZ_IsCacheable(MB_BLK mb); 113 | 114 | /* 115 | flush cache, 在cpu访问前调用 116 | 当offset和length都等于0时候,执行full sync,否则执行partial sync 117 | 成功 返回0 118 | 失败 返回负值 119 | */ 120 | RK_S32 RK_MPI_MMZ_FlushCacheStart(MB_BLK mb, RK_U32 offset, RK_U32 length, RK_U32 flags); 121 | 122 | /* 123 | flush cache, 在cpu访问结束后调用 124 | 当offset和length都等于0时候,执行full sync,否则执行partial sync 125 | 成功 返回0 126 | 失败 返回负值 127 | */ 128 | RK_S32 RK_MPI_MMZ_FlushCacheEnd(MB_BLK mb, RK_U32 offset, RK_U32 length, RK_U32 flags); 129 | 130 | /* 131 | flush cache, 在cpu访问前调用 132 | 指定待刷新内存的虚拟地址及其长度,只支持partial sync 133 | 成功 返回0 134 | 失败 返回负值 135 | */ 136 | RK_S32 RK_MPI_MMZ_FlushCacheVaddrStart(RK_VOID* vaddr, RK_U32 length, RK_U32 flags); 137 | 138 | /* 139 | flush cache, 在cpu访问结束后调用 140 | 指定待刷新内存的虚拟地址及其长度,只支持partial sync 141 | 成功 返回0 142 | 失败 返回负值 143 | */ 144 | RK_S32 RK_MPI_MMZ_FlushCacheVaddrEnd(RK_VOID* vaddr, RK_U32 length, RK_U32 flags); 145 | 146 | /* 147 | flush cache, 在cpu访问前调用 148 | 指定待刷新内存的物理地址及其长度,只支持partial sync 149 | 成功 返回0 150 | 失败 返回负值 151 | */ 152 | RK_S32 RK_MPI_MMZ_FlushCachePaddrStart(RK_U64 vaddr, RK_U32 length, RK_U32 flags); 153 | 154 | /* 155 | flush cache, 在cpu访问结束后调用 156 | 指定待刷新内存的物理地址及其长度,只支持partial sync 157 | 成功 返回0 158 | 失败 返回负值 159 | */ 160 | RK_S32 RK_MPI_MMZ_FlushCachePaddrEnd(RK_U64 vaddr, RK_U32 length, RK_U32 flags); 161 | 162 | #ifdef __cplusplus 163 | #if __cplusplus 164 | } 165 | #endif 166 | #endif /* End of #ifdef __cplusplus */ 167 | 168 | #endif /* __RK_MPI_MMZ_H__ */ -------------------------------------------------------------------------------- /include/3rdparty/rk_mpi_mmz/lib/Linux/aarch64/libmpimmz.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/include/3rdparty/rk_mpi_mmz/lib/Linux/aarch64/libmpimmz.so -------------------------------------------------------------------------------- /include/3rdparty/rk_mpi_mmz/readme.txt: -------------------------------------------------------------------------------- 1 | version:1.6 2 | -------------------------------------------------------------------------------- /include/MvErrorDefine.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MV_ERROR_DEFINE_H_ 3 | #define _MV_ERROR_DEFINE_H_ 4 | 5 | /********************************************************************/ 6 | /// \~chinese 7 | /// \name 正确码定义 8 | /// @{ 9 | /// \~english 10 | /// \name Definition of correct code 11 | /// @{ 12 | #define MV_OK 0x00000000 ///< \~chinese 成功,无错误 \~english Successed, no error 13 | /// @} 14 | 15 | /********************************************************************/ 16 | /// \~chinese 17 | /// \name 通用错误码定义:范围0x80000000-0x800000FF 18 | /// @{ 19 | /// \~english 20 | /// \name Definition of General error code 21 | /// @{ 22 | #define MV_E_HANDLE 0x80000000 ///< \~chinese 错误或无效的句柄 \~english Error or invalid handle 23 | #define MV_E_SUPPORT 0x80000001 ///< \~chinese 不支持的功能 \~english Not supported function 24 | #define MV_E_BUFOVER 0x80000002 ///< \~chinese 缓存已满 \~english Buffer overflow 25 | #define MV_E_CALLORDER 0x80000003 ///< \~chinese 函数调用顺序错误 \~english Function calling order error 26 | #define MV_E_PARAMETER 0x80000004 ///< \~chinese 错误的参数 \~english Incorrect parameter 27 | #define MV_E_RESOURCE 0x80000006 ///< \~chinese 资源申请失败 \~english Applying resource failed 28 | #define MV_E_NODATA 0x80000007 ///< \~chinese 无数据 \~english No data 29 | #define MV_E_PRECONDITION 0x80000008 ///< \~chinese 前置条件有误,或运行环境已发生变化 \~english Precondition error, or running environment changed 30 | #define MV_E_VERSION 0x80000009 ///< \~chinese 版本不匹配 \~english Version mismatches 31 | #define MV_E_NOENOUGH_BUF 0x8000000A ///< \~chinese 传入的内存空间不足 \~english Insufficient memory 32 | #define MV_E_ABNORMAL_IMAGE 0x8000000B ///< \~chinese 异常图像,可能是丢包导致图像不完整 \~english Abnormal image, maybe incomplete image because of lost packet 33 | #define MV_E_LOAD_LIBRARY 0x8000000C ///< \~chinese 动态导入DLL失败 \~english Load library failed 34 | #define MV_E_NOOUTBUF 0x8000000D ///< \~chinese 没有可输出的缓存 \~english No Avaliable Buffer 35 | #define MV_E_UNKNOW 0x800000FF ///< \~chinese 未知的错误 \~english Unknown error 36 | /// @} 37 | 38 | /********************************************************************/ 39 | /// \~chinese 40 | /// \name GenICam系列错误:范围0x80000100-0x800001FF 41 | /// @{ 42 | /// \~english 43 | /// \name GenICam Series Error Codes: Range from 0x80000100 to 0x800001FF 44 | /// @{ 45 | #define MV_E_GC_GENERIC 0x80000100 ///< \~chinese 通用错误 \~english General error 46 | #define MV_E_GC_ARGUMENT 0x80000101 ///< \~chinese 参数非法 \~english Illegal parameters 47 | #define MV_E_GC_RANGE 0x80000102 ///< \~chinese 值超出范围 \~english The value is out of range 48 | #define MV_E_GC_PROPERTY 0x80000103 ///< \~chinese 属性 \~english Property 49 | #define MV_E_GC_RUNTIME 0x80000104 ///< \~chinese 运行环境有问题 \~english Running environment error 50 | #define MV_E_GC_LOGICAL 0x80000105 ///< \~chinese 逻辑错误 \~english Logical error 51 | #define MV_E_GC_ACCESS 0x80000106 ///< \~chinese 节点访问条件有误 \~english Node accessing condition error 52 | #define MV_E_GC_TIMEOUT 0x80000107 ///< \~chinese 超时 \~english Timeout 53 | #define MV_E_GC_DYNAMICCAST 0x80000108 ///< \~chinese 转换异常 \~english Transformation exception 54 | #define MV_E_GC_UNKNOW 0x800001FF ///< \~chinese GenICam未知错误 \~english GenICam unknown error 55 | /// @} 56 | 57 | /********************************************************************/ 58 | /// \~chinese 59 | /// \name GigE_STATUS对应的错误码:范围0x80000200-0x800002FF 60 | /// @{ 61 | /// \~english 62 | /// \name GigE_STATUS Error Codes: Range from 0x80000200 to 0x800002FF 63 | /// @{ 64 | #define MV_E_NOT_IMPLEMENTED 0x80000200 ///< \~chinese 命令不被设备支持 \~english The command is not supported by device 65 | #define MV_E_INVALID_ADDRESS 0x80000201 ///< \~chinese 访问的目标地址不存在 \~english The target address being accessed does not exist 66 | #define MV_E_WRITE_PROTECT 0x80000202 ///< \~chinese 目标地址不可写 \~english The target address is not writable 67 | #define MV_E_ACCESS_DENIED 0x80000203 ///< \~chinese 设备无访问权限 \~english No permission 68 | #define MV_E_BUSY 0x80000204 ///< \~chinese 设备忙,或网络断开 \~english Device is busy, or network disconnected 69 | #define MV_E_PACKET 0x80000205 ///< \~chinese 网络包数据错误 \~english Network data packet error 70 | #define MV_E_NETER 0x80000206 ///< \~chinese 网络相关错误 \~english Network error 71 | #define MV_E_IP_CONFLICT 0x80000221 ///< \~chinese 设备IP冲突 \~english Device IP conflict 72 | /// @} 73 | 74 | /********************************************************************/ 75 | /// \~chinese 76 | /// \name USB_STATUS对应的错误码:范围0x80000300-0x800003FF 77 | /// @{ 78 | /// \~english 79 | /// \name USB_STATUS Error Codes: Range from 0x80000300 to 0x800003FF 80 | /// @{ 81 | #define MV_E_USB_READ 0x80000300 ///< \~chinese 读usb出错 \~english Reading USB error 82 | #define MV_E_USB_WRITE 0x80000301 ///< \~chinese 写usb出错 \~english Writing USB error 83 | #define MV_E_USB_DEVICE 0x80000302 ///< \~chinese 设备异常 \~english Device exception 84 | #define MV_E_USB_GENICAM 0x80000303 ///< \~chinese GenICam相关错误 \~english GenICam error 85 | #define MV_E_USB_BANDWIDTH 0x80000304 ///< \~chinese 带宽不足 该错误码新增 \~english Insufficient bandwidth, this error code is newly added 86 | #define MV_E_USB_DRIVER 0x80000305 ///< \~chinese 驱动不匹配或者未装驱动 \~english Driver mismatch or unmounted drive 87 | #define MV_E_USB_UNKNOW 0x800003FF ///< \~chinese USB未知的错误 \~english USB unknown error 88 | /// @} 89 | 90 | /********************************************************************/ 91 | /// \~chinese 92 | /// \name 升级时对应的错误码:范围0x80000400-0x800004FF 93 | /// @{ 94 | /// \~english 95 | /// \name Upgrade Error Codes: Range from 0x80000400 to 0x800004FF 96 | /// @{ 97 | #define MV_E_UPG_FILE_MISMATCH 0x80000400 ///< \~chinese 升级固件不匹配 \~english Firmware mismatches 98 | #define MV_E_UPG_LANGUSGE_MISMATCH 0x80000401 ///< \~chinese 升级固件语言不匹配 \~english Firmware language mismatches 99 | #define MV_E_UPG_CONFLICT 0x80000402 ///< \~chinese 升级冲突(设备已经在升级了再次请求升级即返回此错误) \~english Upgrading conflicted (repeated upgrading requests during device upgrade) 100 | #define MV_E_UPG_INNER_ERR 0x80000403 ///< \~chinese 升级时相机内部出现错误 \~english Camera internal error during upgrade 101 | #define MV_E_UPG_UNKNOW 0x800004FF ///< \~chinese 升级时未知错误 \~english Unknown error during upgrade 102 | /// @} 103 | 104 | #endif //_MV_ERROR_DEFINE_H_ 105 | -------------------------------------------------------------------------------- /include/MvISPErrorDefine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/include/MvISPErrorDefine.h -------------------------------------------------------------------------------- /include/PixelType.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _MV_PIXEL_TYPE_H_ 3 | #define _MV_PIXEL_TYPE_H_ 4 | 5 | //#include "Base/GCTypes.h" 6 | 7 | 8 | /************************************************************************/ 9 | /* GigE Vision (2.0.03) PIXEL FORMATS */ 10 | /************************************************************************/ 11 | 12 | // Indicate if pixel is monochrome or RGB 13 | #define MV_GVSP_PIX_MONO 0x01000000 14 | #define MV_GVSP_PIX_RGB 0x02000000 // deprecated in version 1.1 15 | #define MV_GVSP_PIX_COLOR 0x02000000 16 | #define MV_GVSP_PIX_CUSTOM 0x80000000 17 | #define MV_GVSP_PIX_COLOR_MASK 0xFF000000 18 | 19 | // Indicate effective number of bits occupied by the pixel (including padding). 20 | // This can be used to compute amount of memory required to store an image. 21 | #define MV_PIXEL_BIT_COUNT(n) ((n) << 16) 22 | 23 | #define MV_GVSP_PIX_EFFECTIVE_PIXEL_SIZE_MASK 0x00FF0000 24 | #define MV_GVSP_PIX_EFFECTIVE_PIXEL_SIZE_SHIFT 16 25 | 26 | // Pixel ID: lower 16-bit of the pixel formats 27 | #define MV_GVSP_PIX_ID_MASK 0x0000FFFF 28 | #define MV_GVSP_PIX_COUNT 0x46 // next Pixel ID available 29 | 30 | 31 | enum MvGvspPixelType 32 | { 33 | // Undefined pixel type 34 | #ifdef WIN32 35 | PixelType_Gvsp_Undefined = 0xFFFFFFFF, 36 | #else 37 | PixelType_Gvsp_Undefined = -1, 38 | #endif 39 | // Mono buffer format defines 40 | PixelType_Gvsp_Mono1p = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(1) | 0x0037), 41 | PixelType_Gvsp_Mono2p = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(2) | 0x0038), 42 | PixelType_Gvsp_Mono4p = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(4) | 0x0039), 43 | PixelType_Gvsp_Mono8 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0001), 44 | PixelType_Gvsp_Mono8_Signed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0002), 45 | PixelType_Gvsp_Mono10 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0003), 46 | PixelType_Gvsp_Mono10_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0004), 47 | PixelType_Gvsp_Mono12 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0005), 48 | PixelType_Gvsp_Mono12_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0006), 49 | PixelType_Gvsp_Mono14 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0025), 50 | PixelType_Gvsp_Mono16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0007), 51 | 52 | // Bayer buffer format defines 53 | PixelType_Gvsp_BayerGR8 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0008), 54 | PixelType_Gvsp_BayerRG8 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0009), 55 | PixelType_Gvsp_BayerGB8 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000A), 56 | PixelType_Gvsp_BayerBG8 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000B), 57 | PixelType_Gvsp_BayerGR10 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000C), 58 | PixelType_Gvsp_BayerRG10 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000D), 59 | PixelType_Gvsp_BayerGB10 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000E), 60 | PixelType_Gvsp_BayerBG10 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000F), 61 | PixelType_Gvsp_BayerGR12 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0010), 62 | PixelType_Gvsp_BayerRG12 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0011), 63 | PixelType_Gvsp_BayerGB12 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0012), 64 | PixelType_Gvsp_BayerBG12 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0013), 65 | PixelType_Gvsp_BayerGR10_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0026), 66 | PixelType_Gvsp_BayerRG10_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0027), 67 | PixelType_Gvsp_BayerGB10_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0028), 68 | PixelType_Gvsp_BayerBG10_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0029), 69 | PixelType_Gvsp_BayerGR12_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002A), 70 | PixelType_Gvsp_BayerRG12_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002B), 71 | PixelType_Gvsp_BayerGB12_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002C), 72 | PixelType_Gvsp_BayerBG12_Packed = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002D), 73 | PixelType_Gvsp_BayerGR16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x002E), 74 | PixelType_Gvsp_BayerRG16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x002F), 75 | PixelType_Gvsp_BayerGB16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0030), 76 | PixelType_Gvsp_BayerBG16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0031), 77 | 78 | // RGB Packed buffer format defines 79 | PixelType_Gvsp_RGB8_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0014), 80 | PixelType_Gvsp_BGR8_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0015), 81 | PixelType_Gvsp_RGBA8_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0016), 82 | PixelType_Gvsp_BGRA8_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0017), 83 | PixelType_Gvsp_RGB10_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0018), 84 | PixelType_Gvsp_BGR10_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0019), 85 | PixelType_Gvsp_RGB12_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x001A), 86 | PixelType_Gvsp_BGR12_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x001B), 87 | PixelType_Gvsp_RGB16_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0033), 88 | PixelType_Gvsp_BGR16_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x004B), 89 | PixelType_Gvsp_RGBA16_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x0064), 90 | PixelType_Gvsp_BGRA16_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x0051), 91 | PixelType_Gvsp_RGB10V1_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x001C), 92 | PixelType_Gvsp_RGB10V2_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x001D), 93 | PixelType_Gvsp_RGB12V1_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(36) | 0X0034), 94 | PixelType_Gvsp_RGB565_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0035), 95 | PixelType_Gvsp_BGR565_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0X0036), 96 | 97 | // YUV Packed buffer format defines 98 | PixelType_Gvsp_YUV411_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x001E), 99 | PixelType_Gvsp_YUV422_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x001F), 100 | PixelType_Gvsp_YUV422_YUYV_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0032), 101 | PixelType_Gvsp_YUV444_Packed = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0020), 102 | PixelType_Gvsp_YCBCR8_CBYCR = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x003A), 103 | PixelType_Gvsp_YCBCR422_8 = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x003B), 104 | PixelType_Gvsp_YCBCR422_8_CBYCRY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0043), 105 | PixelType_Gvsp_YCBCR411_8_CBYYCRYY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x003C), 106 | PixelType_Gvsp_YCBCR601_8_CBYCR = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x003D), 107 | PixelType_Gvsp_YCBCR601_422_8 = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x003E), 108 | PixelType_Gvsp_YCBCR601_422_8_CBYCRY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0044), 109 | PixelType_Gvsp_YCBCR601_411_8_CBYYCRYY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x003F), 110 | PixelType_Gvsp_YCBCR709_8_CBYCR = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0040), 111 | PixelType_Gvsp_YCBCR709_422_8 = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0041), 112 | PixelType_Gvsp_YCBCR709_422_8_CBYCRY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0045), 113 | PixelType_Gvsp_YCBCR709_411_8_CBYYCRYY = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(12) | 0x0042), 114 | 115 | // RGB Planar buffer format defines 116 | PixelType_Gvsp_RGB8_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0021), 117 | PixelType_Gvsp_RGB10_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0022), 118 | PixelType_Gvsp_RGB12_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0023), 119 | PixelType_Gvsp_RGB16_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0024), 120 | 121 | // 自定义的图片格式 122 | PixelType_Gvsp_Jpeg = (MV_GVSP_PIX_CUSTOM | MV_PIXEL_BIT_COUNT(24) | 0x0001), 123 | 124 | PixelType_Gvsp_Coord3D_ABC32f = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(96) | 0x00C0),//0x026000C0 125 | PixelType_Gvsp_Coord3D_ABC32f_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(96) | 0x00C1),//0x026000C1 126 | 127 | // 该值被废弃,请参考PixelType_Gvsp_Coord3D_AC32f_64; the value is discarded 128 | PixelType_Gvsp_Coord3D_AC32f = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(40) | 0x00C2), 129 | // 该值被废弃; the value is discarded (已放入Chunkdata) 130 | PixelType_Gvsp_COORD3D_DEPTH_PLUS_MASK = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(28) | 0x0001), 131 | 132 | PixelType_Gvsp_Coord3D_ABC32 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(96) | 0x3001),//0x82603001 133 | PixelType_Gvsp_Coord3D_AB32f = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x3002),//0x82403002 134 | PixelType_Gvsp_Coord3D_AB32 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x3003),//0x82403003 135 | PixelType_Gvsp_Coord3D_AC32f_64 = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x00C2),//0x024000C2 136 | PixelType_Gvsp_Coord3D_AC32f_Planar = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x00C3),//0x024000C3 137 | PixelType_Gvsp_Coord3D_AC32 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x3004),//0x82403004 138 | PixelType_Gvsp_Coord3D_A32f = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(32) | 0x00BD),//0x012000BD 139 | PixelType_Gvsp_Coord3D_A32 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(32) | 0x3005),//0x81203005 140 | PixelType_Gvsp_Coord3D_C32f = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(32) | 0x00BF),//0x012000BF 141 | PixelType_Gvsp_Coord3D_C32 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(32) | 0x3006),//0x81203006 142 | 143 | PixelType_Gvsp_Coord3D_ABC16 = (MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x00B9),//0x023000B9 144 | PixelType_Gvsp_Coord3D_C16 = (MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x00B8),//0x011000B8 145 | 146 | //无损压缩像素格式定义 147 | PixelType_Gvsp_HB_Mono8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0001), 148 | PixelType_Gvsp_HB_Mono10 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0003), 149 | PixelType_Gvsp_HB_Mono10_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0004), 150 | PixelType_Gvsp_HB_Mono12 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0005), 151 | PixelType_Gvsp_HB_Mono12_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0006), 152 | PixelType_Gvsp_HB_Mono16 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0007), 153 | PixelType_Gvsp_HB_BayerGR8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0008), 154 | PixelType_Gvsp_HB_BayerRG8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0009), 155 | PixelType_Gvsp_HB_BayerGB8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000A), 156 | PixelType_Gvsp_HB_BayerBG8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x000B), 157 | PixelType_Gvsp_HB_BayerRBGG8 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(8) | 0x0046), 158 | PixelType_Gvsp_HB_BayerGR10 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000C), 159 | PixelType_Gvsp_HB_BayerRG10 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000D), 160 | PixelType_Gvsp_HB_BayerGB10 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000E), 161 | PixelType_Gvsp_HB_BayerBG10 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x000F), 162 | PixelType_Gvsp_HB_BayerGR12 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0010), 163 | PixelType_Gvsp_HB_BayerRG12 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0011), 164 | PixelType_Gvsp_HB_BayerGB12 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0012), 165 | PixelType_Gvsp_HB_BayerBG12 = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(16) | 0x0013), 166 | PixelType_Gvsp_HB_BayerGR10_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0026), 167 | PixelType_Gvsp_HB_BayerRG10_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0027), 168 | PixelType_Gvsp_HB_BayerGB10_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0028), 169 | PixelType_Gvsp_HB_BayerBG10_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x0029), 170 | PixelType_Gvsp_HB_BayerGR12_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002A), 171 | PixelType_Gvsp_HB_BayerRG12_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002B), 172 | PixelType_Gvsp_HB_BayerGB12_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002C), 173 | PixelType_Gvsp_HB_BayerBG12_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_MONO | MV_PIXEL_BIT_COUNT(12) | 0x002D), 174 | PixelType_Gvsp_HB_YUV422_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x001F), 175 | PixelType_Gvsp_HB_YUV422_YUYV_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(16) | 0x0032), 176 | PixelType_Gvsp_HB_RGB8_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0014), 177 | PixelType_Gvsp_HB_BGR8_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(24) | 0x0015), 178 | PixelType_Gvsp_HB_RGBA8_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0016), 179 | PixelType_Gvsp_HB_BGRA8_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(32) | 0x0017), 180 | PixelType_Gvsp_HB_RGB16_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x0033), 181 | PixelType_Gvsp_HB_BGR16_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(48) | 0x004B), 182 | PixelType_Gvsp_HB_RGBA16_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x0064), 183 | PixelType_Gvsp_HB_BGRA16_Packed = (MV_GVSP_PIX_CUSTOM | MV_GVSP_PIX_COLOR | MV_PIXEL_BIT_COUNT(64) | 0x0051), 184 | 185 | }; 186 | 187 | //enum MvUsbPixelType 188 | //{ 189 | // 190 | //}; 191 | 192 | //跨平台定义 193 | //Cross Platform Definition 194 | #ifdef WIN32 195 | typedef __int64 int64_t; 196 | typedef unsigned __int64 uint64_t; 197 | #else 198 | #include 199 | #endif 200 | 201 | 202 | #endif /* _MV_PIXEL_TYPE_H_ */ 203 | -------------------------------------------------------------------------------- /include/ThreadPool.hpp: -------------------------------------------------------------------------------- 1 | #ifndef THREADPOOL_H 2 | #define THREADPOOL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace dpool 15 | { 16 | 17 | class ThreadPool 18 | { 19 | public: 20 | using MutexGuard = std::lock_guard; 21 | using UniqueLock = std::unique_lock; 22 | using Thread = std::thread; 23 | using ThreadID = std::thread::id; 24 | using Task = std::function; 25 | 26 | ThreadPool() 27 | : ThreadPool(Thread::hardware_concurrency()) 28 | { 29 | } 30 | 31 | explicit ThreadPool(size_t maxThreads) 32 | : quit_(false), 33 | currentThreads_(0), 34 | idleThreads_(0), 35 | maxThreads_(maxThreads) 36 | { 37 | } 38 | 39 | // disable the copy operations 40 | ThreadPool(const ThreadPool &) = delete; 41 | ThreadPool &operator=(const ThreadPool &) = delete; 42 | 43 | ~ThreadPool() 44 | { 45 | { 46 | MutexGuard guard(mutex_); 47 | quit_ = true; 48 | } 49 | cv_.notify_all(); 50 | 51 | for (auto &elem : threads_) 52 | { 53 | assert(elem.second.joinable()); 54 | elem.second.join(); 55 | } 56 | } 57 | 58 | template 59 | auto submit(Func &&func, Ts &&...params) 60 | -> std::future::type> 61 | { 62 | auto execute = std::bind(std::forward(func), std::forward(params)...); 63 | 64 | using ReturnType = typename std::result_of::type; 65 | using PackagedTask = std::packaged_task; 66 | 67 | auto task = std::make_shared(std::move(execute)); 68 | auto result = task->get_future(); 69 | 70 | MutexGuard guard(mutex_); 71 | assert(!quit_); 72 | 73 | tasks_.emplace([task]() 74 | { (*task)(); }); 75 | if (idleThreads_ > 0) 76 | { 77 | cv_.notify_one(); 78 | } 79 | else if (currentThreads_ < maxThreads_) 80 | { 81 | Thread t(&ThreadPool::worker, this); 82 | assert(threads_.find(t.get_id()) == threads_.end()); 83 | threads_[t.get_id()] = std::move(t); 84 | ++currentThreads_; 85 | } 86 | 87 | return result; 88 | } 89 | 90 | size_t threadsNum() const 91 | { 92 | MutexGuard guard(mutex_); 93 | return currentThreads_; 94 | } 95 | 96 | private: 97 | void worker() 98 | { 99 | while (true) 100 | { 101 | Task task; 102 | { 103 | UniqueLock uniqueLock(mutex_); 104 | ++idleThreads_; 105 | auto hasTimedout = !cv_.wait_for(uniqueLock, 106 | std::chrono::seconds(WAIT_SECONDS), 107 | [this]() 108 | { 109 | return quit_ || !tasks_.empty(); 110 | }); 111 | --idleThreads_; 112 | if (tasks_.empty()) 113 | { 114 | if (quit_) 115 | { 116 | --currentThreads_; 117 | return; 118 | } 119 | if (hasTimedout) 120 | { 121 | --currentThreads_; 122 | joinFinishedThreads(); 123 | finishedThreadIDs_.emplace(std::this_thread::get_id()); 124 | return; 125 | } 126 | } 127 | task = std::move(tasks_.front()); 128 | tasks_.pop(); 129 | } 130 | task(); 131 | } 132 | } 133 | 134 | void joinFinishedThreads() 135 | { 136 | while (!finishedThreadIDs_.empty()) 137 | { 138 | auto id = std::move(finishedThreadIDs_.front()); 139 | finishedThreadIDs_.pop(); 140 | auto iter = threads_.find(id); 141 | 142 | assert(iter != threads_.end()); 143 | assert(iter->second.joinable()); 144 | 145 | iter->second.join(); 146 | threads_.erase(iter); 147 | } 148 | } 149 | 150 | static constexpr size_t WAIT_SECONDS = 2; 151 | 152 | bool quit_; 153 | size_t currentThreads_; 154 | size_t idleThreads_; 155 | size_t maxThreads_; 156 | 157 | mutable std::mutex mutex_; 158 | std::condition_variable cv_; 159 | std::queue tasks_; 160 | std::queue finishedThreadIDs_; 161 | std::unordered_map threads_; 162 | }; 163 | 164 | constexpr size_t ThreadPool::WAIT_SECONDS; 165 | 166 | } // namespace dpool 167 | 168 | #endif /* THREADPOOL_H */ -------------------------------------------------------------------------------- /include/drm_func.h: -------------------------------------------------------------------------------- 1 | #ifndef __DRM_FUNC_H__ 2 | #define __DRM_FUNC_H__ 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include // open function 8 | #include // close function 9 | #include 10 | #include 11 | 12 | 13 | #include 14 | #include "libdrm/drm_fourcc.h" 15 | #include "xf86drm.h" 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | typedef int (* FUNC_DRM_IOCTL)(int fd, unsigned long request, void *arg); 22 | 23 | typedef struct _drm_context{ 24 | void *drm_handle; 25 | FUNC_DRM_IOCTL io_func; 26 | } drm_context; 27 | 28 | /* memory type definitions. */ 29 | enum drm_rockchip_gem_mem_type 30 | { 31 | /* Physically Continuous memory and used as default. */ 32 | ROCKCHIP_BO_CONTIG = 1 << 0, 33 | /* cachable mapping. */ 34 | ROCKCHIP_BO_CACHABLE = 1 << 1, 35 | /* write-combine mapping. */ 36 | ROCKCHIP_BO_WC = 1 << 2, 37 | ROCKCHIP_BO_SECURE = 1 << 3, 38 | ROCKCHIP_BO_MASK = ROCKCHIP_BO_CONTIG | ROCKCHIP_BO_CACHABLE | 39 | ROCKCHIP_BO_WC | ROCKCHIP_BO_SECURE 40 | }; 41 | 42 | int drm_init(drm_context *drm_ctx); 43 | 44 | void* drm_buf_alloc(drm_context *drm_ctx,int drm_fd, int TexWidth, int TexHeight,int bpp,int *fd,unsigned int *handle,size_t *actual_size); 45 | 46 | int drm_buf_destroy(drm_context *drm_ctx,int drm_fd,int buf_fd, int handle,void *drm_buf,size_t size); 47 | 48 | void drm_deinit(drm_context *drm_ctx, int drm_fd); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | #endif /*__DRM_FUNC_H__*/ -------------------------------------------------------------------------------- /include/librknn_api.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/include/librknn_api.so -------------------------------------------------------------------------------- /include/librknnrt.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/include/librknnrt.so -------------------------------------------------------------------------------- /include/postprocess.h: -------------------------------------------------------------------------------- 1 | #ifndef _RKNN_ZERO_COPY_DEMO_POSTPROCESS_H_ 2 | #define _RKNN_ZERO_COPY_DEMO_POSTPROCESS_H_ 3 | 4 | #include 5 | #include 6 | 7 | #define OBJ_NAME_MAX_SIZE 16 8 | #define OBJ_NUMB_MAX_SIZE 64 9 | #define OBJ_CLASS_NUM 80 10 | #define NMS_THRESH 0.45 11 | #define BOX_THRESH 0.25 12 | #define PROP_BOX_SIZE (5+OBJ_CLASS_NUM) 13 | 14 | typedef struct _BOX_RECT 15 | { 16 | int left; 17 | int right; 18 | int top; 19 | int bottom; 20 | } BOX_RECT; 21 | 22 | typedef struct __detect_result_t 23 | { 24 | char name[OBJ_NAME_MAX_SIZE]; 25 | BOX_RECT box; 26 | float prop; 27 | } detect_result_t; 28 | 29 | typedef struct _detect_result_group_t 30 | { 31 | int id; 32 | int count; 33 | detect_result_t results[OBJ_NUMB_MAX_SIZE]; 34 | } detect_result_group_t; 35 | 36 | int post_process(int8_t *input0, int8_t *input1, int8_t *input2, int model_in_h, int model_in_w, 37 | float conf_threshold, float nms_threshold, float scale_w, float scale_h, 38 | std::vector &qnt_zps, std::vector &qnt_scales, 39 | detect_result_group_t *group); 40 | 41 | void deinitPostProcess(); 42 | #endif //_RKNN_ZERO_COPY_DEMO_POSTPROCESS_H_ 43 | -------------------------------------------------------------------------------- /include/rga_func.h: -------------------------------------------------------------------------------- 1 | #ifndef __RGA_FUNC_H__ 2 | #define __RGA_FUNC_H__ 3 | 4 | #include 5 | #include "RgaApi.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | typedef int(* FUNC_RGA_INIT)(); 12 | typedef void(* FUNC_RGA_DEINIT)(); 13 | typedef int(* FUNC_RGA_BLIT)(rga_info_t *, rga_info_t *, rga_info_t *); 14 | 15 | typedef struct _rga_context{ 16 | void *rga_handle; 17 | FUNC_RGA_INIT init_func; 18 | FUNC_RGA_DEINIT deinit_func; 19 | FUNC_RGA_BLIT blit_func; 20 | } rga_context; 21 | 22 | int RGA_init(rga_context* rga_ctx); 23 | 24 | void img_resize_fast(rga_context *rga_ctx, int src_fd, int src_w, int src_h, uint64_t dst_phys, int dst_w, int dst_h); 25 | 26 | void img_resize_slow(rga_context *rga_ctx, void *src_virt, int src_w, int src_h, void *dst_virt, int dst_w, int dst_h); 27 | 28 | int RGA_deinit(rga_context* rga_ctx); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | #endif/*__RGA_FUNC_H__*/ 34 | -------------------------------------------------------------------------------- /include/rknnPool.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _rknnPool_H 2 | #define _rknnPool_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "rga.h" 8 | #include "im2d.h" 9 | #include "RgaUtils.h" 10 | #include "rknn_api.h" 11 | #include "postprocess.h" 12 | #include "opencv2/core/core.hpp" 13 | #include "opencv2/imgcodecs.hpp" 14 | #include "opencv2/imgproc.hpp" 15 | #include "ThreadPool.hpp" 16 | using cv::Mat; 17 | using std::queue; 18 | using std::vector; 19 | 20 | static unsigned char *load_data(FILE *fp, size_t ofst, size_t sz); 21 | static unsigned char *load_model(const char *filename, int *model_size); 22 | 23 | class rknn_lite 24 | { 25 | private: 26 | rknn_context rkModel; 27 | unsigned char *model_data; 28 | rknn_sdk_version version; 29 | rknn_input_output_num io_num; 30 | rknn_tensor_attr *input_attrs; 31 | rknn_tensor_attr *output_attrs; 32 | rknn_input inputs[1]; 33 | int ret; 34 | int channel = 3; 35 | int width = 0; 36 | int height = 0; 37 | public: 38 | Mat ori_img; 39 | int interf(); 40 | rknn_lite(char *dst, int n); 41 | ~rknn_lite(); 42 | }; 43 | 44 | rknn_lite::rknn_lite(char *model_name, int n) 45 | { 46 | /* Create the neural network */ 47 | printf("Loading mode...\n"); 48 | int model_data_size = 0; 49 | // 读取模型文件数据 50 | model_data = load_model(model_name, &model_data_size); 51 | // 通过模型文件初始化rknn类 52 | ret = rknn_init(&rkModel, model_data, model_data_size, 0, NULL); 53 | if (ret < 0) 54 | { 55 | printf("rknn_init error ret=%d\n", ret); 56 | exit(-1); 57 | } 58 | // 59 | rknn_core_mask core_mask; 60 | if (n == 0) 61 | core_mask = RKNN_NPU_CORE_0; 62 | else if(n == 1) 63 | core_mask = RKNN_NPU_CORE_1; 64 | else 65 | core_mask = RKNN_NPU_CORE_2; 66 | int ret = rknn_set_core_mask(rkModel, core_mask); 67 | if (ret < 0) 68 | { 69 | printf("rknn_init core error ret=%d\n", ret); 70 | exit(-1); 71 | } 72 | 73 | // 初始化rknn类的版本 74 | ret = rknn_query(rkModel, RKNN_QUERY_SDK_VERSION, &version, sizeof(rknn_sdk_version)); 75 | if (ret < 0) 76 | { 77 | printf("rknn_init error ret=%d\n", ret); 78 | exit(-1); 79 | } 80 | 81 | // 获取模型的输入参数 82 | ret = rknn_query(rkModel, RKNN_QUERY_IN_OUT_NUM, &io_num, sizeof(io_num)); 83 | if (ret < 0) 84 | { 85 | printf("rknn_init error ret=%d\n", ret); 86 | exit(-1); 87 | } 88 | 89 | // 设置输入数组 90 | input_attrs = new rknn_tensor_attr[io_num.n_input]; 91 | memset(input_attrs, 0, sizeof(input_attrs)); 92 | for (int i = 0; i < io_num.n_input; i++) 93 | { 94 | input_attrs[i].index = i; 95 | ret = rknn_query(rkModel, RKNN_QUERY_INPUT_ATTR, &(input_attrs[i]), sizeof(rknn_tensor_attr)); 96 | if (ret < 0) 97 | { 98 | printf("rknn_init error ret=%d\n", ret); 99 | exit(-1); 100 | } 101 | } 102 | 103 | // 设置输出数组 104 | output_attrs = new rknn_tensor_attr[io_num.n_output]; 105 | memset(output_attrs, 0, sizeof(output_attrs) ); 106 | for (int i = 0; i < io_num.n_output; i++) 107 | { 108 | output_attrs[i].index = i; 109 | ret = rknn_query(rkModel, RKNN_QUERY_OUTPUT_ATTR, &(output_attrs[i]), sizeof(rknn_tensor_attr)); 110 | } 111 | 112 | // 设置输入参数 113 | if (input_attrs[0].fmt == RKNN_TENSOR_NCHW) 114 | { 115 | printf("model is NCHW input fmt\n"); 116 | channel = input_attrs[0].dims[1]; 117 | height = input_attrs[0].dims[2]; 118 | width = input_attrs[0].dims[3]; 119 | } 120 | else 121 | { 122 | printf("model is NHWC input fmt\n"); 123 | height = input_attrs[0].dims[1]; 124 | width = input_attrs[0].dims[2]; 125 | channel = input_attrs[0].dims[3]; 126 | } 127 | 128 | memset(inputs, 0, sizeof(inputs)); 129 | inputs[0].index = 0; 130 | inputs[0].type = RKNN_TENSOR_UINT8; 131 | inputs[0].size = width * height * channel; 132 | inputs[0].fmt = RKNN_TENSOR_NHWC; 133 | inputs[0].pass_through = 0; 134 | } 135 | 136 | rknn_lite::~rknn_lite() 137 | { 138 | ret = rknn_destroy(rkModel); 139 | delete[] input_attrs; 140 | delete[] output_attrs; 141 | if (model_data) 142 | free(model_data); 143 | } 144 | 145 | int rknn_lite::interf() 146 | { 147 | cv::Mat img; 148 | // 获取图像宽高 149 | int img_width = ori_img.cols; 150 | int img_height = ori_img.rows; 151 | cv::cvtColor(ori_img, img, cv::COLOR_BGR2RGB); 152 | 153 | // init rga context 154 | // rga是rk自家的绘图库,绘图效率高于OpenCV 155 | rga_buffer_t src; 156 | rga_buffer_t dst; 157 | memset(&src, 0, sizeof(src)); 158 | memset(&dst, 0, sizeof(dst)); 159 | im_rect src_rect; 160 | im_rect dst_rect; 161 | memset(&src_rect, 0, sizeof(src_rect)); 162 | memset(&dst_rect, 0, sizeof(dst_rect)); 163 | 164 | // You may not need resize when src resulotion equals to dst resulotion 165 | void *resize_buf = nullptr; 166 | // 如果输入图像不是指定格式 167 | if (img_width != width || img_height != height) 168 | { 169 | resize_buf = malloc( height * width * channel); 170 | memset(resize_buf, 0x00, height * width * channel); 171 | 172 | src = wrapbuffer_virtualaddr((void *)img.data, img_width, img_height, RK_FORMAT_RGB_888); 173 | dst = wrapbuffer_virtualaddr((void *)resize_buf, width, height, RK_FORMAT_RGB_888); 174 | ret = imcheck(src, dst, src_rect, dst_rect); 175 | if (IM_STATUS_NOERROR != ret) 176 | { 177 | printf("%d, check error! %s", __LINE__, imStrError((IM_STATUS) ret)); 178 | exit(-1); 179 | } 180 | IM_STATUS STATUS = imresize(src, dst); 181 | 182 | cv::Mat resize_img(cv::Size( width, height), CV_8UC3, resize_buf); 183 | inputs[0].buf = resize_buf; 184 | } 185 | else 186 | inputs[0].buf = (void *)img.data; 187 | 188 | // 设置rknn的输入数据 189 | rknn_inputs_set( rkModel, io_num.n_input, inputs); 190 | 191 | // 设置输出 192 | rknn_output outputs[ io_num.n_output]; 193 | memset(outputs, 0, sizeof(outputs)); 194 | for (int i = 0; i < io_num.n_output; i++) 195 | outputs[i].want_float = 0; 196 | // 调用npu进行推演 197 | ret = rknn_run( rkModel, NULL); 198 | // 获取npu的推演输出结果 199 | ret = rknn_outputs_get( rkModel, io_num.n_output, outputs, NULL); 200 | 201 | // 总之就是绘图部分 202 | // post process 203 | // width是模型需要的输入宽度, img_width是图片的实际宽度 204 | const float nms_threshold = NMS_THRESH; 205 | const float box_conf_threshold = BOX_THRESH; 206 | float scale_w = (float) width / img_width; 207 | float scale_h = (float) height / img_height; 208 | 209 | detect_result_group_t detect_result_group; 210 | std::vector out_scales; 211 | std::vector out_zps; 212 | for (int i = 0; i < io_num.n_output; ++i) 213 | { 214 | out_scales.push_back( output_attrs[i].scale); 215 | out_zps.push_back( output_attrs[i].zp); 216 | } 217 | post_process((int8_t *)outputs[0].buf, (int8_t *)outputs[1].buf, (int8_t *)outputs[2].buf, height, width, 218 | box_conf_threshold, nms_threshold, scale_w, scale_h, out_zps, out_scales, &detect_result_group); 219 | 220 | // Draw Objects 221 | char text[256]; 222 | for (int i = 0; i < detect_result_group.count; i++) 223 | { 224 | detect_result_t *det_result = &(detect_result_group.results[i]); 225 | sprintf(text, "%s %.1f%%", det_result->name, det_result->prop * 100); 226 | int x1 = det_result->box.left; 227 | int y1 = det_result->box.top; 228 | rectangle(ori_img, cv::Point(x1, y1), cv::Point(det_result->box.right, det_result->box.bottom), cv::Scalar(0, 0, 255, 0), 3); 229 | putText(ori_img, text, cv::Point(x1, y1 + 12), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(255, 255, 255)); 230 | } 231 | ret = rknn_outputs_release( rkModel, io_num.n_output, outputs); 232 | if (resize_buf) 233 | { 234 | free(resize_buf); 235 | } 236 | return 0; 237 | } 238 | 239 | static unsigned char *load_data(FILE *fp, size_t ofst, size_t sz) 240 | { 241 | unsigned char *data; 242 | int ret; 243 | 244 | data = NULL; 245 | 246 | if (NULL == fp) 247 | { 248 | return NULL; 249 | } 250 | 251 | ret = fseek(fp, ofst, SEEK_SET); 252 | if (ret != 0) 253 | { 254 | printf("blob seek failure.\n"); 255 | return NULL; 256 | } 257 | 258 | data = (unsigned char *)malloc(sz); 259 | if (data == NULL) 260 | { 261 | printf("buffer malloc failure.\n"); 262 | return NULL; 263 | } 264 | ret = fread(data, 1, sz, fp); 265 | return data; 266 | } 267 | 268 | static unsigned char *load_model(const char *filename, int *model_size) 269 | { 270 | FILE *fp; 271 | unsigned char *data; 272 | 273 | fp = fopen(filename, "rb"); 274 | if (NULL == fp) 275 | { 276 | printf("Open file %s failed.\n", filename); 277 | return NULL; 278 | } 279 | 280 | fseek(fp, 0, SEEK_END); 281 | int size = ftell(fp); 282 | 283 | data = load_data(fp, 0, size); 284 | 285 | fclose(fp); 286 | 287 | *model_size = size; 288 | return data; 289 | } 290 | 291 | #endif -------------------------------------------------------------------------------- /lib/libFormatConversion.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libFormatConversion.so -------------------------------------------------------------------------------- /lib/libMVGigEVisionSDK.so: -------------------------------------------------------------------------------- 1 | libMVGigEVisionSDK.so.3.2.2.1 -------------------------------------------------------------------------------- /lib/libMVGigEVisionSDK.so.3.2.2.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libMVGigEVisionSDK.so.3.2.2.1 -------------------------------------------------------------------------------- /lib/libMVRender.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libMVRender.so -------------------------------------------------------------------------------- /lib/libMediaProcess.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libMediaProcess.so -------------------------------------------------------------------------------- /lib/libMvCameraControl.so: -------------------------------------------------------------------------------- 1 | libMvCameraControl.so.3.2.2.1 -------------------------------------------------------------------------------- /lib/libMvCameraControl.so.3.2.2.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libMvCameraControl.so.3.2.2.1 -------------------------------------------------------------------------------- /lib/libMvUsb3vTL.so: -------------------------------------------------------------------------------- 1 | libMvUsb3vTL.so.3.2.2.1 -------------------------------------------------------------------------------- /lib/libMvUsb3vTL.so.3.2.2.1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/lib/libMvUsb3vTL.so.3.2.2.1 -------------------------------------------------------------------------------- /model/RK3588/yolov5s_relu_tk2_RK3588_i8.rknn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuaileBenbi/MVS-RKNN/68780530495de17e6675d02ac7ffa88466889760/model/RK3588/yolov5s_relu_tk2_RK3588_i8.rknn -------------------------------------------------------------------------------- /model/coco_80_labels_list.txt: -------------------------------------------------------------------------------- 1 | person 2 | bicycle 3 | car 4 | motorcycle 5 | airplane 6 | bus 7 | train 8 | truck 9 | boat 10 | traffic light 11 | fire hydrant 12 | stop sign 13 | parking meter 14 | bench 15 | bird 16 | cat 17 | dog 18 | horse 19 | sheep 20 | cow 21 | elephant 22 | bear 23 | zebra 24 | giraffe 25 | backpack 26 | umbrella 27 | handbag 28 | tie 29 | suitcase 30 | frisbee 31 | skis 32 | snowboard 33 | sports ball 34 | kite 35 | baseball bat 36 | baseball glove 37 | skateboard 38 | surfboard 39 | tennis racket 40 | bottle 41 | wine glass 42 | cup 43 | fork 44 | knife 45 | spoon 46 | bowl 47 | banana 48 | apple 49 | sandwich 50 | orange 51 | broccoli 52 | carrot 53 | hot dog 54 | pizza 55 | donut 56 | cake 57 | chair 58 | couch 59 | potted plant 60 | bed 61 | dining table 62 | toilet 63 | tv 64 | laptop 65 | mouse 66 | remote 67 | keyboard 68 | cell phone 69 | microwave 70 | oven 71 | toaster 72 | sink 73 | refrigerator 74 | book 75 | clock 76 | vase 77 | scissors 78 | teddy bear 79 | hair drier 80 | toothbrush 81 | -------------------------------------------------------------------------------- /performance.sh: -------------------------------------------------------------------------------- 1 | # 请切换到root用户 2 | 3 | # CPU定频 4 | echo "CPU0-3 可用频率:" 5 | sudo cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies 6 | sudo echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor 7 | sudo echo 1800000 > /sys/devices/system/cpu/cpufreq/policy0/scaling_setspeed 8 | echo "CPU0-3 当前频率:" 9 | sudo cat /sys/devices/system/cpu/cpufreq/policy0/cpuinfo_cur_freq 10 | 11 | echo "CPU4-5 可用频率:" 12 | sudo cat /sys/devices/system/cpu/cpufreq/policy4/scaling_available_frequencies 13 | sudo echo userspace > /sys/devices/system/cpu/cpufreq/policy4/scaling_governor 14 | sudo echo 2400000 > /sys/devices/system/cpu/cpufreq/policy4/scaling_setspeed 15 | echo "CPU4-5 当前频率:" 16 | sudo cat /sys/devices/system/cpu/cpufreq/policy4/cpuinfo_cur_freq 17 | 18 | echo "CPU6-7 可用频率:" 19 | sudo cat /sys/devices/system/cpu/cpufreq/policy6/scaling_available_frequencies 20 | sudo echo userspace > /sys/devices/system/cpu/cpufreq/policy6/scaling_governor 21 | sudo echo 2400000 > /sys/devices/system/cpu/cpufreq/policy6/scaling_setspeed 22 | echo "CPU6-7 当前频率:" 23 | sudo cat /sys/devices/system/cpu/cpufreq/policy6/cpuinfo_cur_freq 24 | 25 | # NPU定频 26 | echo "NPU 可用频率:" 27 | sudo cat /sys/class/devfreq/fdab0000.npu/available_frequencies 28 | sudo echo userspace > /sys/class/devfreq/fdab0000.npu/governor 29 | sudo echo 1000000000 > /sys/class/devfreq/fdab0000.npu/userspace/set_freq 30 | echo "NPU 当前频率:" 31 | sudo cat /sys/class/devfreq/fdab0000.npu/cur_freq -------------------------------------------------------------------------------- /src/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 by Rockchip Electronics Co., Ltd. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | /*------------------------------------------- 16 | Includes 17 | -------------------------------------------*/ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #define _BASETSD_H 24 | 25 | #include "MvCameraControl.h" 26 | #include "opencv2/core/core.hpp" 27 | #include "opencv2/highgui/highgui.hpp" 28 | #include "opencv2/imgproc/imgproc.hpp" 29 | #include "rknnPool.hpp" 30 | #include "ThreadPool.hpp" 31 | 32 | /* MVS */ 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | bool g_bExit = false; 40 | /* === */ 41 | 42 | using std::queue; 43 | using std::time; 44 | using std::time_t; 45 | using std::vector; 46 | 47 | char *model_name = NULL; 48 | // 设置线程数 49 | int n = 12, frames = 0; 50 | // 类似于多个rk模型的集合? 51 | vector rkpool; 52 | // 线程池 53 | dpool::ThreadPool pool(n); 54 | // 线程队列 55 | queue> futs; 56 | 57 | void PressEnterToExit(void) 58 | { 59 | int c; 60 | while ((c = getchar()) != '\n' && c != EOF) 61 | ; 62 | fprintf(stderr, "\nPress enter to exit.\n"); 63 | while (getchar() != '\n') 64 | ; 65 | g_bExit = true; 66 | sleep(1); 67 | } 68 | 69 | bool PrintDeviceInfo(MV_CC_DEVICE_INFO *pstMVDevInfo) 70 | { 71 | if (NULL == pstMVDevInfo) 72 | { 73 | printf("The Pointer of pstMVDevInfo is NULL!\n"); 74 | return false; 75 | } 76 | if (pstMVDevInfo->nTLayerType == MV_GIGE_DEVICE) 77 | { 78 | int nIp1 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0xff000000) >> 24); 79 | int nIp2 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x00ff0000) >> 16); 80 | int nIp3 = ((pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x0000ff00) >> 8); 81 | int nIp4 = (pstMVDevInfo->SpecialInfo.stGigEInfo.nCurrentIp & 0x000000ff); 82 | 83 | // ch:打印当前相机ip和用户自定义名字 | en:print current ip and user defined name 84 | printf("Device Model Name: %s\n", pstMVDevInfo->SpecialInfo.stGigEInfo.chModelName); 85 | printf("CurrentIp: %d.%d.%d.%d\n", nIp1, nIp2, nIp3, nIp4); 86 | printf("UserDefinedName: %s\n\n", pstMVDevInfo->SpecialInfo.stGigEInfo.chUserDefinedName); 87 | } 88 | else if (pstMVDevInfo->nTLayerType == MV_USB_DEVICE) 89 | { 90 | printf("Device Model Name: %s\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chModelName); 91 | printf("UserDefinedName: %s\n\n", pstMVDevInfo->SpecialInfo.stUsb3VInfo.chUserDefinedName); 92 | } 93 | else 94 | { 95 | printf("Not support.\n"); 96 | } 97 | 98 | return true; 99 | } 100 | 101 | static void *WorkThread(void *pUser) 102 | { 103 | int nRet = MV_OK; 104 | 105 | // ch:获取数据包大小 | en:Get payload size 106 | MVCC_INTVALUE stParam; 107 | memset(&stParam, 0, sizeof(MVCC_INTVALUE)); 108 | nRet = MV_CC_GetIntValue(pUser, "PayloadSize", &stParam); 109 | if (MV_OK != nRet) 110 | { 111 | printf("Get PayloadSize fail! nRet [0x%x]\n", nRet); 112 | return NULL; 113 | } 114 | 115 | MV_FRAME_OUT_INFO_EX stImageInfo = {0}; 116 | memset(&stImageInfo, 0, sizeof(MV_FRAME_OUT_INFO_EX)); 117 | unsigned char *pData = (unsigned char *)malloc(sizeof(unsigned char) * stParam.nCurValue); 118 | if (NULL == pData) 119 | { 120 | return NULL; 121 | } 122 | unsigned int nDataSize = stParam.nCurValue; 123 | 124 | struct timeval time; 125 | gettimeofday(&time, nullptr); 126 | auto initTime = time.tv_sec * 1000 + time.tv_usec / 1000; 127 | 128 | gettimeofday(&time, nullptr); 129 | long tmpTime, lopTime = time.tv_sec * 1000 + time.tv_usec / 1000; 130 | 131 | cv::Size newSize(256, 256); 132 | cv::Mat srcImage; 133 | int initFrames = 0; 134 | while (1) 135 | { 136 | if (g_bExit) 137 | { 138 | break; 139 | } 140 | nRet = MV_CC_GetOneFrameTimeout(pUser, pData, nDataSize, &stImageInfo, 1000); 141 | if (nRet == MV_OK) 142 | { 143 | // printf("GetOneFrame, Width[%d], Height[%d], nFrameNum[%d]\n", 144 | // stImageInfo.nWidth, stImageInfo.nHeight, stImageInfo.nFrameNum); 145 | 146 | if (srcImage.empty()) 147 | { 148 | cv::Mat srcImage2(stImageInfo.nHeight, stImageInfo.nWidth, CV_8UC1, pData); 149 | srcImage = srcImage2; 150 | printf("empty!no copy!\n"); 151 | } 152 | else 153 | { 154 | unsigned char *new_data_ptr = srcImage.ptr(); 155 | size_t data_size = stImageInfo.nHeight * stImageInfo.nWidth * srcImage.elemSize(); 156 | memcpy(new_data_ptr, pData, data_size); 157 | } 158 | 159 | // resize图片尺寸 160 | cv::Mat resizedImage; 161 | cv::resize(srcImage, resizedImage, newSize); 162 | // 使用resizedImage 163 | 164 | // 如果需要,可以显示图像 165 | // cv::imshow("Image", resizedImage); 166 | // cv::waitKey(30); 167 | 168 | if (initFrames < n) 169 | { 170 | rknn_lite *ptr = new rknn_lite(model_name, initFrames % 3); 171 | rkpool.push_back(ptr); 172 | ptr->ori_img = resizedImage; 173 | futs.push(pool.submit(&rknn_lite::interf, &(*ptr))); 174 | initFrames += 1; 175 | continue; 176 | } 177 | 178 | if (futs.front().get() != 0) 179 | break; 180 | futs.pop(); 181 | cv::imshow("Camera FPS", rkpool[frames % n]->ori_img); 182 | if (cv::waitKey(1) == 'q') // 延时1毫秒,按q键退出 183 | break; 184 | // if (!capture.read(rkpool[frames % n]->ori_img)) 185 | // break; 186 | rkpool[frames % n]->ori_img = resizedImage; 187 | 188 | futs.push(pool.submit(&rknn_lite::interf, &(*rkpool[frames++ % n]))); 189 | 190 | if (frames % 60 == 0) 191 | { 192 | gettimeofday(&time, nullptr); 193 | tmpTime = time.tv_sec * 1000 + time.tv_usec / 1000; 194 | printf("60帧平均帧率:\t%f帧\n", 60000.0 / (float)(tmpTime - lopTime)); 195 | lopTime = tmpTime; 196 | } 197 | 198 | // rkpool[frames % n]->ori_img = resizedImage; 199 | // futs.push(pool.submit(&rknn_lite::interf, &(*rkpool[frames++ % n]))); 200 | 201 | // if (frames % 60 == 0) 202 | // { 203 | // gettimeofday(&time, nullptr); 204 | // tmpTime = time.tv_sec * 1000 + time.tv_usec / 1000; 205 | // printf("60帧平均帧率:\t%f帧\n", 60000.0 / (float)(tmpTime - lopTime)); 206 | // lopTime = tmpTime; 207 | // } 208 | } 209 | else 210 | { 211 | printf("No data[%x]\n", nRet); 212 | } 213 | } 214 | 215 | free(pData); 216 | 217 | gettimeofday(&time, nullptr); 218 | printf("\n平均帧率:\t%f帧\n", float(frames) / (float)(time.tv_sec * 1000 + time.tv_usec / 1000 - initTime + 0.0001) * 1000.0); 219 | 220 | // 释放剩下的资源 221 | while (!futs.empty()) 222 | { 223 | if (futs.front().get()) 224 | break; 225 | futs.pop(); 226 | } 227 | for (int i = 0; i < n; i++) 228 | delete rkpool[i]; 229 | // capture.release(); 230 | cv::destroyAllWindows(); 231 | 232 | return 0; 233 | } 234 | 235 | int main(int argc, char **argv) 236 | { 237 | /* 模型加载 */ 238 | model_name = (char *)argv[1]; // 参数二,模型所在路径 239 | printf("模型名称:\t%s\n", model_name); 240 | printf("线程数:\t%d\n", n); 241 | 242 | // 初始化 243 | // for (int i = 0; i < n; i++) 244 | // { 245 | // rknn_lite *ptr = new rknn_lite(model_name, i % 3); 246 | // rkpool.push_back(ptr); 247 | // // capture >> ptr->ori_img; 248 | // futs.push(pool.submit(&rknn_lite::interf, &(*ptr))); 249 | // } 250 | 251 | /* 摄像头初始化 */ 252 | int nRet = MV_OK; 253 | void *handle = NULL; 254 | do 255 | { 256 | MV_CC_DEVICE_INFO_LIST stDeviceList; 257 | memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST)); 258 | 259 | // 枚举设备 260 | // enum device 261 | nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList); 262 | if (MV_OK != nRet) 263 | { 264 | printf("MV_CC_EnumDevices fail! nRet [%x]\n", nRet); 265 | break; 266 | } 267 | 268 | if (stDeviceList.nDeviceNum > 0) 269 | { 270 | for (int i = 0; i < stDeviceList.nDeviceNum; i++) 271 | { 272 | printf("[device %d]:\n", i); 273 | MV_CC_DEVICE_INFO *pDeviceInfo = stDeviceList.pDeviceInfo[i]; 274 | if (NULL == pDeviceInfo) 275 | { 276 | break; 277 | } 278 | PrintDeviceInfo(pDeviceInfo); 279 | } 280 | } 281 | else 282 | { 283 | printf("Find No Devices!\n"); 284 | break; 285 | } 286 | 287 | printf("Please Intput camera index: "); 288 | unsigned int nIndex = 0; 289 | scanf("%d", &nIndex); 290 | 291 | if (nIndex >= stDeviceList.nDeviceNum) 292 | { 293 | printf("Intput error!\n"); 294 | break; 295 | } 296 | 297 | // 选择设备并创建句柄 298 | // select device and create handle 299 | nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[nIndex]); 300 | if (MV_OK != nRet) 301 | { 302 | printf("MV_CC_CreateHandle fail! nRet [%x]\n", nRet); 303 | break; 304 | } 305 | 306 | // 打开设备 307 | // open device 308 | nRet = MV_CC_OpenDevice(handle); 309 | if (MV_OK != nRet) 310 | { 311 | printf("MV_CC_OpenDevice fail! nRet [%x]\n", nRet); 312 | break; 313 | } 314 | 315 | // ch:探测网络最佳包大小(只对GigE相机有效) | en:Detection network optimal package size(It only works for the GigE camera) 316 | if (stDeviceList.pDeviceInfo[nIndex]->nTLayerType == MV_GIGE_DEVICE) 317 | { 318 | int nPacketSize = MV_CC_GetOptimalPacketSize(handle); 319 | if (nPacketSize > 0) 320 | { 321 | nRet = MV_CC_SetIntValue(handle, "GevSCPSPacketSize", nPacketSize); 322 | if (nRet != MV_OK) 323 | { 324 | printf("Warning: Set Packet Size fail nRet [0x%x]!\n", nRet); 325 | } 326 | } 327 | else 328 | { 329 | printf("Warning: Get Packet Size fail nRet [0x%x]!\n", nPacketSize); 330 | } 331 | } 332 | 333 | // 设置触发模式为off 334 | // set trigger mode as off 335 | nRet = MV_CC_SetEnumValue(handle, "TriggerMode", 0); 336 | if (MV_OK != nRet) 337 | { 338 | printf("MV_CC_SetTriggerMode fail! nRet [%x]\n", nRet); 339 | break; 340 | } 341 | 342 | // 开始取流 343 | // start grab image 344 | nRet = MV_CC_StartGrabbing(handle); 345 | if (MV_OK != nRet) 346 | { 347 | printf("MV_CC_StartGrabbing fail! nRet [%x]\n", nRet); 348 | break; 349 | } 350 | 351 | pthread_t nThreadID; 352 | 353 | nRet = pthread_create(&nThreadID, NULL, WorkThread, handle); 354 | if (nRet != 0) 355 | { 356 | printf("thread create failed.ret = %d\n", nRet); 357 | break; 358 | } 359 | 360 | PressEnterToExit(); 361 | 362 | // 停止取流 363 | // end grab image 364 | nRet = MV_CC_StopGrabbing(handle); 365 | if (MV_OK != nRet) 366 | { 367 | printf("MV_CC_StopGrabbing fail! nRet [%x]\n", nRet); 368 | break; 369 | } 370 | 371 | // 关闭设备 372 | // close device 373 | nRet = MV_CC_CloseDevice(handle); 374 | if (MV_OK != nRet) 375 | { 376 | printf("MV_CC_CloseDevice fail! nRet [%x]\n", nRet); 377 | break; 378 | } 379 | 380 | // 销毁句柄 381 | // destroy handle 382 | nRet = MV_CC_DestroyHandle(handle); 383 | if (MV_OK != nRet) 384 | { 385 | printf("MV_CC_DestroyHandle fail! nRet [%x]\n", nRet); 386 | break; 387 | } 388 | 389 | } while (0); 390 | 391 | /* 之前的代码 392 | 嘻 393 | 嘻 394 | 嘻 395 | 嘻 396 | */ 397 | 398 | return 0; 399 | 400 | // char *model_name = NULL; 401 | // if (argc != 3) 402 | // { 403 | // printf("Usage: %s \n", argv[0]); 404 | // return -1; 405 | // } 406 | // model_name = (char *)argv[1]; // 参数二,模型所在路径 407 | // char *image_name = argv[2]; // 参数三, 视频/摄像头 408 | // printf("模型名称:\t%s\n", model_name); 409 | 410 | // cv::VideoCapture capture; 411 | // cv::namedWindow("Hikvision Camera"); 412 | // if (strlen(image_name) == 1) 413 | // // capture.open((int)(image_name[0] - '0')); 414 | // capture.open('rtsp://admin:admin@169.254.46.208/ch1/main/av_stream'); 415 | // // gst-launch-1.0 -vv udpsrc uri=udp://239.192.1.1:1042 caps="video/mpegts" ! queue2 use-buffering=true max-size-buffers=1000 ! tsparse ! decodebin ! videoconvert ! videoscale ! xvimagesink 416 | // else 417 | // capture.open(image_name); 418 | 419 | // // 设置线程数 420 | // int n = 12, frames = 0; 421 | // printf("线程数:\t%d\n", n); 422 | // // 类似于多个rk模型的集合? 423 | // vector rkpool; 424 | // // 线程池 425 | // dpool::ThreadPool pool(n); 426 | // // 线程队列 427 | // queue> futs; 428 | 429 | // // 初始化 430 | // for (int i = 0; i < n; i++) 431 | // { 432 | // rknn_lite *ptr = new rknn_lite(model_name, i % 3); 433 | // rkpool.push_back(ptr); 434 | // capture >> ptr->ori_img; 435 | // futs.push(pool.submit(&rknn_lite::interf, &(*ptr))); 436 | // } 437 | 438 | // struct timeval time; 439 | // gettimeofday(&time, nullptr); 440 | // auto initTime = time.tv_sec * 1000 + time.tv_usec / 1000; 441 | 442 | // gettimeofday(&time, nullptr); 443 | // long tmpTime, lopTime = time.tv_sec * 1000 + time.tv_usec / 1000; 444 | 445 | // while (capture.isOpened()) 446 | // { 447 | // if (futs.front().get() != 0) 448 | // break; 449 | // futs.pop(); 450 | // cv::imshow("Camera FPS", rkpool[frames % n]->ori_img); 451 | // if (cv::waitKey(1) == 'q') // 延时1毫秒,按q键退出 452 | // break; 453 | // if (!capture.read(rkpool[frames % n]->ori_img)) 454 | // break; 455 | // futs.push(pool.submit(&rknn_lite::interf, &(*rkpool[frames++ % n]))); 456 | 457 | // if (frames % 60 == 0) 458 | // { 459 | // gettimeofday(&time, nullptr); 460 | // tmpTime = time.tv_sec * 1000 + time.tv_usec / 1000; 461 | // printf("60帧平均帧率:\t%f帧\n", 60000.0 / (float)(tmpTime - lopTime)); 462 | // lopTime = tmpTime; 463 | // } 464 | // } 465 | 466 | // gettimeofday(&time, nullptr); 467 | // printf("\n平均帧率:\t%f帧\n", float(frames) / (float)(time.tv_sec * 1000 + time.tv_usec / 1000 - initTime + 0.0001) * 1000.0); 468 | 469 | // // 释放剩下的资源 470 | // while (!futs.empty()) 471 | // { 472 | // if (futs.front().get()) 473 | // break; 474 | // futs.pop(); 475 | // } 476 | // for (int i = 0; i < n; i++) 477 | // delete rkpool[i]; 478 | // capture.release(); 479 | // cv::destroyAllWindows(); 480 | // return 0; 481 | } 482 | -------------------------------------------------------------------------------- /src/postprocess.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 by Rockchip Electronics Co., Ltd. All Rights Reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "postprocess.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #define LABEL_NALE_TXT_PATH "./model/coco_80_labels_list.txt" 27 | 28 | static char* labels[OBJ_CLASS_NUM]; 29 | 30 | const int anchor0[6] = {10, 13, 16, 30, 33, 23}; 31 | const int anchor1[6] = {30, 61, 62, 45, 59, 119}; 32 | const int anchor2[6] = {116, 90, 156, 198, 373, 326}; 33 | 34 | inline static int clamp(float val, int min, int max) { return val > min ? (val < max ? val : max) : min; } 35 | 36 | char* readLine(FILE* fp, char* buffer, int* len) 37 | { 38 | int ch; 39 | int i = 0; 40 | size_t buff_len = 0; 41 | 42 | buffer = (char*)malloc(buff_len + 1); 43 | if (!buffer) 44 | return NULL; // Out of memory 45 | 46 | while ((ch = fgetc(fp)) != '\n' && ch != EOF) { 47 | buff_len++; 48 | void* tmp = realloc(buffer, buff_len + 1); 49 | if (tmp == NULL) { 50 | free(buffer); 51 | return NULL; // Out of memory 52 | } 53 | buffer = (char*)tmp; 54 | 55 | buffer[i] = (char)ch; 56 | i++; 57 | } 58 | buffer[i] = '\0'; 59 | 60 | *len = buff_len; 61 | 62 | // Detect end 63 | if (ch == EOF && (i == 0 || ferror(fp))) { 64 | free(buffer); 65 | return NULL; 66 | } 67 | return buffer; 68 | } 69 | 70 | int readLines(const char* fileName, char* lines[], int max_line) 71 | { 72 | FILE* file = fopen(fileName, "r"); 73 | char* s; 74 | int i = 0; 75 | int n = 0; 76 | 77 | if (file == NULL) { 78 | printf("Open %s fail!\n", fileName); 79 | return -1; 80 | } 81 | 82 | while ((s = readLine(file, s, &n)) != NULL) { 83 | lines[i++] = s; 84 | if (i >= max_line) 85 | break; 86 | } 87 | fclose(file); 88 | return i; 89 | } 90 | 91 | int loadLabelName(const char* locationFilename, char* label[]) 92 | { 93 | printf("loadLabelName %s\n", locationFilename); 94 | readLines(locationFilename, label, OBJ_CLASS_NUM); 95 | return 0; 96 | } 97 | 98 | static float CalculateOverlap(float xmin0, float ymin0, float xmax0, float ymax0, float xmin1, float ymin1, float xmax1, 99 | float ymax1) 100 | { 101 | float w = fmax(0.f, fmin(xmax0, xmax1) - fmax(xmin0, xmin1) + 1.0); 102 | float h = fmax(0.f, fmin(ymax0, ymax1) - fmax(ymin0, ymin1) + 1.0); 103 | float i = w * h; 104 | float u = (xmax0 - xmin0 + 1.0) * (ymax0 - ymin0 + 1.0) + (xmax1 - xmin1 + 1.0) * (ymax1 - ymin1 + 1.0) - i; 105 | return u <= 0.f ? 0.f : (i / u); 106 | } 107 | 108 | static int nms(int validCount, std::vector& outputLocations, std::vector classIds, std::vector& order, 109 | int filterId, float threshold) 110 | { 111 | for (int i = 0; i < validCount; ++i) { 112 | if (order[i] == -1 || classIds[i] != filterId) { 113 | continue; 114 | } 115 | int n = order[i]; 116 | for (int j = i + 1; j < validCount; ++j) { 117 | int m = order[j]; 118 | if (m == -1 || classIds[i] != filterId) { 119 | continue; 120 | } 121 | float xmin0 = outputLocations[n * 4 + 0]; 122 | float ymin0 = outputLocations[n * 4 + 1]; 123 | float xmax0 = outputLocations[n * 4 + 0] + outputLocations[n * 4 + 2]; 124 | float ymax0 = outputLocations[n * 4 + 1] + outputLocations[n * 4 + 3]; 125 | 126 | float xmin1 = outputLocations[m * 4 + 0]; 127 | float ymin1 = outputLocations[m * 4 + 1]; 128 | float xmax1 = outputLocations[m * 4 + 0] + outputLocations[m * 4 + 2]; 129 | float ymax1 = outputLocations[m * 4 + 1] + outputLocations[m * 4 + 3]; 130 | 131 | float iou = CalculateOverlap(xmin0, ymin0, xmax0, ymax0, xmin1, ymin1, xmax1, ymax1); 132 | 133 | if (iou > threshold) { 134 | order[j] = -1; 135 | } 136 | } 137 | } 138 | return 0; 139 | } 140 | 141 | static int quick_sort_indice_inverse(std::vector& input, int left, int right, std::vector& indices) 142 | { 143 | float key; 144 | int key_index; 145 | int low = left; 146 | int high = right; 147 | if (left < right) { 148 | key_index = indices[left]; 149 | key = input[left]; 150 | while (low < high) { 151 | while (low < high && input[high] <= key) { 152 | high--; 153 | } 154 | input[low] = input[high]; 155 | indices[low] = indices[high]; 156 | while (low < high && input[low] >= key) { 157 | low++; 158 | } 159 | input[high] = input[low]; 160 | indices[high] = indices[low]; 161 | } 162 | input[low] = key; 163 | indices[low] = key_index; 164 | quick_sort_indice_inverse(input, left, low - 1, indices); 165 | quick_sort_indice_inverse(input, low + 1, right, indices); 166 | } 167 | return low; 168 | } 169 | 170 | 171 | inline static int32_t __clip(float val, float min, float max) 172 | { 173 | float f = val <= min ? min : (val >= max ? max : val); 174 | return f; 175 | } 176 | 177 | static int8_t qnt_f32_to_affine(float f32, int32_t zp, float scale) 178 | { 179 | float dst_val = (f32 / scale) + zp; 180 | int8_t res = (int8_t)__clip(dst_val, -128, 127); 181 | return res; 182 | } 183 | 184 | static float deqnt_affine_to_f32(int8_t qnt, int32_t zp, float scale) { return ((float)qnt - (float)zp) * scale; } 185 | 186 | static int process(int8_t* input, int* anchor, int grid_h, int grid_w, int height, int width, int stride, 187 | std::vector& boxes, std::vector& objProbs, std::vector& classId, float threshold, 188 | int32_t zp, float scale) 189 | { 190 | int validCount = 0; 191 | int grid_len = grid_h * grid_w; 192 | float thres = threshold; 193 | int8_t thres_i8 = qnt_f32_to_affine(thres, zp, scale); 194 | for (int a = 0; a < 3; a++) { 195 | for (int i = 0; i < grid_h; i++) { 196 | for (int j = 0; j < grid_w; j++) { 197 | int8_t box_confidence = input[(PROP_BOX_SIZE * a + 4) * grid_len + i * grid_w + j]; 198 | if (box_confidence >= thres_i8) { 199 | int offset = (PROP_BOX_SIZE * a) * grid_len + i * grid_w + j; 200 | int8_t* in_ptr = input + offset; 201 | float box_x = deqnt_affine_to_f32(*in_ptr, zp, scale) * 2.0 - 0.5; 202 | float box_y = deqnt_affine_to_f32(in_ptr[grid_len], zp, scale) * 2.0 - 0.5; 203 | float box_w = deqnt_affine_to_f32(in_ptr[2 * grid_len], zp, scale) * 2.0; 204 | float box_h = deqnt_affine_to_f32(in_ptr[3 * grid_len], zp, scale) * 2.0; 205 | box_x = (box_x + j) * (float)stride; 206 | box_y = (box_y + i) * (float)stride; 207 | box_w = box_w * box_w * (float)anchor[a * 2]; 208 | box_h = box_h * box_h * (float)anchor[a * 2 + 1]; 209 | box_x -= (box_w / 2.0); 210 | box_y -= (box_h / 2.0); 211 | 212 | int8_t maxClassProbs = in_ptr[5 * grid_len]; 213 | int maxClassId = 0; 214 | for (int k = 1; k < OBJ_CLASS_NUM; ++k) { 215 | int8_t prob = in_ptr[(5 + k) * grid_len]; 216 | if (prob > maxClassProbs) { 217 | maxClassId = k; 218 | maxClassProbs = prob; 219 | } 220 | } 221 | if (maxClassProbs>thres_i8){ 222 | objProbs.push_back(deqnt_affine_to_f32(maxClassProbs, zp, scale)* deqnt_affine_to_f32(box_confidence, zp, scale)); 223 | classId.push_back(maxClassId); 224 | validCount++; 225 | boxes.push_back(box_x); 226 | boxes.push_back(box_y); 227 | boxes.push_back(box_w); 228 | boxes.push_back(box_h); 229 | } 230 | } 231 | } 232 | } 233 | } 234 | return validCount; 235 | } 236 | 237 | int post_process(int8_t* input0, int8_t* input1, int8_t* input2, int model_in_h, int model_in_w, float conf_threshold, 238 | float nms_threshold, float scale_w, float scale_h, std::vector& qnt_zps, 239 | std::vector& qnt_scales, detect_result_group_t* group) 240 | { 241 | static int init = -1; 242 | if (init == -1) { 243 | int ret = 0; 244 | ret = loadLabelName(LABEL_NALE_TXT_PATH, labels); 245 | if (ret < 0) { 246 | return -1; 247 | } 248 | 249 | init = 0; 250 | } 251 | memset(group, 0, sizeof(detect_result_group_t)); 252 | 253 | std::vector filterBoxes; 254 | std::vector objProbs; 255 | std::vector classId; 256 | 257 | // stride 8 258 | int stride0 = 8; 259 | int grid_h0 = model_in_h / stride0; 260 | int grid_w0 = model_in_w / stride0; 261 | int validCount0 = 0; 262 | validCount0 = process(input0, (int*)anchor0, grid_h0, grid_w0, model_in_h, model_in_w, stride0, filterBoxes, objProbs, 263 | classId, conf_threshold, qnt_zps[0], qnt_scales[0]); 264 | 265 | // stride 16 266 | int stride1 = 16; 267 | int grid_h1 = model_in_h / stride1; 268 | int grid_w1 = model_in_w / stride1; 269 | int validCount1 = 0; 270 | validCount1 = process(input1, (int*)anchor1, grid_h1, grid_w1, model_in_h, model_in_w, stride1, filterBoxes, objProbs, 271 | classId, conf_threshold, qnt_zps[1], qnt_scales[1]); 272 | 273 | // stride 32 274 | int stride2 = 32; 275 | int grid_h2 = model_in_h / stride2; 276 | int grid_w2 = model_in_w / stride2; 277 | int validCount2 = 0; 278 | validCount2 = process(input2, (int*)anchor2, grid_h2, grid_w2, model_in_h, model_in_w, stride2, filterBoxes, objProbs, 279 | classId, conf_threshold, qnt_zps[2], qnt_scales[2]); 280 | 281 | int validCount = validCount0 + validCount1 + validCount2; 282 | // no object detect 283 | if (validCount <= 0) { 284 | return 0; 285 | } 286 | 287 | std::vector indexArray; 288 | for (int i = 0; i < validCount; ++i) { 289 | indexArray.push_back(i); 290 | } 291 | 292 | quick_sort_indice_inverse(objProbs, 0, validCount - 1, indexArray); 293 | 294 | std::set class_set(std::begin(classId), std::end(classId)); 295 | 296 | for (auto c : class_set) { 297 | nms(validCount, filterBoxes, classId, indexArray, c, nms_threshold); 298 | } 299 | 300 | int last_count = 0; 301 | group->count = 0; 302 | /* box valid detect target */ 303 | for (int i = 0; i < validCount; ++i) { 304 | if (indexArray[i] == -1 || last_count >= OBJ_NUMB_MAX_SIZE) { 305 | continue; 306 | } 307 | int n = indexArray[i]; 308 | 309 | float x1 = filterBoxes[n * 4 + 0]; 310 | float y1 = filterBoxes[n * 4 + 1]; 311 | float x2 = x1 + filterBoxes[n * 4 + 2]; 312 | float y2 = y1 + filterBoxes[n * 4 + 3]; 313 | int id = classId[n]; 314 | float obj_conf = objProbs[i]; 315 | 316 | group->results[last_count].box.left = (int)(clamp(x1, 0, model_in_w) / scale_w); 317 | group->results[last_count].box.top = (int)(clamp(y1, 0, model_in_h) / scale_h); 318 | group->results[last_count].box.right = (int)(clamp(x2, 0, model_in_w) / scale_w); 319 | group->results[last_count].box.bottom = (int)(clamp(y2, 0, model_in_h) / scale_h); 320 | group->results[last_count].prop = obj_conf; 321 | char* label = labels[id]; 322 | strncpy(group->results[last_count].name, label, OBJ_NAME_MAX_SIZE); 323 | 324 | // printf("result %2d: (%4d, %4d, %4d, %4d), %s\n", i, group->results[last_count].box.left, 325 | // group->results[last_count].box.top, 326 | // group->results[last_count].box.right, group->results[last_count].box.bottom, label); 327 | last_count++; 328 | } 329 | group->count = last_count; 330 | 331 | return 0; 332 | } 333 | 334 | void deinitPostProcess() 335 | { 336 | for (int i = 0; i < OBJ_CLASS_NUM; i++) { 337 | if (labels[i] != nullptr) { 338 | free(labels[i]); 339 | labels[i] = nullptr; 340 | } 341 | } 342 | } 343 | --------------------------------------------------------------------------------