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

Add Outline Object Effect #971

Merged
merged 15 commits into from
Sep 16, 2024

Conversation

potatoes1286
Copy link
Contributor

Not related to any issue. But it's an effect I use often, so I decided to implement it, especially as the code is similar(ish) to the feather effect.

Located in Object > Outline Object.

It outlines an object on a transparent background.

There already is an outline effect, but this differs. This one does not replace the original image, and is more flexible.

image

Personally, my usual use case for an effect like this:

image
image

Has six options:

Radius modifies outline width.

Tolerance modifies what is defined as the "border" of the object.

Alpha Gradient defines whether the outline's alpha falls off, or remains a constant alpha.

Color Gradient defines whether or not the outline blends between primary color > secondary color or not. Otherwise, remains just the primary color.

Outline Border outlines the border of the image.

Fill Object Background fills the background of the object with the primary color. Only really noticeable on translucent objects, but is on by default for anti-aliased borders of an object.

5 tests added.

Was unsure what to name this, as we already have an Outline effect. But the new category was made, so i decided to name it Outline Object. (Maybe we should rename Feather > Feather Object now, because there's Align Object, Outline Object, and Feather)

// Removing this causes preview to not update to lower radius levels
var srcRow = srcData.Slice (y * srcWidth, srcWidth);
var dstRow = dest.GetPixelData ().Slice (y * srcWidth, srcWidth);
for (int x = left; x <= right; x++)
Copy link
Member

Choose a reason for hiding this comment

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

This loop could be replaced by CopyTo()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if (destRow[x].A == 255)
continue;

if (Data.FillObjectBackground && destRow[x].A >= Data.Tolerance)
Copy link
Member

Choose a reason for hiding this comment

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

I'm not entirely sure if I'm understanding the use case for the Fill Object Background toggle, but it might be more clear to label it as making the object opaque since it's not filling with a new colour?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To show, 1st is pic before, 2nd is without, 3rd is with fill object background

image
image
image

I'm also not too sure what to name this, but I decided "fill object background" was most fitting.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, yeah that seems like a reasonable label then 👍

/// <param name="colorTop">The color layered on top. Color must be in premultiplied form. See <see cref="ToPremultipliedAlpha"/>.</param>
/// <param name="colorBottom">The color layered below. Color must be in premultiplied form. See <see cref="ToPremultipliedAlpha"/>.</param>
/// <returns>Premultiplied form of the alpha-blend between colorTop and colorBottom.</returns>
public static ColorBgra AlphaBlend (ColorBgra colorTop, ColorBgra colorBottom)
Copy link
Member

Choose a reason for hiding this comment

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

I think it should also be possible to do this blending using the NormalBlendOp class, so I'd suggest giving that a try!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Removed the alphablend method while i was at it

@cameronwhite
Copy link
Member

I don't mind the Outline Object name, but the original Outline also could probably be called something like "Outline Edges" since it's more based around edge detection

@cameronwhite cameronwhite merged commit b9e28ac into PintaProject:master Sep 16, 2024
5 checks passed
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