* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACES_INNER_API_ALGORITHM_ALGORITHM_COMMON_H
#define INTERFACES_INNER_API_ALGORITHM_ALGORITHM_COMMON_H
#include <optional>
#include <stdint.h>
#include "refbase.h"
#include "surface_buffer.h"
#include "v1_0/buffer_handle_meta_key_type.h"
#include "v1_0/cm_color_space.h"
#include "v1_0/hdr_static_metadata.h"
#include "algorithm_errors.h"
typedef struct OpenGLContext OpenGLContext;
typedef struct ClContext ClContext;
extern "C" int SetupOpencl(void **pHandle, const char *vendorName, char *deviceName);
namespace OHOS {
namespace Media {
namespace VideoProcessingEngine {
constexpr uint8_t COLORPRIMARIES_OFFSET = 0;
constexpr uint8_t TRANSFUNC_OFFSET = 8;
constexpr uint8_t MATRIX_OFFSET = 16;
constexpr uint8_t RANGE_OFFSET = 21;
constexpr uint32_t COLORPRIMARIES_MASK = 0x000000FF;
constexpr uint32_t TRANSFUNC_MASK = 0x0000FF00;
constexpr uint32_t MATRIX_MASK = 0x001F0000;
constexpr uint32_t RANGE_MASK = 0xFFE00000;
}
}
}
typedef struct {
unsigned int systemStartCode;
unsigned int minimumMaxRgbPq;
unsigned int averageMaxRgbPq;
unsigned int varianceMaxRgbPq;
unsigned int maximumMaxRgbPq;
unsigned int toneMappingMode;
unsigned int toneMappingParamNum;
unsigned int targetedSystemDisplayMaximumLuminance[2];
unsigned int baseFlag[4];
unsigned int baseParamMp[2];
unsigned int baseParamMm[2];
unsigned int baseParamMa[2];
unsigned int baseParamMb[2];
unsigned int baseParamMn[2];
unsigned int baseParamK1[2];
unsigned int baseParamK2[2];
unsigned int baseParamK3[2];
unsigned int baseParamDeltaMode[2];
unsigned int baseParamDelta[2];
unsigned int threeSplineFlag[2];
unsigned int threeSplineNum[2];
unsigned int threeSplineThMode[2][4];
unsigned int threeSplineThMb[2][4];
unsigned int threeSplineTh[2][4][3];
unsigned int threeSplineStrength[2][4];
unsigned int colorSaturationMappingFlag;
unsigned int colorSaturationNum;
unsigned int colorSaturationGain[16];
} HdrVividMetadataV1;
namespace OHOS {
namespace Media {
namespace VideoProcessingEngine {
constexpr int MAX_IMAGE_SIZE = 8880;
using namespace HDI::Display::Graphic::Common::V1_0;
struct ColorSpaceDescription {
CM_ColorSpaceInfo colorSpaceInfo;
CM_HDR_Metadata_Type metadataType;
static VPEAlgoErrCode Create(const sptr<SurfaceBuffer> &buffer, ColorSpaceDescription &desc);
bool operator < (const ColorSpaceDescription &desc) const;
};
enum class RenderIntent {
RENDER_INTENT_PERCEPTUAL,
RENDER_INTENT_RELATIVE_COLORIMETRIC,
RENDER_INTENT_ABSOLUTE_COLORIMETRIC,
RENDER_INTENT_SATURATION
};
enum class MetadataGeneratorAlgoType {
META_GEN_ALGO_TYPE_IMAGE,
META_GEN_ALGO_TYPE_VIDEO
};
enum class VideoMetadataGeneratorStyle {
META_GEN_CONTRAST_STYLE = 0,
META_GEN_BRIGHT_STYLE = 1
};
struct ColorSpaceConverterParameter {
RenderIntent renderIntent;
std::optional<double> sdrUIBrightnessRatio {
std::nullopt
};
bool isVideo = false;
};
struct ColorSpaceConverterDisplayParameter {
ColorSpaceDescription inputColorSpace;
ColorSpaceDescription outputColorSpace;
std::vector<uint8_t> staticMetadata;
std::vector<uint8_t> dynamicMetadata;
std::vector<float> layerLinearMatrix;
float tmoNits;
float currentDisplayNits;
float sdrNits;
int32_t width;
int32_t height;
bool disableHdrFloatHeadRoom;
std::vector<uint8_t> adaptiveFOVMetadata;
};
struct MetadataGeneratorParameter {
MetadataGeneratorAlgoType algoType = MetadataGeneratorAlgoType::META_GEN_ALGO_TYPE_IMAGE;
bool isOldHdrVivid = false;
float avgGainmapGray = 0.0;
VideoMetadataGeneratorStyle styleType = VideoMetadataGeneratorStyle::META_GEN_CONTRAST_STYLE;
};
uint32_t GetColorSpaceType(const CM_ColorSpaceInfo &colorSpaceInfo);
CM_ColorSpaceInfo GetColorSpaceInfo(const uint32_t colorSpaceType);
int SetupOpengl(std::shared_ptr<OpenGLContext> &openglHandle);
}
}
}
#endif