-
Notifications
You must be signed in to change notification settings - Fork 527
Add NoiseStyle and NoiseFilter support with animation binding and SVG export #3483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
24e4a25
51084c1
60b8865
d6f138f
7f78297
3ce4ced
f88a1b7
1034537
7328118
3b4b399
1de37eb
940b6da
54a88d8
84b21d1
71a68e3
4098cb4
493f125
330c852
fedb2f8
d70000c
7ef1187
84cc33c
275aabc
19fe1c4
87bb94c
1af0759
5011c3a
a4326a3
e05133a
3d0e359
3ed9283
591fa99
42a9333
4946b97
2813c87
8498ae0
a218983
71a6baf
ae79c84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Tencent is pleased to support the open source community by making libpag available. | ||
| // | ||
| // Copyright (C) 2026 Tencent. 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. | ||
| // | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "pagx/nodes/LayerFilter.h" | ||
| #include "pagx/types/BlendMode.h" | ||
| #include "pagx/types/Color.h" | ||
| #include "pagx/types/NoiseMode.h" | ||
|
|
||
| namespace pagx { | ||
|
|
||
| /** | ||
| * A noise filter that overlays procedural Perlin noise on the layer. Three noise modes are | ||
| * available: Mono (single color), Duo (two complementary colors), and Multi (preserving original | ||
| * noise RGB with enhanced contrast). | ||
| */ | ||
| class NoiseFilter : public LayerFilter { | ||
| public: | ||
| /** | ||
| * The noise mode. The default value is Mono. | ||
| */ | ||
| NoiseMode mode = NoiseMode::Mono; | ||
|
|
||
| /** | ||
| * The noise grain size. Larger values produce coarser grains. Must be positive. The default value | ||
| * is 4.0. | ||
| */ | ||
| float size = 4.0f; | ||
|
|
||
| /** | ||
| * The noise density in [0, 1]. Controls the proportion of visible noise pixels. The default value | ||
| * is 0.5. | ||
| */ | ||
| float density = 0.5f; | ||
|
|
||
| /** | ||
| * The random seed for the noise pattern. The default value is 0. | ||
| */ | ||
| float seed = 0.0f; | ||
|
|
||
| /** | ||
| * The blend mode used to composite the noise with the source image. The default value is Normal. | ||
| */ | ||
| BlendMode blendMode = BlendMode::Normal; | ||
|
|
||
| /** | ||
| * The noise color for Mono mode. The alpha component controls the noise opacity. | ||
| */ | ||
| Color color = {}; | ||
|
|
||
| /** | ||
| * The first noise color for Duo mode. The alpha component controls its opacity. | ||
| */ | ||
| Color firstColor = {}; | ||
|
|
||
| /** | ||
| * The second noise color for Duo mode. The alpha component controls its opacity. | ||
| */ | ||
| Color secondColor = {}; | ||
|
|
||
| /** | ||
| * The overall noise opacity for Multi mode, in [0, 1]. The default value is 0.15. | ||
| */ | ||
| float opacity = 0.15f; | ||
|
|
||
| NodeType nodeType() const override { | ||
| return NodeType::NoiseFilter; | ||
| } | ||
|
|
||
| private: | ||
| NoiseFilter() = default; | ||
|
|
||
| friend class PAGXDocument; | ||
| }; | ||
|
|
||
| } // namespace pagx |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Tencent is pleased to support the open source community by making libpag available. | ||
| // | ||
| // Copyright (C) 2026 Tencent. 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. | ||
| // | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "pagx/nodes/LayerStyle.h" | ||
| #include "pagx/types/Color.h" | ||
| #include "pagx/types/NoiseMode.h" | ||
|
|
||
| namespace pagx { | ||
|
|
||
| /** | ||
| * A noise layer style that overlays procedural Perlin noise above the layer content. Three noise | ||
| * modes are available: Mono (single color), Duo (two complementary colors), and Multi (preserving | ||
| * original noise RGB with enhanced contrast). | ||
| */ | ||
| class NoiseStyle : public LayerStyle { | ||
| public: | ||
| /** | ||
| * The noise mode. The default value is Mono. | ||
| */ | ||
| NoiseMode mode = NoiseMode::Mono; | ||
|
|
||
| /** | ||
| * The noise grain size. Larger values produce coarser grains. Must be positive. The default value | ||
| * is 4.0. | ||
| */ | ||
| float size = 4.0f; | ||
|
|
||
| /** | ||
| * The noise density in [0, 1]. Controls the proportion of visible noise pixels. The default value | ||
| * is 0.5. | ||
| */ | ||
| float density = 0.5f; | ||
|
|
||
| /** | ||
| * The random seed for the noise pattern. The default value is 0. | ||
| */ | ||
| float seed = 0.0f; | ||
|
|
||
| /** | ||
| * The noise color for Mono mode. The alpha component controls the noise opacity. | ||
| */ | ||
| Color color = {}; | ||
|
|
||
| /** | ||
| * The first noise color for Duo mode. The alpha component controls its opacity. | ||
| */ | ||
| Color firstColor = {}; | ||
|
|
||
| /** | ||
| * The second noise color for Duo mode. The alpha component controls its opacity. | ||
| */ | ||
| Color secondColor = {}; | ||
|
Comment on lines
+59
to
+69
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [API 易用性] 这意味着用户构造 Duo 模式但忘记同时设置 对应的 tgfx 端默认值更合理: 建议让 pagx 默认值与 tgfx 一致,至少 Color secondColor = {1.0f, 1.0f, 1.0f, 1.0f};
|
||
|
|
||
| /** | ||
| * The overall noise opacity for Multi mode, in [0, 1]. The default value is 0.15. | ||
| */ | ||
| float opacity = 0.15f; | ||
|
|
||
| NodeType nodeType() const override { | ||
| return NodeType::NoiseStyle; | ||
| } | ||
|
|
||
| private: | ||
| NoiseStyle() = default; | ||
|
|
||
| friend class PAGXDocument; | ||
| }; | ||
|
|
||
| } // namespace pagx | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,7 +90,7 @@ class TextBox : public Group { | |
| return NodeType::TextBox; | ||
| } | ||
|
|
||
| protected: | ||
| protected: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [代码规范] 这一处 |
||
| void onMeasure(LayoutContext* context) override; | ||
| void setLayoutSize(LayoutContext* context, float targetWidth, float targetHeight) override; | ||
| void updateLayout(LayoutContext* context) override; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Tencent is pleased to support the open source community by making libpag available. | ||
| // | ||
| // Copyright (C) 2026 Tencent. 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. | ||
| // | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| #pragma once | ||
|
|
||
| namespace pagx { | ||
|
|
||
| /** | ||
| * Noise modes for the NoiseFilter. | ||
| */ | ||
| enum class NoiseMode { | ||
| /** | ||
| * Single-color noise. Noise pixels are filled with one color. | ||
| */ | ||
| Mono, | ||
| /** | ||
| * Dual-color noise. The noise source is split into two complementary regions. | ||
| */ | ||
| Duo, | ||
| /** | ||
| * Multi-color noise preserving original Perlin noise RGB with enhanced contrast. | ||
| */ | ||
| Multi | ||
| }; | ||
|
|
||
| } // namespace pagx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[API 设计 / 文档]
NoiseStyle同时暴露了color(Mono 用)、firstColor/secondColor(Duo 用)、opacity(Multi 用)四个字段,但任意时刻只有一组生效。这种"扁平字段 + mode 切换"的设计是相对 tgfx 的子类层次(MonoNoiseStyle/DuoNoiseStyle/MultiNoiseStyle)的折衷,便于用户构造,但带来副作用:bindNoiseStyleChannels中的 UB 风险(见 LayerBuilder.cpp 行级评论)。建议在 class doc(这段顶部注释)中明确写出:"非当前 mode 对应的字段会被忽略;切换 mode 后请重新设置对应字段。"目前的字段级注释"used in X mode"较容易被忽略。
NoiseFilter.h同样建议。