pajoye          Fri Jan 27 13:36:30 2006 UTC

  Modified files:              (Branch: PHP_5_1)
    /php-src/ext/gd     gd.c gd_ctx.c 
    /php-src/ext/gd/libgd       gd.h gd_png.c 
  Log:
  - MFH: add filter option to imagepng
  - add constants
    PS: If someone can check why #include "png.h" fails, it will be cleaner
  
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd.c?r1=1.312.2.16&r2=1.312.2.17&diff_format=u
Index: php-src/ext/gd/gd.c
diff -u php-src/ext/gd/gd.c:1.312.2.16 php-src/ext/gd/gd.c:1.312.2.17
--- php-src/ext/gd/gd.c:1.312.2.16      Tue Jan 17 23:47:08 2006
+++ php-src/ext/gd/gd.c Fri Jan 27 13:36:29 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd.c,v 1.312.2.16 2006/01/17 23:47:08 tony2001 Exp $ */
+/* $Id: gd.c,v 1.312.2.17 2006/01/27 13:36:29 pajoye Exp $ */
 
 /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
@@ -451,6 +451,22 @@
 #else
        REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
 #endif
+
+#ifdef HAVE_GD_PNG
+
+/*
+ * cannot include #include "png.h"
+ * /usr/include/pngconf.h:310:2: error: #error png.h already includes setjmp.h 
with some additional fixup.
+ * as error, use the values for now...
+ */
+       REGISTER_LONG_CONSTANT("PNG_NO_FILTER",         0x00, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_FILTER_NONE",       0x08, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_FILTER_SUB",        0x10, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_FILTER_UP",         0x20, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_FILTER_AVG",        0x40, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_FILTER_PAETH",      0x80, CONST_CS | 
CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("PNG_ALL_FILTERS",       0x08 | 0x10 | 0x20 | 
0x40 | 0x80, CONST_CS | CONST_PERSISTENT);
+#endif
        return SUCCESS;
 }
 /* }}} */
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/gd_ctx.c?r1=1.22.2.4&r2=1.22.2.5&diff_format=u
Index: php-src/ext/gd/gd_ctx.c
diff -u php-src/ext/gd/gd_ctx.c:1.22.2.4 php-src/ext/gd/gd_ctx.c:1.22.2.5
--- php-src/ext/gd/gd_ctx.c:1.22.2.4    Sun Jan  1 12:50:06 2006
+++ php-src/ext/gd/gd_ctx.c     Fri Jan 27 13:36:29 2006
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: gd_ctx.c,v 1.22.2.4 2006/01/01 12:50:06 sniper Exp $ */
+/* $Id: gd_ctx.c,v 1.22.2.5 2006/01/27 13:36:29 pajoye Exp $ */
 
 #include "php_gd.h"
 
@@ -49,12 +49,13 @@
 /* {{{ _php_image_output_ctx */
 static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int 
image_type, char *tn, void (*func_p)())
 {
-       zval **imgind, **file, **quality;
+       zval **imgind, **file, **quality, **basefilter;
        gdImagePtr im;
        char *fn = NULL;
        FILE *fp = NULL;
        int argc = ZEND_NUM_ARGS();
        int q = -1, i;
+       int f = -1;
        gdIOCtx *ctx;
 
        /* The third (quality) parameter for Wbmp stands for the threshold when 
called from image2wbmp().
@@ -65,7 +66,8 @@
        if (argc < 2 && image_type == PHP_GDIMG_TYPE_XBM) {
                WRONG_PARAM_COUNT;
        }
-       if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, 
&file, &quality) == FAILURE)
+
+       if (argc < 1 || argc > 4 || zend_get_parameters_ex(argc, &imgind, 
&file, &quality, &basefilter) == FAILURE)
        {
                WRONG_PARAM_COUNT;
        }
@@ -75,9 +77,13 @@
        if (argc > 1) {
                convert_to_string_ex(file);
                fn = Z_STRVAL_PP(file);
-               if (argc == 3) {
+               if (argc >= 3) {
                        convert_to_long_ex(quality);
                        q = Z_LVAL_PP(quality);/* or colorindex for foreground 
of BW images (defaults to black) */
+                       if (argc == 4) {
+                               convert_to_long_ex(basefilter);
+                               f = Z_LVAL_PP(basefilter);
+                       }
                }
        }
 
@@ -115,9 +121,11 @@
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"Invalid threshold value '%d'. It must be between 0 and 255", q);
                        }
                case PHP_GDIMG_TYPE_JPG:
-               case PHP_GDIMG_TYPE_PNG:
                        (*func_p)(im, ctx, q);
                        break;
+               case PHP_GDIMG_TYPE_PNG:
+                       (*func_p)(im, ctx, q, f);
+                       break;
                case PHP_GDIMG_TYPE_XBM:
                case PHP_GDIMG_TYPE_WBM:
                        if (argc < 3) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/libgd/gd.h?r1=1.26.2.1&r2=1.26.2.2&diff_format=u
Index: php-src/ext/gd/libgd/gd.h
diff -u php-src/ext/gd/libgd/gd.h:1.26.2.1 php-src/ext/gd/libgd/gd.h:1.26.2.2
--- php-src/ext/gd/libgd/gd.h:1.26.2.1  Sun Oct  9 12:06:27 2005
+++ php-src/ext/gd/libgd/gd.h   Fri Jan 27 13:36:30 2006
@@ -444,8 +444,8 @@
  * compression (smallest files) but takes a long time to compress, and
  * -1 selects the default compiled into the zlib library.
  */
-void gdImagePngEx(gdImagePtr im, FILE * out, int level);
-void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level);
+void gdImagePngEx(gdImagePtr im, FILE * out, int level, int basefilter);
+void gdImagePngCtxEx(gdImagePtr im, gdIOCtx * out, int level, int basefilter);
 
 void gdImageWBMP(gdImagePtr image, int fg, FILE *out);
 void gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out);
@@ -489,7 +489,7 @@
 
 /* Best to free this memory with gdFree(), not free() */
 void* gdImageGdPtr(gdImagePtr im, int *size);
-void *gdImagePngPtrEx(gdImagePtr im, int *size, int level);
+void *gdImagePngPtrEx(gdImagePtr im, int *size, int level, int basefilter);
 
 /* Best to free this memory with gdFree(), not free() */
 void* gdImageGd2Ptr(gdImagePtr im, int cs, int fmt, int *size);
http://cvs.php.net/viewcvs.cgi/php-src/ext/gd/libgd/gd_png.c?r1=1.17.4.1&r2=1.17.4.2&diff_format=u
Index: php-src/ext/gd/libgd/gd_png.c
diff -u php-src/ext/gd/libgd/gd_png.c:1.17.4.1 
php-src/ext/gd/libgd/gd_png.c:1.17.4.2
--- php-src/ext/gd/libgd/gd_png.c:1.17.4.1      Thu Aug 18 12:54:43 2005
+++ php-src/ext/gd/libgd/gd_png.c       Fri Jan 27 13:36:30 2006
@@ -384,17 +384,17 @@
        return im;
 }
 
-void gdImagePngEx (gdImagePtr im, FILE * outFile, int level)
+void gdImagePngEx (gdImagePtr im, FILE * outFile, int level, int basefilter)
 {
        gdIOCtx *out = gdNewFileCtx(outFile);
-       gdImagePngCtxEx(im, out, level);
+       gdImagePngCtxEx(im, out, level, basefilter);
        out->gd_free(out);
 }
 
 void gdImagePng (gdImagePtr im, FILE * outFile)
 {
        gdIOCtx *out = gdNewFileCtx(outFile);
-       gdImagePngCtxEx(im, out, -1);
+       gdImagePngCtxEx(im, out, -1, -1);
        out->gd_free(out);
 }
 
@@ -402,18 +402,18 @@
 {
        void *rv;
        gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
-       gdImagePngCtxEx(im, out, -1);
+       gdImagePngCtxEx(im, out, -1, -1);
        rv = gdDPExtractData(out, size);
        out->gd_free(out);
 
        return rv;
 }
 
-void * gdImagePngPtrEx (gdImagePtr im, int *size, int level)
+void * gdImagePngPtrEx (gdImagePtr im, int *size, int level, int basefilter)
 {
        void *rv;
        gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
-       gdImagePngCtxEx(im, out, level);
+       gdImagePngCtxEx(im, out, level, basefilter);
        rv = gdDPExtractData(out, size);
        out->gd_free(out);
        return rv;
@@ -421,14 +421,14 @@
 
 void gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
 {
-       gdImagePngCtxEx(im, outfile, -1);
+       gdImagePngCtxEx(im, outfile, -1, -1);
 }
 
 /* This routine is based in part on code from Dale Lutz (Safe Software Inc.)
  *  and in part on demo code from Chapter 15 of "PNG: The Definitive Guide"
  *  (http://www.cdrom.com/pub/png/pngbook.html).
  */
-void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level)
+void gdImagePngCtxEx (gdImagePtr im, gdIOCtx * outfile, int level, int 
basefilter)
 {
        int i, j, bit_depth = 0, interlace_type;
        int width = im->sx;
@@ -484,7 +484,10 @@
 
        /* 2.0.12: this is finally a parameter */
        png_set_compression_level(png_ptr, level);
-
+       if (basefilter >= 0) {
+               png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, basefilter);
+       }
+       
        /* can set this to a smaller value without compromising compression if 
all
         * image data is 16K or less; will save some decoder memory [min == 8]
         */

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to