diff options
Diffstat (limited to 'Build/source/libs/gd/libgd-src/tests/gdimagecrop')
6 files changed, 202 insertions, 1 deletions
diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/CMakeLists.txt b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/CMakeLists.txt index 4b1e97e292c..43f6f6c14cd 100644 --- a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/CMakeLists.txt +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/CMakeLists.txt @@ -1,6 +1,10 @@ -SET(TESTS_FILES +LIST(APPEND TESTS_FILES bug00297 + bug00432 + bug00485_auto + bug00485_threshold php_bug_72494 + bug00486 ) ADD_GD_TESTS() diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/Makemodule.am b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/Makemodule.am index fe73c1de929..1725f6cbc5f 100644 --- a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/Makemodule.am +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/Makemodule.am @@ -1,5 +1,9 @@ libgd_test_programs += \ gdimagecrop/bug00297 \ + gdimagecrop/bug00432 \ + gdimagecrop/bug00485_auto \ + gdimagecrop/bug00485_threshold \ + gdimagecrop/bug00486 \ gdimagecrop/php_bug_72494 EXTRA_DIST += \ diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00432.c b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00432.c new file mode 100644 index 00000000000..d3f681f9857 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00432.c @@ -0,0 +1,45 @@ +/** + * Test that gdImageCrop() retains transparency + * + * We create an image with transparent pixels, crop the image, and check whether + * all pixels are identical to the respective source image. + * + * See <https://github.com/libgd/libgd/issues/432> + */ + + +#include "gd.h" +#include "gdtest.h" + + +#define WIDTH 10 +#define HEIGHT 10 +#define XOFF 1 +#define YOFF 1 + + +int main() +{ + gdImagePtr src, dst; + gdRect crop = {XOFF, YOFF, WIDTH-XOFF-1, HEIGHT-YOFF-1}; + int i, j; + + src = gdImageCreateTrueColor(WIDTH, HEIGHT); + gdImageAlphaBlending(src, gdEffectReplace); + gdImageFilledRectangle(src, 0, 0, WIDTH-1, HEIGHT-1, + gdTrueColorAlpha(gdRedMax, gdGreenMax, gdBlueMax, gdAlphaMax)); + + dst = gdImageCrop(src, &crop); + gdTestAssert(dst != NULL); + + for (i = 0; i < gdImageSX(dst); i++) { + for (j = 0; j < gdImageSY(dst); j++) { + gdTestAssert(gdImageGetPixel(dst, i, j) == gdImageGetPixel(src, i+XOFF, j+YOFF)); + } + } + + gdImageDestroy(src); + gdImageDestroy(dst); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_auto.c b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_auto.c new file mode 100644 index 00000000000..3c0627e49d8 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_auto.c @@ -0,0 +1,52 @@ +/** + * Test that gdImageCropAuto() works pixel precise + * + * We test that a single black pixel anywhere (but the corners) on an 8x8 pixel + * image with a white background is auto-cropped to a 1x1 pixel image with a + * black pixel. + * + * See <https://github.com/libgd/libgd/issues/485> + */ + + +#include "gd.h" +#include "gdtest.h" + + +gdImagePtr createWhiteImageWithBlackPixelAt(int x, int y) +{ + gdImagePtr im = gdImageCreateTrueColor(8, 8); + gdImageFilledRectangle(im, 0, 0, 7, 7, 0xffffff); + gdImageSetPixel(im, x, y, 0x000000); + return im; +} + + +int main() +{ + int x, y, height, width, color; + gdImagePtr orig, cropped; + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { + if ((x == 0 && (y == 0 || y == 7)) || (x == 7 && (y == 0 || y == 7))) { + continue; // skip the corners + } + orig = createWhiteImageWithBlackPixelAt(x, y); + cropped = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssertMsg(cropped != NULL, "Pixel at %d, %d: unexpected NULL crop\n", x, y); + if (cropped) { + width = gdImageSX(cropped); + gdTestAssertMsg(width == 1, "Pixel at %d, %d: unexpected width (%d)\n", x, y, width); + height = gdImageSY(cropped); + gdTestAssertMsg(height == 1, "Pixel at %d, %d: unexpected height (%d)\n", x, y, height); + color = gdImageGetPixel(cropped, 0, 0); + gdTestAssertMsg(color == 0x000000, "Pixel at %d, %d: unexpected color (%d)\n", x, y, color); + gdImageDestroy(cropped); + } + gdImageDestroy(orig); + } + } + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_threshold.c b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_threshold.c new file mode 100644 index 00000000000..31ac38f1577 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00485_threshold.c @@ -0,0 +1,48 @@ +/** + * Test that gdImageCropThreshold() works pixel precise + * + * We test that a single black pixel anywhere on an 8x8 pixel image with a white + * background is threshold-cropped to a 1x1 pixel image with a black pixel. + * + * See <https://github.com/libgd/libgd/issues/485> + */ + + +#include "gd.h" +#include "gdtest.h" + + +gdImagePtr createWhiteImageWithBlackPixelAt(int x, int y) +{ + gdImagePtr im = gdImageCreateTrueColor(8, 8); + gdImageFilledRectangle(im, 0, 0, 7, 7, 0xffffff); + gdImageSetPixel(im, x, y, 0x000000); + return im; +} + + +int main() +{ + int x, y, height, width, color; + gdImagePtr orig, cropped; + + for (y = 0; y < 8; y++) { + for (x = 0; x < 8; x++) { + orig = createWhiteImageWithBlackPixelAt(x, y); + cropped = gdImageCropThreshold(orig, 0xffffff, 1.0); + gdTestAssertMsg(cropped != NULL, "Pixel at %d, %d: unexpected NULL crop\n", x, y); + if (cropped) { + width = gdImageSX(cropped); + gdTestAssertMsg(width == 1, "Pixel at %d, %d: unexpected width (%d)\n", x, y, width); + height = gdImageSY(cropped); + gdTestAssertMsg(height == 1, "Pixel at %d, %d: unexpected height (%d)\n", x, y, height); + color = gdImageGetPixel(cropped, 0, 0); + gdTestAssertMsg(color == 0x000000, "Pixel at %d, %d: unexpected color (%d)\n", x, y, color); + gdImageDestroy(cropped); + } + gdImageDestroy(orig); + } + } + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00486.c b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00486.c new file mode 100644 index 00000000000..289d88fe596 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gdimagecrop/bug00486.c @@ -0,0 +1,48 @@ +/** + * Test that gdImageCropAuto() crops left and right as well + * + * We test that an image with four unicolored quadrants, where either both left + * quadrants or both right quadrants have the same color, but the remaining + * quadrants have different colors, are treated identically by + * gdImageCropAuto(…, GD_CROP_SIDES). + * + * See <https://github.com/libgd/libgd/issues/486> + */ + + +#include "gd.h" +#include "gdtest.h" + + +int main() +{ + gdImagePtr orig, croppedLeft, croppedRight; + int red, green, blue; + + orig = gdImageCreateTrueColor(8, 8); + red = gdImageColorAllocate(orig, 255, 0, 0); + green = gdImageColorAllocate(orig, 0, 255, 0); + blue = gdImageColorAllocate(orig, 0, 0, 255); + + gdImageFilledRectangle(orig, 0, 0, 3, 3, green); // tl + gdImageFilledRectangle(orig, 4, 0, 7, 3, red); // tr + gdImageFilledRectangle(orig, 0, 4, 3, 7, green); // bl + gdImageFilledRectangle(orig, 4, 4, 7, 7, blue); // br + croppedLeft = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssert(croppedLeft != NULL); + + gdImageFilledRectangle(orig, 0, 0, 3, 3, red); // tl + gdImageFilledRectangle(orig, 4, 0, 7, 3, green); // tr + gdImageFilledRectangle(orig, 0, 4, 3, 7, blue); // bl + gdImageFilledRectangle(orig, 4, 4, 7, 7, green); // br + croppedRight = gdImageCropAuto(orig, GD_CROP_SIDES); + gdTestAssert(croppedRight != NULL); + + gdAssertImageEquals(croppedRight, croppedLeft); + + gdImageDestroy(orig); + gdImageDestroy(croppedLeft); + gdImageDestroy(croppedRight); + + return gdNumFailures(); +} |