mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 01:00:50 +00:00
commit
fe0fa0c184
10
bundle.json
10
bundle.json
@ -128,6 +128,7 @@
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/effect/effectChain:libeffectchain",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/effect/color_picker:color_picker",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/effect/skia_effectChain:skeffectchain",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/effect/effect_ndk:native_effect_ndk",
|
||||
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:EGL",
|
||||
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:GLESv2",
|
||||
"//foundation/graphic/graphic_2d/frameworks/opengl_wrapper:GLESv3",
|
||||
@ -318,6 +319,15 @@
|
||||
"header_base": "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics/drawing_ndk/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/graphic/graphic_2d/rosen/modules/effect/effect_ndk:native_effect_ndk",
|
||||
"header": {
|
||||
"header_files": [
|
||||
],
|
||||
"header_base": "//foundation/graphic/graphic_2d/rosen/modules/effect/effect_ndk/include"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "so",
|
||||
"name": "//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics_new",
|
||||
|
117
rosen/modules/effect/effect_ndk/BUILD.gn
Normal file
117
rosen/modules/effect/effect_ndk/BUILD.gn
Normal file
@ -0,0 +1,117 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.. All rights reserved.
|
||||
# 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")
|
||||
effect_root = "$graphic_2d_root/rosen/modules/effect"
|
||||
effect_ndk_include_dir =
|
||||
"$graphic_2d_root/rosen/modules/effect/effect_ndk/include"
|
||||
effect_ndk_src_dir = "$graphic_2d_root/rosen/modules/effect/effect_ndk/src"
|
||||
|
||||
config("export_config") {
|
||||
include_dirs = [ "$effect_ndk_include_dir" ]
|
||||
}
|
||||
|
||||
template("effect_ndk_source_set") {
|
||||
forward_variables_from(invoker, "*")
|
||||
|
||||
ohos_source_set(target_name) {
|
||||
defines += invoker.defines
|
||||
cflags_cc += invoker.cflags_cc
|
||||
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hilog:libhilog",
|
||||
"image_framework:image",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"$effect_root//skia_effectChain:skeffectchain",
|
||||
"$effect_root/color_picker:color_picker",
|
||||
]
|
||||
public_external_deps = [ "jsoncpp:jsoncpp" ]
|
||||
|
||||
configs = [ ":export_config" ]
|
||||
sources = [
|
||||
"$effect_ndk_src_dir/effect_filter.cpp",
|
||||
"$effect_ndk_src_dir/filter/filter.cpp",
|
||||
]
|
||||
|
||||
if (is_arkui_x) {
|
||||
defines += [ "CROSS_PLATFORM" ]
|
||||
}
|
||||
if (ace_enable_gpu) {
|
||||
defines += [ "ACE_ENABLE_GPU" ]
|
||||
}
|
||||
if (is_emulator) {
|
||||
defines += [ "ROSEN_EMULATOR" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"$graphic_2d_root/rosen/modules/render_service_base/include",
|
||||
"$graphic_2d_root/modules/2d_graphics/include",
|
||||
]
|
||||
|
||||
if (platform == "ohos" || platform == "ohos_ng") {
|
||||
defines += [ "OHOS_PLATFORM" ]
|
||||
external_deps += [
|
||||
"bounds_checking_function:libsec_static",
|
||||
"image_framework:pixelmap",
|
||||
"image_framework:pixelmap_ndk",
|
||||
]
|
||||
deps = [ "$graphic_2d_root/rosen/modules/render_service_base:librender_service_base" ]
|
||||
} else {
|
||||
deps = []
|
||||
cflags = [ "-std=c++17" ]
|
||||
|
||||
if (!is_arkui_x) {
|
||||
deps += [ "$rosen_root/modules/platform:hilog" ]
|
||||
}
|
||||
}
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
||||
}
|
||||
|
||||
effect_ndk_source_set("effect_ndk_source_ohos") {
|
||||
platform = "ohos"
|
||||
defines = []
|
||||
cflags_cc = []
|
||||
}
|
||||
|
||||
ohos_shared_library("native_effect_ndk") {
|
||||
sanitize = {
|
||||
cfi = true
|
||||
cfi_cross_dso = true
|
||||
debug = false
|
||||
}
|
||||
platform = current_os
|
||||
if (platform == "mingw") {
|
||||
platform = "windows"
|
||||
}
|
||||
public_configs = [ ":export_config" ]
|
||||
|
||||
if (platform == "ohos") {
|
||||
deps = [ "$effect_root/effect_ndk:effect_ndk_source_ohos" ]
|
||||
symlink_target_name = [ "libnative_effect.so" ]
|
||||
innerapi_tags = [ "ndk" ]
|
||||
}
|
||||
part_name = "graphic_2d"
|
||||
subsystem_name = "graphic"
|
||||
}
|
141
rosen/modules/effect/effect_ndk/include/effect_filter.h
Normal file
141
rosen/modules/effect/effect_ndk/include/effect_filter.h
Normal file
@ -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 <b>OH_Filter</b> 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 <b>OH_Filter</b> 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
|
94
rosen/modules/effect/effect_ndk/include/effect_types.h
Normal file
94
rosen/modules/effect/effect_ndk/include/effect_types.h
Normal file
@ -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 <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#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
|
112
rosen/modules/effect/effect_ndk/src/effect_filter.cpp
Normal file
112
rosen/modules/effect/effect_ndk/src/effect_filter.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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 "effect_filter.h"
|
||||
|
||||
#include "filter/filter.h"
|
||||
#include "sk_image_chain.h"
|
||||
#include "sk_image_filter_factory.h"
|
||||
|
||||
#include "utils/log.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace Rosen;
|
||||
|
||||
static Filter* CastToFilter(OH_Filter* filter)
|
||||
{
|
||||
return reinterpret_cast<Filter*>(filter);
|
||||
}
|
||||
|
||||
static OH_Filter* CastToOH_Filter(Filter* filter)
|
||||
{
|
||||
return reinterpret_cast<OH_Filter*>(filter);
|
||||
}
|
||||
|
||||
EffectErrorCode OH_Filter_CreateEffect(OH_PixelmapNative* pixelmap, OH_Filter** filter)
|
||||
{
|
||||
if (!pixelmap || !filter) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
*filter = CastToOH_Filter(new Filter(pixelmap->GetInnerPixelmap()));
|
||||
if (*filter == nullptr) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
|
||||
EffectErrorCode OH_Filter_Release(OH_Filter* filter)
|
||||
{
|
||||
if (filter == nullptr) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
delete CastToFilter(filter);
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
|
||||
EffectErrorCode OH_Filter_Blur(OH_Filter* filter, float radius)
|
||||
{
|
||||
if (!filter || !(CastToFilter(filter)->Blur(radius))) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
EffectErrorCode OH_Filter_Brighten(OH_Filter* filter, float brightness)
|
||||
{
|
||||
if (!filter || !(CastToFilter(filter)->Brightness(brightness))) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
|
||||
EffectErrorCode OH_Filter_GrayScale(OH_Filter* filter)
|
||||
{
|
||||
if (!filter || !(CastToFilter(filter)->Grayscale())) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
EffectErrorCode OH_Filter_Invert(OH_Filter* filter)
|
||||
{
|
||||
if (!filter || !(CastToFilter(filter)->Invert())) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
EffectErrorCode OH_Filter_SetColorMatrix(OH_Filter* filter, OH_Filter_ColorMatrix* matrix)
|
||||
{
|
||||
if (!filter || !matrix) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
PixelColorMatrix colorMatrix;
|
||||
for (size_t i = 0; i < colorMatrix.MATRIX_SIZE; i++) {
|
||||
colorMatrix.val[i] = matrix->val[i];
|
||||
}
|
||||
if (!(CastToFilter(filter)->SetColorMatrix(colorMatrix))) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
||||
|
||||
EffectErrorCode OH_Filter_GetEffectPixelMap(OH_Filter* filter, OH_PixelmapNative** pixelmap)
|
||||
{
|
||||
if (!pixelmap || !filter) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
*pixelmap = new OH_PixelmapNative(CastToFilter(filter)->GetPixelMap());
|
||||
if (pixelmap == nullptr) {
|
||||
return EFFECT_BAD_PARAMETER;
|
||||
}
|
||||
return EFFECT_SUCCESS;
|
||||
}
|
98
rosen/modules/effect/effect_ndk/src/filter/filter.cpp
Normal file
98
rosen/modules/effect/effect_ndk/src/filter/filter.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 "filter.h"
|
||||
|
||||
#include "sk_image_chain.h"
|
||||
#include "utils/log.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
Filter::Filter(std::shared_ptr<OHOS::Media::PixelMap> pixelMap) : srcPixelMap_(pixelMap)
|
||||
{}
|
||||
|
||||
void Filter::Render(bool forceCPU)
|
||||
{
|
||||
Rosen::SKImageChain skImage(srcPixelMap_);
|
||||
for (auto filter : skFilters_) {
|
||||
skImage.SetFilters(filter);
|
||||
}
|
||||
skImage.ForceCPU(forceCPU);
|
||||
skImage.Draw();
|
||||
dstPixelMap_ = skImage.GetPixelMap();
|
||||
}
|
||||
|
||||
void Filter::AddNextFilter(sk_sp<SkImageFilter> filter)
|
||||
{
|
||||
skFilters_.emplace_back(filter);
|
||||
}
|
||||
|
||||
std::shared_ptr<OHOS::Media::PixelMap> Filter::GetPixelMap()
|
||||
{
|
||||
Render(true);
|
||||
return dstPixelMap_;
|
||||
}
|
||||
|
||||
bool Filter::Blur(float radius)
|
||||
{
|
||||
auto blur = Rosen::SKImageFilterFactory::Blur(radius);
|
||||
if (!blur) {
|
||||
return false;
|
||||
}
|
||||
AddNextFilter(blur);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filter::Brightness(float brightness)
|
||||
{
|
||||
auto bright = Rosen::SKImageFilterFactory::Brightness(brightness);
|
||||
if (!bright) {
|
||||
return false;
|
||||
}
|
||||
AddNextFilter(bright);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filter::Grayscale()
|
||||
{
|
||||
auto grayscale = Rosen::SKImageFilterFactory::Grayscale();
|
||||
if (!grayscale) {
|
||||
return false;
|
||||
}
|
||||
AddNextFilter(grayscale);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filter::Invert()
|
||||
{
|
||||
auto invert = Rosen::SKImageFilterFactory::Invert();
|
||||
if (!invert) {
|
||||
return false;
|
||||
}
|
||||
AddNextFilter(invert);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filter::SetColorMatrix(const PixelColorMatrix& matrix)
|
||||
{
|
||||
auto applyColorMatrix = Rosen::SKImageFilterFactory::ApplyColorMatrix(matrix);
|
||||
if (!applyColorMatrix) {
|
||||
return false;
|
||||
}
|
||||
AddNextFilter(applyColorMatrix);
|
||||
return true;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
49
rosen/modules/effect/effect_ndk/src/filter/filter.h
Normal file
49
rosen/modules/effect/effect_ndk/src/filter/filter.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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 EFFECT_NATIVE_FILTER_H
|
||||
#define EFFECT_NATIVE_FILTER_H
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
#include "include/core/SkImageFilter.h"
|
||||
#include "pixelmap_native_impl.h"
|
||||
#include "sk_image_filter_factory.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class Filter {
|
||||
public:
|
||||
Filter(){};
|
||||
explicit Filter(std::shared_ptr<OHOS::Media::PixelMap> pixelMap);
|
||||
|
||||
std::shared_ptr<OHOS::Media::PixelMap> GetPixelMap();
|
||||
bool Blur(float radius);
|
||||
bool Brightness(float brightness);
|
||||
bool Grayscale();
|
||||
bool Invert();
|
||||
bool SetColorMatrix(const PixelColorMatrix& matrix);
|
||||
private:
|
||||
void AddNextFilter(sk_sp<SkImageFilter> filter);
|
||||
void Render(bool forceCPU);
|
||||
std::vector<sk_sp<SkImageFilter> > skFilters_;
|
||||
std::shared_ptr<OHOS::Media::PixelMap> srcPixelMap_ = nullptr;
|
||||
std::shared_ptr<OHOS::Media::PixelMap> dstPixelMap_ = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // EFFECT_NATIVE_FILTER_H
|
Loading…
Reference in New Issue
Block a user