Signed-off-by: 俞超麒 <yuchaoqi1@h-partners.com>
This commit is contained in:
俞超麒 2024-09-06 11:37:43 +08:00
parent c18a8ae29f
commit 2a882d858c
10 changed files with 708 additions and 4 deletions

View File

@ -129,7 +129,8 @@
"//foundation/graphic/graphic_2d/frameworks/vulkan_layers:vulkan_swapchain_layer",
"//foundation/graphic/graphic_2d/frameworks/vulkan_layers:vulkan_swapchain_layer_json",
"//foundation/graphic/graphic_2d/rosen/modules/graphics_effect:libgraphics_effect",
"//foundation/graphic/graphic_2d/rosen/modules/hyper_graphic_manager/core/native_display_soloist:libnative_display_soloist"
"//foundation/graphic/graphic_2d/rosen/modules/hyper_graphic_manager/core/native_display_soloist:libnative_display_soloist",
"//foundation/graphic/graphic_2d/utils/color_manager/ndk:libnative_color_space_manager"
],
"fwk_group": [
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
@ -390,11 +391,22 @@
"header_files": [
"color_space_object_convertor.h",
"js_color_space.h",
"js_color_space_utils.h"
"js_color_space_utils.h",
"ndk_color_space.h"
],
"header_base": "//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/color_manager/color_space_object_convertor"
}
},
{
"type": "so",
"name": "//foundation/graphic/graphic_2d/utils/color_manager/ndk:libnative_color_space_manager",
"header": {
"header_files": [
"native_color_space_manager.h"
],
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/color_manager"
}
},
{
"type": "so",
"name": "//foundation/graphic/graphic_2d/interfaces/kits/napi/graphic/hdr_capability:hdr_capability_utils",

View File

@ -17,6 +17,7 @@
#define OHOS_ROSEN_COLOR_MANAGER_COMMON_H
#include <cstdint>
#include <map>
namespace OHOS {
namespace ColorManager {

View File

@ -0,0 +1,229 @@
/*
* Copyright (c) 2024 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.
*/
/**
* @addtogroup NativeColorSpaceManager
* @{
*
* @brief Provides the native colorSpaceManager capability.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @since 13
* @version 1.0
*/
/**
* @file native_color_space_manager.h
*
* @brief Defines the functions for obtaining and using a native colorSpaceManager.
*
* @library libnative_color_space_manager.so
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @since 13
* @version 1.0
*/
#ifndef C_INCLUDE_NATIVE_COLOR_SPACE_MANAGER_H_
#define C_INCLUDE_NATIVE_COLOR_SPACE_MANAGER_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Defines a colorspace manager.
* @since 13
*/
typedef struct OH_NativeColorSpaceManager OH_NativeColorSpaceManager;
/**
* @brief Enumerates color space types.
* @since 13
*/
typedef enum {
/** Indicates an unknown color space. */
NONE = 0,
/** Indicates the color space based on Adobe RGB. */
ADOBE_RGB = 1,
/** Indicates the color space based on SMPTE RP 431-2-2007 and IEC 61966-2.1:1999. */
DCI_P3 = 2,
/** Indicates the color space based on SMPTE RP 431-2-2007 and IEC 61966-2.1:1999. */
DISPLAY_P3 = 3,
/** Indicates the standard red green blue (SRGB) color space based on IEC 61966-2.1:1999. */
SRGB = 4,
/** Indicates the color space based on ITU-R BT.709. */
BT709 = 6,
/** Indicates the color space based on ITU-R BT.601. */
BT601_EBU = 7,
/** Indicates the color space based on ITU-R BT.601. */
BT601_SMPTE_C = 8,
/** Indicates the color space based on ITU-R BT.2020. */
BT2020_HLG = 9,
/** Indicates the color space based on ITU-R BT.2020. */
BT2020_PQ = 10,
/** PRIMARIES_P3_D65 | TRANSFUNC_HLG | RANGE_FULL */
P3_HLG = 11,
/** PRIMARIES_P3_D65 | TRANSFUNC_PQ | RANGE_FULL */
P3_PQ = 12,
/** PRIMARIES_ADOBE_RGB | TRANSFUNC_ADOBE_RGB | RANGE_LIMIT */
ADOBE_RGB_LIMIT = 13,
/** PRIMARIES_P3_D65 | TRANSFUNC_SRGB | RANGE_LIMIT */
DISPLAY_P3_LIMIT = 14,
/** PRIMARIES_SRGB | TRANSFUNC_SRGB | RANGE_LIMIT */
SRGB_LIMIT = 15,
/** PRIMARIES_BT709 | TRANSFUNC_BT709 | RANGE_LIMIT */
BT709_LIMIT = 16,
/** PRIMARIES_BT601_P | TRANSFUNC_BT709 | RANGE_LIMIT */
BT601_EBU_LIMIT = 17,
/** PRIMARIES_BT601_N | TRANSFUNC_BT709 | RANGE_LIMIT */
BT601_SMPTE_C_LIMIT = 18,
/** PRIMARIES_BT2020 | TRANSFUNC_HLG | RANGE_LIMIT */
BT2020_HLG_LIMIT = 19,
/** PRIMARIES_BT2020 | TRANSFUNC_PQ | RANGE_LIMIT */
BT2020_PQ_LIMIT = 20,
/** PRIMARIES_P3_D65 | TRANSFUNC_HLG | RANGE_LIMIT */
P3_HLG_LIMIT = 21,
/** PRIMARIES_P3_D65 | TRANSFUNC_PQ | RANGE_LIMIT */
P3_PQ_LIMIT = 22,
/** PRIMARIES_P3_D65 | TRANSFUNC_LINEAR */
LINEAR_P3 = 23,
/** PRIMARIES_SRGB | TRANSFUNC_LINEAR */
LINEAR_SRGB = 24,
/** PRIMARIES_BT709 | TRANSFUNC_LINEAR */
LINEAR_BT709 = LINEAR_SRGB,
/** PRIMARIES_BT2020 | TRANSFUNC_LINEAR */
LINEAR_BT2020 = 25,
/** PRIMARIES_SRGB | TRANSFUNC_SRGB | RANGE_FULL */
DISPLAY_SRGB = SRGB,
/** PRIMARIES_P3_D65 | TRANSFUNC_SRGB | RANGE_FULL */
DISPLAY_P3_SRGB = DISPLAY_P3,
/** PRIMARIES_P3_D65 | TRANSFUNC_HLG | RANGE_FULL */
DISPLAY_P3_HLG = P3_HLG,
/** PRIMARIES_DISPLAY_P3 | TRANSFUNC_PQ | RANGE_FULL */
DISPLAY_P3_PQ = P3_PQ,
/** Indicates a customized color space. */
CUSTOM = 5,
} ColorSpaceName;
/**
* @brief Describes the primary colors red, green, blue and white point coordinated as (x, y)
* in color space, in terms of real world chromaticities.
* @since 13
*/
typedef struct {
/** Coordinate value x of red color */
float rX;
/** Coordinate value y of red color */
float rY;
/** Coordinate value x of green color */
float gX;
/** Coordinate value y of green color */
float gY;
/** Coordinate value x of blue color */
float bX;
/** Coordinate value y of blue color */
float bY;
/** Coordinate value x of white point */
float wX;
/** Coordinate value y of white point */
float wY;
} ColorSpacePrimaries;
/**
* @brief Indicates white point coordinated as (x, y) return array.
* @since 13
*/
typedef struct {
/** Indicates white point return array */
float arr[2];
} WhitePointArray;
/**
* @brief Creates a <b>NativeColorSpaceManager</b> instance by colorSpaceName.
* A new <b>NativeColorSpaceManager</b> instance is created each time this function is called.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param colorSpaceName Indicates the NativeColorSpace connection name.
* @return Returns the pointer to the <b>NativeColorSpaceManager</b> instance created.
* Creation failed, cause memory shortage.
* @since 13
* @version 1.0
*/
OH_NativeColorSpaceManager* OH_NativeColorSpaceManager_CreateFromName(ColorSpaceName colorSpaceName);
/**
* @brief Creates a <b>NativeColorSpaceManager</b> instance by primaries and gamma.
* A new <b>NativeColorSpaceManager</b> instance is created each time this function is called.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param primaries Indicates the NativeColorSpace connection primaries.
* @param gamma Indicates the NativeColorSpace connection gamma.
* @return Returns the pointer to the <b>NativeColorSpaceManager</b> instance created.
* Creation failed, cause memory shortage.
* @since 13
* @version 1.0
*/
OH_NativeColorSpaceManager* OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma(
ColorSpacePrimaries primaries, float gamma);
/**
* @brief Delete the NativeColorSpaceManager instance.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param nativeColorSpaceManager Indicates the pointer to a <b>NativeColorSpaceManager</b> instance.
* @since 13
* @version 1.0
*/
void OH_NativeColorSpaceManager_Destroy(OH_NativeColorSpaceManager* nativeColorSpaceManager);
/**
* @brief Get colorSpace name.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param nativeColorSpaceManager Indicates the pointer to a <b>NativeColorSpaceManager</b> instance.
* @return Returns value, return value > 0 && value <= 25, success, return value == 0 , failed.
* @since 13
* @version 1.0
*/
int OH_NativeColorSpaceManager_GetColorSpaceName(
OH_NativeColorSpaceManager* nativeColorSpaceManager);
/**
* @brief Get white point.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param nativeColorSpaceManager Indicates the pointer to a <b>NativeColorSpaceManager</b> instance.
* @return Returns float array, return array = <0.f, 0.f>, failed, otherwise, true.
* @since 13
* @version 1.0
*/
WhitePointArray OH_NativeColorSpaceManager_GetWhitePoint(
OH_NativeColorSpaceManager* nativeColorSpaceManager);
/**
* @brief Get gamma.
*
* @syscap SystemCapability.Graphic.Graphic2D.ColorManager.Core
* @param nativeColorSpaceManager Indicates the pointer to a <b>NativeColorSpaceManager</b> instance.
* @return Returns float, return value == 0.f, failed, otherwise, true.
* @since 13
* @version 1.0
*/
float OH_NativeColorSpaceManager_GetGamma(OH_NativeColorSpaceManager* nativeColorSpaceManager);
#ifdef __cplusplus
}
#endif
/** @} */
#endif

View File

@ -1,4 +1,4 @@
# Copyright (c) 2022-2023 Huawei Device Co., Ltd.
# Copyright (c) 2022-2024 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
@ -47,8 +47,10 @@ if (current_os == "ohos") {
"$graphic_2d_root/utils/color_manager:color_manager_public_config",
]
deps = [ "$graphic_2d_root/utils/color_manager:color_manager" ]
if (is_arkui_x) {
deps = [ "$arkui_root/napi:ace_napi" ]
deps += [ "$arkui_root/napi:ace_napi" ]
include_dirs = [ "$hilog_root/interfaces/native/innerkits/include" ]
} else {
external_deps = [

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 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 OHOS_NDK_COLOR_SPACE_H
#define OHOS_NDK_COLOR_SPACE_H
#include "color_space.h"
#ifdef __cplusplus
extern "C" {
#endif
struct NativeColorSpaceManager {
public:
explicit NativeColorSpaceManager(
OHOS::ColorManager::ColorSpaceName colorSpaceName) : colorSpaceNDKToken_(colorSpaceName)
{}
NativeColorSpaceManager(
OHOS::ColorManager::ColorSpacePrimaries primaries, float gamma) : colorSpaceNDKToken_(primaries, gamma)
{}
NativeColorSpaceManager(
OHOS::ColorManager::ColorSpace colorSpace) : colorSpaceNDKToken_(colorSpace)
{}
const OHOS::ColorManager::ColorSpace& GetInnerColorSpace()
{
return colorSpaceNDKToken_;
}
private:
OHOS::ColorManager::ColorSpace colorSpaceNDKToken_;
};
#ifdef __cplusplus
};
#endif
#endif //OHOS_NDK_COLOR_SPACE_H

View File

@ -0,0 +1,57 @@
# Copyright (c) 2024 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.
import("//build/ohos.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
## Build libnative_color_space_manager.so
config("native_color_space_manager_config") {
visibility = [ ":*" ]
cflags = [
"-Wall",
"-Werror",
"-g3",
]
}
ohos_shared_library("libnative_color_space_manager") {
sources = [ "native_color_space_manager.cpp" ]
include_dirs = [
"$graphic_2d_root/interfaces/inner_api/common",
"$graphic_2d_root/interfaces/inner_api/color_manager",
"$graphic_2d_root/interfaces/kits/napi/graphic/color_manager/color_space_object_convertor",
"$graphic_2d_root/rosen/modules/render_service_base/include",
"$graphic_2d_root/utils/color_manager/export",
]
configs = [ ":native_color_space_manager_config" ]
output_extension = "so"
deps = [
"$graphic_2d_root/interfaces/kits/napi/graphic/color_manager:color_space_object_convertor",
"$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
]
innerapi_tags = [ "ndk" ]
external_deps = [ "hilog:libhilog" ]
public_external_deps = [ "c_utils:utils" ]
part_name = "graphic_2d"
subsystem_name = "graphic"
}
## Build libnative_color_space_manager.so

View File

@ -0,0 +1,163 @@
/*
* Copyright (c) 2024 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.
*/
#include "color_manager_common.h"
#include "native_color_space_manager.h"
#include "ndk_color_space.h"
#include "platform/common/rs_log.h"
const std::map<ColorSpaceName, OHOS::ColorManager::ColorSpaceName> OH_TO_NATIVE_COLOR_SPACE_NAME_MAP {
{ ColorSpaceName::NONE, OHOS::ColorManager::ColorSpaceName::NONE },
{ ColorSpaceName::ADOBE_RGB, OHOS::ColorManager::ColorSpaceName::ADOBE_RGB },
{ ColorSpaceName::DCI_P3, OHOS::ColorManager::ColorSpaceName::DCI_P3 },
{ ColorSpaceName::DISPLAY_P3, OHOS::ColorManager::ColorSpaceName::DISPLAY_P3 },
{ ColorSpaceName::SRGB, OHOS::ColorManager::ColorSpaceName::SRGB },
{ ColorSpaceName::BT709, OHOS::ColorManager::ColorSpaceName::BT709 },
{ ColorSpaceName::BT601_EBU, OHOS::ColorManager::ColorSpaceName::BT601_EBU },
{ ColorSpaceName::BT601_SMPTE_C, OHOS::ColorManager::ColorSpaceName::BT601_SMPTE_C },
{ ColorSpaceName::BT2020_HLG, OHOS::ColorManager::ColorSpaceName::BT2020_HLG },
{ ColorSpaceName::BT2020_PQ, OHOS::ColorManager::ColorSpaceName::BT2020_PQ },
{ ColorSpaceName::P3_HLG, OHOS::ColorManager::ColorSpaceName::P3_HLG },
{ ColorSpaceName::P3_PQ, OHOS::ColorManager::ColorSpaceName::P3_PQ },
{ ColorSpaceName::ADOBE_RGB_LIMIT, OHOS::ColorManager::ColorSpaceName::ADOBE_RGB_LIMIT },
{ ColorSpaceName::DISPLAY_P3_LIMIT, OHOS::ColorManager::ColorSpaceName::DISPLAY_P3_LIMIT },
{ ColorSpaceName::SRGB_LIMIT, OHOS::ColorManager::ColorSpaceName::SRGB_LIMIT },
{ ColorSpaceName::BT709_LIMIT, OHOS::ColorManager::ColorSpaceName::BT709_LIMIT },
{ ColorSpaceName::BT601_EBU_LIMIT, OHOS::ColorManager::ColorSpaceName::BT601_EBU_LIMIT },
{ ColorSpaceName::BT601_SMPTE_C_LIMIT, OHOS::ColorManager::ColorSpaceName::BT601_SMPTE_C_LIMIT },
{ ColorSpaceName::BT2020_HLG_LIMIT, OHOS::ColorManager::ColorSpaceName::BT2020_HLG_LIMIT },
{ ColorSpaceName::BT2020_PQ_LIMIT, OHOS::ColorManager::ColorSpaceName::BT2020_PQ_LIMIT },
{ ColorSpaceName::P3_HLG_LIMIT, OHOS::ColorManager::ColorSpaceName::P3_HLG_LIMIT },
{ ColorSpaceName::P3_PQ_LIMIT, OHOS::ColorManager::ColorSpaceName::P3_PQ_LIMIT },
{ ColorSpaceName::LINEAR_P3, OHOS::ColorManager::ColorSpaceName::LINEAR_P3 },
{ ColorSpaceName::LINEAR_SRGB, OHOS::ColorManager::ColorSpaceName::LINEAR_SRGB },
{ ColorSpaceName::LINEAR_BT709, OHOS::ColorManager::ColorSpaceName::LINEAR_BT709 },
{ ColorSpaceName::LINEAR_BT2020, OHOS::ColorManager::ColorSpaceName::LINEAR_BT2020 },
{ ColorSpaceName::DISPLAY_SRGB, OHOS::ColorManager::ColorSpaceName::DISPLAY_SRGB },
{ ColorSpaceName::DISPLAY_P3_SRGB, OHOS::ColorManager::ColorSpaceName::DISPLAY_P3_SRGB },
{ ColorSpaceName::DISPLAY_P3_HLG, OHOS::ColorManager::ColorSpaceName::DISPLAY_P3_HLG },
{ ColorSpaceName::DISPLAY_P3_PQ, OHOS::ColorManager::ColorSpaceName::DISPLAY_P3_PQ },
{ ColorSpaceName::CUSTOM, OHOS::ColorManager::ColorSpaceName::CUSTOM },
};
void OHPrimariesToColorSpacePrimaries(
const ColorSpacePrimaries& primaries, OHOS::ColorManager::ColorSpacePrimaries& csPrimaries)
{
csPrimaries.rX = primaries.rX;
csPrimaries.rY = primaries.rY;
csPrimaries.gX = primaries.gX;
csPrimaries.gY = primaries.gY;
csPrimaries.bX = primaries.bX;
csPrimaries.bY = primaries.bY;
csPrimaries.wX = primaries.wX;
csPrimaries.wY = primaries.wY;
}
static NativeColorSpaceManager* OHNativeColorSpaceManagerToNativeColorSpaceManager(
OH_NativeColorSpaceManager* nativeColorSpaceManager)
{
return reinterpret_cast<NativeColorSpaceManager*>(nativeColorSpaceManager);
}
static OH_NativeColorSpaceManager* NativeColorSpaceManagerToOHNativeColorSpaceManager(
NativeColorSpaceManager* nativeColorSpaceManager)
{
return reinterpret_cast<OH_NativeColorSpaceManager*>(nativeColorSpaceManager);
}
OH_NativeColorSpaceManager* OH_NativeColorSpaceManager_CreateFromName(
ColorSpaceName colorSpaceName)
{
if (colorSpaceName > ColorSpaceName::LINEAR_BT2020 || colorSpaceName < ColorSpaceName::NONE) {
RS_LOGE("ColorSpaceName is invalid: %{public}d", OHOS::ColorManager::CMErrorCode::CM_ERROR_INVALID_PARAM);
return nullptr;
}
if (colorSpaceName == ColorSpaceName::NONE || colorSpaceName == ColorSpaceName::CUSTOM) {
RS_LOGE("ColorSpaceName is invalid: %{public}d",
OHOS::ColorManager::CMErrorCode::CM_ERROR_ABNORMAL_PARAM_VALUE);
return nullptr;
}
auto csName = OH_TO_NATIVE_COLOR_SPACE_NAME_MAP.at(colorSpaceName);
NativeColorSpaceManager* nativeColorSpaceManager = new(std::nothrow) NativeColorSpaceManager(csName);
if (!nativeColorSpaceManager) {
RS_LOGE("create colorspace error");
return nullptr;
}
return NativeColorSpaceManagerToOHNativeColorSpaceManager(nativeColorSpaceManager);
}
OH_NativeColorSpaceManager* OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma(
ColorSpacePrimaries primaries, float gamma)
{
OHOS::ColorManager::ColorSpacePrimaries csPrimaries;
OHPrimariesToColorSpacePrimaries(primaries, csPrimaries);
NativeColorSpaceManager* nativeColorSpaceManager = new(std::nothrow) NativeColorSpaceManager(csPrimaries, gamma);
if (!nativeColorSpaceManager) {
RS_LOGE("create colorspace error");
return nullptr;
}
return NativeColorSpaceManagerToOHNativeColorSpaceManager(nativeColorSpaceManager);
}
void OH_NativeColorSpaceManager_Destroy(OH_NativeColorSpaceManager* nativeColorSpaceManager)
{
if (!nativeColorSpaceManager) {
RS_LOGE("Parameter is nullptr, please check");
return;
}
delete OHNativeColorSpaceManagerToNativeColorSpaceManager(nativeColorSpaceManager);
}
int OH_NativeColorSpaceManager_GetColorSpaceName(
OH_NativeColorSpaceManager* nativeColorSpaceManager)
{
NativeColorSpaceManager* nativeCPM = OHNativeColorSpaceManagerToNativeColorSpaceManager(
nativeColorSpaceManager);
if (!nativeCPM) {
RS_LOGE("Parameter is nullptr, please check: %{public}d",
OHOS::ColorManager::CMErrorCode::CM_ERROR_INVALID_PARAM);
return 0;
}
return nativeCPM->GetInnerColorSpace().GetColorSpaceName();
}
WhitePointArray OH_NativeColorSpaceManager_GetWhitePoint(
OH_NativeColorSpaceManager* nativeColorSpaceManager)
{
NativeColorSpaceManager* nativeCPM = OHNativeColorSpaceManagerToNativeColorSpaceManager(
nativeColorSpaceManager);
if (!nativeCPM) {
RS_LOGE("Parameter is nullptr, please check: %{public}d",
OHOS::ColorManager::CMErrorCode::CM_ERROR_INVALID_PARAM);
return WhitePointArray();
}
WhitePointArray whitePointArray;
whitePointArray.arr[0] = nativeCPM->GetInnerColorSpace().GetWhitePoint()[0];
whitePointArray.arr[1] = nativeCPM->GetInnerColorSpace().GetWhitePoint()[1];
return whitePointArray;
}
float OH_NativeColorSpaceManager_GetGamma(
OH_NativeColorSpaceManager* nativeColorSpaceManager)
{
NativeColorSpaceManager* nativeCPM = OHNativeColorSpaceManagerToNativeColorSpaceManager(
nativeColorSpaceManager);
if (!nativeCPM) {
RS_LOGE("Parameter is nullptr, please check: %{public}d",
OHOS::ColorManager::CMErrorCode::CM_ERROR_INVALID_PARAM);
return 0.f;
}
return nativeCPM->GetInnerColorSpace().GetGamma();
}

View File

@ -15,6 +15,7 @@ group("test") {
testonly = true
deps = [
"fuzztest:fuzztest",
"native_color_space_manager:unittest",
"unittest:unittest",
]
}

View File

@ -0,0 +1,52 @@
# Copyright (c) 2024 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.
import("//build/test.gni")
import("//foundation/graphic/graphic_2d/graphic_config.gni")
ohos_unittest("native_color_space_manager_test") {
module_out_path = "graphic_2d/utils/color_manager/ndk"
cflags = [
"-Wall",
"-Werror",
"-g3",
"-Dprivate=public",
"-Dprotected=public",
]
sources = [ "native_color_space_manager_test.cpp" ]
include_dirs = [ "$graphic_2d_root/interfaces/inner_api/color_manager" ]
deps = [
"$graphic_2d_root/rosen/modules/render_service_base:librender_service_base",
"$graphic_2d_root/rosen/modules/render_service_base:render_service_base_src",
"$graphic_2d_root/utils/color_manager/ndk:libnative_color_space_manager",
"$graphic_2d_root/utils/test_header:test_header",
]
external_deps = [
"c_utils:utils",
"hilog:libhilog",
]
part_name = "graphic_2d"
subsystem_name = "graphic"
}
group("unittest") {
testonly = true
deps = [ ":native_color_space_manager_test" ]
}

View File

@ -0,0 +1,135 @@
/*
* Copyright (c) 2024 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, Hardware
* 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.
*/
#include "gtest/gtest.h"
#include "common/rs_common_def.h"
#include "native_color_space_manager.h"
using namespace testing;
using namespace testing::ext;
namespace {
constexpr int CSNAME_END = 26;
constexpr float RED_X = 1.1f;
constexpr float RED_Y = 1.2f;
constexpr float GREEN_X = 1.3f;
constexpr float GREEN_Y = 1.4f;
constexpr float BLUE_X = 1.5f;
constexpr float BLUE_Y = 1.6f;
constexpr float WHITE_X = 1.7f;
constexpr float WHITE_Y = 1.8f;
}
class NativeColorSpaceManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
void NativeColorSpaceManagerTest::SetUpTestCase() {}
void NativeColorSpaceManagerTest::TearDownTestCase() {}
void NativeColorSpaceManagerTest::SetUp() {}
void NativeColorSpaceManagerTest::TearDown() {}
/*
* @tc.name: OH_NativeColorSpaceManager_CreateFromName
* @tc.desc: Test OH_NativeColorSpaceManager_CreateFromName, test wrong colorSpaceName
* @tc.type: FUNC
* @tc.require: issueIALHL4
*/
HWTEST_F(NativeColorSpaceManagerTest, OH_NativeColorSpaceManager_CreateFromName, TestSize.Level1)
{
OH_NativeColorSpaceManager* nativeColorSpaceManager = nullptr;
ColorSpaceName colorSpaceName = ColorSpaceName::NONE;
nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromName(colorSpaceName);
ASSERT_TRUE(nativeColorSpaceManager == nullptr);
colorSpaceName = ColorSpaceName::CUSTOM;
nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromName(colorSpaceName);
ASSERT_TRUE(nativeColorSpaceManager == nullptr);
colorSpaceName = static_cast<ColorSpaceName>(CSNAME_END);
nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromName(colorSpaceName);
ASSERT_TRUE(nativeColorSpaceManager == nullptr);
colorSpaceName = static_cast<ColorSpaceName>(-1);
nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromName(colorSpaceName);
ASSERT_TRUE(nativeColorSpaceManager == nullptr);
}
/*
* @tc.name: OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma
* @tc.desc: Test OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma, test true primaries and gamma
* @tc.type: FUNC
* @tc.require: issueIALHL4
*/
HWTEST_F(NativeColorSpaceManagerTest, OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma, TestSize.Level1)
{
ColorSpacePrimaries colorSpacePrimaries = {RED_X, RED_Y, GREEN_X, GREEN_Y, BLUE_X, BLUE_Y, WHITE_X, WHITE_Y};
float gamma = 1.f;
OH_NativeColorSpaceManager* nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromPrimariesAndGamma(
colorSpacePrimaries, gamma);
WhitePointArray array = OH_NativeColorSpaceManager_GetWhitePoint(nativeColorSpaceManager);
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(array.arr[0], WHITE_X));
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(array.arr[1], WHITE_Y));
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(OH_NativeColorSpaceManager_GetGamma(nativeColorSpaceManager), 1.f));
}
/*
* @tc.name: OH_NativeColorSpaceManager_GetColorSpaceName
* @tc.desc: Test OH_NativeColorSpaceManager_GetColorSpaceName, test getColorSpaceName;
* @tc.type: FUNC
* @tc.require: issueIALHL4
*/
HWTEST_F(NativeColorSpaceManagerTest, OH_NativeColorSpaceManager_GetColorSpaceName, TestSize.Level1)
{
OH_NativeColorSpaceManager* nativeColorSpaceManager = nullptr;
ColorSpaceName colorSpaceName = static_cast<ColorSpaceName>(
OH_NativeColorSpaceManager_GetColorSpaceName(nativeColorSpaceManager));
ASSERT_TRUE(colorSpaceName == ColorSpaceName::NONE);
colorSpaceName = ColorSpaceName::SRGB;
nativeColorSpaceManager = OH_NativeColorSpaceManager_CreateFromName(colorSpaceName);
ASSERT_TRUE(nativeColorSpaceManager != nullptr);
colorSpaceName = static_cast<ColorSpaceName>(
OH_NativeColorSpaceManager_GetColorSpaceName(nativeColorSpaceManager));
ASSERT_TRUE(colorSpaceName == ColorSpaceName::SRGB);
}
/*
* @tc.name: OH_NativeColorSpaceManager_GetWhitePoint
* @tc.desc: Test OH_NativeColorSpaceManager_GetWhitePoint, test nativeColorSpaceManager is nullptr;
* @tc.type: FUNC
* @tc.require: issueIALHL4
*/
HWTEST_F(NativeColorSpaceManagerTest, OH_NativeColorSpaceManager_GetWhitePoint, TestSize.Level1)
{
OH_NativeColorSpaceManager* nativeColorSpaceManager = nullptr;
WhitePointArray array = OH_NativeColorSpaceManager_GetWhitePoint(nativeColorSpaceManager);
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(array.arr[0], 0.f));
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(array.arr[1], 0.f));
}
/*
* @tc.name: OH_NativeColorSpaceManager_GetGamma
* @tc.desc: Test OH_NativeColorSpaceManager_GetGamma, test nativeColorSpaceManager is nullptr;
* @tc.type: FUNC
* @tc.require: issueIALHL4
*/
HWTEST_F(NativeColorSpaceManagerTest, OH_NativeColorSpaceManager_GetGamma, TestSize.Level1)
{
OH_NativeColorSpaceManager* nativeColorSpaceManager = nullptr;
float gamma = OH_NativeColorSpaceManager_GetGamma(nativeColorSpaceManager);
ASSERT_TRUE(OHOS::Rosen::ROSEN_EQ(gamma, 0.f));
}