Skip to content
Merged
Show file tree
Hide file tree
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 Jun 4, 2026
c5a300d
Add NoiseStyle node definition and SVG export support
zfw1234567 Jun 5, 2026
dea733c
Remove NoiseFilterWithShadow test case
zfw1234567 Jun 5, 2026
63cb0ea
Add NoiseFilter test for all element types and update feOffset to use…
zfw1234567 Jun 5, 2026
d4fc805
Fix SVG contentBounds for Repeater and add second test group with lay…
zfw1234567 Jun 5, 2026
f034899
Align ComputeElementBounds with tgfx rendering for Path, Group and Te…
zfw1234567 Jun 7, 2026
3222b45
Add Text::contentBounds and use it in ComputeElementBounds for SVG fi…
zfw1234567 Jun 7, 2026
1b14e59
Use TextBlob getTightBounds for precise Text contentBounds aligned wi…
zfw1234567 Jun 7, 2026
d70b264
Add fontFamily and fontStyle to Text elements in NoiseFilterAllElemen…
zfw1234567 Jun 7, 2026
1b49aac
Use system Helvetica font in NoiseFilterAllElements test for consiste…
zfw1234567 Jun 7, 2026
3eb313d
Remove feOffset from noise filter SVG export and use stitchTiles=stit…
zfw1234567 Jun 8, 2026
6cf7129
Align Multi noise filter SVG export with Figma using feComponentTrans…
zfw1234567 Jun 8, 2026
4b2fb4a
Align Multi noise SVG export with tgfx MakeDarkDensityFilter and remo…
zfw1234567 Jun 8, 2026
b40f365
Fix CR issues: TextBox empty bounds early return, ComputeLayerBounds …
zfw1234567 Jun 8, 2026
6341dea
Add NoiseFilterWithDropShadow test case with large shadow offset for …
zfw1234567 Jun 8, 2026
352e049
Apply code formatting to SVGExporter.cpp.
zfw1234567 Jun 8, 2026
49f0c10
Remove NoiseFilterOnText and NoiseFilterWithDropShadow test cases.
zfw1234567 Jun 8, 2026
c50a3b1
Accept screenshot baseline for NoiseFilter tests.
zfw1234567 Jun 8, 2026
9937c39
Add NoiseStyleWithDropShadow test case for DuoNoiseStyle plus DropSha…
zfw1234567 Jun 8, 2026
329567f
Change test to DuoNoiseFilter plus DropShadowStyle for cross-testing …
zfw1234567 Jun 8, 2026
b8b4bbd
Remove contentBounds parameter from SVG filter and style export pipel…
zfw1234567 Jun 8, 2026
fa105e2
Update baseline versions for noise filter tests after content simplif…
zfw1234567 Jun 8, 2026
8cbf050
Remove NoiseFilterWithDropShadowStyle test case and its baseline entry.
zfw1234567 Jun 8, 2026
b54e98e
Fix rebase conflict resolution issues in PAGXTest.cpp.
zfw1234567 Jun 8, 2026
4102d81
Add NoiseStyleModes test covering Mono, Duo and Multi noise styles fo…
zfw1234567 Jun 9, 2026
ab4941c
Fix writeShadowMerge skipping feMerge when only NoiseStyle exists wit…
zfw1234567 Jun 9, 2026
da167f5
Accept screenshot baseline for NoiseStyleModes test.
zfw1234567 Jun 9, 2026
eacb6e1
Add section separator for noise filter primitives in SVGExporter.
zfw1234567 Jun 9, 2026
8a03fbd
Fix merged separator lines in PAGXTest.cpp to match origin/main format.
zfw1234567 Jun 9, 2026
b7fba47
Restore blank lines between section separators and test cases in PAGX…
zfw1234567 Jun 9, 2026
a218045
Remove unused Text::contentBounds and TextBox::contentBounds functions.
zfw1234567 Jun 9, 2026
937a0ea
Remove unused includes for GlyphRunRenderer in Text and TextBox.
zfw1234567 Jun 9, 2026
b94d4a1
Add animation binding support for NoiseFilter and NoiseStyle.
zfw1234567 Jun 10, 2026
a931e0f
Add animation binding tests for NoiseFilter and NoiseStyle channels.
zfw1234567 Jun 10, 2026
73aaa60
Update noise animation test with 40-frame export across 4 modes and c…
zfw1234567 Jun 10, 2026
d82a742
Accept screenshot baseline for NoiseFilter animation export test.
zfw1234567 Jun 10, 2026
74d5b8c
Revert package-lock.json to origin/main version.
zfw1234567 Jun 10, 2026
126228e
Reduce noise animation export test from 40 frames to 12 frames.
zfw1234567 Jun 10, 2026
fdb3cb9
Refactor noise SVG export and fix mode-specific channel bindings with…
zfw1234567 Jun 15, 2026
49a4cef
Fix noise SVG export issues: rename final variable, clamp opacity, sk…
zfw1234567 Jun 15, 2026
6900e18
Add sRGB fallback to applyFloodColor P3 style for browser compatibility.
zfw1234567 Jun 15, 2026
50bb157
Add size guard for NoiseStyle to avoid null pointer registration when…
zfw1234567 Jun 15, 2026
b51200f
Update comments to include NoiseFilter and NoiseStyle in subclass lists.
zfw1234567 Jun 15, 2026
295d1a6
Extract duplicate noise filter blend and style clip logic into helper…
zfw1234567 Jun 15, 2026
607f9c4
Add PAGXImporter parsing for NoiseStyle and NoiseFilter nodes.
zfw1234567 Jun 15, 2026
021f96a
Add comments explaining writeNoiseBand density-to-band mapping consta…
zfw1234567 Jun 15, 2026
a68731b
Replace lambdas with static helpers and extract duplicated SVG export…
zfw1234567 Jun 15, 2026
25cc6af
Add forward declarations for ParseNoiseStyle and ParseNoiseFilter.
zfw1234567 Jun 15, 2026
e25fac8
Fix ExportNoiseFilterAnimation surface not cleared between frames.
zfw1234567 Jun 15, 2026
e1c63bb
Accept updated baselines for ExportNoiseFilterAnimation after autoCle…
zfw1234567 Jun 15, 2026
bf644e5
Apply code formatting to writeNoiseResultBlend parameter alignment.
zfw1234567 Jun 15, 2026
fbe3d73
Add design intent comment for NoiseStyle SourceGraphic blend and stre…
zfw1234567 Jun 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/pagx/nodes/LayerFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
namespace pagx {

/**
* Base class for layer filters (BlurFilter, DropShadowFilter, InnerShadowFilter, BlendFilter, ColorMatrixFilter).
* Base class for layer filters (BlurFilter, DropShadowFilter, InnerShadowFilter, BlendFilter,
* ColorMatrixFilter, NoiseFilter).
*/
class LayerFilter : public Node {
public:
Expand Down
2 changes: 1 addition & 1 deletion include/pagx/nodes/LayerStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
namespace pagx {

/**
* Base class for layer styles (DropShadowStyle, InnerShadowStyle, BackgroundBlurStyle).
* Base class for layer styles (DropShadowStyle, InnerShadowStyle, BackgroundBlurStyle, NoiseStyle).
*/
class LayerStyle : public Node {
public:
Expand Down
8 changes: 8 additions & 0 deletions include/pagx/nodes/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ enum class NodeType {
* A background blur layer style.
*/
BackgroundBlurStyle,
/**
* A noise layer style.
*/
NoiseStyle,

// Layer Filters
/**
Expand All @@ -139,6 +143,10 @@ enum class NodeType {
* A color matrix filter.
*/
ColorMatrixFilter,
/**
* A noise filter.
*/
NoiseFilter,

// Elements (geometry, painters, modifiers, containers)
/**
Expand Down
97 changes: 97 additions & 0 deletions include/pagx/nodes/NoiseFilter.h
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
91 changes: 91 additions & 0 deletions include/pagx/nodes/NoiseStyle.h
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 {
Comment on lines +28 to +33

Copy link
Copy Markdown
Collaborator

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)的折衷,便于用户构造,但带来副作用:

  1. 用户从代码层面看不出哪些字段必须设置(Issue 请问下 ios有没有可以监听动画播放实时进度的API #5 默认值问题就是这个的副作用);
  2. 序列化/反序列化无法决定要不要写出未使用的字段;
  3. 引发 bindNoiseStyleChannels 中的 UB 风险(见 LayerBuilder.cpp 行级评论)。

建议在 class doc(这段顶部注释)中明确写出:"非当前 mode 对应的字段会被忽略;切换 mode 后请重新设置对应字段。"目前的字段级注释"used in X mode"较容易被忽略。

NoiseFilter.h 同样建议。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复。补充了:

  • 类顶部注释:"Mode-specific fields for inactive modes are ignored; set the fields for the new mode after changing mode."
  • 每个 mode 专属字段注释标注被哪些 mode 忽略,如 color → "Ignored by Duo and Multi modes."
  • NoiseFilter.h 同步处理。

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
41 changes: 41 additions & 0 deletions include/pagx/types/NoiseMode.h
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
Loading
Loading