1 /* 2 * Copyright (c) 2025 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 INTERFACES_INNER_API_ALGORITHM_ALGORITHM_COMMON_H 17 #define INTERFACES_INNER_API_ALGORITHM_ALGORITHM_COMMON_H 18 19 #include <optional> 20 #include <stdint.h> 21 #include "refbase.h" 22 #include "surface_buffer.h" 23 #include "v1_0/buffer_handle_meta_key_type.h" 24 #include "v1_0/cm_color_space.h" 25 #include "v1_0/hdr_static_metadata.h" 26 #include "algorithm_errors.h" 27 28 typedef struct OpenGLContext OpenGLContext; 29 typedef struct ClContext ClContext; 30 extern "C" int SetupOpencl(void **pHandle, const char *vendorName, char *deviceName); 31 32 namespace OHOS { 33 namespace Media { 34 namespace VideoProcessingEngine { 35 constexpr uint8_t COLORPRIMARIES_OFFSET = 0; 36 constexpr uint8_t TRANSFUNC_OFFSET = 8; 37 constexpr uint8_t MATRIX_OFFSET = 16; 38 constexpr uint8_t RANGE_OFFSET = 21; 39 constexpr uint32_t COLORPRIMARIES_MASK = 0x000000FF; 40 constexpr uint32_t TRANSFUNC_MASK = 0x0000FF00; 41 constexpr uint32_t MATRIX_MASK = 0x001F0000; 42 constexpr uint32_t RANGE_MASK = 0xFFE00000; 43 } // namespace VideoProcessingEngine 44 } // namespace Media 45 } // namespace OHOS 46 47 typedef struct { 48 unsigned int systemStartCode; // 表示系统版本号 49 // minimum_maxrgb_pq,表示显示内容的最小亮度,pq域,范围从0~4095 50 unsigned int minimumMaxRgbPq; 51 unsigned int averageMaxRgbPq; // average_maxrgb_pq,表示显示内容的平均亮度,pq域,范围从0.0~4095 52 // variance_maxrgb_pq,表示显示内容的变化范围,pq域,范围从0.0~4095 53 unsigned int varianceMaxRgbPq; 54 unsigned int maximumMaxRgbPq; // maximum_maxrgb_pq,表示显示内容的最大亮度,pq域,范围从0.0~4095 55 // tone_mapping_enable_mode_flag,取值为0或1,若为0,则不传曲线参数,否则传输参数 56 unsigned int toneMappingMode; 57 // tone_mapping_para_enable_num,表示当前色调映射参数组的数目减1, 58 // 为0时色调映射参数组的数目为1,为1时色调映射参数组的数目为2 59 unsigned int toneMappingParamNum; 60 // targeted_system_display_maximum_luminancePq,参考目标显示器最高亮度,范围从0.0~4095, 61 // 数组长度为2说明有2组参数,tone_mapping_param_num 62 unsigned int targetedSystemDisplayMaximumLuminance[2]; 63 // base_enable_flag,基础曲线标识,取值为0或1,为0则不传输基础曲线参数,为1则传输参数 64 unsigned int baseFlag[4]; 65 unsigned int baseParamMp[2]; // 范围0~16383 66 unsigned int baseParamMm[2]; // 范围0~63 67 unsigned int baseParamMa[2]; // 范围0~1023 68 unsigned int baseParamMb[2]; // 范围0~1023 69 unsigned int baseParamMn[2]; // 范围0~63 70 unsigned int baseParamK1[2]; // 分小于等于1 和 大于1两种情况 71 unsigned int baseParamK2[2]; // 分小于等于1 和 大于1两种情况 72 unsigned int baseParamK3[2]; // 分小于等于1 和 1~2 和 大于2两种情况 73 // base_param_delta_enable_mode,标识当前基础曲线映射参数的调整系数模式 74 unsigned int baseParamDeltaMode[2]; 75 // base_param_enable_delta,标识当前基础曲线映射参数的调整系数值,范围0~127 76 unsigned int baseParamDelta[2]; 77 // 3Spline_enable_flag,二值变量,为1时标识传输三次样条参数,为0时不传 78 unsigned int threeSplineFlag[2]; 79 unsigned int threeSplineNum[2]; // 3Spline_enable_num,标识三次样条区间数量,取值为0和1 80 // 3Spline_TH_enable_mode,标识色调映射的三次样条模式,范围为0~3, 81 // 这里数组长度4是由于P3Spline_num 82 unsigned int threeSplineThMode[2][4]; 83 // 3Spline_TH_enable_MB,指示色调映射的三次样条区间参数的斜率和暗区偏移量 84 unsigned int threeSplineThMb[2][4]; 85 // 3Spline_TH_enable, 指示色调映射的三次样条区间参数,范围0~4095,第三维度表示三次样 86 // 条区间参数(0~4095)、三次样条区间1偏移量(0~1023)和三次样条区间2偏移量(0~1023) 87 unsigned int threeSplineTh[2][4][3]; 88 // 3Spline_enable_Strength,指示色调映射的三次样条区间的修正幅度参数,范围0~255 89 unsigned int threeSplineStrength[2][4]; 90 unsigned int colorSaturationMappingFlag; // 对应标准中color_saturation_mapping_enable_flag 91 unsigned int colorSaturationNum; // 对应标准中color_saturation_enable_num 92 unsigned int colorSaturationGain[16]; // 对应标准中color_saturation_enable_gain 93 } HdrVividMetadataV1; 94 95 namespace OHOS { 96 namespace Media { 97 namespace VideoProcessingEngine { 98 constexpr int MAX_IMAGE_SIZE = 8880; 99 using namespace HDI::Display::Graphic::Common::V1_0; 100 101 struct ColorSpaceDescription { 102 CM_ColorSpaceInfo colorSpaceInfo; 103 CM_HDR_Metadata_Type metadataType; 104 105 static VPEAlgoErrCode Create(const sptr<SurfaceBuffer> &buffer, ColorSpaceDescription &desc); 106 bool operator < (const ColorSpaceDescription &desc) const; 107 }; 108 109 enum class RenderIntent { 110 RENDER_INTENT_PERCEPTUAL, // 感性意图 111 RENDER_INTENT_RELATIVE_COLORIMETRIC, // 相对比色意图 112 RENDER_INTENT_ABSOLUTE_COLORIMETRIC, // 绝对比色渲染意图 113 RENDER_INTENT_SATURATION // 饱和度意图 114 }; 115 116 enum class MetadataGeneratorAlgoType { 117 META_GEN_ALGO_TYPE_IMAGE, // image 118 META_GEN_ALGO_TYPE_VIDEO // video 119 }; 120 121 struct ColorSpaceConverterParameter { 122 RenderIntent renderIntent; // 渲染意图 123 std::optional<double> sdrUIBrightnessRatio { 124 std::nullopt 125 }; // 为当输入sdr ui,需要配置值,亮度打折,sdr亮度调节系数。范围[1, 6]. 126 bool isVideo = false; // 当为视频抽帧资源时,配置为true不生成元数据。图片默认均生成元数据 127 }; 128 129 struct ColorSpaceConverterDisplayParameter { 130 ColorSpaceDescription inputColorSpace; // 色彩空间信息 131 ColorSpaceDescription outputColorSpace; // 色彩空间信息 132 std::vector<uint8_t> staticMetadata; // 静态元数据 133 std::vector<uint8_t> dynamicMetadata; // 动态元数据 134 std::vector<float> layerLinearMatrix; // 线性域转换矩阵,作用在原色域上 135 float tmoNits; // TMO目标亮度 136 float currentDisplayNits; // 屏幕当前亮度,和tmoNits相除得到sdr亮度打折比 137 float sdrNits; // SDR亮度 138 int32_t width; // 宽度 139 int32_t height; // 高度 140 bool disableHdrFloatHeadRoom; // 不使用HDRfp16方案做额外提亮 141 std::vector<uint8_t> adaptiveFOVMetadata; // 缩放重适应元数据 142 }; 143 144 struct MetadataGeneratorParameter { 145 MetadataGeneratorAlgoType algoType = MetadataGeneratorAlgoType::META_GEN_ALGO_TYPE_IMAGE; 146 bool isOldHdrVivid = false; 147 float avgGainmapGray = 0.0; 148 }; 149 150 uint32_t GetColorSpaceType(const CM_ColorSpaceInfo &colorSpaceInfo); 151 CM_ColorSpaceInfo GetColorSpaceInfo(const uint32_t colorSpaceType); 152 int SetupOpengl(std::shared_ptr<OpenGLContext> &openglHandle); 153 } // namespace VideoProcessingEngine 154 } // namespace Media 155 } // namespace OHOS 156 #endif // INTERFACES_INNER_API_ALGORITHM_ALGORITHM_COMMON_H 157