From 77a394550e27c1ca203cf1a918902e0c281361c4 Mon Sep 17 00:00:00 2001 From: wang_wei Date: Tue, 23 Apr 2024 22:08:13 +0800 Subject: [PATCH] add effect Signed-off-by: wang_wei Change-Id: Ic28808dd53cb77d333436667b64f534a7759bf17 --- graphic/graphic_2d/native_effect/BUILD.gn | 34 +++++ .../graphic_2d/native_effect/effect_filter.h | 141 ++++++++++++++++++ .../graphic_2d/native_effect/effect_types.h | 94 ++++++++++++ .../native_effect/libnative_effect.ndk.json | 10 ++ 4 files changed, 279 insertions(+) create mode 100644 graphic/graphic_2d/native_effect/BUILD.gn create mode 100644 graphic/graphic_2d/native_effect/effect_filter.h create mode 100644 graphic/graphic_2d/native_effect/effect_types.h create mode 100644 graphic/graphic_2d/native_effect/libnative_effect.ndk.json diff --git a/graphic/graphic_2d/native_effect/BUILD.gn b/graphic/graphic_2d/native_effect/BUILD.gn new file mode 100644 index 000000000..fecb1ae42 --- /dev/null +++ b/graphic/graphic_2d/native_effect/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright (c) 2021 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("//build/ohos/ndk/ndk.gni") + +ohos_ndk_headers("native_effect_header") { + dest_dir = "$ndk_headers_out_dir/native_effect" + sources = [ + "./effect_filter.h", + "./effect_types.h", + ] +} + +ohos_ndk_library("libnative_effect_ndk") { + output_name = "native_effect" + output_extension = "so" + ndk_description_file = "./libnative_effect.ndk.json" + system_capability = "SystemCapability.Multimedia.Image.Core" + system_capability_headers = [ + "native_effect/effect_filter.h", + "native_effect/effect_types.h", + ] +} diff --git a/graphic/graphic_2d/native_effect/effect_filter.h b/graphic/graphic_2d/native_effect/effect_filter.h new file mode 100644 index 000000000..6f05c0f60 --- /dev/null +++ b/graphic/graphic_2d/native_effect/effect_filter.h @@ -0,0 +1,141 @@ +/* + * 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 C_INCLUDE_EFFECT_FILTER_H +#define C_INCLUDE_EFFECT_FILTER_H + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for obtaining effect filter and information. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +/** + * @file effect_filter.h + * + * @brief Declares the APIs that can access a effect filter. + * + * @library libnative_effect.so + * @syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +#include "effect_types.h" +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Creates an OH_Filter object. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param pixelmap The pixelmap pointer to create filter. + * @param filter The OH_Filter pointer will be operated. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_CreateEffect(OH_PixelmapNative* pixelmap, OH_Filter** filter); + +/** + * @brief Release an OH_Filter object. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @return Returns {@link EffectErrorCode} + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_Release(OH_Filter* filter); + +/** + * @brief Creates a blur effect and then add to the filter. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @param radius The radius of the blur effect. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_Blur(OH_Filter* filter, float radius); + +/** + * @brief Creates a brighten effect and then add to the filter. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @param brightness The brightness of the brighten effect. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_Brighten(OH_Filter* filter, float brightness); + +/** + * @brief Creates a gray scale effect and then add to the filter. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_GrayScale(OH_Filter* filter); + +/** + * @brief Creates a invert effect and then add to the filter. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_Invert(OH_Filter* filter); + +/** + * @brief Creates a effect with a matrix and then add to the filter. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @param matrix The {@link OH_Filter_ColorMatrix} pointer to create a custom effect. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_SetColorMatrix(OH_Filter* filter, OH_Filter_ColorMatrix* matrix); + +/** + * @brief Get a pixelmap with the filter effect. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @param filter The OH_Filter pointer will be operated. + * @param pixelmap The pixelmap pointer wiil be operated. + * @return Returns {@link EffectErrorCode}. + * @since 12 + * @version 1.0 + */ +EffectErrorCode OH_Filter_GetEffectPixelMap(OH_Filter* filter, OH_PixelmapNative** pixelmap); + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif diff --git a/graphic/graphic_2d/native_effect/effect_types.h b/graphic/graphic_2d/native_effect/effect_types.h new file mode 100644 index 000000000..e73052533 --- /dev/null +++ b/graphic/graphic_2d/native_effect/effect_types.h @@ -0,0 +1,94 @@ +/* + * 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 C_INCLUDE_EFFECT_TYPES_H +#define C_INCLUDE_EFFECT_TYPES_H + +/** + * @addtogroup image + * @{ + * + * @brief Provides APIs for obtaining effect filter and information. + * + * @syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +/** + * @file effect_types.h + * + * @brief Declares the data types for effect filter. + * + * @library libnative_effect.so + * @syscap SystemCapability.Multimedia.Image.Core + * @since 12 + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Defines a effect filter. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_Filter OH_Filter; + +/** + * @brief Defines a pixelmap. + * + * @since 12 + * @version 1.0 + */ +typedef struct OH_PixelmapNative OH_PixelmapNative; + +/** + * @brief Defines a matrix for create effect filter. + * + * @since 12 + * @version 1.0 + */ +struct OH_Filter_ColorMatrix { + /** val mast be 5*4 */ + float val[20]; +}; + +/** + * @brief Defines a effect filter error code. + * + * @since 12 + * @version 1.0 + */ +typedef enum { + /** success */ + EFFECT_SUCCESS = 0, + /** invalid parameter */ + EFFECT_BAD_PARAMETER = 401, + /** unsupported operations */ + EFFECT_UNSUPPORTED_OPERATION = 7600201, + /** unknown error */ + EFFECT_UNKNOWN_ERROR = 7600901, +} EffectErrorCode; + +#ifdef __cplusplus +} +#endif +/** @} */ +#endif \ No newline at end of file diff --git a/graphic/graphic_2d/native_effect/libnative_effect.ndk.json b/graphic/graphic_2d/native_effect/libnative_effect.ndk.json new file mode 100644 index 000000000..83a34f0a7 --- /dev/null +++ b/graphic/graphic_2d/native_effect/libnative_effect.ndk.json @@ -0,0 +1,10 @@ +[ + { "name": "OH_Filter_CreateEffect" }, + { "name": "OH_Filter_Release" }, + { "name": "OH_Filter_Blur" }, + { "name": "OH_Filter_Brighten" }, + { "name": "OH_Filter_GrayScale" }, + { "name": "OH_Filter_Invert" }, + { "name": "OH_Filter_SetColorMatrix" }, + { "name": "OH_Filter_GetEffectPixelMap" } +] \ No newline at end of file -- Gitee