summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-01-06 12:49:07 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-01-14 18:25:27 +0100
commit03bd4333f62d89047ba4e9ce3625e44c063391de (patch)
treecd21ce180a71b0b541a3527a6fd62f852de1a0f6
parent127d6f3f39235478d124635822343c2cd1205f4d (diff)
downloadphp-git-03bd4333f62d89047ba4e9ce3625e44c063391de.tar.gz
Add imagegetinterpolation()
While `imagesetinterpolation()` is available as of PHP 5.5.0, there is no according getter function, so users would have to track the current interpolation method manually. To remedy this, we introduce `imagegetinterpolation()` as thin wrapper for `gdImageGetInterpolationMethod()` (which has been introduced with libgd 2.1.1), and use `im->interpolation_id` as fallback for older libgd. Since our bundled libgd does not yet have this function, we add it. We also simplify the recently introduced bug79068.phpt, where it is sufficient to check that the interpolation method has not been changed.
-rw-r--r--NEWS1
-rw-r--r--UPGRADING2
-rw-r--r--ext/gd/config.m417
-rw-r--r--ext/gd/config.w321
-rw-r--r--ext/gd/gd.c21
-rw-r--r--ext/gd/gd.stub.php2
-rw-r--r--ext/gd/gd_arginfo.h2
-rw-r--r--ext/gd/libgd/gd_interpolation.c23
-rw-r--r--ext/gd/php_gd.h1
-rw-r--r--ext/gd/tests/bug79068.phpt8
-rw-r--r--ext/gd/tests/bug79068.pngbin798 -> 0 bytes
-rw-r--r--ext/gd/tests/imageinterpolation_basic.phpt59
12 files changed, 123 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 2d0556cbab..762526a3de 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ PHP NEWS
. Made the $num_points parameter of php_imagepolygon optional. (cmb)
. Removed deprecated image2wbmp(). (cmb)
. Removed deprecated png2wbmp() and jpeg2wbmp(). (cmb)
+ . Added imagegetinterpolation(). (cmb)
- Intl:
. Removed deprecated INTL_IDNA_VARIANT_2003. (cmb)
diff --git a/UPGRADING b/UPGRADING
index 1d616a53fd..8ffbbbb5a7 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -394,6 +394,8 @@ PHP 8.0 UPGRADE NOTES
imagefilledpolygon() is now optional, i.e. these functions may be called
with either 3 or 4 arguments. If the arguments is omitted, it is calculated
as count($points)/2.
+ . The function imagegetinterpolation() to get the current interpolation method
+ has been added.
========================================
10. New Global Constants
diff --git a/ext/gd/config.m4 b/ext/gd/config.m4
index 194687208d..2839077037 100644
--- a/ext/gd/config.m4
+++ b/ext/gd/config.m4
@@ -120,14 +120,15 @@ AC_DEFUN([PHP_GD_JISX0208],[
])
AC_DEFUN([PHP_GD_CHECK_VERSION],[
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromPng, [AC_DEFINE(HAVE_GD_PNG, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromWebp, [AC_DEFINE(HAVE_GD_WEBP, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromJpeg, [AC_DEFINE(HAVE_GD_JPG, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromXpm, [AC_DEFINE(HAVE_GD_XPM, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromBmp, [AC_DEFINE(HAVE_GD_BMP, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageCreateFromTga, [AC_DEFINE(HAVE_GD_TGA, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdImageStringFT, [AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
- PHP_CHECK_LIBRARY(gd, gdVersionString, [AC_DEFINE(HAVE_GD_LIBVERSION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromPng, [AC_DEFINE(HAVE_GD_PNG, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromWebp, [AC_DEFINE(HAVE_GD_WEBP, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromJpeg, [AC_DEFINE(HAVE_GD_JPG, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromXpm, [AC_DEFINE(HAVE_GD_XPM, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromBmp, [AC_DEFINE(HAVE_GD_BMP, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageCreateFromTga, [AC_DEFINE(HAVE_GD_TGA, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageStringFT, [AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdVersionString, [AC_DEFINE(HAVE_GD_LIBVERSION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
+ PHP_CHECK_LIBRARY(gd, gdImageGetInterpolationMethod, [AC_DEFINE(HAVE_GD_GET_INTERPOLATION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
])
dnl
diff --git a/ext/gd/config.w32 b/ext/gd/config.w32
index 6695976d0e..8fe44def2b 100644
--- a/ext/gd/config.w32
+++ b/ext/gd/config.w32
@@ -72,6 +72,7 @@ if (PHP_GD != "no") {
/D HAVE_LIBPNG \
/D HAVE_XPM \
/D HAVE_COLORCLOSESTHWB \
+/D HAVE_GD_GET_INTERPOLATION \
/D USE_GD_IOCTX \
/D MSWIN32 \
");
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 68c5f4fe31..1775ae4627 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -294,6 +294,7 @@ static const zend_function_entry gd_functions[] = {
PHP_FE(imageaffine, arginfo_imageaffine)
PHP_FE(imageaffinematrixconcat, arginfo_imageaffinematrixconcat)
PHP_FE(imageaffinematrixget, arginfo_imageaffinematrixget)
+ PHP_FE(imagegetinterpolation, arginfo_imagegetinterpolation)
PHP_FE(imagesetinterpolation, arginfo_imagesetinterpolation)
PHP_FE(imagesettile, arginfo_imagesettile)
PHP_FE(imagesetbrush, arginfo_imagesetbrush)
@@ -4100,6 +4101,26 @@ PHP_FUNCTION(imageaffinematrixconcat)
}
} /* }}} */
+/* {{{ proto resource imagegetinterpolation(resource im)
+ Get the default interpolation method. */
+PHP_FUNCTION(imagegetinterpolation)
+{
+ zval *IM;
+ gdImagePtr im;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &IM, gd_image_ce) == FAILURE) {
+ RETURN_THROWS();
+ }
+ im = php_gd_libgdimageptr_from_zval_p(IM);
+
+#ifdef HAVE_GD_GET_INTERPOLATION
+ RETURN_LONG(gdImageGetInterpolationMethod(im));
+#else
+ RETURN_LONG(im->interpolation_id);
+#endif
+}
+/* }}} */
+
/* {{{ proto resource imagesetinterpolation(resource im [, int method]])
Set the default interpolation method, passing -1 or 0 sets it to the libgd default (bilinear). */
PHP_FUNCTION(imagesetinterpolation)
diff --git a/ext/gd/gd.stub.php b/ext/gd/gd.stub.php
index 3dbb694856..5138e2596a 100644
--- a/ext/gd/gd.stub.php
+++ b/ext/gd/gd.stub.php
@@ -232,6 +232,8 @@ function imageaffinematrixget(int $type, $options = UNKNOWN): array|false {}
function imageaffinematrixconcat(array $m1, array $m2): array|false {}
+function imagegetinterpolation(GdImage $im): int {}
+
function imagesetinterpolation(GdImage $im, int $method = IMG_BILENEAR_FIXED): bool {}
function imageresolution(GdImage $im, int $res_x = UNKNOWN, int $res_y = UNKNOWN): array|bool {}
diff --git a/ext/gd/gd_arginfo.h b/ext/gd/gd_arginfo.h
index 14fce4d6d1..0d8554864d 100644
--- a/ext/gd/gd_arginfo.h
+++ b/ext/gd/gd_arginfo.h
@@ -556,6 +556,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imageaffinematrixconcat, 0, 2, M
ZEND_ARG_TYPE_INFO(0, m2, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
+#define arginfo_imagegetinterpolation arginfo_imagecolorstotal
+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imagesetinterpolation, 0, 1, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, im, GdImage, 0)
ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c
index 6ea81ea61c..1a7cf209dc 100644
--- a/ext/gd/libgd/gd_interpolation.c
+++ b/ext/gd/libgd/gd_interpolation.c
@@ -2534,6 +2534,29 @@ int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id)
return 1;
}
+/**
+ * Function: gdImageGetInterpolationMethod
+ *
+ * Get the current interpolation method
+ *
+ * This is here so that the value can be read via a language or VM with an FFI
+ * but no (portable) way to extract the value from the struct.
+ *
+ * Parameters:
+ * im - The image.
+ *
+ * Returns:
+ * The current interpolation method.
+ *
+ * See also:
+ * - <gdInterpolationMethod>
+ * - <gdImageSetInterpolationMethod>
+ */
+gdInterpolationMethod gdImageGetInterpolationMethod(gdImagePtr im)
+{
+ return im->interpolation_id;
+}
+
#ifdef _MSC_VER
# pragma optimize("", on)
#endif
diff --git a/ext/gd/php_gd.h b/ext/gd/php_gd.h
index 8e4cff35ef..d429530479 100644
--- a/ext/gd/php_gd.h
+++ b/ext/gd/php_gd.h
@@ -134,6 +134,7 @@ PHP_FUNCTION(imagescale);
PHP_FUNCTION(imageaffine);
PHP_FUNCTION(imageaffinematrixget);
PHP_FUNCTION(imageaffinematrixconcat);
+PHP_FUNCTION(imagegetinterpolation);
PHP_FUNCTION(imagesetinterpolation);
PHP_FUNCTION(imagesetthickness);
diff --git a/ext/gd/tests/bug79068.phpt b/ext/gd/tests/bug79068.phpt
index 391424b119..835b0b3670 100644
--- a/ext/gd/tests/bug79068.phpt
+++ b/ext/gd/tests/bug79068.phpt
@@ -6,16 +6,12 @@ if (!extension_loaded('gd')) die('skip gd extension not available');
?>
--FILE--
<?php
-require_once __DIR__ . '/func.inc';
-
$src = imagecreatetruecolor(100, 100);
imagefilledrectangle($src, 0, 0, 99, 99, 0xffffff);
imageline($src, 10, 10, 90, 90, 0x000000);
imagesetinterpolation($src, IMG_BSPLINE);
imageaffine($src, [1, 1, 1, 1, 1, 1]);
-$dst = imagerotate($src, 80, 0xffffff);
-
-test_image_equals_file(__DIR__ . '/bug79068.png', $dst);
+var_dump(imagegetinterpolation($src) === IMG_BSPLINE);
?>
--EXPECT--
-The images are equal.
+bool(true)
diff --git a/ext/gd/tests/bug79068.png b/ext/gd/tests/bug79068.png
deleted file mode 100644
index 805edc1c56..0000000000
--- a/ext/gd/tests/bug79068.png
+++ /dev/null
Binary files differ
diff --git a/ext/gd/tests/imageinterpolation_basic.phpt b/ext/gd/tests/imageinterpolation_basic.phpt
new file mode 100644
index 0000000000..80e88647d8
--- /dev/null
+++ b/ext/gd/tests/imageinterpolation_basic.phpt
@@ -0,0 +1,59 @@
+--TEST--
+imagegetinterpolation() and imagesetinterpolation() basic test
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$methods = array(
+ IMG_BELL,
+ IMG_BESSEL,
+ IMG_BILINEAR_FIXED,
+ IMG_BICUBIC,
+ IMG_BICUBIC_FIXED,
+ IMG_BLACKMAN,
+ IMG_BOX,
+ IMG_BSPLINE,
+ IMG_CATMULLROM,
+ IMG_GAUSSIAN,
+ IMG_GENERALIZED_CUBIC,
+ IMG_HERMITE,
+ IMG_HAMMING,
+ IMG_HANNING,
+ IMG_MITCHELL,
+ IMG_NEAREST_NEIGHBOUR,
+ IMG_POWER,
+ IMG_QUADRATIC,
+ IMG_SINC,
+ IMG_TRIANGLE,
+ IMG_WEIGHTED4,
+);
+$im = imagecreate(8, 8);
+foreach ($methods as $method) {
+ imagesetinterpolation($im, $method);
+ var_dump(imagegetinterpolation($im) === $method);
+}
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+bool(true)