Pixel interpolation problem with rotated transparent images
Swiss army knife of image processing
Brought to you by:
bfriesen
Using GraphicsMagick 1.3.5 2009-01-26 Q8
Rotated 24-bits PNGs, when composited together on a background, can show black borders where there should be semi-transparent pixels.
See the reference topic for more info/test images
Reference topic: http://sourceforge.net/projects/graphicsmagick/forums/forum/250738/topic/3859284
Hey there!
I haven't tried the latest version of GM, but I was wondering, since that bug is still open, whether you'd had the chance to look into it?
Thanks
Olivier
On Thu, 18 Apr 2013, Olivier Lance wrote:
I have not looked into this issue yet.
Previously there was a similar issue with image resize and someone
contributed a patch to fix it.
Bob
Bob Friesenhahn
bfriesen@simple.dallas.tx.us, http://www.simplesystems.org/users/bfriesen/
GraphicsMagick Maintainer, http://www.GraphicsMagick.org/
Hi,
This issue has affected me also. I had a quick look at the source code and noticed two issues in BlendCompositePixel() defined in the file alpha_composite.h that causes this behaviour when using rotate/shear.
Firstly, the blended pixel is assigned the opacity of the rotated/sheared pixel rather than averaging the opacity of the rotated/sheared pixel with the opacity of the background according to the amount of each present (alpha).
Secondly, the blended pixel always averages the red, green and blue components of the sheared/rotated pixel with the background. This is incorrect behaviour if either the sheared/rotated pixel or the background is fully transparent. A fully transparent pixel has no colour regardless of its values of red, green or blue and should not influence the colour of the blended pixel. Otherwise, when large amounts of the blended pixel is made up of the background, the background colour (typically white or black) shows through causing either black or white artefacts as described above.
I have attached a patch of alpha_composite.h against the release version of v1.3.18 that fixes both issues. I have also attached a small C program that rotates a red rectangle and composites it onto a purple background which I used to test the patch.
Cheers,
Troy Patteson
Troy, that's great!
Let's hope this fix quickly makes it to production :)
Thanks!
Troy Patteson's patch was applied as Mercurial changeset 13976:f1198a123b87. The full GM test suite (including those depending on comparison with expected results) still passes and generated images still look as before so the patch must not be too risky. Much thanks to Troy for the patch.