Basically, a custom algorithm, according to this thread :
Take the 3x3 neighborhood around the pixel, the alpha threshold, and then see if any of the eight pixels around the pixel have a different alpha value. If so, a circle of a given radius centered on a pixel. To do inside / outside, modulate the threshold alpha channel (negate to do the other side). You will have to spawn a large neighborhood if the radius of the circle is larger than a pixel (which probably is).
This is implemented using morphological operations on a gray scale. This is also the same method that is used to expand / contract. Basically, to stroke the center of the selection (or alpha channel), what would you do, first make two separate copies of the selection. The first choice will expand with the radius of the stroke, while the second will shrink. Then impact opacity would be obtained by subtracting the second choice from the first.
To perform internal and external strokes, you cut / halve the radius and subtract the parts that intersect with the original selection.
It should be noted that the most general morphological algorithm requires operations O (m * n), where m is the number of pixels in the image, and n is the number of elements in the "structuring element". However, for some special cases, this can be optimized for O (m) operations (for example, if the structuring element is a rectangle or diamond).
Vonc
source share