Skip to content

refactor: port more layers to Cobra renderer: HalfTone2 & 3 - #3300

Merged
ice0 merged 7 commits into
synfig:masterfrom
rodolforg:port-halftone-layers
Mar 17, 2025
Merged

ice0 merged 7 commits into
synfig:masterfrom
rodolforg:port-halftone-layers

Conversation

@rodolforg

Copy link
Copy Markdown
Contributor

No description provided.

@rodolforg

Copy link
Copy Markdown
Contributor Author

Remaining layers without Cobra support:

  1. Bevel
  2. Curve Warp
  3. Sphere Distort
  4. Twirl
  5. Metaballs
  6. Radial Blur
  7. Curve Gradient
  8. Noise Distort
  9. Noise Gradient
  10. Plant

@rodolforg
rodolforg force-pushed the port-halftone-layers branch 3 times, most recently from 3e8c8df to 886a867 Compare January 16, 2024 12:12
@morevnaproject

Copy link
Copy Markdown
Member

Hi @rodolforg! I have tested this branch, comparing with results of Synfig 1.0.2.
And, unfortunately, it gives different result for Halftone2.

Here is a test set -
halftone2.zip

Render results from version 1.0.2 -
halftone2-synfig-1.0.2.zip

Render results from this PR -
halftone2-pr.zip

You were right about 1px offset - it is still present for Halftone2 and Halftone3 in this PR. I was expected it will disappear, because they are ported to Cobra. But for some reason the offset is still here.

I think the problem is because you use build_rendering_task_vfunc.
Instead try to use build_composite_fork_task_vfunc.
This is because Halftone2 class is Layer_CompositeFork.

This will change how you interact with context

So, I suggest to replace this line:

Halftone2::build_rendering_task_vfunc(Context context) const

to this:

Halftone2::build_composite_fork_task_vfunc(ContextParams /* context_params */, rendering::Task::Handle sub_task)const

Please take a look at Blur module to see how it is handled for Layer_CompositeFork:
https://github.com/synfig/synfig/blob/master/synfig-core/src/modules/mod_filter/blur.cpp#L178

You can use sub_task variable to get context under the Halftone layer.

@rodolforg
rodolforg force-pushed the port-halftone-layers branch 2 times, most recently from 0924537 to 62fc197 Compare July 27, 2024 15:21
@rodolforg
rodolforg force-pushed the port-halftone-layers branch 3 times, most recently from 9136d6f to 9999828 Compare August 10, 2024 18:12
@morevnaproject

Copy link
Copy Markdown
Member

I have made more tests for Halftone 2

And I see differences in results - It is shift again, but it is different kind.

Please see the test file
halftone2-rectangle-size-05x05-origin-000x000-angle000-type-diamond.sif.zip

halftone2-result-1.0.2.png
halftone2-result-1 0 2

halftone2-result-pr.png
halftone2-result-pr

You can see the pattern inside of the shape - it is shifted
Peek 2024-08-11 13-24

@rodolforg
rodolforg force-pushed the port-halftone-layers branch 2 times, most recently from 0c8adcb to be8b8a1 Compare August 11, 2024 12:49
@morevnaproject

Copy link
Copy Markdown
Member

Hi! Thank you for the fixes! My previous tests now giving identical results with earlier Synfig version (1.0.2).

But I found 2 cases, which give non-identical results:

  1. Non-zero angle parameter
    halftone2-rectangle-size-05x05-origin-000x000-angle030-type-symmetric.sif.zip

This is result from 1.0.2
halftone2-rectangle-size-05x05-origin-000x000-angle030-type-symmetric-1 0 2

This is result from the latest PR
halftone2-rectangle-size-05x05-origin-000x000-angle030-type-symmetric-pr

It seems like the problem in direction of rotation

  1. Non-zero offset parameter
    halftone2-rectangle-size-05x05-origin-009x201-angle000-type-symmetric.sif.zip

This is result from 1.0.2
halftone2-rectangle-size-05x05-origin-009x201-angle000-type-symmetric-1 0 2

This is result from the latest PR
halftone2-rectangle-size-05x05-origin-009x201-angle000-type-symmetric-pr

My Halftone 3 tests are failing too. Looks like it is because the same problem with Angle parameter -
halftone3.zip

@rodolforg

Copy link
Copy Markdown
Contributor Author

@morevnaproject rebased and I believe I fixed the pointed issues.

@Zloi-KoteikA

Copy link
Copy Markdown
Collaborator

Hi. The test revealed the following:
In Halftone 2 and 3, when an image is added to a layer, the picture starts shifting down and to the
right by 1 pixel. Everything else is OK

Halftone2
Peek 2025-02-10 12-08

Halftone3
Peek 2025-02-10 12-06

@rodolforg

Copy link
Copy Markdown
Contributor Author

Thank you so much for testing, @Zloi-KoteikA ! The image layer itself has this displacement/shift/offset/bias :)
Try this same file but with HalfTone layer disabled on both 1.0.2 and this PR versions.

Is HalfTone3 OK too?

@Zloi-KoteikA

Zloi-KoteikA commented Feb 10, 2025 •

Copy link
Copy Markdown
Collaborator

I tried to disable Halftone. @rodolforg, you're right . This is the offset of the image layer. Versions 1.0.2 and PR have no difference.

@rodolforg
rodolforg force-pushed the port-halftone-layers branch from 7d4e65f to d7e1b57 Compare February 14, 2025 23:13
@rodolforg

rodolforg commented Feb 14, 2025 •

Copy link
Copy Markdown
Contributor Author

Rebased to master branch and fixed some typos in the last commit message.
@morevnaproject @ice0 so this PR looks good to be merged 👍

@rodolforg
rodolforg force-pushed the port-halftone-layers branch from d7e1b57 to af34d26 Compare March 6, 2025 22:18
@rodolforg
rodolforg force-pushed the port-halftone-layers branch from af34d26 to dbc5b43 Compare March 16, 2025 14:10
@Zloi-KoteikA

Copy link
Copy Markdown
Collaborator

Сonducted tests of these files (https://github.com/user-attachments/files/16581023/halftone3.zip). Results are identical to version 1.0.2.

This PR creates a new interface for rendering Transformation
for TaskFilterPixelSW (actually TaskHalftone2 & TaskHalftone3).

For better layer rendering, it lets the transformations of
upper layers be propagated to lower layers (in other words, pass through
this task), as TaskInterfaceTransformationPass does.
Differently of the latter, though, this new interface,
called TaskInterfaceTransformationGetAndPass, pass the transformation
matrix not only to lower (i.e. context) layer, but to this task too.

HalfTone2 and HalfTone3 layers create masks with shapes that are
affected by the upper transformations, and that is the reason to create
this new interface.
So, the lower layers are better rendered due to the propagation of the
upper transformations (more precise rendering), as the same time as the
filter mask is correctly build with such transformation info.
@rodolforg
rodolforg force-pushed the port-halftone-layers branch from dbc5b43 to ac871ad Compare March 17, 2025 09:57

void pre_run(const Matrix3& /*matrix*/) const override
{
supersample_size = 1/std::fabs(get_pixels_per_unit()[0]*(halftone.param_size.get(Vector())).mag());

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.

Looks like possible division on zero

if (task)
synfig::error(_("Internal error: Cobra task %s isn't a TaskPixelProcessorBase"), task->get_token()->name.c_str());
else
synfig::error(_("Internal error: this TaskPaintPixelSW isn't even a Task"));

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.

Is this correct?
I mean TaskPaintPixelSW? Looks like should be TaskFilterPixelSW?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done


void pre_run(const Matrix3& /*matrix*/) const override
{
supersample = 1/std::fabs(get_pixels_per_unit()[0]*(tone[0].param_size.get(Vector())).mag());

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.

Looks like possible division on zero

@ice0
ice0 merged commit 5a4a58c into synfig:master Mar 17, 2025
@ice0

ice0 commented Mar 17, 2025

Copy link
Copy Markdown
Collaborator

Merged. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants