Skip to content

Smooth brush and smooth clone stamp tool#1988

Open
ryan-de-boer wants to merge 1 commit intoPintaProject:masterfrom
ryan-de-boer:rdeboer_smooth
Open

Smooth brush and smooth clone stamp tool#1988
ryan-de-boer wants to merge 1 commit intoPintaProject:masterfrom
ryan-de-boer:rdeboer_smooth

Conversation

@ryan-de-boer
Copy link

I added a smooth brush. I took the code from BrushCollectionAddin, ported it to latest style and fixed a fade to black instead of fade to transparent on smooth edges.

I noticed the clone stamp did not have a smooth feature so I added it too. I also made it so the first mouse down applies the stamp instead of just mouse move.

See this for more information (and an image):
#1984

tmp_surface.Flush ();

unsafe {
Span<byte> data = tmp_surface.GetData ();
Copy link
Member

Choose a reason for hiding this comment

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

This was copied from code in an old add-in, correct?
We've removed nearly all unsafe code from Pinta so this would need to be changed to use surface.GetPixelData()

if ((dest_rect.Width > 0) && (dest_rect.Height > 0)) {

//Allow Clipping through a temporary surface
ImageSurface tmp_surface = new ImageSurface (Format.Argb32, dest_rect.Width, dest_rect.Height);
Copy link
Member

Choose a reason for hiding this comment

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

Allocating a temporary surface on mouse move is not ideal. From reading the code I'm not sure whether it's actually necessary either - I'm pretty sure this could be done directly on the appropriate region of the layer's surface.

But thinking about this operation more, I don't know if all of this code is even necessary - you might be able to get Cairo to produce this effect by just drawing with a radial gradient? https://www.cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-create-radial
If that is the case then it could likely be merged into the Normal brush. A recent PR #1885 added the ability to define parameters for each brush which could be used to enable and control the smoothness

BrushStrokeArgs strokeArgs)
{
int rad = (int) (g.LineWidth / 2.0) + 1;
int stroke_a = (int) (255.0 * strokeArgs.StrokeColor.A);
Copy link
Member

Choose a reason for hiding this comment

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

If you need this for writing into the image surface, use strokeArgs.StrokeColor.ToColorBgra() which also handles converting to premultiplied alpha

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.

2 participants