]> granicus.if.org Git - php/commitdiff
- initial webp support, rely on libpx, final version will be either w/o dep or using...
authorPierre Joye <pajoye@php.net>
Mon, 4 Oct 2010 22:30:35 +0000 (22:30 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 4 Oct 2010 22:30:35 +0000 (22:30 +0000)
ext/gd/config.m4
ext/gd/config.w32
ext/gd/gd.c
ext/gd/gd_ctx.c
ext/gd/libgd/gd.h
ext/gd/php_gd.h

index 34144c45378bfa76cb2d468a6a22f6021e9e9196..f68f5dd06c210bf22e011a920c4e230fdc839d18 100644 (file)
@@ -10,6 +10,11 @@ PHP_ARG_WITH(gd, for GD support,
 [  --with-gd[=DIR]         Include GD support.  DIR is the GD library base
                           install directory [BUNDLED]])
 
+if test -z "$PHP_VPX_DIR"; then
+  PHP_ARG_WITH(vpx-dir, for the location of libvpx,
+  [  --with-vpx-dir[=DIR]     GD: Set the path to libvpx install prefix], no, no)
+fi
+
 if test -z "$PHP_JPEG_DIR"; then
   PHP_ARG_WITH(jpeg-dir, for the location of libjpeg,
   [  --with-jpeg-dir[=DIR]     GD: Set the path to libjpeg install prefix], no, no)
@@ -68,6 +73,32 @@ AC_DEFUN([PHP_GD_ZLIB],[
        fi
 ])
 
+AC_DEFUN([PHP_GD_VPX],[
+  if test "$PHP_VPX_DIR" != "no"; then
+
+    for i in $PHP_VPX_DIR /usr/local /usr; do
+      test -f $i/$PHP_VPX_DIR/libvpx.$SHLIB_SUFFIX_NAME || test -f $i/$PHP_LIBDIR/libvpx.a && GD_VPX_DIR=$i && break
+    done
+
+    if test -z "$GD_VPX_DIR"; then
+      AC_MSG_ERROR([libvpx.(a|so) not found.])
+    fi
+
+    PHP_CHECK_LIBRARY(vpx,vpx_codec_destroy,
+    [
+      PHP_ADD_INCLUDE($GD_VPX_DIR/include)
+      PHP_ADD_LIBRARY(pthread)
+      PHP_ADD_LIBRARY_WITH_PATH(vpx, $GD_VPX_DIR/$PHP_LIBDIR, GD_SHARED_LIBADD)
+    ],[
+      AC_MSG_ERROR([Problem with libvpx.(a|so). Please check config.log for more information.])
+    ],[
+      -L$GD_VPX_DIR/$PHP_LIBDIR
+    ])
+  else
+    AC_MSG_RESULT([If configure fails try --with-vpx-dir=<DIR>])
+  fi
+])
+
 AC_DEFUN([PHP_GD_JPEG],[
   if test "$PHP_JPEG_DIR" != "no"; then
 
@@ -265,12 +296,12 @@ dnl
 if test "$PHP_GD" = "yes"; then
   GD_MODULE_TYPE=builtin
   extra_sources="libgd/gd.c libgd/gd_gd.c libgd/gd_gd2.c libgd/gd_io.c libgd/gd_io_dp.c \
-                 libgd/gd_io_file.c libgd/gd_ss.c libgd/gd_io_ss.c libgd/gd_png.c libgd/gd_jpeg.c \
-                 libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c libgd/gdfontmb.c libgd/gdfontl.c \
-                 libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c libgd/gdcache.c libgd/gdkanji.c \
-                 libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c libgd/gd_topal.c libgd/gd_gif_in.c \
-                 libgd/xbm.c libgd/gd_gif_out.c libgd/gd_security.c libgd/gd_filter.c \
-                 libgd/gd_pixelate.c libgd/gd_arc.c libgd/gd_rotate.c libgd/gd_color.c"
+                 libgd/gd_io_file.c libgd/gd_ss.c libgd/gd_io_ss.c libgd/webpimg.c libgd/gd_webp.c \
+                 libgd/gd_png.c libgd/gd_jpeg.c libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c \
+                 libgd/gdfontmb.c libgd/gdfontl.c libgd/gdfontg.c libgd/gdtables.c libgd/gdft.c \
+                 libgd/gdcache.c libgd/gdkanji.c libgd/wbmp.c libgd/gd_wbmp.c libgd/gdhelpers.c \
+                 libgd/gd_topal.c libgd/gd_gif_in.c libgd/xbm.c libgd/gd_gif_out.c libgd/gd_security.c \
+                 libgd/gd_filter.c libgd/gd_pixelate.c libgd/gd_arc.c libgd/gd_rotate.c libgd/gd_color.c"
 
 dnl check for fabsf and floorf which are available since C99
   AC_CHECK_FUNCS(fabsf floorf)
@@ -283,6 +314,7 @@ dnl Various checks for GD features
   PHP_GD_TTSTR
   PHP_GD_JISX0208
   PHP_GD_JPEG
+  PHP_GD_VPX
   PHP_GD_PNG
   PHP_GD_XPM
   PHP_GD_FREETYPE2
@@ -317,6 +349,11 @@ dnl Make sure the libgd/ is first in the include path
 dnl Depending which libraries were included to PHP configure,
 dnl enable the support in bundled GD library
 
+  if test -n "$GD_VPX_DIR"; then
+    AC_DEFINE(HAVE_GD_WEBP, 1, [ ])
+    GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBVPX"
+  fi
+
   if test -n "$GD_JPEG_DIR"; then
     AC_DEFINE(HAVE_GD_JPG, 1, [ ])
     GDLIB_CFLAGS="$GDLIB_CFLAGS -DHAVE_LIBJPEG"
@@ -349,6 +386,7 @@ else
 dnl Various checks for GD features
   PHP_GD_ZLIB
   PHP_GD_TTSTR
+  PHP_GD_VPX
   PHP_GD_JPEG
   PHP_GD_PNG
   PHP_GD_XPM
index 340424b6bfa4f981fb24156f89893675a869d353..b05dbe445e27066fe38c3887931bd408ea529a6b 100644 (file)
@@ -5,7 +5,9 @@ ARG_WITH("gd", "Bundled GD support", "yes,shared");
 ARG_WITH("t1lib", "t1lib support", "yes");
 
 if (PHP_GD != "no") {
-       if (CHECK_LIB("libjpeg_a.lib;libjpeg.lib", "gd", PHP_GD) &&
+       if (
+               CHECK_LIB("vpxmt.lib", "gd", PHP_GD) &&
+               CHECK_LIB("libjpeg_a.lib;libjpeg.lib", "gd", PHP_GD) &&
                CHECK_LIB("freetype_a.lib;freetype.lib", "gd", PHP_GD) &&
                CHECK_LIB("libpng_a.lib;libpng.lib", "gd", PHP_GD) &&
                CHECK_HEADER_ADD_INCLUDE("gd.h", "CFLAGS_GD", PHP_GD + ";ext\\gd\\libgd") &&
@@ -34,7 +36,7 @@ if (PHP_GD != "no") {
                        gdft.c gd_gd2.c gd_gd.c gd_gif_in.c gd_gif_out.c gdhelpers.c gd_io.c gd_io_dp.c \
                        gd_io_file.c gd_io_ss.c gd_jpeg.c gdkanji.c gd_png.c gd_ss.c \
                        gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c xbm.c gd_security.c \
-                       gd_filter.c gd_pixelate.c gd_arc.c gd_rotate.c gd_color.c", "gd");
+                       gd_filter.c gd_pixelate.c gd_arc.c gd_rotate.c gd_color.c webpimg.c gd_webp.c ", "gd");
                AC_DEFINE('HAVE_LIBGD', 1, 'GD support');
                ADD_FLAG("CFLAGS_GD", " \
 /D HAVE_GD_DYNAMIC_CTX_EX=1 \
@@ -54,12 +56,14 @@ if (PHP_GD != "no") {
 /D HAVE_GD_STRINGTTF=1  \
 /D HAVE_GD_WBMP  \
 /D HAVE_GD_XBM  \
+/D HAVE_GD_WEBP \
 /D HAVE_LIBFREETYPE=1  \
 /D HAVE_LIBGD13=1  \
 /D HAVE_LIBGD15=1  \
 /D HAVE_LIBGD20=1  \
 /D HAVE_LIBGD204=1 \
 /D HAVE_LIBJPEG  \
+/D HAVE_LIBVPX \
 /D HAVE_LIBPNG  \
 /D HAVE_COLORCLOSESTHWB  \
 /D USE_GD_IMGSTRTTF  \
index 431301aad986deb432237c93207bafb5d709b066..4d5a278f1ac2d578fe5409942caa113f233299f8 100644 (file)
@@ -351,6 +351,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0)
 ZEND_END_ARG_INFO()
 #endif
 
+#ifdef HAVE_GD_WEBP
+ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwebp, 0)
+       ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+#endif
+
 #ifdef HAVE_GD_XBM
 ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
        ZEND_ARG_INFO(0, filename)
@@ -409,6 +415,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1)
 ZEND_END_ARG_INFO()
 #endif
 
+#ifdef HAVE_GD_WEBP
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewebp, 0, 0, 1)
+       ZEND_ARG_INFO(0, im)
+       ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+#endif
+
 #ifdef HAVE_GD_JPG
 ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1)
        ZEND_ARG_INFO(0, im)
@@ -946,6 +959,9 @@ const zend_function_entry gd_functions[] = {
 #ifdef HAVE_GD_PNG
        PHP_FE(imagecreatefrompng,                                              arginfo_imagecreatefrompng)
 #endif
+#ifdef HAVE_GD_WEBP
+       PHP_FE(imagecreatefromwebp,                                             arginfo_imagecreatefromwebp)
+#endif
 #ifdef HAVE_GD_GIF_READ
        PHP_FE(imagecreatefromgif,                                              arginfo_imagecreatefromgif)
 #endif
@@ -969,6 +985,9 @@ const zend_function_entry gd_functions[] = {
 #ifdef HAVE_GD_PNG
        PHP_FE(imagepng,                                                                arginfo_imagepng)
 #endif
+#ifdef HAVE_GD_WEBP
+       PHP_FE(imagewebp,                                                               arginfo_imagewebp)
+#endif
 #ifdef HAVE_GD_GIF_CREATE
        PHP_FE(imagegif,                                                                arginfo_imagegif)
 #endif
@@ -2432,6 +2451,23 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
        ioctx_func_p = NULL; /* don't allow sockets without IOCtx */
 #endif
 
+       if (image_type == PHP_GDIMG_TYPE_WEBP) {
+               size_t buff_size;
+               char *buff;
+
+               /* needs to be malloc (persistent) - GD will free() it later */
+               buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1);
+               if (!buff_size) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
+                       goto out_err;
+               }
+               im = (*ioctx_func_p)(buff_size, buff);
+               if (!im) {
+                       goto out_err;
+               }
+               goto register_im;
+       }
+
        /* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
        if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
                if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
@@ -2509,6 +2545,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                fflush(fp);
        }
 
+register_im:
        if (im) {
                ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
                php_stream_close(stream);
@@ -2553,7 +2590,17 @@ PHP_FUNCTION(imagecreatefrompng)
 /* }}} */
 #endif /* HAVE_GD_PNG */
 
-#ifdef HAVE_GD_XBM
+#ifdef HAVE_GD_WEBP
+/* {{{ proto resource imagecreatefrompng(string filename)
+   Create a new image from PNG file or URL */
+PHP_FUNCTION(imagecreatefromwebp)
+{
+       _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageCreateFromWebpPtr, gdImageCreateFromWebpPtr);
+}
+/* }}} */
+#endif /* HAVE_GD_VPX */
+
+#ifdef HAVE_GD_WEBP
 /* {{{ proto resource imagecreatefromxbm(string filename)
    Create a new image from XBM file or URL */
 PHP_FUNCTION(imagecreatefromxbm)
@@ -2807,6 +2854,22 @@ PHP_FUNCTION(imagepng)
 /* }}} */
 #endif /* HAVE_GD_PNG */
 
+
+#ifdef HAVE_GD_WEBP
+/* {{{ proto bool imagewebp(resource im [, string filename[, quality]] )
+   Output PNG image to browser or file */
+PHP_FUNCTION(imagewebp)
+{
+#ifdef USE_GD_IOCTX
+       _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageWebpCtx);
+#else
+       _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageWebpCtx);
+#endif
+}
+/* }}} */
+#endif /* HAVE_GD_WEBP */
+
+
 #ifdef HAVE_GD_JPG
 /* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
    Output JPEG image to browser or file */
index c25a7dc3ac0765751bb631f8c24a51477aee45ae..f747124ff9a1c723b9dcd27fe32ec38f524d1323 100644 (file)
@@ -73,7 +73,9 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                /* PHP_GDIMG_TYPE_GIF
                 * PHP_GDIMG_TYPE_PNG 
                 * PHP_GDIMG_TYPE_JPG 
-                * PHP_GDIMG_TYPE_WBM */
+                * PHP_GDIMG_TYPE_WBM 
+                * PHP_GDIMG_TYPE_WEBP 
+                * */
                if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) {
                        return;
                }               
@@ -125,6 +127,12 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                case PHP_GDIMG_TYPE_JPG:
                        (*func_p)(im, ctx, q);
                        break;
+               case PHP_GDIMG_TYPE_WEBP:
+                       if (q == -1) {
+                               q = 80;
+                       }
+                       (*func_p)(im, ctx, q);
+                       break;
                case PHP_GDIMG_TYPE_PNG:
                        (*func_p)(im, ctx, q, f);
                        break;
index 34bf4c6444909436f4f15cd9715ef2fd8cace0ad..8aedc2c38c28b60bb19a75b9b90de72cfc1ec24e 100644 (file)
@@ -249,6 +249,9 @@ gdImagePtr gdImageCreateFromWBMP(FILE *inFile);
 gdImagePtr gdImageCreateFromWBMPCtx(gdIOCtx *infile);
 gdImagePtr gdImageCreateFromJpeg(FILE *infile, int ignore_warning);
 gdImagePtr gdImageCreateFromJpegCtx(gdIOCtx *infile, int ignore_warning);
+gdImagePtr gdImageCreateFromWebp(FILE *fd);
+gdImagePtr gdImageCreateFromWebpCtx(gdIOCtxPtr in);
+gdImagePtr gdImageCreateFromWebpPtr (int size, void *data);
 
 int gdJpegGetVersionInt();
 const char * gdPngGetVersionString();
@@ -487,6 +490,8 @@ void *gdImageWBMPPtr(gdImagePtr im, int *size, int fg);
 void gdImageJpeg(gdImagePtr im, FILE *out, int quality);
 void gdImageJpegCtx(gdImagePtr im, gdIOCtx *out, int quality);
 
+void gdImageWebpCtx (gdImagePtr im, gdIOCtx * outfile, int quantization);
+
 /* Best to free this memory with gdFree(), not free() */
 void *gdImageJpegPtr(gdImagePtr im, int *size, int quality);
 
index 7fbedbe4e0958f30610d90f097bb9d2cb3037f41..de90925a6d20695afda492dc82059251271c3a6a 100644 (file)
@@ -48,7 +48,8 @@
 #define PHP_GDIMG_CONVERT_WBM   7
 #define PHP_GDIMG_TYPE_GD       8
 #define PHP_GDIMG_TYPE_GD2      9
-#define PHP_GDIMG_TYPE_GD2PART 10
+#define PHP_GDIMG_TYPE_GD2PART  10
+#define PHP_GDIMG_TYPE_WEBP     11
 
 #ifdef PHP_WIN32
 #      define PHP_GD_API __declspec(dllexport)
@@ -135,6 +136,7 @@ PHP_FUNCTION(imagecreatefromstring);
 PHP_FUNCTION(imagecreatefromgif);
 PHP_FUNCTION(imagecreatefromjpeg);
 PHP_FUNCTION(imagecreatefromxbm);
+PHP_FUNCTION(imagecreatefromwebp);
 PHP_FUNCTION(imagecreatefrompng);
 PHP_FUNCTION(imagecreatefromwbmp);
 PHP_FUNCTION(imagecreatefromgd);
@@ -156,6 +158,7 @@ PHP_FUNCTION(imagefontheight);
 PHP_FUNCTION(imagegif );
 PHP_FUNCTION(imagejpeg );
 PHP_FUNCTION(imagepng);
+PHP_FUNCTION(imagewebp);
 PHP_FUNCTION(imagewbmp);
 PHP_FUNCTION(imagegd);
 PHP_FUNCTION(imagegd2);