diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-10 12:41:10 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-10 12:45:13 +0200 |
commit | ca2b34e1f8476d04b63d9e4cbf7455032ead4482 (patch) | |
tree | 4f05f13a9c2fa6c38a4ad7702a29e76b461c69ce /tests/gdimagescale | |
parent | 77c8d359bb81ecf33189efa0c0cf62b2315b1e88 (diff) | |
download | libgd-ca2b34e1f8476d04b63d9e4cbf7455032ead4482.tar.gz |
Fix #329: GD_BILINEAR_FIXED gdImageScale() can cause black border
We're passing `pixel1` as default color to `getPixelOverflow*()` for
pixels which may be outside the valid bounds. `pixel1` is supposed to
be always valid due to the fixed arithmetic's round towards zero
behavior.
Diffstat (limited to 'tests/gdimagescale')
-rw-r--r-- | tests/gdimagescale/.gitignore | 1 | ||||
-rw-r--r-- | tests/gdimagescale/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/gdimagescale/Makemodule.am | 1 | ||||
-rw-r--r-- | tests/gdimagescale/bug00329.c | 53 |
4 files changed, 56 insertions, 0 deletions
diff --git a/tests/gdimagescale/.gitignore b/tests/gdimagescale/.gitignore index 8339a54..e75e0bc 100644 --- a/tests/gdimagescale/.gitignore +++ b/tests/gdimagescale/.gitignore @@ -1,3 +1,4 @@ +/bug00329 /bug00330 /github_bug_00218 /bug_overflow_large_new_size diff --git a/tests/gdimagescale/CMakeLists.txt b/tests/gdimagescale/CMakeLists.txt index 3a472ef..1174e65 100644 --- a/tests/gdimagescale/CMakeLists.txt +++ b/tests/gdimagescale/CMakeLists.txt @@ -1,4 +1,5 @@ LIST(APPEND TESTS_FILES + bug00329 bug00330 github_bug_00218 bug_overflow_large_new_size diff --git a/tests/gdimagescale/Makemodule.am b/tests/gdimagescale/Makemodule.am index 2f4a20c..7710301 100644 --- a/tests/gdimagescale/Makemodule.am +++ b/tests/gdimagescale/Makemodule.am @@ -1,5 +1,6 @@ libgd_test_programs += \ + gdimagescale/bug00329 \ gdimagescale/bug00330 \ gdimagescale/github_bug_00218 \ gdimagescale/bug_overflow_large_new_size diff --git a/tests/gdimagescale/bug00329.c b/tests/gdimagescale/bug00329.c new file mode 100644 index 0000000..0b1b32d --- /dev/null +++ b/tests/gdimagescale/bug00329.c @@ -0,0 +1,53 @@ +/**
+ * Regression test for <https://github.com/libgd/libgd/issues/329>
+ *
+ * We're testing that for truecolor as well as palette images after
+ * GD_BILINEAR_FIXED scaling the corner pixels of the scaled image have the
+ * expected color.
+ */
+
+
+#include <string.h>
+#include "gd.h"
+#include "gdtest.h"
+
+
+static void test(const char *mode)
+{
+ gdImagePtr src, dst;
+ int expected, actual;
+
+ if (strcmp(mode, "palette")) {
+ src = gdImageCreateTrueColor(100, 100);
+ expected = gdTrueColorAlpha(255, 255, 255, gdAlphaOpaque);
+ gdImageFilledRectangle(src, 0,0, 99,99, expected);
+ } else {
+ src = gdImageCreate(100, 100);
+ gdImageColorAllocate(src, 255, 255, 255);
+ expected = gdImageGetTrueColorPixel(src, 49, 49);
+ }
+
+ gdImageSetInterpolationMethod(src, GD_BILINEAR_FIXED);
+ dst = gdImageScale(src, 200, 200);
+
+ actual = gdImageGetPixel(dst, 0, 0);
+ gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
+ actual = gdImageGetPixel(dst, 0, 199);
+ gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
+ actual = gdImageGetPixel(dst, 199, 199);
+ gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
+ actual = gdImageGetPixel(dst, 199, 0);
+ gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
+
+ gdImageDestroy(src);
+ gdImageDestroy(dst);
+}
+
+
+int main()
+{
+ test("palette");
+ test("truecolor");
+
+ return gdNumFailures();
+}
|