Doc->Bug #43475 [Opn->Sus]: Thick styled lines have scrambled patterns
| From: | cmb@php.net | Date: | Thu, 11 Jun 2015 12:53:23 +0000 |
| Subject: | Doc->Bug #43475 [Opn->Sus]: Thick styled lines have scrambled patterns | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193327@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: Open
+Status: Suspended
-Type: Documentation Problem
+Type: Bug
Package: GD related
Operating System: *
PHP Version: 5.2CVS-2008-10-30
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[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)
------------------------------------------------------------------------
[2010-08-02 21:55:39] php at imperium dot be
Lines *do* have the expected style, *EXCEPT* when they are at a 0 or 180 degree angle (e.g. x1==x2).
That is where the 'bug' is at. This is probably because imageline tries to be more
efficient than it should be, drawing a fast rectangle instead of a thick line.
In any case, the style pattern is applied towards the flow of the line instead of linear. This is
the correct approach imho and should not be changed. To achieve the same style pattern with a line
twice as thick you should double your imagesetstyle as well. E.G. in your test case, 16+4+8+4 for
thickness 1 would become 32+8+16+8 for thickness 2.
When you adjust your test case like this, you will see that all works as expected except for
horizontal lines. Thus, GD maintainer, please adjust the inner workings of imageline so it
won't paint a rectangle instead of a thick line (at least not for thickness>1 or when using
styled lines).
jacQues
------------------------------------------------------------------------
[2008-10-30 17:03:59] jani@php.net
Assigned to the GD maintainer.
------------------------------------------------------------------------
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