Browse Source

- MFB: [DOC] always enable imagefilter and imageconvolution, even when built against system's gd

experimental/first_unicode_implementation
Pierre Joye 17 years ago
parent
commit
c62cb674f1
  1. 4
      ext/gd/config.m4
  2. 43
      ext/gd/gd.c
  3. 1
      ext/gd/libgd/gd.h
  4. 49
      ext/gd/libgd/gd_compat.h
  5. 461
      ext/gd/libgd/gd_filter.c
  6. 13
      ext/gd/libgd/gd_intern.h

4
ext/gd/config.m4

@ -274,7 +274,7 @@ if test "$PHP_GD" = "yes"; then
libgd/gdxpm.c libgd/gdfontt.c libgd/gdfonts.c libgd/gdfontmb.c libgd/gdfontl.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/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/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_pixelate.c"
libgd/xbm.c libgd/gd_gif_out.c libgd/gd_security.c libgd/gd_filter.c libgd/gd_pixelate.c"
dnl check for fabsf and floorf which are available since C99 dnl check for fabsf and floorf which are available since C99
AC_CHECK_FUNCS([fabsf floorf]) AC_CHECK_FUNCS([fabsf floorf])
@ -310,7 +310,7 @@ elif test "$PHP_GD" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/libgd) PHP_ADD_BUILD_DIR($ext_builddir/libgd)
GD_MODULE_TYPE=external GD_MODULE_TYPE=external
extra_sources="gdcache.c libgd/gd_compat.c"
extra_sources="gdcache.c libgd/gd_compat.c libgd/gd_filter.c libgd/gd_pixelate.c"
GD_FEATURES=`$GDLIB_CONFIG --features` GD_FEATURES=`$GDLIB_CONFIG --features`

43
ext/gd/gd.c

@ -56,9 +56,10 @@
#if HAVE_LIBGD #if HAVE_LIBGD
#if !HAVE_GD_BUNDLED #if !HAVE_GD_BUNDLED
# include "libgd/gd_compat.h" # include "libgd/gd_compat.h"
#else
extern int overflow2(int a, int b);
#endif #endif
static int le_gd, le_gd_font; static int le_gd, le_gd_font;
#if HAVE_LIBT1 #if HAVE_LIBT1
#include <t1lib.h> #include <t1lib.h>
@ -103,7 +104,6 @@ int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
* IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments * IMAGE_FILTER_MAX_ARGS: define the biggest amout of arguments
* image_filter array in PHP_FUNCTION(imagefilter) * image_filter array in PHP_FUNCTION(imagefilter)
* */ * */
#if HAVE_GD_BUNDLED
#define IMAGE_FILTER_NEGATE 0 #define IMAGE_FILTER_NEGATE 0
#define IMAGE_FILTER_GRAYSCALE 1 #define IMAGE_FILTER_GRAYSCALE 1
#define IMAGE_FILTER_BRIGHTNESS 2 #define IMAGE_FILTER_BRIGHTNESS 2
@ -130,7 +130,7 @@ static void php_image_filter_selective_blur(INTERNAL_FUNCTION_PARAMETERS);
static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_mean_removal(INTERNAL_FUNCTION_PARAMETERS);
static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS);
static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS); static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS);
#endif
/* End Section filters declarations */ /* End Section filters declarations */
static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC); static gdImagePtr _php_image_create_from_string (zval **Data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC);
static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()); static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)());
@ -810,7 +810,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_png2wbmp, 0)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
#endif #endif
#ifdef HAVE_GD_BUNDLED
ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2) ZEND_BEGIN_ARG_INFO_EX(arginfo_imagefilter, 0, 0, 2)
ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, filtertype) ZEND_ARG_INFO(0, filtertype)
@ -826,7 +825,6 @@ ZEND_BEGIN_ARG_INFO(arginfo_imageconvolution, 0)
ZEND_ARG_INFO(0, div) ZEND_ARG_INFO(0, div)
ZEND_ARG_INFO(0, offset) ZEND_ARG_INFO(0, offset)
ZEND_END_ARG_INFO() ZEND_END_ARG_INFO()
#endif
#ifdef HAVE_GD_BUNDLED #ifdef HAVE_GD_BUNDLED
ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0) ZEND_BEGIN_ARG_INFO(arginfo_imageantialias, 0)
@ -987,10 +985,8 @@ const zend_function_entry gd_functions[] = {
PHP_FE(imagexbm, arginfo_imagexbm) PHP_FE(imagexbm, arginfo_imagexbm)
#endif #endif
/* gd filters */ /* gd filters */
#ifdef HAVE_GD_BUNDLED
PHP_FE(imagefilter, arginfo_imagefilter) PHP_FE(imagefilter, arginfo_imagefilter)
PHP_FE(imageconvolution, arginfo_imageconvolution) PHP_FE(imageconvolution, arginfo_imageconvolution)
#endif
{NULL, NULL, NULL} {NULL, NULL, NULL}
}; };
@ -1120,6 +1116,10 @@ PHP_MINIT_FUNCTION(gd)
REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("GD_BUNDLED", 1, CONST_CS | CONST_PERSISTENT);
#else
REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
#endif
/* Section Filters */ /* Section Filters */
REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_NEGATE", IMAGE_FILTER_NEGATE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_GRAYSCALE", IMAGE_FILTER_GRAYSCALE, CONST_CS | CONST_PERSISTENT);
@ -1134,9 +1134,6 @@ PHP_MINIT_FUNCTION(gd)
REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_SMOOTH", IMAGE_FILTER_SMOOTH, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_FILTER_PIXELATE", IMAGE_FILTER_PIXELATE, CONST_CS | CONST_PERSISTENT);
/* End Section Filters */ /* End Section Filters */
#else
REGISTER_LONG_CONSTANT("GD_BUNDLED", 0, CONST_CS | CONST_PERSISTENT);
#endif
#ifdef GD_VERSION_STRING #ifdef GD_VERSION_STRING
REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT); REGISTER_STRING_CONSTANT("GD_VERSION", GD_VERSION_STRING, CONST_CS | CONST_PERSISTENT);
@ -1209,11 +1206,11 @@ PHP_MINFO_FUNCTION(gd)
char tmp[256]; char tmp[256];
#ifdef FREETYPE_PATCH #ifdef FREETYPE_PATCH
snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
snprintf(tmp, sizeof(tmp), "%d.%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR, FREETYPE_PATCH);
#elif defined(FREETYPE_MAJOR) #elif defined(FREETYPE_MAJOR)
snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
snprintf(tmp, sizeof(tmp), "%d.%d", FREETYPE_MAJOR, FREETYPE_MINOR);
#else #else
snprintf(tmp, sizeof(tmp), "1.x");
snprintf(tmp, sizeof(tmp), "1.x");
#endif #endif
php_info_print_table_row(2, "FreeType Version", tmp); php_info_print_table_row(2, "FreeType Version", tmp);
} }
@ -1242,6 +1239,7 @@ PHP_MINFO_FUNCTION(gd)
php_info_print_table_row(2, "libJPEG Version", tmp); php_info_print_table_row(2, "libJPEG Version", tmp);
} }
#endif #endif
#ifdef HAVE_GD_PNG #ifdef HAVE_GD_PNG
php_info_print_table_row(2, "PNG Support", "enabled"); php_info_print_table_row(2, "PNG Support", "enabled");
php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString()); php_info_print_table_row(2, "libPNG Version", gdPngGetVersionString());
@ -2657,7 +2655,6 @@ PHP_FUNCTION(imagecolorallocate)
if (ct < 0) { if (ct < 0) {
RETURN_FALSE; RETURN_FALSE;
} }
RETURN_LONG(ct); RETURN_LONG(ct);
} }
/* }}} */ /* }}} */
@ -2899,6 +2896,7 @@ PHP_FUNCTION(imagegammacorrect)
} }
RETURN_TRUE; RETURN_TRUE;
} }
for (i = 0; i < gdImageColorsTotal(im); i++) { for (i = 0; i < gdImageColorsTotal(im); i++) {
im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5); im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5);
im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5); im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5);
@ -2923,7 +2921,6 @@ PHP_FUNCTION(imagesetpixel)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageSetPixel(im, x, y, col); gdImageSetPixel(im, x, y, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -2968,7 +2965,6 @@ PHP_FUNCTION(imagedashedline)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageDashedLine(im, x1, y1, x2, y2, col); gdImageDashedLine(im, x1, y1, x2, y2, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -2987,7 +2983,6 @@ PHP_FUNCTION(imagerectangle)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageRectangle(im, x1, y1, x2, y2, col); gdImageRectangle(im, x1, y1, x2, y2, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3006,7 +3001,6 @@ PHP_FUNCTION(imagefilledrectangle)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageFilledRectangle(im, x1, y1, x2, y2, col); gdImageFilledRectangle(im, x1, y1, x2, y2, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3076,7 +3070,6 @@ PHP_FUNCTION(imagefilltoborder)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageFillToBorder(im, x, y, border, col); gdImageFillToBorder(im, x, y, border, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3095,7 +3088,6 @@ PHP_FUNCTION(imagefill)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageFill(im, x, y, col); gdImageFill(im, x, y, col);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3446,7 +3438,6 @@ PHP_FUNCTION(imagecopy)
ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH); gdImageCopy(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3466,7 +3457,6 @@ PHP_FUNCTION(imagecopymerge)
ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im_dst, gdImagePtr, &DIM, -1, "Image", le_gd);
gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct); gdImageCopyMerge(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, pct);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -3511,7 +3501,6 @@ PHP_FUNCTION(imagecopyresized)
RETURN_FALSE; RETURN_FALSE;
} }
gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */
@ -4432,8 +4421,6 @@ convert_done:
#endif /* HAVE_LIBGD */ #endif /* HAVE_LIBGD */
/* Section Filters */ /* Section Filters */
#ifdef HAVE_GD_BUNDLED
#define PHP_GD_SINGLE_RES \ #define PHP_GD_SINGLE_RES \
zval *SIM; \ zval *SIM; \
gdImagePtr im_src; \ gdImagePtr im_src; \
@ -4640,7 +4627,6 @@ static void php_image_filter_pixelate(INTERNAL_FUNCTION_PARAMETERS)
RETURN_FALSE; RETURN_FALSE;
} }
/* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] ) U /* {{{ proto bool imagefilter(resource src_im, int filtertype, [args] ) U
Applies Filter an image using a custom angle */ Applies Filter an image using a custom angle */
PHP_FUNCTION(imagefilter) PHP_FUNCTION(imagefilter)
@ -4723,10 +4709,10 @@ PHP_FUNCTION(imageconvolution)
RETURN_BOOL(gdImageConvolution(im_src, matrix, div, offset)); RETURN_BOOL(gdImageConvolution(im_src, matrix, div, offset));
} }
/* }}} */ /* }}} */
/* End section: Filters */ /* End section: Filters */
/* {{{ proto bool imageantialias(resource im, bool on) U
#ifdef HAVE_GD_BUNDLED
/* {{{ proto bool imageantialias(resource im, bool on)
Should antialiased functions used or not*/ Should antialiased functions used or not*/
PHP_FUNCTION(imageantialias) PHP_FUNCTION(imageantialias)
{ {
@ -4740,7 +4726,6 @@ PHP_FUNCTION(imageantialias)
ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd); ZEND_FETCH_RESOURCE(im, gdImagePtr, &IM, -1, "Image", le_gd);
gdImageAntialias(im, alias); gdImageAntialias(im, alias);
RETURN_TRUE; RETURN_TRUE;
} }
/* }}} */ /* }}} */

1
ext/gd/libgd/gd.h

@ -289,6 +289,7 @@ void gdImageDestroy(gdImagePtr im);
void gdImageSetPixel(gdImagePtr im, int x, int y, int color); void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
int gdImageGetTrueColorPixel (gdImagePtr im, int x, int y);
int gdImageGetPixel(gdImagePtr im, int x, int y); int gdImageGetPixel(gdImagePtr im, int x, int y);
void gdImageAABlend(gdImagePtr im); void gdImageAABlend(gdImagePtr im);

49
ext/gd/libgd/gd_compat.h

@ -1,5 +1,54 @@
#ifndef GD_COMPAT_H
#define GD_COMPAT_H 1
#if HAVE_GD_BUNDLED
# include "gd.h"
#else
# include <gd.h>
#endif
const char * gdPngGetVersionString(); const char * gdPngGetVersionString();
int gdJpegGetVersionString(); int gdJpegGetVersionString();
int gdJpegGetVersionInt(); int gdJpegGetVersionInt();
int overflow2(int a, int b); int overflow2(int a, int b);
/* filters section
*
* Negate the imag src, white becomes black,
* The red, green, and blue intensities of an image are negated.
* White becomes black, yellow becomes blue, etc.
*/
int gdImageNegate(gdImagePtr src);
/* Convert the image src to a grayscale image */
int gdImageGrayScale(gdImagePtr src);
/* Set the brightness level <brightness> for the image src */
int gdImageBrightness(gdImagePtr src, int brightness);
/* Set the contrast level <contrast> for the image <src> */
int gdImageContrast(gdImagePtr src, double contrast);
/* Simply adds or substracts respectively red, green or blue to a pixel */
int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha);
/* Image convolution by a 3x3 custom matrix */
int gdImageConvolution(gdImagePtr src, float ft[3][3], float filter_div, float offset);
int gdImageEdgeDetectQuick(gdImagePtr src);
int gdImageGaussianBlur(gdImagePtr im);
int gdImageSelectiveBlur( gdImagePtr src);
int gdImageEmboss(gdImagePtr im);
int gdImageMeanRemoval(gdImagePtr im);
int gdImageSmooth(gdImagePtr im, float weight);
enum gdPixelateMode {
GD_PIXELATE_UPPERLEFT,
GD_PIXELATE_AVERAGE
};
int gdImagePixelate(gdImagePtr im, int block_size, const unsigned int mode);
#endif

461
ext/gd/libgd/gd_filter.c

@ -0,0 +1,461 @@
#if HAVE_GD_BUNDLED
# include "gd.h"
#else
# include <gd.h>
#endif
#include "gd_intern.h"
/* Filters function added on 2003/12
* by Pierre-Alain Joye (pierre@php.net)
**/
/* Begin filters function */
#define GET_PIXEL_FUNCTION(src)(src->trueColor?gdImageGetTrueColorPixel:gdImageGetPixel)
/* invert src image */
int gdImageNegate(gdImagePtr src)
{
int x, y;
int r,g,b,a;
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
if (src==NULL) {
return 0;
}
f = GET_PIXEL_FUNCTION(src);
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
pxl = f (src, x, y);
r = gdImageRed(src, pxl);
g = gdImageGreen(src, pxl);
b = gdImageBlue(src, pxl);
a = gdImageAlpha(src, pxl);
new_pxl = gdImageColorAllocateAlpha(src, 255-r, 255-g, 255-b, a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, 255-r, 255-g, 255-b, a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
return 1;
}
/* Convert the image src to a grayscale image */
int gdImageGrayScale(gdImagePtr src)
{
int x, y;
int r,g,b,a;
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
f = GET_PIXEL_FUNCTION(src);
if (src==NULL) {
return 0;
}
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
pxl = f (src, x, y);
r = gdImageRed(src, pxl);
g = gdImageGreen(src, pxl);
b = gdImageBlue(src, pxl);
a = gdImageAlpha(src, pxl);
r = g = b = (int) (.299 * r + .587 * g + .114 * b);
new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
return 1;
}
/* Set the brightness level <level> for the image src */
int gdImageBrightness(gdImagePtr src, int brightness)
{
int x, y;
int r,g,b,a;
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
f = GET_PIXEL_FUNCTION(src);
if (src==NULL || (brightness < -255 || brightness>255)) {
return 0;
}
if (brightness==0) {
return 1;
}
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
pxl = f (src, x, y);
r = gdImageRed(src, pxl);
g = gdImageGreen(src, pxl);
b = gdImageBlue(src, pxl);
a = gdImageAlpha(src, pxl);
r = r + brightness;
g = g + brightness;
b = b + brightness;
r = (r > 255)? 255 : ((r < 0)? 0:r);
g = (g > 255)? 255 : ((g < 0)? 0:g);
b = (b > 255)? 255 : ((b < 0)? 0:b);
new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
return 1;
}
int gdImageContrast(gdImagePtr src, double contrast)
{
int x, y;
int r,g,b,a;
double rf,gf,bf;
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
f = GET_PIXEL_FUNCTION(src);
if (src==NULL) {
return 0;
}
contrast = (double)(100.0-contrast)/100.0;
contrast = contrast*contrast;
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
pxl = f(src, x, y);
r = gdImageRed(src, pxl);
g = gdImageGreen(src, pxl);
b = gdImageBlue(src, pxl);
a = gdImageAlpha(src, pxl);
rf = (double)r/255.0;
rf = rf-0.5;
rf = rf*contrast;
rf = rf+0.5;
rf = rf*255.0;
bf = (double)b/255.0;
bf = bf-0.5;
bf = bf*contrast;
bf = bf+0.5;
bf = bf*255.0;
gf = (double)g/255.0;
gf = gf-0.5;
gf = gf*contrast;
gf = gf+0.5;
gf = gf*255.0;
rf = (rf > 255.0)? 255.0 : ((rf < 0.0)? 0.0:rf);
gf = (gf > 255.0)? 255.0 : ((gf < 0.0)? 0.0:gf);
bf = (bf > 255.0)? 255.0 : ((bf < 0.0)? 0.0:bf);
new_pxl = gdImageColorAllocateAlpha(src, (int)rf, (int)gf, (int)bf, a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, (int)rf, (int)gf, (int)bf, a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
return 1;
}
int gdImageColor(gdImagePtr src, const int red, const int green, const int blue, const int alpha)
{
int x, y;
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
if (src == NULL) {
return 0;
}
f = GET_PIXEL_FUNCTION(src);
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
int r,g,b,a;
pxl = f(src, x, y);
r = gdImageRed(src, pxl);
g = gdImageGreen(src, pxl);
b = gdImageBlue(src, pxl);
a = gdImageAlpha(src, pxl);
r = r + red;
g = g + green;
b = b + blue;
a = a + alpha;
r = (r > 255)? 255 : ((r < 0)? 0 : r);
g = (g > 255)? 255 : ((g < 0)? 0 : g);
b = (b > 255)? 255 : ((b < 0)? 0 : b);
a = (a > 127)? 127 : ((a < 0)? 0 : a);
new_pxl = gdImageColorAllocateAlpha(src, r, g, b, a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, r, g, b, a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
return 1;
}
int gdImageConvolution(gdImagePtr src, float filter[3][3], float filter_div, float offset)
{
int x, y, i, j, new_a;
float new_r, new_g, new_b;
int new_pxl, pxl=0;
gdImagePtr srcback;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
if (src==NULL) {
return 0;
}
/* We need the orinal image with each safe neoghb. pixel */
srcback = gdImageCreateTrueColor (src->sx, src->sy);
if (srcback==NULL) {
return 0;
}
gdImageSaveAlpha(srcback, 1);
new_pxl = gdImageColorAllocateAlpha(srcback, 0, 0, 0, 127);
gdImageFill(srcback, 0, 0, new_pxl);
gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
f = GET_PIXEL_FUNCTION(src);
for ( y=0; y<src->sy; y++) {
for(x=0; x<src->sx; x++) {
new_r = new_g = new_b = 0;
new_a = gdImageAlpha(srcback, pxl);
for (j=0; j<3; j++) {
int yv = MIN(MAX(y - 1 + j, 0), src->sy - 1);
for (i=0; i<3; i++) {
pxl = f(srcback, MIN(MAX(x - 1 + i, 0), src->sx - 1), yv);
new_r += (float)gdImageRed(srcback, pxl) * filter[j][i];
new_g += (float)gdImageGreen(srcback, pxl) * filter[j][i];
new_b += (float)gdImageBlue(srcback, pxl) * filter[j][i];
}
}
new_r = (new_r/filter_div)+offset;
new_g = (new_g/filter_div)+offset;
new_b = (new_b/filter_div)+offset;
new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
gdImageDestroy(srcback);
return 1;
}
int gdImageSelectiveBlur( gdImagePtr src)
{
int x, y, i, j;
float new_r, new_g, new_b;
int new_pxl, cpxl, pxl, new_a=0;
float flt_r [3][3];
float flt_g [3][3];
float flt_b [3][3];
float flt_r_sum, flt_g_sum, flt_b_sum;
gdImagePtr srcback;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
if (src==NULL) {
return 0;
}
/* We need the orinal image with each safe neoghb. pixel */
srcback = gdImageCreateTrueColor (src->sx, src->sy);
if (srcback==NULL) {
return 0;
}
gdImageCopy(srcback, src,0,0,0,0,src->sx,src->sy);
f = GET_PIXEL_FUNCTION(src);
for(y = 0; y<src->sy; y++) {
for (x=0; x<src->sx; x++) {
flt_r_sum = flt_g_sum = flt_b_sum = 0.0;
cpxl = f(src, x, y);
for (j=0; j<3; j++) {
for (i=0; i<3; i++) {
if ((j == 1) && (i == 1)) {
flt_r[1][1] = flt_g[1][1] = flt_b[1][1] = 0.5;
} else {
pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
new_a = gdImageAlpha(srcback, pxl);
new_r = ((float)gdImageRed(srcback, cpxl)) - ((float)gdImageRed (srcback, pxl));
if (new_r < 0.0f) {
new_r = -new_r;
}
if (new_r != 0) {
flt_r[j][i] = 1.0f/new_r;
} else {
flt_r[j][i] = 1.0f;
}
new_g = ((float)gdImageGreen(srcback, cpxl)) - ((float)gdImageGreen(srcback, pxl));
if (new_g < 0.0f) {
new_g = -new_g;
}
if (new_g != 0) {
flt_g[j][i] = 1.0f/new_g;
} else {
flt_g[j][i] = 1.0f;
}
new_b = ((float)gdImageBlue(srcback, cpxl)) - ((float)gdImageBlue(srcback, pxl));
if (new_b < 0.0f) {
new_b = -new_b;
}
if (new_b != 0) {
flt_b[j][i] = 1.0f/new_b;
} else {
flt_b[j][i] = 1.0f;
}
}
flt_r_sum += flt_r[j][i];
flt_g_sum += flt_g[j][i];
flt_b_sum += flt_b [j][i];
}
}
for (j=0; j<3; j++) {
for (i=0; i<3; i++) {
if (flt_r_sum != 0.0) {
flt_r[j][i] /= flt_r_sum;
}
if (flt_g_sum != 0.0) {
flt_g[j][i] /= flt_g_sum;
}
if (flt_b_sum != 0.0) {
flt_b [j][i] /= flt_b_sum;
}
}
}
new_r = new_g = new_b = 0.0;
for (j=0; j<3; j++) {
for (i=0; i<3; i++) {
pxl = f(src, x-(3>>1)+i, y-(3>>1)+j);
new_r += (float)gdImageRed(srcback, pxl) * flt_r[j][i];
new_g += (float)gdImageGreen(srcback, pxl) * flt_g[j][i];
new_b += (float)gdImageBlue(srcback, pxl) * flt_b[j][i];
}
}
new_r = (new_r > 255.0f)? 255.0f : ((new_r < 0.0f)? 0.0f:new_r);
new_g = (new_g > 255.0f)? 255.0f : ((new_g < 0.0f)? 0.0f:new_g);
new_b = (new_b > 255.0f)? 255.0f : ((new_b < 0.0f)? 0.0f:new_b);
new_pxl = gdImageColorAllocateAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
if (new_pxl == -1) {
new_pxl = gdImageColorClosestAlpha(src, (int)new_r, (int)new_g, (int)new_b, new_a);
}
gdImageSetPixel (src, x, y, new_pxl);
}
}
gdImageDestroy(srcback);
return 1;
}
int gdImageEdgeDetectQuick(gdImagePtr src)
{
float filter[3][3] = {{-1.0,0.0,-1.0},
{0.0,4.0,0.0},
{-1.0,0.0,-1.0}};
return gdImageConvolution(src, filter, 1, 127);
}
int gdImageGaussianBlur(gdImagePtr im)
{
float filter[3][3] = {{1.0,2.0,1.0},
{2.0,4.0,2.0},
{1.0,2.0,1.0}};
return gdImageConvolution(im, filter, 16, 0);
}
int gdImageEmboss(gdImagePtr im)
{
/*
float filter[3][3] = {{1.0,1.0,1.0},
{0.0,0.0,0.0},
{-1.0,-1.0,-1.0}};
*/
float filter[3][3] = {{ 1.5, 0.0, 0.0},
{ 0.0, 0.0, 0.0},
{ 0.0, 0.0,-1.5}};
return gdImageConvolution(im, filter, 1, 127);
}
int gdImageMeanRemoval(gdImagePtr im)
{
float filter[3][3] = {{-1.0,-1.0,-1.0},
{-1.0,9.0,-1.0},
{-1.0,-1.0,-1.0}};
return gdImageConvolution(im, filter, 1, 0);
}
int gdImageSmooth(gdImagePtr im, float weight)
{
float filter[3][3] = {{1.0,1.0,1.0},
{1.0,0.0,1.0},
{1.0,1.0,1.0}};
filter[1][1] = weight;
return gdImageConvolution(im, filter, weight+8, 0);
}
/* End filters function */

13
ext/gd/libgd/gd_intern.h

@ -0,0 +1,13 @@
#ifndef GD_INTERN_H
#define GD_INTERN_H
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#define MIN3(a,b,c) ((a)<(b)?(MIN(a,c)):(MIN(b,c)))
#ifndef MAX
#define MAX(a,b) ((a)<(b)?(b):(a))
#endif
#define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
#endif
Loading…
Cancel
Save