mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2024-11-27 17:21:51 +00:00
update blur with skTileMode
Signed-off-by: zhoujing <zhoujing96@huawei.com>
This commit is contained in:
parent
de63137e1b
commit
1af578cf3a
@ -38,6 +38,10 @@ namespace {
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
static const int32_t ARGS_ONE = 1;
|
||||
static const int32_t ARGS_TWO = 2;
|
||||
static const int32_t PARAM0 = 0;
|
||||
static const int32_t PARAM1 = 1;
|
||||
struct FilterAsyncContext {
|
||||
napi_env env;
|
||||
napi_async_work work;
|
||||
@ -415,8 +419,8 @@ napi_value FilterNapi::GetPixelMapAsync(napi_env env, napi_callback_info info)
|
||||
|
||||
napi_value FilterNapi::Blur(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv[1];
|
||||
size_t argc = ARGS_TWO;
|
||||
napi_value argv[ARGS_TWO];
|
||||
napi_value _this;
|
||||
napi_status status;
|
||||
IMG_JS_ARGS(env, info, status, argc, argv, _this);
|
||||
@ -425,24 +429,30 @@ napi_value FilterNapi::Blur(napi_env env, napi_callback_info info)
|
||||
return nullptr;
|
||||
}
|
||||
float radius = 0.0f;
|
||||
if (argc != 1) {
|
||||
return nullptr;
|
||||
}
|
||||
if (Media::ImageNapiUtils::getType(env, argv[0]) == napi_number) {
|
||||
if (Media::ImageNapiUtils::getType(env, argv[PARAM0]) == napi_number) {
|
||||
double scale = -1.0f;
|
||||
if (IMG_IS_OK(napi_get_value_double(env, argv[0], &scale))) {
|
||||
if (IMG_IS_OK(napi_get_value_double(env, argv[PARAM0], &scale))) {
|
||||
if (scale >= 0) {
|
||||
radius = static_cast<float>(scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t skTileMode = 3;
|
||||
if (argc == ARGS_ONE) {
|
||||
EFFECT_LOG_I("FilterNapi parse input with default skTileMode");
|
||||
} else if (argc == ARGS_TWO) {
|
||||
napi_get_value_int32(env, argv[PARAM1], &skTileMode);
|
||||
}
|
||||
|
||||
FilterNapi* thisFilter = nullptr;
|
||||
NAPI_CALL(env, napi_unwrap(env, _this, reinterpret_cast<void**>(&thisFilter)));
|
||||
if (thisFilter == nullptr) {
|
||||
EFFECT_LOG_I("FilterNapi napi_unwrap is Faild");
|
||||
return nullptr;
|
||||
}
|
||||
auto blur = Rosen::SKImageFilterFactory::Blur(radius);
|
||||
|
||||
auto blur = Rosen::SKImageFilterFactory::Blur(radius, skTileMode);
|
||||
thisFilter->AddNextFilter(blur);
|
||||
return _this;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ struct PixelColorMatrix {
|
||||
|
||||
class SKImageFilterFactory {
|
||||
public:
|
||||
static sk_sp<SkImageFilter> Blur(float radius);
|
||||
static sk_sp<SkImageFilter> Blur(float radius, int32_t skTileMode);
|
||||
static sk_sp<SkImageFilter> Brightness(float degree);
|
||||
static sk_sp<SkImageFilter> Grayscale();
|
||||
static sk_sp<SkImageFilter> Invert();
|
||||
|
@ -23,9 +23,26 @@ static constexpr float GRAYSCALE_PARAONE = 0.2126f;
|
||||
static constexpr float GRAYSCALE_PARATWO = 0.7152f;
|
||||
static constexpr float GRAYSCALE_PARATHREE = 0.0722f;
|
||||
|
||||
sk_sp<SkImageFilter> SKImageFilterFactory::Blur(float radius)
|
||||
static inline SkTileMode ConvertToSkTileMode(int32_t skTileModeNum)
|
||||
{
|
||||
return SkImageFilters::Blur(radius, radius, nullptr);
|
||||
switch (skTileModeNum) {
|
||||
case 0:
|
||||
return SkTileMode::kClamp;
|
||||
case 1:
|
||||
return SkTileMode::kRepeat;
|
||||
case 2:
|
||||
return SkTileMode::kMirror;
|
||||
case 3:
|
||||
return SkTileMode::kDecal;
|
||||
default:
|
||||
return SkTileMode::kDecal;
|
||||
}
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SKImageFilterFactory::Blur(float radius, int32_t skTileModeNum)
|
||||
{
|
||||
SkTileMode skTileMode = ConvertToSkTileMode(skTileModeNum);
|
||||
return SkImageFilters::Blur(radius, radius, skTileMode, nullptr);
|
||||
}
|
||||
|
||||
sk_sp<SkImageFilter> SKImageFilterFactory::Brightness(float degree)
|
||||
|
Loading…
Reference in New Issue
Block a user