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_TEXTURE_TYPE_H
17 #define PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_TEXTURE_ENCODE_TEXTURE_TYPE_H
18 
19 #include "astcenc.h"
20 #ifndef QUALITY_CONTROL
21 #define QUALITY_CONTROL (1)
22 #endif
23 namespace OHOS {
24 namespace ImagePlugin {
25 enum class SutProfile {
26     EXTREME_SPEED = 0,
27     SKIP_SUT = 255
28 }; // the profile of superCompress for texture
29 
30 constexpr uint8_t ASTC_EXTEND_INFO_TLV_NUM = 1; // curren only one group TLV
31 constexpr uint32_t ASTC_EXTEND_INFO_SIZE_DEFINITION_LENGTH = 4; // 4 bytes to discripte for extend info summary bytes
32 constexpr uint8_t ASTC_EXTEND_INFO_TYPE_LENGTH = 1; // 1 byte to discripte the content type for every TLV group
33 constexpr uint32_t ASTC_EXTEND_INFO_LENGTH_LENGTH = 4; // 4 bytes to discripte the content bytes for every TLV group
34 constexpr uint8_t ASTC_EXTEND_INFO_COLOR_SPACE_VALUE_LENGTH = 1; // 1 bytes to discripte the content for color space
35 
36 struct TextureEncodeOptions {
37     int32_t width_;
38     int32_t height_;
39     uint8_t blockX_;
40     uint8_t blockY_;
41     int32_t stride_;
42     QualityProfile privateProfile_; // enum type defined in astc-encoder module: HIGH_QUALITY_PROFILE HIGH_SPEED_PROFILE
43     int32_t blocksNum;
44     int32_t astcBytes;
45     bool enableQualityCheck;
46     bool hardwareFlag;
47     SutProfile sutProfile;
48     int32_t sutBytes;
49     bool outIsSut;
50 };
51 
52 struct AstcEncoder {
53     astcenc_config config;
54     astcenc_profile profile;
55     astcenc_context* codec_context;
56     astcenc_image image_;
57     astcenc_swizzle swizzle_;
58     uint8_t* data_out_;
59     astcenc_error error_;
60 #if defined(QUALITY_CONTROL) && (QUALITY_CONTROL == 1)
61     bool calQualityEnable;
62     int32_t *mse[RGBA_COM + 1];
63 #endif
64 };
65 
66 struct AstcExtendInfo {
67     uint32_t extendBufferSumBytes = 0;
68     uint8_t extendNums = ASTC_EXTEND_INFO_TLV_NUM;
69     uint8_t extendInfoType[ASTC_EXTEND_INFO_TLV_NUM];
70     uint32_t extendInfoLength[ASTC_EXTEND_INFO_TLV_NUM];
71     uint8_t *extendInfoValue[ASTC_EXTEND_INFO_TLV_NUM];
72 };
73 
74 enum class AstcExtendInfoType : uint8_t {
75     COLOR_SPACE = 0
76 };
77 } // namespace ImagePlugin
78 } // namespace OHOS
79 
80 #endif // PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_TEXTURE_ENCODE_TEXTURE_TYPE_H
81