com php-src: Sync with libgd wrt. compilation units: ext/gd/config.m4 ext/gd/config.w32 ext/gd/libgd/gd.c ext/gd/libgd/gd_arc.c
ext/gd/libgd/gd_color.c ext/gd/libgd/gd_color_matc h.c ext/gd/libgd/gd_xbm.c ext/gd/libgd/mathmake.c ext/gd/libgd/xbm.c
| From: | Christoph Michael Becker | Date: | Mon, 19 Sep 2016 22:34:19 +0000 |
| Subject: | com php-src: Sync with libgd wrt. compilation units: ext/gd/config.m4 ext/gd/config.w32 ext/gd/libgd/gd.c ext/gd/libgd/gd_arc.c ext/gd/libgd/gd_color.c ext/gd/libgd/gd_color_matc h.c ext/gd/libgd/gd_xbm.c ext/gd/libgd/mathmake.c ext/gd/libgd/xbm.c |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94593@lists.php.net to get a copy of this message | ||
Commit: be30c34fb8fd67998fdc27fca21b6ed008552e2a
Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 20 Sep 2016 00:10:49 +0200
Parents: a14c220fd953dc4a884e2e8fca43764c349e3965
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=be30c34fb8fd67998fdc27fca21b6ed008552e2a
Log:
Sync with libgd wrt. compilation units
* integrate gd_arc.c into gd.c (as of gd-2.1.0-alpha1)
* rename gd_color.c to gd_color_match.c (as of gd-2.1.0-alpha1)
* remove mathmake.c (as of GD_2_0_34RC1)
* rename xbm.c to gd_xbm.c (as of gd-2.1.0-alpha1)
Changed paths:
M ext/gd/config.m4
M ext/gd/config.w32
M ext/gd/libgd/gd.c
D ext/gd/libgd/gd_arc.c
D ext/gd/libgd/gd_color.c
A ext/gd/libgd/gd_color_match.c
A ext/gd/libgd/gd_xbm.c
D ext/gd/libgd/mathmake.c
D ext/gd/libgd/xbm.c
diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index b7aeeaa..4491428 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -255,8 +255,8 @@ if test "$PHP_GD" = "yes"; then 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_topal.c libgd/gd_gif_in.c libgd/gd_xbm.c libgd/gd_gif_out.c libgd/gd_security.c \ + libgd/gd_filter.c libgd/gd_pixelate.c libgd/gd_rotate.c libgd/gd_color_match.c \ libgd/gd_transform.c libgd/gd_crop.c libgd/gd_interpolation.c libgd/gd_matrix.c" dnl check for fabsf and floorf which are available since C99 diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 715ea50..a27f3b6 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -39,8 +39,8 @@ if (PHP_GD != "no") { gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ 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_transform.c \ - gd_filter.c gd_pixelate.c gd_arc.c gd_rotate.c gd_color.c gd_webp.c \ + gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c gd_xbm.c gd_security.c gd_transform.c \ + gd_filter.c gd_pixelate.c gd_rotate.c gd_color_match.c gd_webp.c \ gd_crop.c gd_interpolation.c gd_matrix.c", "gd"); AC_DEFINE('HAVE_LIBGD', 1, 'GD support'); ADD_FLAG("CFLAGS_GD", " \ diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index dd38a11..35b4397 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -1775,6 +1775,100 @@ void gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e } } +/** + * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse) + * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org) + * See the ellipse function simplification for the equation + * as well as the midpoint algorithm. + */ + +void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c) +{ + int x=0,mx1=0,mx2=0,my1=0,my2=0; + long aq,bq,dx,dy,r,rx,ry,a,b; + + a=w>>1; + b=h>>1; + gdImageSetPixel(im,mx+a, my, c); + gdImageSetPixel(im,mx-a, my, c); + mx1 = mx-a;my1 = my; + mx2 = mx+a;my2 = my; + + aq = a * a; + bq = b * b; + dx = aq << 1; + dy = bq << 1; + r = a * bq; + rx = r << 1; + ry = 0; + x = a; + while (x > 0){ + if (r > 0) { + my1++;my2--; + ry +=dx; + r -=ry; + } + if (r <= 0){ + x--; + mx1++;mx2--; + rx -=dy; + r +=rx; + } + gdImageSetPixel(im,mx1, my1, c); + gdImageSetPixel(im,mx1, my2, c); + gdImageSetPixel(im,mx2, my1, c); + gdImageSetPixel(im,mx2, my2, c); + } +} + +void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) +{ + int x=0,mx1=0,mx2=0,my1=0,my2=0; + long aq,bq,dx,dy,r,rx,ry,a,b; + int i; + int old_y2; + + a=w>>1; + b=h>>1; + + for (x = mx-a; x <= mx+a; x++) { + gdImageSetPixel(im, x, my, c); + } + + mx1 = mx-a;my1 = my; + mx2 = mx+a;my2 = my; + + aq = a * a; + bq = b * b; + dx = aq << 1; + dy = bq << 1; + r = a * bq; + rx = r << 1; + ry = 0; + x = a; + old_y2=-2; + while (x > 0){ + if (r > 0) { + my1++;my2--; + ry +=dx; + r -=ry; + } + if (r <= 0){ + x--; + mx1++;mx2--; + rx -=dy; + r +=rx; + } + if(old_y2!=my2){ + for(i=mx1;i<=mx2;i++){ + gdImageSetPixel(im,i,my1,c); + gdImageSetPixel(im,i,my2,c); + } + } + old_y2 = my2; + } +} + void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) { int lastBorder; diff --git a/ext/gd/libgd/gd_arc.c b/ext/gd/libgd/gd_arc.c deleted file mode 100644 index 1c74871..0000000 --- a/ext/gd/libgd/gd_arc.c +++ /dev/null @@ -1,104 +0,0 @@ -#if HAVE_GD_BUNDLED -# include "gd.h" -#else -# include <gd.h> -#endif - -#include "gd_intern.h" - - -/** - * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse) - * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org) - * See the ellipse function simplification for the equation - * as well as the midpoint algorithm. - */ - -void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c) -{ - int x=0,mx1=0,mx2=0,my1=0,my2=0; - long aq,bq,dx,dy,r,rx,ry,a,b; - - a=w>>1; - b=h>>1; - gdImageSetPixel(im,mx+a, my, c); - gdImageSetPixel(im,mx-a, my, c); - mx1 = mx-a;my1 = my; - mx2 = mx+a;my2 = my; - - aq = a * a; - bq = b * b; - dx = aq << 1; - dy = bq << 1; - r = a * bq; - rx = r << 1; - ry = 0; - x = a; - while (x > 0){ - if (r > 0) { - my1++;my2--; - ry +=dx; - r -=ry; - } - if (r <= 0){ - x--; - mx1++;mx2--; - rx -=dy; - r +=rx; - } - gdImageSetPixel(im,mx1, my1, c); - gdImageSetPixel(im,mx1, my2, c); - gdImageSetPixel(im,mx2, my1, c); - gdImageSetPixel(im,mx2, my2, c); - } -} - -void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) -{ - int x=0,mx1=0,mx2=0,my1=0,my2=0; - long aq,bq,dx,dy,r,rx,ry,a,b; - int i; - int old_y2; - - a=w>>1; - b=h>>1; - - for (x = mx-a; x <= mx+a; x++) { - gdImageSetPixel(im, x, my, c); - } - - mx1 = mx-a;my1 = my; - mx2 = mx+a;my2 = my; - - aq = a * a; - bq = b * b; - dx = aq << 1; - dy = bq << 1; - r = a * bq; - rx = r << 1; - ry = 0; - x = a; - old_y2=-2; - while (x > 0){ - if (r > 0) { - my1++;my2--; - ry +=dx; - r -=ry; - } - if (r <= 0){ - x--; - mx1++;mx2--; - rx -=dy; - r +=rx; - } - if(old_y2!=my2){ - for(i=mx1;i<=mx2;i++){ - gdImageSetPixel(im,i,my1,c); - gdImageSetPixel(im,i,my2,c); - } - } - old_y2 = my2; - } -} - - diff --git a/ext/gd/libgd/gd_color.c b/ext/gd/libgd/gd_color.c deleted file mode 100644 index a4e56b1..0000000 --- a/ext/gd/libgd/gd_color.c +++ /dev/null @@ -1,67 +0,0 @@ -#if HAVE_GD_BUNDLED -# include "gd.h" -# include "gdhelpers.h" -#else -# include <gd.h> -# include "libgd/gdhelpers.h" -#endif - -#include "gd_intern.h" -#include "php.h" - -/* bring the palette colors in im2 to be closer to im1 - * - */ -int gdImageColorMatch (gdImagePtr im1, gdImagePtr im2) -{ - unsigned long *buf; /* stores our calculations */ - unsigned long *bp; /* buf ptr */ - int color, rgb; - int x,y; - int count; - - if( !im1->trueColor ) { - return -1; /* im1 must be True Color */ - } - if( im2->trueColor ) { - return -2; /* im2 must be indexed */ - } - if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { - return -3; /* the images are meant to be the same dimensions */ - } - if (im2->colorsTotal<1) { - return -4; /* At least 1 color must be allocated */ - } - - buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); - memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); - - for (x=0; x<im1->sx; x++) { - for( y=0; y<im1->sy; y++ ) { - color = im2->pixels[y][x]; - rgb = im1->tpixels[y][x]; - bp = buf + (color * 5); - (*(bp++))++; - *(bp++) += gdTrueColorGetRed(rgb); - *(bp++) += gdTrueColorGetGreen(rgb); - *(bp++) += gdTrueColorGetBlue(rgb); - *(bp++) += gdTrueColorGetAlpha(rgb); - } - } - bp = buf; - for (color=0; color<im2->colorsTotal; color++) { - count = *(bp++); - if( count > 0 ) { - im2->red[color] = *(bp++) / count; - im2->green[color] = *(bp++) / count; - im2->blue[color] = *(bp++) / count; - im2->alpha[color] = *(bp++) / count; - } else { - bp += 4; - } - } - gdFree(buf); - return 0; -} - - diff --git a/ext/gd/libgd/gd_color_match.c b/ext/gd/libgd/gd_color_match.c new file mode 100644 index 0000000..a4e56b1 --- /dev/null +++ b/ext/gd/libgd/gd_color_match.c @@ -0,0 +1,67 @@ +#if HAVE_GD_BUNDLED +# include "gd.h" +# include "gdhelpers.h" +#else +# include <gd.h> +# include "libgd/gdhelpers.h" +#endif + +#include "gd_intern.h" +#include "php.h" + +/* bring the palette colors in im2 to be closer to im1 + * + */ +int gdImageColorMatch (gdImagePtr im1, gdImagePtr im2) +{ + unsigned long *buf; /* stores our calculations */ + unsigned long *bp; /* buf ptr */ + int color, rgb; + int x,y; + int count; + + if( !im1->trueColor ) { + return -1; /* im1 must be True Color */ + } + if( im2->trueColor ) { + return -2; /* im2 must be indexed */ + } + if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { + return -3; /* the images are meant to be the same dimensions */ + } + if (im2->colorsTotal<1) { + return -4; /* At least 1 color must be allocated */ + } + + buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); + memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); + + for (x=0; x<im1->sx; x++) { + for( y=0; y<im1->sy; y++ ) { + color = im2->pixels[y][x]; + rgb = im1->tpixels[y][x]; + bp = buf + (color * 5); + (*(bp++))++; + *(bp++) += gdTrueColorGetRed(rgb); + *(bp++) += gdTrueColorGetGreen(rgb); + *(bp++) += gdTrueColorGetBlue(rgb); + *(bp++) += gdTrueColorGetAlpha(rgb); + } + } + bp = buf; + for (color=0; color<im2->colorsTotal; color++) { + count = *(bp++); + if( count > 0 ) { + im2->red[color] = *(bp++) / count; + im2->green[color] = *(bp++) / count; + im2->blue[color] = *(bp++) / count; + im2->alpha[color] = *(bp++) / count; + } else { + bp += 4; + } + } + gdFree(buf); + return 0; +} + + diff --git a/ext/gd/libgd/gd_xbm.c b/ext/gd/libgd/gd_xbm.c new file mode 100644 index 0000000..b351814 --- /dev/null +++ b/ext/gd/libgd/gd_xbm.c @@ -0,0 +1,241 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Marcus Boerger <helly@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#include <stdio.h> +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include "gd.h" +#include "gdhelpers.h" + +#include "php.h" + +#define MAX_XBM_LINE_SIZE 255 + +/* {{{ gdImagePtr gdImageCreateFromXbm */ +gdImagePtr gdImageCreateFromXbm(FILE * fd) +{ + char fline[MAX_XBM_LINE_SIZE]; + char iname[MAX_XBM_LINE_SIZE]; + char *type; + int value; + unsigned int width = 0, height = 0; + int fail = 0; + int max_bit = 0; + + gdImagePtr im; + int bytes = 0, i; + int bit, x = 0, y = 0; + int ch; + char h[8]; + unsigned int b; + + rewind(fd); + while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) { + fline[MAX_XBM_LINE_SIZE-1] = '\0'; + if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { + return 0; + } + if (sscanf(fline, "#define %s %d", iname, &value) == 2) { + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } + + if (!strcmp("width", type)) { + width = (unsigned int) value; + } + if (!strcmp("height", type)) { + height = (unsigned int) value; + } + } else { + if ( sscanf(fline, "static unsigned char %s = {", iname) == 1 + || sscanf(fline, "static char %s = {", iname) == 1) + { + max_bit = 128; + } else if (sscanf(fline, "static unsigned short %s = {", iname) == 1 + || sscanf(fline, "static short %s = {", iname) == 1) + { + max_bit = 32768; + } + if (max_bit) { + bytes = (width * height / 8) + 1; + if (!bytes) { + return 0; + } + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } + if (!strcmp("bits[]", type)) { + break; + } + } + } + } + if (!bytes || !max_bit) { + return 0; + } + + if(!(im = gdImageCreate(width, height))) { + return 0; + } + gdImageColorAllocate(im, 255, 255, 255); + gdImageColorAllocate(im, 0, 0, 0); + h[2] = '\0'; + h[4] = '\0'; + for (i = 0; i < bytes; i++) { + while (1) { + if ((ch=getc(fd)) == EOF) { + fail = 1; + break; + } + if (ch == 'x') { + break; + } + } + if (fail) { + break; + } + /* Get hex value */ + if ((ch=getc(fd)) == EOF) { + break; + } + h[0] = ch; + if ((ch=getc(fd)) == EOF) { + break; + } + h[1] = ch; + if (max_bit == 32768) { + if ((ch=getc(fd)) == EOF) { + break; + } + h[2] = ch; + if ((ch=getc(fd)) == EOF) { + break; + } + h[3] = ch; + } + sscanf(h, "%x", &b); + for (bit = 1; bit <= max_bit; bit = bit << 1) { + gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0); + if (x == im->sx) { + x = 0; + y++; + if (y == im->sy) { + return im; + } + break; + } + } + } + + php_gd_error("EOF before image was complete"); + gdImageDestroy(im); + return 0; +} +/* }}} */ + +/* {{{ gdCtxPrintf */ +void gdCtxPrintf(gdIOCtx * out, const char *format, ...) +{ + char *buf; + int len; + va_list args; + + va_start(args, format); + len = vspprintf(&buf, 0, format, args); + va_end(args); + out->putBuf(out, buf, len); + efree(buf); +} +/* }}} */ + +/* {{{ gdImageXbmCtx */ +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) +{ + int x, y, c, b, sx, sy, p; + char *name, *f; + size_t i, l; + + name = file_name; + if ((f = strrchr(name, '/')) != NULL) name = f+1; + if ((f = strrchr(name, '\\')) != NULL) name = f+1; + name = estrdup(name); + if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; + if ((l = strlen(name)) == 0) { + efree(name); + name = estrdup("image"); + } else { + for (i=0; i<l; i++) { + /* only in C-locale isalnum() would work */ + if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { + name[i] = '_'; + } + } + } + + gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); + gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); + gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); + + efree(name); + + b = 1; + p = 0; + c = 0; + sx = gdImageSX(image); + sy = gdImageSY(image); + for (y = 0; y < sy; y++) { + for (x = 0; x < sx; x++) { + if (gdImageGetPixel(image, x, y) == fg) { + c |= b; + } + if ((b == 128) || (x == sx - 1)) { + b = 1; + if (p) { + gdCtxPrintf(out, ", "); + if (!(p%12)) { + gdCtxPrintf(out, "\n "); + p = 12; + } + } + p++; + gdCtxPrintf(out, "0x%02X", c); + c = 0; + } else { + b <<= 1; + } + } + } + gdCtxPrintf(out, "};\n"); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/ext/gd/libgd/mathmake.c b/ext/gd/libgd/mathmake.c deleted file mode 100644 index 3950c4b..0000000 --- a/ext/gd/libgd/mathmake.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <math.h> - -#define scale 1024 - -int basis[91]; -int cost[360]; - -main (void) -{ - int i; - printf ("#define costScale %d\n", scale); - printf ("int cost[] = {\n "); - for (i = 0; (i <= 90); i++) - { - basis[i] = cos ((double) i * .0174532925) * scale; - } - for (i = 0; (i < 90); i++) - { - printf ("%d,\n ", cost[i] = basis[i]); - } - for (i = 90; (i < 180); i++) - { - printf ("%d,\n ", cost[i] = -basis[180 - i]); - } - for (i = 180; (i < 270); i++) - { - printf ("%d,\n ", cost[i] = -basis[i - 180]); - } - for (i = 270; (i < 359); i++) - { - printf ("%d,\n ", cost[i] = basis[360 - i]); - } - printf ("%d\n", cost[359] = basis[1]); - printf ("};\n"); - printf ("#define sintScale %d\n", scale); - printf ("int sint[] = {\n "); - for (i = 0; (i < 360); i++) - { - int val; - val = cost[(i + 270) % 360]; - if (i != 359) - { - printf ("%d,\n ", val); - } - else - { - printf ("%d\n", val); - } - } - printf ("};\n"); -} diff --git a/ext/gd/libgd/xbm.c b/ext/gd/libgd/xbm.c deleted file mode 100644 index b351814..0000000 --- a/ext/gd/libgd/xbm.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2016 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdio.h> -#include <math.h> -#include <string.h> -#include <stdlib.h> -#include "gd.h" -#include "gdhelpers.h" - -#include "php.h" - -#define MAX_XBM_LINE_SIZE 255 - -/* {{{ gdImagePtr gdImageCreateFromXbm */ -gdImagePtr gdImageCreateFromXbm(FILE * fd) -{ - char fline[MAX_XBM_LINE_SIZE]; - char iname[MAX_XBM_LINE_SIZE]; - char *type; - int value; - unsigned int width = 0, height = 0; - int fail = 0; - int max_bit = 0; - - gdImagePtr im; - int bytes = 0, i; - int bit, x = 0, y = 0; - int ch; - char h[8]; - unsigned int b; - - rewind(fd); - while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) { - fline[MAX_XBM_LINE_SIZE-1] = '\0'; - if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { - return 0; - } - if (sscanf(fline, "#define %s %d", iname, &value) == 2) { - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } - - if (!strcmp("width", type)) { - width = (unsigned int) value; - } - if (!strcmp("height", type)) { - height = (unsigned int) value; - } - } else { - if ( sscanf(fline, "static unsigned char %s = {", iname) == 1 - || sscanf(fline, "static char %s = {", iname) == 1) - { - max_bit = 128; - } else if (sscanf(fline, "static unsigned short %s = {", iname) == 1 - || sscanf(fline, "static short %s = {", iname) == 1) - { - max_bit = 32768; - } - if (max_bit) { - bytes = (width * height / 8) + 1; - if (!bytes) { - return 0; - } - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } - if (!strcmp("bits[]", type)) { - break; - } - } - } - } - if (!bytes || !max_bit) { - return 0; - } - - if(!(im = gdImageCreate(width, height))) { - return 0; - } - gdImageColorAllocate(im, 255, 255, 255); - gdImageColorAllocate(im, 0, 0, 0); - h[2] = '\0'; - h[4] = '\0'; - for (i = 0; i < bytes; i++) { - while (1) { - if ((ch=getc(fd)) == EOF) { - fail = 1; - break; - } - if (ch == 'x') { - break; - } - } - if (fail) { - break; - } - /* Get hex value */ - if ((ch=getc(fd)) == EOF) { - break; - } - h[0] = ch; - if ((ch=getc(fd)) == EOF) { - break; - } - h[1] = ch; - if (max_bit == 32768) { - if ((ch=getc(fd)) == EOF) { - break; - } - h[2] = ch; - if ((ch=getc(fd)) == EOF) { - break; - } - h[3] = ch; - } - sscanf(h, "%x", &b); - for (bit = 1; bit <= max_bit; bit = bit << 1) { - gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0); - if (x == im->sx) { - x = 0; - y++; - if (y == im->sy) { - return im; - } - break; - } - } - } - - php_gd_error("EOF before image was complete"); - gdImageDestroy(im); - return 0; -} -/* }}} */ - -/* {{{ gdCtxPrintf */ -void gdCtxPrintf(gdIOCtx * out, const char *format, ...) -{ - char *buf; - int len; - va_list args; - - va_start(args, format); - len = vspprintf(&buf, 0, format, args); - va_end(args); - out->putBuf(out, buf, len); - efree(buf); -} -/* }}} */ - -/* {{{ gdImageXbmCtx */ -void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) -{ - int x, y, c, b, sx, sy, p; - char *name, *f; - size_t i, l; - - name = file_name; - if ((f = strrchr(name, '/')) != NULL) name = f+1; - if ((f = strrchr(name, '\\')) != NULL) name = f+1; - name = estrdup(name); - if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; - if ((l = strlen(name)) == 0) { - efree(name); - name = estrdup("image"); - } else { - for (i=0; i<l; i++) { - /* only in C-locale isalnum() would work */ - if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { - name[i] = '_'; - } - } - } - - gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); - gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); - gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); - - efree(name); - - b = 1; - p = 0; - c = 0; - sx = gdImageSX(image); - sy = gdImageSY(image); - for (y = 0; y < sy; y++) { - for (x = 0; x < sx; x++) { - if (gdImageGetPixel(image, x, y) == fg) { - c |= b; - } - if ((b == 128) || (x == sx - 1)) { - b = 1; - if (p) { - gdCtxPrintf(out, ", "); - if (!(p%12)) { - gdCtxPrintf(out, "\n "); - p = 12; - } - } - p++; - gdCtxPrintf(out, "0x%02X", c); - c = 0; - } else { - b <<= 1; - } - } - } - gdCtxPrintf(out, "};\n"); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */
diff --git a/ext/gd/config.m4 b/ext/gd/config.m4 index b7aeeaa..4491428 100644 --- a/ext/gd/config.m4 +++ b/ext/gd/config.m4 @@ -255,8 +255,8 @@ if test "$PHP_GD" = "yes"; then 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_topal.c libgd/gd_gif_in.c libgd/gd_xbm.c libgd/gd_gif_out.c libgd/gd_security.c \ + libgd/gd_filter.c libgd/gd_pixelate.c libgd/gd_rotate.c libgd/gd_color_match.c \ libgd/gd_transform.c libgd/gd_crop.c libgd/gd_interpolation.c libgd/gd_matrix.c" dnl check for fabsf and floorf which are available since C99 diff --git a/ext/gd/config.w32 b/ext/gd/config.w32 index 715ea50..a27f3b6 100644 --- a/ext/gd/config.w32 +++ b/ext/gd/config.w32 @@ -39,8 +39,8 @@ if (PHP_GD != "no") { gdcache.c gdfontg.c gdfontl.c gdfontmb.c gdfonts.c gdfontt.c \ 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_transform.c \ - gd_filter.c gd_pixelate.c gd_arc.c gd_rotate.c gd_color.c gd_webp.c \ + gdtables.c gd_topal.c gd_wbmp.c gdxpm.c wbmp.c gd_xbm.c gd_security.c gd_transform.c \ + gd_filter.c gd_pixelate.c gd_rotate.c gd_color_match.c gd_webp.c \ gd_crop.c gd_interpolation.c gd_matrix.c", "gd"); AC_DEFINE('HAVE_LIBGD', 1, 'GD support'); ADD_FLAG("CFLAGS_GD", " \ diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index dd38a11..35b4397 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -1775,6 +1775,100 @@ void gdImageFilledArc (gdImagePtr im, int cx, int cy, int w, int h, int s, int e } } +/** + * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse) + * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org) + * See the ellipse function simplification for the equation + * as well as the midpoint algorithm. + */ + +void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c) +{ + int x=0,mx1=0,mx2=0,my1=0,my2=0; + long aq,bq,dx,dy,r,rx,ry,a,b; + + a=w>>1; + b=h>>1; + gdImageSetPixel(im,mx+a, my, c); + gdImageSetPixel(im,mx-a, my, c); + mx1 = mx-a;my1 = my; + mx2 = mx+a;my2 = my; + + aq = a * a; + bq = b * b; + dx = aq << 1; + dy = bq << 1; + r = a * bq; + rx = r << 1; + ry = 0; + x = a; + while (x > 0){ + if (r > 0) { + my1++;my2--; + ry +=dx; + r -=ry; + } + if (r <= 0){ + x--; + mx1++;mx2--; + rx -=dy; + r +=rx; + } + gdImageSetPixel(im,mx1, my1, c); + gdImageSetPixel(im,mx1, my2, c); + gdImageSetPixel(im,mx2, my1, c); + gdImageSetPixel(im,mx2, my2, c); + } +} + +void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) +{ + int x=0,mx1=0,mx2=0,my1=0,my2=0; + long aq,bq,dx,dy,r,rx,ry,a,b; + int i; + int old_y2; + + a=w>>1; + b=h>>1; + + for (x = mx-a; x <= mx+a; x++) { + gdImageSetPixel(im, x, my, c); + } + + mx1 = mx-a;my1 = my; + mx2 = mx+a;my2 = my; + + aq = a * a; + bq = b * b; + dx = aq << 1; + dy = bq << 1; + r = a * bq; + rx = r << 1; + ry = 0; + x = a; + old_y2=-2; + while (x > 0){ + if (r > 0) { + my1++;my2--; + ry +=dx; + r -=ry; + } + if (r <= 0){ + x--; + mx1++;mx2--; + rx -=dy; + r +=rx; + } + if(old_y2!=my2){ + for(i=mx1;i<=mx2;i++){ + gdImageSetPixel(im,i,my1,c); + gdImageSetPixel(im,i,my2,c); + } + } + old_y2 = my2; + } +} + void gdImageFillToBorder (gdImagePtr im, int x, int y, int border, int color) { int lastBorder; diff --git a/ext/gd/libgd/gd_arc.c b/ext/gd/libgd/gd_arc.c deleted file mode 100644 index 1c74871..0000000 --- a/ext/gd/libgd/gd_arc.c +++ /dev/null @@ -1,104 +0,0 @@ -#if HAVE_GD_BUNDLED -# include "gd.h" -#else -# include <gd.h> -#endif - -#include "gd_intern.h" - - -/** - * Integer Ellipse functions (gdImageEllipse and gdImageFilledEllipse) - * Function added by Pierre-Alain Joye 02/08/2003 (paj@pearfr.org) - * See the ellipse function simplification for the equation - * as well as the midpoint algorithm. - */ - -void gdImageEllipse(gdImagePtr im, int mx, int my, int w, int h, int c) -{ - int x=0,mx1=0,mx2=0,my1=0,my2=0; - long aq,bq,dx,dy,r,rx,ry,a,b; - - a=w>>1; - b=h>>1; - gdImageSetPixel(im,mx+a, my, c); - gdImageSetPixel(im,mx-a, my, c); - mx1 = mx-a;my1 = my; - mx2 = mx+a;my2 = my; - - aq = a * a; - bq = b * b; - dx = aq << 1; - dy = bq << 1; - r = a * bq; - rx = r << 1; - ry = 0; - x = a; - while (x > 0){ - if (r > 0) { - my1++;my2--; - ry +=dx; - r -=ry; - } - if (r <= 0){ - x--; - mx1++;mx2--; - rx -=dy; - r +=rx; - } - gdImageSetPixel(im,mx1, my1, c); - gdImageSetPixel(im,mx1, my2, c); - gdImageSetPixel(im,mx2, my1, c); - gdImageSetPixel(im,mx2, my2, c); - } -} - -void gdImageFilledEllipse (gdImagePtr im, int mx, int my, int w, int h, int c) -{ - int x=0,mx1=0,mx2=0,my1=0,my2=0; - long aq,bq,dx,dy,r,rx,ry,a,b; - int i; - int old_y2; - - a=w>>1; - b=h>>1; - - for (x = mx-a; x <= mx+a; x++) { - gdImageSetPixel(im, x, my, c); - } - - mx1 = mx-a;my1 = my; - mx2 = mx+a;my2 = my; - - aq = a * a; - bq = b * b; - dx = aq << 1; - dy = bq << 1; - r = a * bq; - rx = r << 1; - ry = 0; - x = a; - old_y2=-2; - while (x > 0){ - if (r > 0) { - my1++;my2--; - ry +=dx; - r -=ry; - } - if (r <= 0){ - x--; - mx1++;mx2--; - rx -=dy; - r +=rx; - } - if(old_y2!=my2){ - for(i=mx1;i<=mx2;i++){ - gdImageSetPixel(im,i,my1,c); - gdImageSetPixel(im,i,my2,c); - } - } - old_y2 = my2; - } -} - - diff --git a/ext/gd/libgd/gd_color.c b/ext/gd/libgd/gd_color.c deleted file mode 100644 index a4e56b1..0000000 --- a/ext/gd/libgd/gd_color.c +++ /dev/null @@ -1,67 +0,0 @@ -#if HAVE_GD_BUNDLED -# include "gd.h" -# include "gdhelpers.h" -#else -# include <gd.h> -# include "libgd/gdhelpers.h" -#endif - -#include "gd_intern.h" -#include "php.h" - -/* bring the palette colors in im2 to be closer to im1 - * - */ -int gdImageColorMatch (gdImagePtr im1, gdImagePtr im2) -{ - unsigned long *buf; /* stores our calculations */ - unsigned long *bp; /* buf ptr */ - int color, rgb; - int x,y; - int count; - - if( !im1->trueColor ) { - return -1; /* im1 must be True Color */ - } - if( im2->trueColor ) { - return -2; /* im2 must be indexed */ - } - if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { - return -3; /* the images are meant to be the same dimensions */ - } - if (im2->colorsTotal<1) { - return -4; /* At least 1 color must be allocated */ - } - - buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); - memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); - - for (x=0; x<im1->sx; x++) { - for( y=0; y<im1->sy; y++ ) { - color = im2->pixels[y][x]; - rgb = im1->tpixels[y][x]; - bp = buf + (color * 5); - (*(bp++))++; - *(bp++) += gdTrueColorGetRed(rgb); - *(bp++) += gdTrueColorGetGreen(rgb); - *(bp++) += gdTrueColorGetBlue(rgb); - *(bp++) += gdTrueColorGetAlpha(rgb); - } - } - bp = buf; - for (color=0; color<im2->colorsTotal; color++) { - count = *(bp++); - if( count > 0 ) { - im2->red[color] = *(bp++) / count; - im2->green[color] = *(bp++) / count; - im2->blue[color] = *(bp++) / count; - im2->alpha[color] = *(bp++) / count; - } else { - bp += 4; - } - } - gdFree(buf); - return 0; -} - - diff --git a/ext/gd/libgd/gd_color_match.c b/ext/gd/libgd/gd_color_match.c new file mode 100644 index 0000000..a4e56b1 --- /dev/null +++ b/ext/gd/libgd/gd_color_match.c @@ -0,0 +1,67 @@ +#if HAVE_GD_BUNDLED +# include "gd.h" +# include "gdhelpers.h" +#else +# include <gd.h> +# include "libgd/gdhelpers.h" +#endif + +#include "gd_intern.h" +#include "php.h" + +/* bring the palette colors in im2 to be closer to im1 + * + */ +int gdImageColorMatch (gdImagePtr im1, gdImagePtr im2) +{ + unsigned long *buf; /* stores our calculations */ + unsigned long *bp; /* buf ptr */ + int color, rgb; + int x,y; + int count; + + if( !im1->trueColor ) { + return -1; /* im1 must be True Color */ + } + if( im2->trueColor ) { + return -2; /* im2 must be indexed */ + } + if( (im1->sx != im2->sx) || (im1->sy != im2->sy) ) { + return -3; /* the images are meant to be the same dimensions */ + } + if (im2->colorsTotal<1) { + return -4; /* At least 1 color must be allocated */ + } + + buf = (unsigned long *)safe_emalloc(sizeof(unsigned long), 5 * im2->colorsTotal, 0); + memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal ); + + for (x=0; x<im1->sx; x++) { + for( y=0; y<im1->sy; y++ ) { + color = im2->pixels[y][x]; + rgb = im1->tpixels[y][x]; + bp = buf + (color * 5); + (*(bp++))++; + *(bp++) += gdTrueColorGetRed(rgb); + *(bp++) += gdTrueColorGetGreen(rgb); + *(bp++) += gdTrueColorGetBlue(rgb); + *(bp++) += gdTrueColorGetAlpha(rgb); + } + } + bp = buf; + for (color=0; color<im2->colorsTotal; color++) { + count = *(bp++); + if( count > 0 ) { + im2->red[color] = *(bp++) / count; + im2->green[color] = *(bp++) / count; + im2->blue[color] = *(bp++) / count; + im2->alpha[color] = *(bp++) / count; + } else { + bp += 4; + } + } + gdFree(buf); + return 0; +} + + diff --git a/ext/gd/libgd/gd_xbm.c b/ext/gd/libgd/gd_xbm.c new file mode 100644 index 0000000..b351814 --- /dev/null +++ b/ext/gd/libgd/gd_xbm.c @@ -0,0 +1,241 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2016 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Marcus Boerger <helly@php.net> | + +----------------------------------------------------------------------+ + */ + +/* $Id$ */ + +#include <stdio.h> +#include <math.h> +#include <string.h> +#include <stdlib.h> +#include "gd.h" +#include "gdhelpers.h" + +#include "php.h" + +#define MAX_XBM_LINE_SIZE 255 + +/* {{{ gdImagePtr gdImageCreateFromXbm */ +gdImagePtr gdImageCreateFromXbm(FILE * fd) +{ + char fline[MAX_XBM_LINE_SIZE]; + char iname[MAX_XBM_LINE_SIZE]; + char *type; + int value; + unsigned int width = 0, height = 0; + int fail = 0; + int max_bit = 0; + + gdImagePtr im; + int bytes = 0, i; + int bit, x = 0, y = 0; + int ch; + char h[8]; + unsigned int b; + + rewind(fd); + while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) { + fline[MAX_XBM_LINE_SIZE-1] = '\0'; + if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { + return 0; + } + if (sscanf(fline, "#define %s %d", iname, &value) == 2) { + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } + + if (!strcmp("width", type)) { + width = (unsigned int) value; + } + if (!strcmp("height", type)) { + height = (unsigned int) value; + } + } else { + if ( sscanf(fline, "static unsigned char %s = {", iname) == 1 + || sscanf(fline, "static char %s = {", iname) == 1) + { + max_bit = 128; + } else if (sscanf(fline, "static unsigned short %s = {", iname) == 1 + || sscanf(fline, "static short %s = {", iname) == 1) + { + max_bit = 32768; + } + if (max_bit) { + bytes = (width * height / 8) + 1; + if (!bytes) { + return 0; + } + if (!(type = strrchr(iname, '_'))) { + type = iname; + } else { + type++; + } + if (!strcmp("bits[]", type)) { + break; + } + } + } + } + if (!bytes || !max_bit) { + return 0; + } + + if(!(im = gdImageCreate(width, height))) { + return 0; + } + gdImageColorAllocate(im, 255, 255, 255); + gdImageColorAllocate(im, 0, 0, 0); + h[2] = '\0'; + h[4] = '\0'; + for (i = 0; i < bytes; i++) { + while (1) { + if ((ch=getc(fd)) == EOF) { + fail = 1; + break; + } + if (ch == 'x') { + break; + } + } + if (fail) { + break; + } + /* Get hex value */ + if ((ch=getc(fd)) == EOF) { + break; + } + h[0] = ch; + if ((ch=getc(fd)) == EOF) { + break; + } + h[1] = ch; + if (max_bit == 32768) { + if ((ch=getc(fd)) == EOF) { + break; + } + h[2] = ch; + if ((ch=getc(fd)) == EOF) { + break; + } + h[3] = ch; + } + sscanf(h, "%x", &b); + for (bit = 1; bit <= max_bit; bit = bit << 1) { + gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0); + if (x == im->sx) { + x = 0; + y++; + if (y == im->sy) { + return im; + } + break; + } + } + } + + php_gd_error("EOF before image was complete"); + gdImageDestroy(im); + return 0; +} +/* }}} */ + +/* {{{ gdCtxPrintf */ +void gdCtxPrintf(gdIOCtx * out, const char *format, ...) +{ + char *buf; + int len; + va_list args; + + va_start(args, format); + len = vspprintf(&buf, 0, format, args); + va_end(args); + out->putBuf(out, buf, len); + efree(buf); +} +/* }}} */ + +/* {{{ gdImageXbmCtx */ +void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) +{ + int x, y, c, b, sx, sy, p; + char *name, *f; + size_t i, l; + + name = file_name; + if ((f = strrchr(name, '/')) != NULL) name = f+1; + if ((f = strrchr(name, '\\')) != NULL) name = f+1; + name = estrdup(name); + if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; + if ((l = strlen(name)) == 0) { + efree(name); + name = estrdup("image"); + } else { + for (i=0; i<l; i++) { + /* only in C-locale isalnum() would work */ + if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { + name[i] = '_'; + } + } + } + + gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); + gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); + gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); + + efree(name); + + b = 1; + p = 0; + c = 0; + sx = gdImageSX(image); + sy = gdImageSY(image); + for (y = 0; y < sy; y++) { + for (x = 0; x < sx; x++) { + if (gdImageGetPixel(image, x, y) == fg) { + c |= b; + } + if ((b == 128) || (x == sx - 1)) { + b = 1; + if (p) { + gdCtxPrintf(out, ", "); + if (!(p%12)) { + gdCtxPrintf(out, "\n "); + p = 12; + } + } + p++; + gdCtxPrintf(out, "0x%02X", c); + c = 0; + } else { + b <<= 1; + } + } + } + gdCtxPrintf(out, "};\n"); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/ext/gd/libgd/mathmake.c b/ext/gd/libgd/mathmake.c deleted file mode 100644 index 3950c4b..0000000 --- a/ext/gd/libgd/mathmake.c +++ /dev/null @@ -1,52 +0,0 @@ -#include <stdio.h> -#include <math.h> - -#define scale 1024 - -int basis[91]; -int cost[360]; - -main (void) -{ - int i; - printf ("#define costScale %d\n", scale); - printf ("int cost[] = {\n "); - for (i = 0; (i <= 90); i++) - { - basis[i] = cos ((double) i * .0174532925) * scale; - } - for (i = 0; (i < 90); i++) - { - printf ("%d,\n ", cost[i] = basis[i]); - } - for (i = 90; (i < 180); i++) - { - printf ("%d,\n ", cost[i] = -basis[180 - i]); - } - for (i = 180; (i < 270); i++) - { - printf ("%d,\n ", cost[i] = -basis[i - 180]); - } - for (i = 270; (i < 359); i++) - { - printf ("%d,\n ", cost[i] = basis[360 - i]); - } - printf ("%d\n", cost[359] = basis[1]); - printf ("};\n"); - printf ("#define sintScale %d\n", scale); - printf ("int sint[] = {\n "); - for (i = 0; (i < 360); i++) - { - int val; - val = cost[(i + 270) % 360]; - if (i != 359) - { - printf ("%d,\n ", val); - } - else - { - printf ("%d\n", val); - } - } - printf ("};\n"); -} diff --git a/ext/gd/libgd/xbm.c b/ext/gd/libgd/xbm.c deleted file mode 100644 index b351814..0000000 --- a/ext/gd/libgd/xbm.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2016 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#include <stdio.h> -#include <math.h> -#include <string.h> -#include <stdlib.h> -#include "gd.h" -#include "gdhelpers.h" - -#include "php.h" - -#define MAX_XBM_LINE_SIZE 255 - -/* {{{ gdImagePtr gdImageCreateFromXbm */ -gdImagePtr gdImageCreateFromXbm(FILE * fd) -{ - char fline[MAX_XBM_LINE_SIZE]; - char iname[MAX_XBM_LINE_SIZE]; - char *type; - int value; - unsigned int width = 0, height = 0; - int fail = 0; - int max_bit = 0; - - gdImagePtr im; - int bytes = 0, i; - int bit, x = 0, y = 0; - int ch; - char h[8]; - unsigned int b; - - rewind(fd); - while (fgets(fline, MAX_XBM_LINE_SIZE, fd)) { - fline[MAX_XBM_LINE_SIZE-1] = '\0'; - if (strlen(fline) == MAX_XBM_LINE_SIZE-1) { - return 0; - } - if (sscanf(fline, "#define %s %d", iname, &value) == 2) { - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } - - if (!strcmp("width", type)) { - width = (unsigned int) value; - } - if (!strcmp("height", type)) { - height = (unsigned int) value; - } - } else { - if ( sscanf(fline, "static unsigned char %s = {", iname) == 1 - || sscanf(fline, "static char %s = {", iname) == 1) - { - max_bit = 128; - } else if (sscanf(fline, "static unsigned short %s = {", iname) == 1 - || sscanf(fline, "static short %s = {", iname) == 1) - { - max_bit = 32768; - } - if (max_bit) { - bytes = (width * height / 8) + 1; - if (!bytes) { - return 0; - } - if (!(type = strrchr(iname, '_'))) { - type = iname; - } else { - type++; - } - if (!strcmp("bits[]", type)) { - break; - } - } - } - } - if (!bytes || !max_bit) { - return 0; - } - - if(!(im = gdImageCreate(width, height))) { - return 0; - } - gdImageColorAllocate(im, 255, 255, 255); - gdImageColorAllocate(im, 0, 0, 0); - h[2] = '\0'; - h[4] = '\0'; - for (i = 0; i < bytes; i++) { - while (1) { - if ((ch=getc(fd)) == EOF) { - fail = 1; - break; - } - if (ch == 'x') { - break; - } - } - if (fail) { - break; - } - /* Get hex value */ - if ((ch=getc(fd)) == EOF) { - break; - } - h[0] = ch; - if ((ch=getc(fd)) == EOF) { - break; - } - h[1] = ch; - if (max_bit == 32768) { - if ((ch=getc(fd)) == EOF) { - break; - } - h[2] = ch; - if ((ch=getc(fd)) == EOF) { - break; - } - h[3] = ch; - } - sscanf(h, "%x", &b); - for (bit = 1; bit <= max_bit; bit = bit << 1) { - gdImageSetPixel(im, x++, y, (b & bit) ? 1 : 0); - if (x == im->sx) { - x = 0; - y++; - if (y == im->sy) { - return im; - } - break; - } - } - } - - php_gd_error("EOF before image was complete"); - gdImageDestroy(im); - return 0; -} -/* }}} */ - -/* {{{ gdCtxPrintf */ -void gdCtxPrintf(gdIOCtx * out, const char *format, ...) -{ - char *buf; - int len; - va_list args; - - va_start(args, format); - len = vspprintf(&buf, 0, format, args); - va_end(args); - out->putBuf(out, buf, len); - efree(buf); -} -/* }}} */ - -/* {{{ gdImageXbmCtx */ -void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out) -{ - int x, y, c, b, sx, sy, p; - char *name, *f; - size_t i, l; - - name = file_name; - if ((f = strrchr(name, '/')) != NULL) name = f+1; - if ((f = strrchr(name, '\\')) != NULL) name = f+1; - name = estrdup(name); - if ((f = strrchr(name, '.')) != NULL && !strcasecmp(f, ".XBM")) *f = '\0'; - if ((l = strlen(name)) == 0) { - efree(name); - name = estrdup("image"); - } else { - for (i=0; i<l; i++) { - /* only in C-locale isalnum() would work */ - if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) { - name[i] = '_'; - } - } - } - - gdCtxPrintf(out, "#define %s_width %d\n", name, gdImageSX(image)); - gdCtxPrintf(out, "#define %s_height %d\n", name, gdImageSY(image)); - gdCtxPrintf(out, "static unsigned char %s_bits[] = {\n ", name); - - efree(name); - - b = 1; - p = 0; - c = 0; - sx = gdImageSX(image); - sy = gdImageSY(image); - for (y = 0; y < sy; y++) { - for (x = 0; x < sx; x++) { - if (gdImageGetPixel(image, x, y) == fg) { - c |= b; - } - if ((b == 128) || (x == sx - 1)) { - b = 1; - if (p) { - gdCtxPrintf(out, ", "); - if (!(p%12)) { - gdCtxPrintf(out, "\n "); - p = 12; - } - } - p++; - gdCtxPrintf(out, "0x%02X", c); - c = 0; - } else { - b <<= 1; - } - } - } - gdCtxPrintf(out, "};\n"); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */