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