1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 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 #ifndef PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_TEXTURE_ENCODE_IMAGE_COMPRESSOR_H 17 #define PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_TEXTURE_ENCODE_IMAGE_COMPRESSOR_H 18 19 #include <cstdint> 20 #include <mutex> 21 22 #ifndef USE_OPENCL_WRAPPER 23 #define USE_OPENCL_WRAPPER 24 #endif 25 #include "CL/cl_ext.h" 26 #include "opencl_wrapper.h" 27 28 namespace OHOS { 29 namespace ImagePlugin { 30 namespace AstcEncBasedCl { 31 32 #define CL_ASTC_SHARE_LIB_API 33 34 extern std::mutex checkClBinPathMutex; 35 36 enum CL_ASTC_STATUS { 37 CL_ASTC_ENC_SUCCESS = 0, 38 CL_ASTC_ENC_FAILED 39 }; 40 41 struct ClAstcImageOption { 42 uint8_t *data = nullptr; 43 int32_t stride = 0; 44 int32_t width = 0; 45 int32_t height = 0; 46 }; 47 48 struct ClAstcObjEnc { 49 uint32_t *blockErrs_ = nullptr; 50 size_t astcSize = 0; 51 cl_mem inputImage = nullptr; 52 cl_mem astcResult = nullptr; 53 cl_mem errBuffer = nullptr; 54 }; 55 56 struct ClAstcHandle { 57 cl_device_id deviceID = 0; 58 cl_context context = nullptr; 59 cl_command_queue queue = nullptr; 60 cl_kernel kernel = nullptr; 61 ClAstcObjEnc encObj; 62 }; 63 64 CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClCreate(ClAstcHandle **handle, const std::string &clBinPath); 65 66 CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClFillImage(ClAstcImageOption *imageIn, uint8_t *data, 67 int32_t stride, int32_t width, int32_t height); 68 69 CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClEncImage(ClAstcHandle *handle, const ClAstcImageOption *imageIn, 70 uint8_t *buffer); 71 72 CL_ASTC_SHARE_LIB_API CL_ASTC_STATUS AstcClClose(ClAstcHandle *handle); 73 } 74 } 75 } 76 #endif