Skip to content
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

#482 - Masks are now rendered #825

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

thenkles
Copy link

@thenkles thenkles commented Feb 3, 2021

Fixes issue #482

What does this implement/fix? Explain your changes.

Adds support for alpha masks.

Any other comments?

The ImagesAreEqual method in SvgTestHelper has been updated to increase performance and additional parameter has been added: allowedDifference. This is the maximum deviation allowed for each pixel's component, i.e. if allowedDifference is 1, and the expected pixel is RGBA(100, 100, 100, 100), then RGBA(101, 101, 101, 101), RGBA(99, 99, 99, 99), etc. will also be accepted. This was required because the results are not always pixel perfect equal when tests are run on different targets.

@thenkles thenkles marked this pull request as draft February 5, 2021 21:02
@thenkles thenkles marked this pull request as ready for review February 7, 2021 17:57
@mrbean-bremen
Copy link
Member

If someone wants to review this, please go ahead! I was going to review it for some time now, but didn't get to it due to time constraints, so I would appreciate if someone else could have a look. At a first glance, it looked quite good.

Copy link
Contributor

@H1Gdev H1Gdev left a comment

Choose a reason for hiding this comment

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

It does not seem to dispose Bitmap.

Source/ExtensionMethods/RectangleFExtensions.cs Outdated Show resolved Hide resolved
@@ -144,6 +144,62 @@ Many performance improvements by using SourceGenerators instad of reflection.
<PropertyGroup Condition="'$(TargetFramework)' != 'net452'">
<DefineConstants>$(DefineConstants);USE_SOURCE_GENERATORS</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this property required for each ?

Copy link
Author

Choose a reason for hiding this comment

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

I suppose so? That was auto-generated so I'm not 100% sure but please let me know what you think the better approach would be.

@thenkles
Copy link
Author

Regarding disposing bitmaps, I'll have a look into it later.

@tebjan
Copy link
Contributor

tebjan commented Feb 19, 2021

I think we cannot introduce the unsafe flag, many bigger enterprise projects don't allow to reference assemblies with that flag.

New .NET versions have many new safe memory operations. Probably worth looking at them.

And for bitmap disposal, you should use using statements, if possible.

@thenkles
Copy link
Author

I think we cannot introduce the unsafe flag, many bigger enterprise projects don't allow to reference assemblies with that flag.

New .NET versions have many new safe memory operations. Probably worth looking at them.

Ok, that's a fair point. Any details on these new memory operations I could read?

@H1Gdev
Copy link
Contributor

H1Gdev commented Feb 19, 2021

How about using Span ?
I don't know if can completely remove unsafe.

@mrbean-bremen
Copy link
Member

@tebjan , @H1Gdev - did you have another look after the latest changes? It's been a while...

@H1Gdev
Copy link
Contributor

H1Gdev commented Aug 19, 2021

@mrbean-bremen

I will check source files, but it will take some time because there are many changes...

Copy link
Contributor

@H1Gdev H1Gdev left a comment

Choose a reason for hiding this comment

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

At first, please clarify dispose responsibility of mask to be set in ISvgRenderer.SetMask().
And delete DisposeMask() method.
Do you use stack for mask bitmaps ?

Assert.Greater(equalPercentage, 99);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add CRLF.


public void SetMask(Bitmap mask)
{
_mask = mask;
Copy link
Contributor

Choose a reason for hiding this comment

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

_mask?.Dispose();
_mask = mask;

Copy link
Contributor

Choose a reason for hiding this comment

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

And dispose _mask in Dispose method.

return _mask;
}

public void DisposeMask()
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete this method.
Use SetMask(null);

{
_innerGraphics = graphics;
_disposable = disposable;
this.RenderSize = renderSize;
Copy link
Contributor

@H1Gdev H1Gdev Aug 19, 2021

Choose a reason for hiding this comment

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

remove this.
Please omit this as much as possible.

return new[]
{
rectangle.Location,
rectangle.Location + rectangle.Size
Copy link
Contributor

Choose a reason for hiding this comment

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

here should consider five points like this, If there are only two points, there will have issue with the bounds when the transform contains rotation

 return new[]
            {
                rectangle.Location,
                rectangle.Location + rectangle.Size,
                new PointF(rectangle.X,rectangle.Y+rectangle.Height),
                new PointF(rectangle.X+rectangle.Width,rectangle.Y)
            };

Copy link
Contributor

Choose a reason for hiding this comment

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

you can verify this by this transform : "matrix(0.51 0.51 -0.51 0.51 776.90 96.03)"

@paulushub
Copy link
Contributor

@thenkles Sorry for the delay is resolving this PR. Please can you rework and repost this for consideration?

@paulushub
Copy link
Contributor

@thenkles Sorry for the delay, please can you update this project for consideration?

@paulushub paulushub removed their assignment Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants