Menu

#558 Ugly stroke anti-alias

v1.0_(example)
closed-fixed
None
5
2018-04-18
2018-04-18
bglyne
No

When the stroke anti-alias is on and the background is 100% transparent, the border of the stroke is obviously supposed to be the gradient from the stroke color to transparency, but it is not in reality. The border is actually the gradient from stroke color to the (solid) background color as if the alpha channel was not there. On the other hand, if the background is not 100% transparent, say 99% transparent, the anti-alias gradient is correctly from the stroke color to the 99% transparent.

This behavior is subtle. Obviously it won't cause trouble in most cases, but it causes ugly path borders if the Magick::Image is to be blit-ed to somewhere else e.g. the device context of a window control.

The following example reads file src.png, draws a circle with orange stroke, and writes the result image to file dst.png. If room-in dst.png in an image editor, and turn off all channels except the alpha one, you can see in the top left area of the alpha channel there is no gradient. It's like a monochrome mask (see picture below). In contrast, in the bottom right area, the gradient is beautiful, because the background is transparent but not 100% transparent.

#include <Magick++.h>

int main(int argc, char *argv[])
{
    Magick::InitializeMagick(NULL);
    Magick::Image *img = new Magick::Image("src.png");
    img->fillColor(Magick::Color(0x00,0x00,0x00,0xFF));
    img->strokeAntiAlias(true);
    img->strokeColor(Magick::Color(0xFF, 0xAF, 0x00, 0x00));
    img->draw(Magick::DrawableCircle(150,150, 150,25));
    img->write("dst.png");
    delete img;
    return 0;
}

file src.png read by the above example

file dst.png output by the above example

a piece of the top-left area of the alpha channel (an ugly monochrome mask) seen in image editor

a piece of the bottom-right area of the alpha channel seen in image editor

My operating system is Debian 9. The version of GraphicsMagick is 1.3.28.

By the way, my English is not good. If any information is missing, please let me know, and I'll try my best to explain it again. Thanks.

Discussion

  • Bob Friesenhahn

    Bob Friesenhahn - 2018-04-18

    On Wed, 18 Apr 2018, bglyne wrote:

    When the stroke anti-alias is on and the background is 100%
    transparent, the border of the stroke is obviously supposed to be
    the gradient from the stroke color to transparency, but it is not in
    reality. The border is actually the gradient from stroke color to
    the (solid) background color as if the alpha channel was not there.
    On the other hand, if the background is not 100% transparent, say
    99% transparent, the anti-alias gradient is correctly from the
    stroke color to the 99% transparent.

    As it happens, we have a volunteer (Greg Wolfe) who has made
    significant improvements to the SVG support since the last release.
    Some of his fixes are for the stroke antialiasing and colors.

    Are you able to build development GraphicsMagick from source code and
    assist with verifying that this issue is fixed to your satisfaction
    and possibly find other remaining SVG issues?

    Bob

     
  • Gregory J Wolfe

    Gregory J Wolfe - 2018-04-18

    This problem was fixed by change set 87d618564d42, dated 2/22/18. I ran an SVG version of your test program using the attached SVG file GM#558.svg and your input image src.png. The "ugly stroke anti-alias" is not in the output. Thanks for a very complete and understandable statement of the problem, including the inputs and outputs of your test.

    The command to render the attached SVG file should be:

    gm convert -background "rgba(0,0,0,255)" GM#558.svg GM#558.png

     

    Last edit: Gregory J Wolfe 2018-04-18
  • Bob Friesenhahn

    Bob Friesenhahn - 2018-04-18
    • assigned_to: Gregory J Wolfe
     
  • Gregory J Wolfe

    Gregory J Wolfe - 2018-04-18
    • status: open --> closed-fixed
     
  • bglyne

    bglyne - 2018-04-18

    The fixed is confirmed, no longer ugly border when linking against GraphicsMagick-1.4.020180414 that can be downloaded from here. It works perfectly. Thanks. Have a nice day. :)

     

Log in to post a comment.

MongoDB Logo MongoDB