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