-
Notifications
You must be signed in to change notification settings - Fork 528
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
Merged
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
3c1e1d2
Accept baseline for NoiseFilter SVG export test.
zfw1234567 c5a300d
Add NoiseStyle node definition and SVG export support
zfw1234567 dea733c
Remove NoiseFilterWithShadow test case
zfw1234567 63cb0ea
Add NoiseFilter test for all element types and update feOffset to use…
zfw1234567 d4fc805
Fix SVG contentBounds for Repeater and add second test group with lay…
zfw1234567 f034899
Align ComputeElementBounds with tgfx rendering for Path, Group and Te…
zfw1234567 3222b45
Add Text::contentBounds and use it in ComputeElementBounds for SVG fi…
zfw1234567 1b14e59
Use TextBlob getTightBounds for precise Text contentBounds aligned wi…
zfw1234567 d70b264
Add fontFamily and fontStyle to Text elements in NoiseFilterAllElemen…
zfw1234567 1b49aac
Use system Helvetica font in NoiseFilterAllElements test for consiste…
zfw1234567 3eb313d
Remove feOffset from noise filter SVG export and use stitchTiles=stit…
zfw1234567 6cf7129
Align Multi noise filter SVG export with Figma using feComponentTrans…
zfw1234567 4b2fb4a
Align Multi noise SVG export with tgfx MakeDarkDensityFilter and remo…
zfw1234567 b40f365
Fix CR issues: TextBox empty bounds early return, ComputeLayerBounds …
zfw1234567 6341dea
Add NoiseFilterWithDropShadow test case with large shadow offset for …
zfw1234567 352e049
Apply code formatting to SVGExporter.cpp.
zfw1234567 49f0c10
Remove NoiseFilterOnText and NoiseFilterWithDropShadow test cases.
zfw1234567 c50a3b1
Accept screenshot baseline for NoiseFilter tests.
zfw1234567 9937c39
Add NoiseStyleWithDropShadow test case for DuoNoiseStyle plus DropSha…
zfw1234567 329567f
Change test to DuoNoiseFilter plus DropShadowStyle for cross-testing …
zfw1234567 b8b4bbd
Remove contentBounds parameter from SVG filter and style export pipel…
zfw1234567 fa105e2
Update baseline versions for noise filter tests after content simplif…
zfw1234567 8cbf050
Remove NoiseFilterWithDropShadowStyle test case and its baseline entry.
zfw1234567 b54e98e
Fix rebase conflict resolution issues in PAGXTest.cpp.
zfw1234567 4102d81
Add NoiseStyleModes test covering Mono, Duo and Multi noise styles fo…
zfw1234567 ab4941c
Fix writeShadowMerge skipping feMerge when only NoiseStyle exists wit…
zfw1234567 da167f5
Accept screenshot baseline for NoiseStyleModes test.
zfw1234567 eacb6e1
Add section separator for noise filter primitives in SVGExporter.
zfw1234567 8a03fbd
Fix merged separator lines in PAGXTest.cpp to match origin/main format.
zfw1234567 b7fba47
Restore blank lines between section separators and test cases in PAGX…
zfw1234567 a218045
Remove unused Text::contentBounds and TextBox::contentBounds functions.
zfw1234567 937a0ea
Remove unused includes for GlyphRunRenderer in Text and TextBox.
zfw1234567 b94d4a1
Add animation binding support for NoiseFilter and NoiseStyle.
zfw1234567 a931e0f
Add animation binding tests for NoiseFilter and NoiseStyle channels.
zfw1234567 73aaa60
Update noise animation test with 40-frame export across 4 modes and c…
zfw1234567 d82a742
Accept screenshot baseline for NoiseFilter animation export test.
zfw1234567 74d5b8c
Revert package-lock.json to origin/main version.
zfw1234567 126228e
Reduce noise animation export test from 40 frames to 12 frames.
zfw1234567 fdb3cb9
Refactor noise SVG export and fix mode-specific channel bindings with…
zfw1234567 49a4cef
Fix noise SVG export issues: rename final variable, clamp opacity, sk…
zfw1234567 6900e18
Add sRGB fallback to applyFloodColor P3 style for browser compatibility.
zfw1234567 50bb157
Add size guard for NoiseStyle to avoid null pointer registration when…
zfw1234567 b51200f
Update comments to include NoiseFilter and NoiseStyle in subclass lists.
zfw1234567 295d1a6
Extract duplicate noise filter blend and style clip logic into helper…
zfw1234567 607f9c4
Add PAGXImporter parsing for NoiseStyle and NoiseFilter nodes.
zfw1234567 021f96a
Add comments explaining writeNoiseBand density-to-band mapping consta…
zfw1234567 a68731b
Replace lambdas with static helpers and extract duplicated SVG export…
zfw1234567 25cc6af
Add forward declarations for ParseNoiseStyle and ParseNoiseFilter.
zfw1234567 e25fac8
Fix ExportNoiseFilterAnimation surface not cleared between frames.
zfw1234567 e1c63bb
Accept updated baselines for ExportNoiseFilterAnimation after autoCle…
zfw1234567 bf644e5
Apply code formatting to writeNoiseResultBlend parameter alignment.
zfw1234567 fbe3d73
Add design intent comment for NoiseStyle SourceGraphic blend and stre…
zfw1234567 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // 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). Mode-specific fields for inactive modes are ignored; set the | ||
| * fields for the new mode after changing mode. | ||
| */ | ||
| 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. Ignored by Duo and Multi modes. The alpha component controls the | ||
| * noise opacity. The default value is black. | ||
| */ | ||
| Color color = {}; | ||
|
|
||
| /** | ||
| * The first noise color for Duo mode. Ignored by Mono and Multi modes. The alpha component | ||
| * controls its opacity. The default value is black. | ||
| */ | ||
| Color firstColor = {}; | ||
|
|
||
| /** | ||
| * The second noise color for Duo mode. Ignored by Mono and Multi modes. The alpha component | ||
| * controls its opacity. The default value is white. | ||
| */ | ||
| Color secondColor = {1.0f, 1.0f, 1.0f, 1.0f}; | ||
|
|
||
| /** | ||
| * The overall noise opacity for Multi mode, in [0, 1]. Ignored by Mono and Duo modes. 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| ///////////////////////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // 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). Mode-specific fields for inactive modes are ignored; | ||
| * set the fields for the new mode after changing mode. | ||
| */ | ||
| 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. Ignored by Duo and Multi modes. The alpha component controls the | ||
| * noise opacity. The default value is black. | ||
| */ | ||
| Color color = {}; | ||
|
|
||
| /** | ||
| * The first noise color for Duo mode. Ignored by Mono and Multi modes. The alpha component | ||
| * controls its opacity. The default value is black. | ||
| */ | ||
| Color firstColor = {}; | ||
|
|
||
| /** | ||
| * The second noise color for Duo mode. Ignored by Mono and Multi modes. The alpha component | ||
| * controls its opacity. The default value is white. | ||
| */ | ||
| Color secondColor = {1.0f, 1.0f, 1.0f, 1.0f}; | ||
|
|
||
| /** | ||
| * The overall noise opacity for Multi mode, in [0, 1]. Ignored by Mono and Duo modes. 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 noise filters and noise layer styles. | ||
| */ | ||
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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同样建议。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.
已修复。补充了: