Bug #43475 [Sus]: Thick styled lines have scrambled patterns

From: Date: Thu, 11 Jun 2015 17:15:59 +0000
Subject: Bug #43475 [Sus]: Thick styled lines have scrambled patterns
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193332@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=43475&edit=1 ID: 43475 Updated by: cmb@php.net Reported by: lb2048 at pobox dot com Summary: Thick styled lines have scrambled patterns Status: Suspended Type: Bug Package: GD related Operating System: * PHP Version: 5.2CVS-2008-10-30 Assigned To: cmb Block user comment: N Private report: N New Comment: The libgd ticket: <https://github.com/libgd/libgd/issues/167>. Previous Comments: ------------------------------------------------------------------------ [2015-06-11 17:15:26] cmb@php.net I have filed a ticket against libgd now. I've noticed a minor issue wrt. to jacQues' ImageStyleThicken() function: it only works correctly for even thickness values, because libgd rounds odd thickness values to the next smaller even value. ------------------------------------------------------------------------ [2015-06-11 12:53:21] cmb@php.net Sorry for the late reply. > Horizontal thick lines patterns look scrambled to me. Indeed! I had a closer look at the issue, and found that horizontal and vertical lines do call gdImageFilledRectangle when the thickness is greater than 1 for performance reasons. The relevant code of gdImageFilledRectangle[1] loops over the x and y coordinates, and calls gdImageSetPixel which iterates over the style pattern[2]. As is, this works fine for vertical lines, but not for horizontal lines. Swapping the for loops in gdImageFilledRectangle will make horizontal lines look fine, but will break vertical lines. I'm not sure (yet) how to solve this issue, but anyhow, this is an issue that should preferably be fixed upstream in libgd. I'll file a bug report there later, and switch this ticket to "suspended" until a resolution is found. [1] <https://github.com/php/php-src/blob/PHP-5.6.9/ext/gd/libgd/gd.c#L2145-L2149> [2] <https://github.com/php/php-src/blob/PHP-5.6.9/ext/gd/libgd/gd.c#L724-L735> ------------------------------------------------------------------------ [2015-05-08 00:05:54] lb2048 at pobox dot com I agree that changing the way it works would be bad, and the way it works should be better documented. I do not agree that the issue raised by "jacQues" has been fixed. After replicating my pattern bits by the line thickness, as stated in that comment, I do see reasonable thick styled lines, except for horizontal lines. Horizontal thick lines patterns look scrambled to me. (jacQues said in 2010 that vertical lines were also bad. I don't see that now - my vertical lines seem OK.) Now using php-5.6.8; same results with php-5.5.24. ------------------------------------------------------------------------ [2015-05-07 18:09:25] cmb@php.net > Lines *do* have the expected style, *EXCEPT* when they are at a > 0 or 180 degree angle (e.g. x1==x2). This issue seems to have been fixed in the meantime, see <http://imgur.com/AIn9RLh>. > I think the width and style should be independent, and I think > the current behavior may be unintentional. Even if it had been unintentional, changing it now would be a massive BC break. However, I believe the behavior is intentional, because as it is you can apply 2D styles instead of 1D styles only. If you have the need for linear styles, you can use a function such as ImageStyleThicken() contributed by jacQues. All in all, this issue seems to be a documentation problem. The imagesetstyle man page should be improved to document how the function works for thick lines, and probably a respective example should be added. ------------------------------------------------------------------------ [2010-08-03 03:51:50] lbayuk at pobox dot com OK, thanks, now I understand what it is doing. It is applying the pixels from the style across the width of the line first, then along the length second. But I don't agree that it is working correctly. I think the width and style should be independent, and I think the current behavior may be unintentional. Because gdImageSetPixel increments the style pointer for every pixel, then the order in which the higher-level drawing routines put down the pixels makes a difference in how the pattern is applied. Surely this cannot be useful. As an example, the problem you found with horizontal and vertical lines. If the width is > 1, these are optimized as filled rectangles. But filled rectangles with IMG_COLOR_STYLED are unpredictable, because the result depends on the remainder when dividing the rectangle width by the style array size. (Try drawing 2 filled rectangles with an IMG_COLOR_STYLED pattern, where 1 rectangle is 1 pixel wider than the other. They will look very different.) I would like to hear what the PHP GD maintainer thinks about this. (FYI, now using PHP-5.3.3 with same results) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=43475 -- Edit this bug report at https://bugs.php.net/bug.php?id=43475&edit=1

« previous php.bugs (#193332) next »