• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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     EXTREME_SPEED_A = 1,
28     HIGH_CR_LEVEL1 = 2,
29     SKIP_SUT = 255
30 }; // the profile of superCompress for texture
31 
32 constexpr uint8_t ASTC_EXTEND_INFO_TLV_NUM = 1; // curren only one group TLV
33 constexpr uint32_t ASTC_EXTEND_INFO_SIZE_DEFINITION_LENGTH = 4; // 4 bytes to discripte for extend info summary bytes
34 constexpr uint8_t ASTC_EXTEND_INFO_TYPE_LENGTH = 1; // 1 byte to discripte the content type for every TLV group
35 constexpr uint32_t ASTC_EXTEND_INFO_LENGTH_LENGTH = 4; // 4 bytes to discripte the content bytes for every TLV group
36 constexpr uint8_t ASTC_EXTEND_INFO_COLOR_SPACE_VALUE_LENGTH = 1; // 1 bytes to discripte the content for color space
37 
38 enum class TextureEncodeType {
39     ASTC = 0,
40     SDR_SUT_SUPERFAST_4X4 = 1,
41     SDR_ASTC_4X4 = 2,
42 };
43 
44 struct TextureEncodeOptions {
45     int32_t width_;
46     int32_t height_;
47     uint8_t blockX_;
48     uint8_t blockY_;
49     int32_t stride_;
50     QualityProfile privateProfile_; // enum type defined in astc-encoder module: HIGH_QUALITY_PROFILE HIGH_SPEED_PROFILE
51     int32_t blocksNum;
52     int32_t astcBytes;
53     bool enableQualityCheck;
54     bool hardwareFlag;
55     SutProfile sutProfile;
56     int32_t sutBytes;
57     bool outIsSut;
58     uint8_t expandNums;
59     uint8_t *extInfoBuf;
60     int32_t extInfoBytes;
61     TextureEncodeType textureEncodeType;
62 };
63 
64 struct AstcEncoder {
65     astcenc_config config;
66     astcenc_profile profile;
67     astcenc_context* codec_context;
68     astcenc_image image_;
69     astcenc_swizzle swizzle_;
70     uint8_t* data_out_;
71     astcenc_error error_;
72 #if defined(QUALITY_CONTROL) && (QUALITY_CONTROL == 1)
73     bool calQualityEnable;
74     int32_t *mse[RGBA_COM + 1];
75 #endif
76 };
77 
78 struct AstcExtendInfo {
79     uint32_t extendBufferSumBytes = 0;
80     uint8_t extendNums = ASTC_EXTEND_INFO_TLV_NUM;
81     uint8_t extendInfoType[ASTC_EXTEND_INFO_TLV_NUM];
82     uint32_t extendInfoLength[ASTC_EXTEND_INFO_TLV_NUM];
83     uint8_t *extendInfoValue[ASTC_EXTEND_INFO_TLV_NUM];
84 };
85 
86 enum class AstcExtendInfoType : uint8_t {
87     COLOR_SPACE = 0
88 };
89 
90 using SutQulityProfile = std::tuple<uint8_t, SutProfile, QualityProfile>;
91 
92 static const std::map<std::string, SutQulityProfile> SUT_FORMAT_MAP = {
93     {"image/sdr_sut_superfast_4x4",
94         {92, SutProfile::HIGH_CR_LEVEL1, QualityProfile::CUSTOMIZED_PROFILE}},
95 };
96 
97 static const std::map<std::string, std::map<uint8_t, QualityProfile>> ASTC_FORMAT_MAP = {
98     {"image/sdr_astc_4x4",
99         {
100             {92, QualityProfile::CUSTOMIZED_PROFILE},
101             {85, QualityProfile::HIGH_SPEED_PROFILE}
102         }
103     },
104 };
105 } // namespace ImagePlugin
106 } // namespace OHOS
107 
108 #endif // PLUGINS_COMMON_LIBS_IMAGE_LIBEXTPLUGIN_INCLUDE_TEXTURE_ENCODE_TEXTURE_TYPE_H
109