Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line #236

Merged
merged 1 commit into from Jun 20, 2016

Conversation

cmb69
Copy link
Contributor

@cmb69 cmb69 commented Jun 17, 2016

As reported in https://bugs.php.net/64641 1-dimensional horizontal
filled polygons are not drawn at all.

This commit does not yet fix the bug, but rather adds a failing test case
to show the behavior. This test should be marked as XFAIL, but I don't
know how to do that yet.

The patch suggested in the PHP bug report was used to create
php_bug_64641.png which is the expected image, but this patch would break
tests/imagefilledpolygon/gdimagefilledpolygon1. From a quick glance at the
resulting image diff, it seems the patch is plain wrong.

@vapier
Copy link
Member

vapier commented Jun 17, 2016

for autotools, i think you want to:

  • define XFAIL_TESTS in tests/Makefile.am at the top like TESTS
  • add the test both to TESTS and XFAIL_TESTS in the Makemodule.am file

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 17, 2016

Thanks, Mike. I've committed the respective changes, but please don't merge this PR yet – I'm hoping to actually fix the bug ASAP.

@pierrejoye
Copy link
Contributor

A quick note :)

Polygon drawing uses scanot lines algorithm. We could loop over the points and draw a single line if the points are aligned (vertically or horizontallly).

Changing the main algorithm for this special case is not necessary nor desired (add complexity).

@pierrejoye
Copy link
Contributor

See https://www.cs.rit.edu/~icss571/filling/index.html

For a detailed explanation

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 18, 2016

Thanks, Pierre. I'll still have to digest the algorithm, but it seems I've found the culprit, namely the special case handling of horizontal edges. Obviously, that can't work for a 1-dimensional polygon (i.e. consisting of horizontal edges only), because the edge table (im->polyInts[]) would be empty.

So, yes, we need some special handling for 1-dimensional polygons as you've suggested. I'll work on a patch.

@pierrejoye
Copy link
Contributor

Btw document it could do it as well :)

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 19, 2016

I have committed the fix now, and removed the XFAIL provisions.

Btw document it could do it as well :)

I've thought about that as well, but IMHO it seems to be an arbitrary restriction (Why can I draw a vertical filled polygon, but not a horizontal one? Why can I draw an unfilled horizontal polygon, but not a filled one?)

Furthermore, during testing the patch against PHP I've noticed several other test failures. It turned out the gdImageFilledPolygon() is used in gdImageFilledArc(), so this is also affected by the fix. An example (expected, actual, diff):

imagecolorallocatealpha_basic imagecolorallocatealpha_basic out imagecolorallocatealpha_basic diff

As one can see, the actual arc is more symmetric than the expected arc (we have a single pixel at the top and bottom, as well as at the left and right hand side). IMO a good reason to apply the fix. We would have to assess the effect of this BC break, though.

Just seen that all Travis checks are failing; I'll have a look at this right away.

@pierrejoye
Copy link
Contributor

pierrejoye commented Jun 19, 2016

Hm. I thought I rewrote this function using the same algorithm I use for ellipse, except for antialised operations. Have to check that.

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 19, 2016

I thought I rewrote this function using the same algorithm I use for
ellipse, except for antialised operations.

gdImageArc() just forwards to gdImageFilledArc(), and this is using gdImageFilledPolygon().

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 19, 2016

Just seen that all Travis checks are failing; I'll have a look at this right away.

I don't understand, why the checks are failing. Apparently, that is caused by failing to fopen() the expected image, but I don't see why this can happen. Locally, the tests are running fine (after git clean). Maybe a Travis hickup?

@pierrejoye
Copy link
Contributor

Hm doesn't it have to use the absolute path to the expected image?

@pierrejoye
Copy link
Contributor

@cmb69
Copy link
Contributor Author

cmb69 commented Jun 19, 2016

Hm doesn't it have to use the absolute path to the expected image?
See https://github.com/libgd/libgd/blob/master/tests/gdimagerotate/bug00067.c for an example

According to @vapier sprintf() shouldn't be used anymore for constructing gdAssertImageEqualsToFile() paths. And according to the code relative paths are looked up in tests/.

@vapier
Copy link
Member

vapier commented Jun 19, 2016

yes, you shouldn't attempt to construct your own paths anymore. the gdtest helpers should cover all your needs. this deals with all the edge cases with build/test envs.

that said, the issue here is that you need to add all new images to EXTRA_DIST in the Makemodule.am file. notice that the failing section is make distcheck which verifies a release passes.

As reported in <https://bugs.php.net/64641> 1-dimensional horizontal
filled polygons are not drawn at all. That is caused by the scanline
algorithm used for drawing filled polygons which skips the drawing of
horizontal edges, because that is normally not necessary. If, however,
the polygon consists of horizontal edges only, that obviously doesn't
work, so we add a special case handling.
@cmb69
Copy link
Contributor Author

cmb69 commented Jun 20, 2016

that said, the issue here is that you need to add all new images to EXTRA_DIST in the Makemodule.am file.

Thanks! I could have noticed that myself, though…

I've pushed the fix. If the Travis checks succeed, I'll merge later (and also commit the fix to PHP 5.6+).

@cmb69 cmb69 merged commit f9f10fa into libgd:master Jun 20, 2016
@cmb69 cmb69 deleted the imagefilledpolygon branch June 20, 2016 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants