mirror of
https://github.com/php/php-src.git
synced 2026-04-27 18:23:26 +02:00
Synchronized bundled gd with gd 2.0.11 (bug fixes).
MFH 1) Use Zend allocation macros instead of native allocation functions. 2) Better error reporting mechanism. 3) Some style fixes, which allow easier code synchronization & maintenance.
This commit is contained in:
+201
-147
File diff suppressed because it is too large
Load Diff
+6
-4
@@ -36,6 +36,8 @@
|
||||
* sizes of a few tens of elements.
|
||||
*/
|
||||
|
||||
#include "php.h"
|
||||
|
||||
/* This just seems unessacary */
|
||||
#if PHP_WIN32
|
||||
#define ENABLE_GD_TTF
|
||||
@@ -61,7 +63,7 @@ gdCacheCreate(
|
||||
{
|
||||
gdCache_head_t *head;
|
||||
|
||||
head = (gdCache_head_t *)malloc(sizeof(gdCache_head_t));
|
||||
head = (gdCache_head_t *)pemalloc(sizeof(gdCache_head_t), 1);
|
||||
head->mru = NULL;
|
||||
head->size = size;
|
||||
head->gdCacheTest = gdCacheTest;
|
||||
@@ -80,9 +82,9 @@ gdCacheDelete( gdCache_head_t *head )
|
||||
(*(head->gdCacheRelease))(elem->userdata);
|
||||
prev = elem;
|
||||
elem = elem->next;
|
||||
free((char *)prev);
|
||||
pefree((char *)prev, 1);
|
||||
}
|
||||
free((char *)head);
|
||||
pefree((char *)head, 1);
|
||||
}
|
||||
|
||||
void *
|
||||
@@ -114,7 +116,7 @@ gdCacheGet( gdCache_head_t *head, void *keydata )
|
||||
return NULL;
|
||||
}
|
||||
if (i < head->size) { /* cache still growing - add new elem */
|
||||
elem = (gdCache_element_t *)malloc(sizeof(gdCache_element_t));
|
||||
elem = (gdCache_element_t *)pemalloc(sizeof(gdCache_element_t), 1);
|
||||
}
|
||||
else { /* cache full - replace least-recently-used */
|
||||
/* preveprev becomes new end of list */
|
||||
|
||||
+23
-19
@@ -334,15 +334,16 @@ fontFetch ( char **error, void *key )
|
||||
short platform, encoding;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
a = (font_t *)malloc(sizeof(font_t));
|
||||
a = (font_t *)pemalloc(sizeof(font_t), 1);
|
||||
#ifdef VIRTUAL_DIR
|
||||
/* a->fontname will be freed in fontRelease() later on */
|
||||
if (virtual_filepath(b->fontname, &a->fontname TSRMLS_CC)) {
|
||||
*error = "Could not find/open font";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
a->fontname = (char *)malloc(strlen(b->fontname) + 1);
|
||||
a->fontname = (char *)pemalloc(strlen(b->fontname) + 1, 1);
|
||||
strcpy(a->fontname, b->fontname);
|
||||
#endif
|
||||
a->ptsize = b->ptsize;
|
||||
@@ -357,6 +358,7 @@ fontFetch ( char **error, void *key )
|
||||
else {
|
||||
*error = "Could not read font";
|
||||
}
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
/* get face properties and allocate preload arrays */
|
||||
@@ -365,20 +367,19 @@ fontFetch ( char **error, void *key )
|
||||
/* create instance */
|
||||
if (TT_New_Instance(a->face, &a->instance)) {
|
||||
*error = "Could not create face instance";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (TT_Set_Instance_Resolutions(a->instance, RESOLUTION, RESOLUTION)) {
|
||||
*error = "Could not set device resolutions";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
map_found = 0;
|
||||
a->have_char_map_Unicode = 0;
|
||||
a->have_char_map_Big5 = 0;
|
||||
a->have_char_map_Roman = 0;
|
||||
}
|
||||
|
||||
if (TT_Set_Instance_CharSize(a->instance, (TT_F26Dot6)(a->ptsize*64))) {
|
||||
*error = "Could not set character size";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -403,13 +404,14 @@ a->have_char_map_Roman = 0;
|
||||
TT_Get_CharMap(a->face, i, &a->char_map_Roman);
|
||||
a->have_char_map_Roman = 1;
|
||||
map_found++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! map_found) {
|
||||
*error = "Unable to find a CharMap that I can handle";
|
||||
return NULL;
|
||||
}
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
a->matrix.xx = (TT_Fixed) (a->cos_a * (1<<16));
|
||||
a->matrix.yx = (TT_Fixed) (a->sin_a * (1<<16));
|
||||
@@ -430,8 +432,8 @@ fontRelease( void *element )
|
||||
gdCacheDelete(a->glyphCache);
|
||||
TT_Done_Instance(a->instance);
|
||||
TT_Close_Face(a->face);
|
||||
free(a->fontname);
|
||||
free( (char *)element );
|
||||
pefree(a->fontname, 1);
|
||||
pefree((char *)element, 1);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
@@ -458,7 +460,7 @@ glyphFetch ( char **error, void *key )
|
||||
int crect[8], xmin, xmax, ymin, ymax;
|
||||
double cos_a, sin_a;
|
||||
|
||||
a = (glyph_t *)malloc(sizeof(glyph_t));
|
||||
a = (glyph_t *)pemalloc(sizeof(glyph_t), 1);
|
||||
a->character = b->character;
|
||||
a->hinting = b->hinting;
|
||||
a->gray_render = b->gray_render;
|
||||
@@ -467,6 +469,7 @@ glyphFetch ( char **error, void *key )
|
||||
/* create glyph container */
|
||||
if ((TT_New_Glyph(b->font->face, &a->glyph))) {
|
||||
*error = "Could not create glyph container";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -483,6 +486,7 @@ glyphFetch ( char **error, void *key )
|
||||
}
|
||||
if ((err=TT_Load_Glyph(b->font->instance, a->glyph, glyph_code, flags))) {
|
||||
*error = "TT_Load_Glyph problem";
|
||||
pefree(a, 1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -540,7 +544,7 @@ glyphRelease( void *element )
|
||||
|
||||
gdCacheDelete(a->bitmapCache);
|
||||
TT_Done_Glyph( a->glyph );
|
||||
free( (char *)element );
|
||||
pefree ((char *)element, 1);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
@@ -565,11 +569,11 @@ bitmapFetch ( char **error, void *key )
|
||||
bitmap_t *a;
|
||||
bitmapkey_t *b=(bitmapkey_t *)key;
|
||||
|
||||
a = (bitmap_t *)malloc(sizeof(bitmap_t));
|
||||
a = (bitmap_t *)pemalloc(sizeof(bitmap_t), 1);
|
||||
a->xoffset = b->xoffset;
|
||||
a->yoffset = b->yoffset;
|
||||
|
||||
b->glyph->Bit.bitmap = a->bitmap = (char *)malloc(b->glyph->Bit.size);
|
||||
b->glyph->Bit.bitmap = a->bitmap = (char *)pemalloc(b->glyph->Bit.size, 1);
|
||||
memset(a->bitmap, 0, b->glyph->Bit.size);
|
||||
/* render glyph */
|
||||
if (b->glyph->gray_render) {
|
||||
@@ -588,8 +592,8 @@ bitmapRelease( void *element )
|
||||
{
|
||||
bitmap_t *a=(bitmap_t *)element;
|
||||
|
||||
free( a->bitmap );
|
||||
free( (char *)element );
|
||||
pefree (a->bitmap, 1);
|
||||
pefree ((char *)element, 1);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
@@ -615,7 +619,7 @@ tweenColorFetch (char **error, void *key)
|
||||
int pixel, npixel, bg, fg;
|
||||
gdImagePtr im;
|
||||
|
||||
a = (tweencolor_t *)malloc(sizeof(tweencolor_t));
|
||||
a = (tweencolor_t *)pemalloc(sizeof(tweencolor_t), 1);
|
||||
pixel = a->pixel = b->pixel;
|
||||
bg = a->bgcolor = b->bgcolor;
|
||||
fg = a->fgcolor = b->fgcolor;
|
||||
@@ -638,7 +642,7 @@ tweenColorFetch (char **error, void *key)
|
||||
static void
|
||||
tweenColorRelease(void *element)
|
||||
{
|
||||
free((char *)element);
|
||||
pefree((char *)element, 1);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
+801
-656
File diff suppressed because it is too large
Load Diff
+13
-1
@@ -30,6 +30,11 @@ extern "C" {
|
||||
#include <stdio.h>
|
||||
#include "gd_io.h"
|
||||
|
||||
void php_gd_error_ex(int type, const char *format, ...);
|
||||
|
||||
void php_gd_error(const char *format, ...);
|
||||
|
||||
|
||||
/* The maximum number of palette entries in palette-based images.
|
||||
In the wonderful new world of gd 2.0, you can of course have
|
||||
many more colors when using truecolor mode. */
|
||||
@@ -136,6 +141,8 @@ typedef struct gdImageStruct {
|
||||
To do that, build your image as a truecolor image,
|
||||
then quantize down to 8 bits. */
|
||||
int alphaBlendingFlag;
|
||||
/* Should antialias functions be used */
|
||||
int antialias;
|
||||
/* Should the alpha channel of the image be saved? This affects
|
||||
PNG at the moment; other future formats may also
|
||||
have that capability. JPEG doesn't. */
|
||||
@@ -239,6 +246,7 @@ void gdImageSetPixel(gdImagePtr im, int x, int y, int color);
|
||||
int gdImageGetPixel(gdImagePtr im, int x, int y);
|
||||
|
||||
void gdImageLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
void gdImageAALine(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
|
||||
/* For backwards compatibility only. Use gdImageSetStyle()
|
||||
for much more flexible line drawing. */
|
||||
@@ -248,7 +256,6 @@ void gdImageDashedLine(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
|
||||
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
/* Solid bar. Upper left corner first, lower right corner second. */
|
||||
void gdImageFilledRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color);
|
||||
int gdImageBoundsSafe(gdImagePtr im, int x, int y);
|
||||
void gdImageChar(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
|
||||
void gdImageCharUp(gdImagePtr im, gdFontPtr f, int x, int y, int c, int color);
|
||||
void gdImageString(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s, int color);
|
||||
@@ -300,6 +307,8 @@ int gdImageColorClosest(gdImagePtr im, int r, int g, int b);
|
||||
beats the exact same color with radically different
|
||||
transparency */
|
||||
int gdImageColorClosestAlpha(gdImagePtr im, int r, int g, int b, int a);
|
||||
/* An alternate method */
|
||||
int gdImageColorClosestHWB(gdImagePtr im, int r, int g, int b);
|
||||
/* Returns exact, 100% opaque matches only */
|
||||
int gdImageColorExact(gdImagePtr im, int r, int g, int b);
|
||||
/* Returns an exact match only, including alpha */
|
||||
@@ -472,6 +481,7 @@ void gdImageSetThickness(gdImagePtr im, int thickness);
|
||||
/* On or off (1 or 0) for all three of these. */
|
||||
void gdImageInterlace(gdImagePtr im, int interlaceArg);
|
||||
void gdImageAlphaBlending(gdImagePtr im, int alphaBlendingArg);
|
||||
void gdImageAntialias(gdImagePtr im, int antialias);
|
||||
void gdImageSaveAlpha(gdImagePtr im, int saveAlphaArg);
|
||||
|
||||
/* Macros to access information about images. */
|
||||
@@ -539,4 +549,6 @@ int gdImageCompare(gdImagePtr im1, gdImagePtr im2);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define gdImageBoundsSafe(im, x, y) (!(y < 0 || y >= (im)->sy || x < 0 || x >= (im)->sx))
|
||||
|
||||
#endif /* GD_H */
|
||||
|
||||
@@ -726,12 +726,12 @@ main (int argc, char *argv[])
|
||||
out = fopen ("test/arctest.png", "wb");
|
||||
if (!out)
|
||||
{
|
||||
fprintf (stderr, "Can't create test/arctest.png\n");
|
||||
php_gd_error("Can't create test/arctest.png\n");
|
||||
exit (1);
|
||||
}
|
||||
gdImagePng (im, out);
|
||||
fclose (out);
|
||||
fprintf (stderr, "Test image written to test/arctest.png\n");
|
||||
php_gd_error("Test image written to test/arctest.png\n");
|
||||
/* Destroy it */
|
||||
gdImageDestroy (im);
|
||||
|
||||
|
||||
+576
-665
File diff suppressed because it is too large
Load Diff
+22
-15
@@ -4,6 +4,8 @@
|
||||
#include <stdlib.h>
|
||||
#include "gd.h"
|
||||
|
||||
#include "php.h"
|
||||
|
||||
/* Used only when debugging GIF compression code */
|
||||
/* #define DEBUGGING_ENVARS */
|
||||
|
||||
@@ -290,19 +292,24 @@ GetDataBlock_(gdIOCtx *fd, unsigned char *buf)
|
||||
static int
|
||||
GetDataBlock(gdIOCtx *fd, unsigned char *buf)
|
||||
{
|
||||
int rv;
|
||||
int i;
|
||||
|
||||
rv = GetDataBlock_(fd,buf);
|
||||
if (VERBOSE)
|
||||
{ printf("[GetDataBlock returning %d",rv);
|
||||
if (rv > 0)
|
||||
{ printf(":");
|
||||
for (i=0;i<rv;i++) printf(" %02x",buf[i]);
|
||||
}
|
||||
printf("]\n");
|
||||
}
|
||||
return(rv);
|
||||
int rv;
|
||||
int i;
|
||||
char *tmp = NULL;
|
||||
|
||||
rv = GetDataBlock_(fd,buf);
|
||||
if (VERBOSE) {
|
||||
if (rv > 0) {
|
||||
tmp = emalloc((3*sizeof(char)*rv) + 1);
|
||||
for (i=0;i<rv;i++) {
|
||||
sprintf(&tmp[3*sizeof(char)*i], " %02x", buf[i]);
|
||||
}
|
||||
} else {
|
||||
tmp = estrdup("");
|
||||
}
|
||||
php_gd_error_ex(E_NOTICE, "[GetDataBlock returning %d: %s]", rv, tmp);
|
||||
efree(tmp);
|
||||
}
|
||||
return(rv);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -352,7 +359,7 @@ GetCode(gdIOCtx *fd, int code_size, int flag)
|
||||
int rv;
|
||||
|
||||
rv = GetCode_(fd,code_size,flag);
|
||||
if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
|
||||
if (VERBOSE) php_gd_error_ex(E_NOTICE, "[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
|
||||
return(rv);
|
||||
}
|
||||
|
||||
@@ -484,7 +491,7 @@ LWZReadByte(gdIOCtx *fd, int flag, int input_code_size)
|
||||
int rv;
|
||||
|
||||
rv = LWZReadByte_(fd,flag,input_code_size);
|
||||
if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
|
||||
if (VERBOSE) php_gd_error_ex(E_NOTICE, "[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
|
||||
return(rv);
|
||||
}
|
||||
|
||||
|
||||
+334
-485
File diff suppressed because it is too large
Load Diff
+46
-57
@@ -7,8 +7,8 @@
|
||||
/* JCE: Arrange HAVE_LIBPNG so that it can be set in gd.h */
|
||||
#ifdef HAVE_LIBPNG
|
||||
|
||||
#include "gdhelpers.h"
|
||||
#include "png.h" /* includes zlib.h and setjmp.h */
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
@@ -59,15 +59,12 @@ gdPngErrorHandler (png_structp png_ptr, png_const_charp msg)
|
||||
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||
* been defined. */
|
||||
|
||||
fprintf (stderr, "gd-png: fatal libpng error: %s\n", msg);
|
||||
fflush (stderr);
|
||||
php_gd_error_ex(E_ERROR, "gd-png: fatal libpng error: %s\n", msg);
|
||||
|
||||
jmpbuf_ptr = png_get_error_ptr (png_ptr);
|
||||
if (jmpbuf_ptr == NULL)
|
||||
{ /* we are completely hosed now */
|
||||
fprintf (stderr,
|
||||
"gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
|
||||
fflush (stderr);
|
||||
php_gd_error_ex(E_ERROR, "gd-png: EXTREMELY fatal error: jmpbuf unrecoverable; terminating.\n");
|
||||
exit (99);
|
||||
}
|
||||
|
||||
@@ -116,7 +113,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
png_byte sig[8];
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
png_uint_32 width, height, rowbytes;
|
||||
png_uint_32 width, height, rowbytes, w, h;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
int num_palette, num_trans;
|
||||
png_colorp palette;
|
||||
@@ -127,7 +124,6 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
png_bytepp row_pointers = NULL;
|
||||
gdImagePtr im = NULL;
|
||||
int i, j, *open = NULL;
|
||||
png_uint_32 ui, uj;
|
||||
volatile int transparent = -1;
|
||||
volatile int palette_allocated = FALSE;
|
||||
|
||||
@@ -149,14 +145,14 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
|
||||
php_gd_error("gd-png error: cannot allocate libpng main struct\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
|
||||
php_gd_error("gd-png error: cannot allocate libpng info struct\n");
|
||||
png_destroy_read_struct (&png_ptr, NULL, NULL);
|
||||
return NULL;
|
||||
}
|
||||
@@ -170,7 +166,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
if (setjmp (gdPngJmpbufStruct.jmpbuf))
|
||||
{
|
||||
fprintf (stderr, "gd-png error: setjmp returns error condition\n");
|
||||
php_gd_error("gd-png error: setjmp returns error condition\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
@@ -194,7 +190,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
}
|
||||
if (im == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate gdImage struct\n");
|
||||
php_gd_error("gd-png error: cannot allocate gdImage struct\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
gdFree (image_data);
|
||||
gdFree (row_pointers);
|
||||
@@ -210,7 +206,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
png_get_PLTE (png_ptr, info_ptr, &palette, &num_palette);
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "gd-png color_type is palette, colors: %d\n",
|
||||
php_gd_error("gd-png color_type is palette, colors: %d\n",
|
||||
num_palette);
|
||||
#endif /* DEBUG */
|
||||
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
@@ -227,7 +223,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
im->alpha[i] = gdAlphaMax - (trans[i] >> 1);
|
||||
if ((trans[i] == 0) && (firstZero))
|
||||
{
|
||||
transparent = i;
|
||||
transparent = i;
|
||||
firstZero = 0;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +235,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
/* create a fake palette and check for single-shade transparency */
|
||||
if ((palette = (png_colorp) gdMalloc (256 * sizeof (png_color))) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate gray palette\n");
|
||||
php_gd_error("gd-png error: cannot allocate gray palette\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
@@ -307,22 +303,22 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
rowbytes = png_get_rowbytes (png_ptr, info_ptr);
|
||||
if ((image_data = (png_bytep) gdMalloc (rowbytes * height)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate image data\n");
|
||||
php_gd_error("gd-png error: cannot allocate image data\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
return NULL;
|
||||
}
|
||||
if ((row_pointers = (png_bytepp) gdMalloc (height * sizeof (png_bytep))) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate row pointers\n");
|
||||
php_gd_error("gd-png error: cannot allocate row pointers\n");
|
||||
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
|
||||
gdFree (image_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* set the individual row_pointers to point at the correct offsets */
|
||||
for (uj = 0; uj < height; ++uj)
|
||||
for (h = 0; h < height; ++h)
|
||||
{
|
||||
row_pointers[uj] = image_data + uj * rowbytes;
|
||||
row_pointers[h] = image_data + h * rowbytes;
|
||||
}
|
||||
|
||||
png_read_image (png_ptr, row_pointers); /* read whole image... */
|
||||
@@ -353,44 +349,44 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
switch (color_type)
|
||||
{
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
for (uj = 0; uj < height; uj++)
|
||||
for (h = 0; h < height; h++)
|
||||
{
|
||||
int boffset = 0;
|
||||
for (ui = 0; ui < width; ui++)
|
||||
for (w = 0; w < width; w++)
|
||||
{
|
||||
register png_byte r = row_pointers[uj][boffset++];
|
||||
register png_byte g = row_pointers[uj][boffset++];
|
||||
register png_byte b = row_pointers[uj][boffset++];
|
||||
im->tpixels[uj][ui] = gdTrueColor (r, g, b);
|
||||
register png_byte r = row_pointers[h][boffset++];
|
||||
register png_byte g = row_pointers[h][boffset++];
|
||||
register png_byte b = row_pointers[h][boffset++];
|
||||
im->tpixels[h][w] = gdTrueColor (r, g, b);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||
for (uj = 0; uj < height; uj++)
|
||||
for (h = 0; h < height; h++)
|
||||
{
|
||||
int boffset = 0;
|
||||
for (ui = 0; ui < width; ui++)
|
||||
for (w = 0; w < width; w++)
|
||||
{
|
||||
register png_byte r = row_pointers[uj][boffset++];
|
||||
register png_byte g = row_pointers[uj][boffset++];
|
||||
register png_byte b = row_pointers[uj][boffset++];
|
||||
register png_byte r = row_pointers[h][boffset++];
|
||||
register png_byte g = row_pointers[h][boffset++];
|
||||
register png_byte b = row_pointers[h][boffset++];
|
||||
/* gd has only 7 bits of alpha channel resolution, and
|
||||
127 is transparent, 0 opaque. A moment of convenience,
|
||||
a lifetime of compatibility. */
|
||||
register png_byte a = gdAlphaMax -
|
||||
(row_pointers[uj][boffset++] >> 1);
|
||||
im->tpixels[uj][ui] = gdTrueColorAlpha (r, g, b, a);
|
||||
(row_pointers[h][boffset++] >> 1);
|
||||
im->tpixels[h][w] = gdTrueColorAlpha (r, g, b, a);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* Palette image, or something coerced to be one */
|
||||
for (uj = 0; uj < height; ++uj)
|
||||
for (h = 0; h < height; ++h)
|
||||
{
|
||||
for (ui = 0; ui < width; ++ui)
|
||||
for (w = 0; w < width; ++w)
|
||||
{
|
||||
register png_byte idx = row_pointers[uj][ui];
|
||||
im->pixels[uj][ui] = idx;
|
||||
register png_byte idx = row_pointers[h][w];
|
||||
im->pixels[h][w] = idx;
|
||||
open[idx] = 0;
|
||||
}
|
||||
}
|
||||
@@ -402,7 +398,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile)
|
||||
{
|
||||
if (!open[i])
|
||||
{
|
||||
fprintf (stderr, "gd-png warning: image data references out-of-range"
|
||||
php_gd_error("gd-png warning: image data references out-of-range"
|
||||
" color index (%d)\n", i);
|
||||
}
|
||||
}
|
||||
@@ -467,14 +463,14 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng main struct\n");
|
||||
php_gd_error("gd-png error: cannot allocate libpng main struct\n");
|
||||
return;
|
||||
}
|
||||
|
||||
info_ptr = png_create_info_struct (png_ptr);
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: cannot allocate libpng info struct\n");
|
||||
php_gd_error("gd-png error: cannot allocate libpng info struct\n");
|
||||
png_destroy_write_struct (&png_ptr, (png_infopp) NULL);
|
||||
return;
|
||||
}
|
||||
@@ -482,7 +478,7 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
#ifndef PNG_SETJMP_NOT_SUPPORTED
|
||||
if (setjmp (gdPngJmpbufStruct.jmpbuf))
|
||||
{
|
||||
fprintf (stderr, "gd-png error: setjmp returns error condition\n");
|
||||
php_gd_error("gd-png error: setjmp returns error condition\n");
|
||||
png_destroy_write_struct (&png_ptr, &info_ptr);
|
||||
return;
|
||||
}
|
||||
@@ -565,9 +561,10 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
}
|
||||
if (im->trueColor && (!im->saveAlphaFlag) && (transparent >= 0))
|
||||
{
|
||||
trans_rgb_value.red = gdTrueColorGetRed (im->trueColor);
|
||||
trans_rgb_value.green = gdTrueColorGetGreen (im->trueColor);
|
||||
trans_rgb_value.blue = gdTrueColorGetBlue (im->trueColor);
|
||||
/* 2.0.9: fixed by Thomas Winzig */
|
||||
trans_rgb_value.red = gdTrueColorGetRed (im->transparent);
|
||||
trans_rgb_value.green = gdTrueColorGetGreen (im->transparent);
|
||||
trans_rgb_value.blue = gdTrueColorGetBlue (im->transparent);
|
||||
png_set_tRNS (png_ptr, info_ptr, 0, 0, &trans_rgb_value);
|
||||
}
|
||||
if (!im->trueColor)
|
||||
@@ -596,7 +593,7 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
{
|
||||
trans_values[i] = 255 -
|
||||
((im->alpha[i] << 1) +
|
||||
(im->alpha[i] >> 7));
|
||||
(im->alpha[i] >> 6));
|
||||
}
|
||||
png_set_tRNS (png_ptr, info_ptr, trans_values, 256, NULL);
|
||||
#endif
|
||||
@@ -615,9 +612,10 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
{
|
||||
if (im->alpha[i] != gdAlphaOpaque)
|
||||
{
|
||||
/* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
|
||||
trans_values[j] = 255 -
|
||||
((im->alpha[i] << 1) +
|
||||
(im->alpha[i] >> 7));
|
||||
(im->alpha[i] >> 6));
|
||||
mapping[i] = j++;
|
||||
}
|
||||
else
|
||||
@@ -670,20 +668,10 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
/* Our little 7-bit alpha channel trick costs us a bit here. */
|
||||
png_bytep *row_pointers;
|
||||
row_pointers = gdMalloc (sizeof (png_bytep) * height);
|
||||
if (row_pointers == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: unable to allocate row_pointers\n");
|
||||
}
|
||||
for (j = 0; j < height; ++j)
|
||||
{
|
||||
int bo = 0;
|
||||
if ((row_pointers[j] = (png_bytep) gdMalloc (width * channels)) == NULL)
|
||||
{
|
||||
fprintf (stderr, "gd-png error: unable to allocate rows\n");
|
||||
for (i = 0; i < j; ++i)
|
||||
gdFree (row_pointers[i]);
|
||||
return;
|
||||
}
|
||||
row_pointers[j] = (png_bytep) gdMalloc (width * channels);
|
||||
for (i = 0; i < width; ++i)
|
||||
{
|
||||
unsigned char a;
|
||||
@@ -698,7 +686,8 @@ gdImagePngCtx (gdImagePtr im, gdIOCtx * outfile)
|
||||
127 maps to 255. We also have to invert to match
|
||||
PNG's convention in which 255 is opaque. */
|
||||
a = gdTrueColorGetAlpha (im->tpixels[j][i]);
|
||||
row_pointers[j][bo++] = 255 - ((a << 1) + (a >> 7));
|
||||
/* Andrew Hull: >> 6, not >> 7! (gd 2.0.5) */
|
||||
row_pointers[j][bo++] = 255 - ((a << 1) + (a >> 6));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ gdImageCreateFromPngSource (gdSourcePtr inSource)
|
||||
void
|
||||
gdImagePngToSink (gdImagePtr im, gdSinkPtr outSink)
|
||||
{
|
||||
fprintf(stderr,"PNG support is not available\n");
|
||||
php_gd_error("PNG support is not available\n");
|
||||
}
|
||||
gdImagePtr
|
||||
gdImageCreateFromPngSource (gdSourcePtr inSource)
|
||||
{
|
||||
fprintf(stderr,"PNG support is not available\n");
|
||||
php_gd_error("PNG support is not available\n");
|
||||
return NULL;
|
||||
}
|
||||
#endif /* HAVE_LIBPNG */
|
||||
|
||||
@@ -1626,7 +1626,7 @@ gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
|
||||
return -3; /* the images are meant to be the same dimensions */
|
||||
}
|
||||
|
||||
buf = (unsigned long *)malloc( sizeof(unsigned long) * 5 * im2->colorsTotal );
|
||||
buf = (unsigned long *)gdMalloc( sizeof(unsigned long) * 5 * im2->colorsTotal );
|
||||
memset( buf, 0, sizeof(unsigned long) * 5 * im2->colorsTotal );
|
||||
|
||||
for( x=0; x<im1->sx; x++ ) {
|
||||
@@ -1653,6 +1653,6 @@ gdImageColorMatch (gdImagePtr im1, gdImagePtr im2)
|
||||
bp += 4;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
gdFree(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
void
|
||||
gd_putout (int i, void *out)
|
||||
{
|
||||
gdPutC ((unsigned char)i, (gdIOCtx *) out);
|
||||
gdPutC (i, (gdIOCtx *) out);
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
|
||||
|
||||
/* create the WBMP */
|
||||
if ((wbmp = createwbmp (gdImageSX (image), gdImageSY (image), WBMP_WHITE)) == NULL)
|
||||
fprintf (stderr, "Could not create WBMP\n");
|
||||
php_gd_error("Could not create WBMP\n");
|
||||
|
||||
/* fill up the WBMP structure */
|
||||
pos = 0;
|
||||
@@ -123,7 +123,7 @@ gdImageWBMPCtx (gdImagePtr image, int fg, gdIOCtx * out)
|
||||
|
||||
/* write the WBMP to a gd file descriptor */
|
||||
if (writewbmp (wbmp, &gd_putout, out))
|
||||
fprintf (stderr, "Could not save WBMP\n");
|
||||
php_gd_error("Could not save WBMP\n");
|
||||
/* des submitted this bugfix: gdFree the memory. */
|
||||
freewbmp (wbmp);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ gdCacheCreate (
|
||||
{
|
||||
gdCache_head_t *head;
|
||||
|
||||
head = (gdCache_head_t *) gdMalloc (sizeof (gdCache_head_t));
|
||||
head = (gdCache_head_t *) gdPMalloc(sizeof (gdCache_head_t));
|
||||
head->mru = NULL;
|
||||
head->size = size;
|
||||
head->gdCacheTest = gdCacheTest;
|
||||
@@ -86,9 +86,9 @@ gdCacheDelete (gdCache_head_t * head)
|
||||
(*(head->gdCacheRelease)) (elem->userdata);
|
||||
prev = elem;
|
||||
elem = elem->next;
|
||||
gdFree ((char *) prev);
|
||||
gdPFree ((char *) prev);
|
||||
}
|
||||
gdFree ((char *) head);
|
||||
gdPFree ((char *) head);
|
||||
}
|
||||
|
||||
void *
|
||||
@@ -125,7 +125,7 @@ gdCacheGet (gdCache_head_t * head, void *keydata)
|
||||
}
|
||||
if (i < head->size)
|
||||
{ /* cache still growing - add new elem */
|
||||
elem = (gdCache_element_t *) gdMalloc (sizeof (gdCache_element_t));
|
||||
elem = (gdCache_element_t *) gdPMalloc(sizeof (gdCache_element_t));
|
||||
}
|
||||
else
|
||||
{ /* cache full - replace least-recently-used */
|
||||
|
||||
+189
-162
@@ -19,24 +19,37 @@
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
extern int access(const char *pathname, int mode);
|
||||
#define access _access
|
||||
#ifndef R_OK
|
||||
#define R_OK 2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* number of antialised colors for indexed bitmaps */
|
||||
/* overwrite Windows GDI define in case of windows build */
|
||||
#ifdef NUMCOLORS
|
||||
#undef NUMCOLORS
|
||||
#endif
|
||||
#define NUMCOLORS 8
|
||||
|
||||
char *
|
||||
gdImageStringTTF (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y, char *string)
|
||||
{
|
||||
/* 2.0.6: valid return */
|
||||
return gdImageStringFT (im, brect, fg, fontlist, ptsize,
|
||||
angle, x, y, string);
|
||||
}
|
||||
|
||||
#ifndef HAVE_LIBFREETYPE
|
||||
char *
|
||||
gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y, char *string,
|
||||
gdFTStringExtraPtr strex)
|
||||
{
|
||||
return "libgd was not built with FreeType font support\n";
|
||||
}
|
||||
|
||||
char *
|
||||
gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y, char *string)
|
||||
@@ -86,8 +99,13 @@ gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
#define TRUE !FALSE
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -330,159 +348,161 @@ fontTest (void *element, void *key)
|
||||
return (strcmp (a->fontlist, b->fontlist) == 0);
|
||||
}
|
||||
|
||||
static void *
|
||||
fontFetch (char **error, void *key)
|
||||
static void *fontFetch (char **error, void *key)
|
||||
{
|
||||
font_t *a;
|
||||
fontkey_t *b = (fontkey_t *) key;
|
||||
int n;
|
||||
int font_found = 0;
|
||||
unsigned short platform, encoding;
|
||||
char *fontsearchpath, *fontlist;
|
||||
char *fullname = NULL;
|
||||
char *name, *path, *dir;
|
||||
char *strtok_ptr;
|
||||
FT_Error err;
|
||||
FT_CharMap found = 0;
|
||||
FT_CharMap charmap;
|
||||
font_t *a;
|
||||
fontkey_t *b = (fontkey_t *) key;
|
||||
int n;
|
||||
int font_found = 0;
|
||||
unsigned short platform, encoding;
|
||||
char *fontsearchpath, *fontlist;
|
||||
char *fullname = NULL;
|
||||
char *name, *path=NULL, *dir;
|
||||
char *strtok_ptr;
|
||||
FT_Error err;
|
||||
FT_CharMap found = 0;
|
||||
FT_CharMap charmap;
|
||||
|
||||
a = (font_t *) gdMalloc (sizeof (font_t));
|
||||
a->fontlist = strdup (b->fontlist);
|
||||
a->library = b->library;
|
||||
a = (font_t *) gdPMalloc(sizeof(font_t));
|
||||
a->fontlist = gdPEstrdup(b->fontlist);
|
||||
a->library = b->library;
|
||||
|
||||
/*
|
||||
* Search the pathlist for any of a list of font names.
|
||||
*/
|
||||
fontsearchpath = getenv ("GDFONTPATH");
|
||||
if (!fontsearchpath)
|
||||
fontsearchpath = DEFAULT_FONTPATH;
|
||||
fontlist = strdup (a->fontlist);
|
||||
/*
|
||||
* Search the pathlist for any of a list of font names.
|
||||
*/
|
||||
fontsearchpath = getenv ("GDFONTPATH");
|
||||
if (!fontsearchpath) {
|
||||
fontsearchpath = DEFAULT_FONTPATH;
|
||||
}
|
||||
fontlist = gdEstrdup(a->fontlist);
|
||||
|
||||
/*
|
||||
* Must use gd_strtok_r else pointer corrupted by strtok in nested loop.
|
||||
*/
|
||||
for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name;
|
||||
name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr))
|
||||
{
|
||||
|
||||
/* make a fresh copy each time - strtok corrupts it. */
|
||||
path = strdup (fontsearchpath);
|
||||
/*
|
||||
* Allocate an oversized buffer that is guaranteed to be
|
||||
* big enough for all paths to be tested.
|
||||
*/
|
||||
fullname = gdRealloc (fullname,
|
||||
strlen (fontsearchpath) + strlen (name) + 6);
|
||||
/* if name is an absolute filename then test directly */
|
||||
if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\')))
|
||||
{
|
||||
sprintf (fullname, "%s", name);
|
||||
if (access (fullname, R_OK) == 0)
|
||||
{
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Must use gd_strtok_r else pointer corrupted by strtok in nested loop.
|
||||
*/
|
||||
for (name = gd_strtok_r (fontlist, LISTSEPARATOR, &strtok_ptr); name; name = gd_strtok_r (0, LISTSEPARATOR, &strtok_ptr)) {
|
||||
/* make a fresh copy each time - strtok corrupts it. */
|
||||
path = gdEstrdup (fontsearchpath);
|
||||
|
||||
/*
|
||||
* Allocate an oversized buffer that is guaranteed to be
|
||||
* big enough for all paths to be tested.
|
||||
*/
|
||||
fullname = gdRealloc (fullname, strlen (fontsearchpath) + strlen (name) + 6);
|
||||
|
||||
/* if name is an absolute filename then test directly */
|
||||
if (*name == '/' || (name[0] != 0 && name[1] == ':' && (name[2] == '/' || name[2] == '\\'))) {
|
||||
sprintf(fullname, "%s", name);
|
||||
if (access(fullname, R_OK) == 0) {
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (dir = strtok (path, PATHSEPARATOR); dir; dir = strtok (0, PATHSEPARATOR)) {
|
||||
sprintf(fullname, "%s/%s", dir, name);
|
||||
if (access (fullname, R_OK) == 0) {
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
sprintf(fullname, "%s/%s.ttf", dir, name);
|
||||
if (access (fullname, R_OK) == 0) {
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
sprintf(fullname, "%s/%s.pfa", dir, name);
|
||||
if (access(fullname, R_OK) == 0) {
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
sprintf (fullname, "%s/%s.pfb", dir, name);
|
||||
if (access(fullname, R_OK) == 0) {
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
gdFree(path);
|
||||
path = NULL;
|
||||
if (font_found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (dir = strtok (path, PATHSEPARATOR); dir;
|
||||
dir = strtok (0, PATHSEPARATOR))
|
||||
{
|
||||
sprintf (fullname, "%s/%s", dir, name);
|
||||
if (access (fullname, R_OK) == 0)
|
||||
{
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
sprintf (fullname, "%s/%s.ttf", dir, name);
|
||||
if (access (fullname, R_OK) == 0)
|
||||
{
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
sprintf (fullname, "%s/%s.pfa", dir, name);
|
||||
if (access (fullname, R_OK) == 0)
|
||||
{
|
||||
font_found++;
|
||||
break;
|
||||
|
||||
if (path) {
|
||||
gdFree(path);
|
||||
}
|
||||
sprintf (fullname, "%s/%s.pfb", dir, name);
|
||||
if (access (fullname, R_OK) == 0)
|
||||
{
|
||||
font_found++;
|
||||
break;
|
||||
}
|
||||
|
||||
gdFree(fontlist);
|
||||
|
||||
if (!font_found) {
|
||||
gdPFree(a->fontlist);
|
||||
gdPFree(a);
|
||||
if (fullname) {
|
||||
gdFree(fullname);
|
||||
}
|
||||
*error = "Could not find/open font";
|
||||
return NULL;
|
||||
}
|
||||
gdFree (path);
|
||||
if (font_found)
|
||||
break;
|
||||
}
|
||||
gdFree (fontlist);
|
||||
if (!font_found)
|
||||
{
|
||||
*error = "Could not find/open font";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
err = FT_New_Face (*b->library, fullname, 0, &a->face);
|
||||
if (err)
|
||||
{
|
||||
*error = "Could not read font";
|
||||
return NULL;
|
||||
}
|
||||
gdFree (fullname);
|
||||
err = FT_New_Face (*b->library, fullname, 0, &a->face);
|
||||
if (err) {
|
||||
gdPFree(a->fontlist);
|
||||
gdPFree(a);
|
||||
if (fullname) {
|
||||
gdFree(fullname);
|
||||
}
|
||||
*error = "Could not read font";
|
||||
return NULL;
|
||||
}
|
||||
gdFree(fullname);
|
||||
|
||||
/* FIXME - This mapping stuff is imcomplete - where is the spec? */
|
||||
/* FIXME - This mapping stuff is imcomplete - where is the spec? */
|
||||
|
||||
a->have_char_map_unicode = 0;
|
||||
a->have_char_map_big5 = 0;
|
||||
a->have_char_map_sjis = 0;
|
||||
a->have_char_map_apple_roman = 0;
|
||||
for (n = 0; n < a->face->num_charmaps; n++)
|
||||
{
|
||||
charmap = a->face->charmaps[n];
|
||||
platform = charmap->platform_id;
|
||||
encoding = charmap->encoding_id;
|
||||
if ((platform == 3 && encoding == 1) /* Windows Unicode */
|
||||
|| (platform == 3 && encoding == 0) /* Windows Symbol */
|
||||
|| (platform == 2 && encoding == 1) /* ISO Unicode */
|
||||
|| (platform == 0))
|
||||
{ /* Apple Unicode */
|
||||
a->have_char_map_unicode = 1;
|
||||
found = charmap;
|
||||
a->have_char_map_unicode = 0;
|
||||
a->have_char_map_big5 = 0;
|
||||
a->have_char_map_sjis = 0;
|
||||
a->have_char_map_apple_roman = 0;
|
||||
for (n = 0; n < a->face->num_charmaps; n++) {
|
||||
charmap = a->face->charmaps[n];
|
||||
platform = charmap->platform_id;
|
||||
encoding = charmap->encoding_id;
|
||||
if ((platform == 3 && encoding == 1) /* Windows Unicode */
|
||||
|| (platform == 3 && encoding == 0) /* Windows Symbol */
|
||||
|| (platform == 2 && encoding == 1) /* ISO Unicode */
|
||||
|| (platform == 0))
|
||||
{ /* Apple Unicode */
|
||||
a->have_char_map_unicode = 1;
|
||||
found = charmap;
|
||||
} else if (platform == 3 && encoding == 4) { /* Windows Big5 */
|
||||
a->have_char_map_big5 = 1;
|
||||
found = charmap;
|
||||
} else if (platform == 3 && encoding == 2) { /* Windows Sjis */
|
||||
a->have_char_map_sjis = 1;
|
||||
found = charmap;
|
||||
} else if ((platform == 1 && encoding == 0) /* Apple Roman */
|
||||
|| (platform == 2 && encoding == 0))
|
||||
{ /* ISO ASCII */
|
||||
a->have_char_map_apple_roman = 1;
|
||||
found = charmap;
|
||||
}
|
||||
}
|
||||
else if (platform == 3 && encoding == 4)
|
||||
{ /* Windows Big5 */
|
||||
a->have_char_map_big5 = 1;
|
||||
found = charmap;
|
||||
if (!found) {
|
||||
gdPFree(a->fontlist);
|
||||
gdPFree(a);
|
||||
*error = "Unable to find a CharMap that I can handle";
|
||||
return NULL;
|
||||
}
|
||||
else if (platform == 3 && encoding == 2)
|
||||
{ /* Windows Sjis */
|
||||
a->have_char_map_sjis = 1;
|
||||
found = charmap;
|
||||
}
|
||||
else if ((platform == 1 && encoding == 0) /* Apple Roman */
|
||||
|| (platform == 2 && encoding == 0))
|
||||
{ /* ISO ASCII */
|
||||
a->have_char_map_apple_roman = 1;
|
||||
found = charmap;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
*error = "Unable to find a CharMap that I can handle";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (void *) a;
|
||||
/* 2.0.5: we should actually return this */
|
||||
a->face->charmap = found;
|
||||
return (void *) a;
|
||||
}
|
||||
|
||||
static void
|
||||
fontRelease (void *element)
|
||||
static void fontRelease (void *element)
|
||||
{
|
||||
font_t *a = (font_t *) element;
|
||||
font_t *a = (font_t *) element;
|
||||
|
||||
FT_Done_Face (a->face);
|
||||
gdFree (a->fontlist);
|
||||
gdFree ((char *) element);
|
||||
FT_Done_Face (a->face);
|
||||
gdPFree(a->fontlist);
|
||||
gdPFree((char *) element);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
@@ -570,7 +590,7 @@ gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitm
|
||||
{
|
||||
unsigned char *pixel = NULL;
|
||||
int *tpixel = NULL;
|
||||
int x, y, row, col, pc;
|
||||
int x, y, row, col, pc, pcr;
|
||||
|
||||
tweencolor_t *tc_elem;
|
||||
tweencolorkey_t tc_key;
|
||||
@@ -584,6 +604,7 @@ gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitm
|
||||
for (row = 0; row < bitmap.rows; row++)
|
||||
{
|
||||
pc = row * bitmap.pitch;
|
||||
pcr = pc;
|
||||
y = pen_y + row;
|
||||
/* clip if out of bounds */
|
||||
if (y >= im->sy || y < 0)
|
||||
@@ -602,17 +623,20 @@ gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitm
|
||||
}
|
||||
else if (bitmap.pixel_mode == ft_pixel_mode_mono)
|
||||
{
|
||||
level = ((bitmap.buffer[pc / 8]
|
||||
<< (pc % 8)) & 128) ? gdAlphaOpaque :
|
||||
gdAlphaTransparent;
|
||||
/* 2.0.5: mode_mono fix from Giuliano Pochini */
|
||||
level = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
|
||||
? gdAlphaTransparent :
|
||||
gdAlphaOpaque;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Unsupported ft_pixel_mode";
|
||||
}
|
||||
if (fg >= 0) {
|
||||
if ((fg >= 0) && (im->trueColor)) {
|
||||
/* Consider alpha in the foreground color itself to be an
|
||||
upper bound on how opaque things get */
|
||||
upper bound on how opaque things get, when truecolor is
|
||||
available. Without truecolor this results in far too many
|
||||
color indexes. */
|
||||
level = level * (gdAlphaMax - gdTrueColorGetAlpha(fg)) / gdAlphaMax;
|
||||
}
|
||||
level = gdAlphaMax - level;
|
||||
@@ -640,7 +664,9 @@ gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitm
|
||||
/* Non-truecolor case, restored to its more or less original form */
|
||||
for (row = 0; row < bitmap.rows; row++)
|
||||
{
|
||||
int pcr;
|
||||
pc = row * bitmap.pitch;
|
||||
pcr = pc;
|
||||
if(bitmap.pixel_mode==ft_pixel_mode_mono)
|
||||
pc *= 8; /* pc is measured in bits for monochrome images */
|
||||
|
||||
@@ -667,6 +693,9 @@ gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg, FT_Bitmap bitm
|
||||
{
|
||||
tc_key.pixel = ((bitmap.buffer[pc / 8]
|
||||
<< (pc % 8)) & 128) ? NUMCOLORS : 0;
|
||||
/* 2.0.5: mode_mono fix from Giuliano Pochini */
|
||||
tc_key.pixel = ((bitmap.buffer[(col>>3)+pcr]) & (1<<(~col&0x07)))
|
||||
? NUMCOLORS : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -729,17 +758,19 @@ gdFreeFontCache()
|
||||
|
||||
/********************************************************************/
|
||||
/* gdImageStringFT - render a utf8 string onto a gd image */
|
||||
|
||||
char *
|
||||
gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y, char *string)
|
||||
double ptsize, double angle, int x, int y, char *string)
|
||||
{
|
||||
return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, NULL);
|
||||
return gdImageStringFTEx(im, brect, fg, fontlist,
|
||||
ptsize, angle, x, y, string, 0);
|
||||
}
|
||||
|
||||
char *
|
||||
gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
double ptsize, double angle, int x, int y, char *string,
|
||||
gdFTStringExtra * strex)
|
||||
gdFTStringExtraPtr strex)
|
||||
{
|
||||
FT_BBox bbox, glyph_bbox;
|
||||
FT_Matrix matrix;
|
||||
@@ -761,10 +792,9 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
int render = (im && (im->trueColor || (fg <= 255 && fg >= -255)));
|
||||
FT_BitmapGlyph bm;
|
||||
int render_mode = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT;
|
||||
|
||||
/* fine tuning */
|
||||
/* Now tuneable thanks to Wez Furlong */
|
||||
double linespace = LINESPACE;
|
||||
|
||||
/* 2.0.6: put this declaration with the other declarations! */
|
||||
/*
|
||||
* make a new tweenColorCache on every call
|
||||
* because caching colormappings between calls
|
||||
@@ -774,6 +804,11 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
*/
|
||||
gdCache_head_t *tc_cache;
|
||||
|
||||
if (strex) {
|
||||
if ((strex->flags & gdFTEX_LINESPACE) == gdFTEX_LINESPACE) {
|
||||
linespace = strex->linespacing;
|
||||
}
|
||||
}
|
||||
tc_cache = gdCacheCreate( TWEENCOLORCACHESIZE,
|
||||
tweenColorTest, tweenColorFetch, tweenColorRelease );
|
||||
|
||||
@@ -810,12 +845,6 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
return "Could not set character size";
|
||||
}
|
||||
|
||||
/* pull in supplied extended settings */
|
||||
if (strex) {
|
||||
if ((strex->flags & gdFTEX_LINESPACE) == gdFTEX_LINESPACE)
|
||||
linespace = strex->linespacing;
|
||||
}
|
||||
|
||||
matrix.xx = (FT_Fixed) (cos_a * (1 << 16));
|
||||
matrix.yx = (FT_Fixed) (sin_a * (1 << 16));
|
||||
matrix.xy = -matrix.yx;
|
||||
@@ -860,8 +889,8 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
if (ch == '\r')
|
||||
{
|
||||
penf.x = 0;
|
||||
x1 = (int)((penf.x * cos_a - penf.y * sin_a + 32.0) / 64.0);
|
||||
y1 = (int)((penf.x * sin_a + penf.y * cos_a + 32.0) / 64.0);
|
||||
x1 = (int)(penf.x * cos_a - penf.y * sin_a + 32) / 64;
|
||||
y1 = (int)(penf.x * sin_a + penf.y * cos_a + 32) / 64;
|
||||
pen.x = pen.y = 0;
|
||||
previous = 0; /* clear kerning flag */
|
||||
next++;
|
||||
@@ -870,10 +899,10 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
/* newlines */
|
||||
if (ch == '\n')
|
||||
{
|
||||
penf.y = penf.y - (int)(face->size->metrics.height * LINESPACE);
|
||||
penf.y -= (long)(face->size->metrics.height * linespace);
|
||||
penf.y = (penf.y - 32) & -64; /* round to next pixel row */
|
||||
x1 = (int)((penf.x * cos_a - penf.y * sin_a + 32.0) / 64.0);
|
||||
y1 = (int)((penf.x * sin_a + penf.y * cos_a + 32.0) / 64.0);
|
||||
x1 = (int)(penf.x * cos_a - penf.y * sin_a + 32) / 64;
|
||||
y1 = (int)(penf.x * sin_a + penf.y * cos_a + 32) / 64;
|
||||
pen.x = pen.y = 0;
|
||||
previous = 0; /* clear kerning flag */
|
||||
next++;
|
||||
@@ -936,10 +965,8 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist,
|
||||
next++;
|
||||
}
|
||||
}
|
||||
|
||||
/* set rotation transform */
|
||||
FT_Set_Transform(face, &matrix, NULL);
|
||||
|
||||
/* Convert character code to glyph index */
|
||||
glyph_index = FT_Get_Char_Index (face, ch);
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "php.h"
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
#include <stdlib.h>
|
||||
@@ -76,27 +74,3 @@ gd_strtok_r (char *s, char *sep, char **state)
|
||||
*state = s;
|
||||
return result;
|
||||
}
|
||||
|
||||
void *
|
||||
gdCalloc (size_t nmemb, size_t size)
|
||||
{
|
||||
return calloc (nmemb, size);
|
||||
}
|
||||
|
||||
void *
|
||||
gdMalloc (size_t size)
|
||||
{
|
||||
return malloc (size);
|
||||
}
|
||||
|
||||
void *
|
||||
gdRealloc (void *ptr, size_t size)
|
||||
{
|
||||
return realloc (ptr, size);
|
||||
}
|
||||
|
||||
void
|
||||
gdFree (void *ptr)
|
||||
{
|
||||
free (ptr);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define GDHELPERS_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "php.h"
|
||||
|
||||
/* TBB: strtok_r is not universal; provide an implementation of it. */
|
||||
|
||||
@@ -11,10 +12,14 @@ extern char *gd_strtok_r(char *s, char *sep, char **state);
|
||||
in gd.h, where callers can utilize it to correctly
|
||||
free memory allocated by these functions with the
|
||||
right version of free(). */
|
||||
void *gdCalloc(size_t nmemb, size_t size);
|
||||
void *gdMalloc(size_t size);
|
||||
void *gdRealloc(void *ptr, size_t size);
|
||||
char *gdEstrdup(const char *ptr);
|
||||
#define gdCalloc(nmemb, size) ecalloc(nmemb, size)
|
||||
#define gdMalloc(size) emalloc(size)
|
||||
#define gdRealloc(ptr, size) erealloc(ptr, size)
|
||||
#define gdEstrdup(ptr) estrdup(ptr)
|
||||
#define gdFree(ptr) efree(ptr)
|
||||
#define gdPMalloc(ptr) pemalloc(ptr, 1)
|
||||
#define gdPFree(ptr) pefree(ptr, 1)
|
||||
#define gdPEstrdup(ptr) pestrdup(ptr, 1)
|
||||
|
||||
#endif /* GDHELPERS_H */
|
||||
|
||||
|
||||
@@ -72,13 +72,15 @@ debug (const char *format,...)
|
||||
static void
|
||||
error (const char *format,...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start (args, format);
|
||||
fprintf (stderr, "%s: ", LIBNAME);
|
||||
vfprintf (stderr, format, args);
|
||||
fprintf (stderr, "\n");
|
||||
va_end (args);
|
||||
va_list args;
|
||||
char *tmp;
|
||||
TSRMLS_FETCH();
|
||||
|
||||
va_start(args, format);
|
||||
vspprintf(&tmp, 0, format, args);
|
||||
va_end(args);
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s: %s", LIBNAME, tmp);
|
||||
efree(tmp);
|
||||
}
|
||||
|
||||
/* DetectKanjiCode() derived from DetectCodeType() by Ken Lunde. */
|
||||
|
||||
+4
-16
@@ -7,21 +7,13 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "gd.h"
|
||||
#include "gdhelpers.h"
|
||||
|
||||
#ifndef HAVE_XPM
|
||||
gdImagePtr
|
||||
gdImageCreateFromXpm (char *filename)
|
||||
{
|
||||
fprintf (stderr, "libgd was not built with xpm support\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#else
|
||||
#ifdef HAVE_XPM
|
||||
|
||||
#include <X11/xpm.h>
|
||||
#include <string.h>
|
||||
|
||||
gdImagePtr
|
||||
gdImageCreateFromXpm (char *filename)
|
||||
@@ -46,8 +38,6 @@ gdImageCreateFromXpm (char *filename)
|
||||
|
||||
number = image.ncolors;
|
||||
colors = (int *) gdMalloc (sizeof (int) * number);
|
||||
if (colors == NULL)
|
||||
return (0);
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
switch (strlen (image.colorTable[i].c_color))
|
||||
@@ -125,15 +115,13 @@ gdImageCreateFromXpm (char *filename)
|
||||
|
||||
colors[i] = gdImageColorResolve (im, red, green, blue);
|
||||
if (colors[i] == -1)
|
||||
fprintf (stderr, "ARRRGH\n");
|
||||
php_gd_error("ARRRGH\n");
|
||||
}
|
||||
|
||||
apixel = (char *) gdMalloc (image.cpp + 1);
|
||||
if (apixel == NULL)
|
||||
return (0);
|
||||
apixel[image.cpp] = '\0';
|
||||
|
||||
pointer = image.data;
|
||||
pointer = (int *) image.data;
|
||||
for (i = 0; i < image.height; i++)
|
||||
{
|
||||
for (j = 0; j < image.width; j++)
|
||||
|
||||
+9
-4
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
+----------------------------------------------------------------------+
|
||||
| PHP Version 4 |
|
||||
+----------------------------------------------------------------------+
|
||||
@@ -58,11 +58,14 @@ extern zend_module_entry gd_module_entry;
|
||||
PHP_MINFO_FUNCTION(gd);
|
||||
PHP_MINIT_FUNCTION(gd);
|
||||
PHP_MSHUTDOWN_FUNCTION(gd);
|
||||
PHP_RSHUTDOWN_FUNCTION(gd);
|
||||
|
||||
PHP_FUNCTION(gd_info);
|
||||
PHP_FUNCTION(imagearc);
|
||||
PHP_FUNCTION(imageellipse);
|
||||
PHP_FUNCTION(imagechar);
|
||||
PHP_FUNCTION(imagecharup);
|
||||
PHP_FUNCTION(imageistruecolor);
|
||||
PHP_FUNCTION(imagecolorallocate);
|
||||
PHP_FUNCTION(imagepalettecopy);
|
||||
PHP_FUNCTION(imagecolorat);
|
||||
@@ -83,26 +86,27 @@ PHP_FUNCTION(imagecreate);
|
||||
PHP_FUNCTION(imageftbbox);
|
||||
PHP_FUNCTION(imagefttext);
|
||||
|
||||
#ifdef HAVE_LIBGD20
|
||||
PHP_FUNCTION(imagecreatetruecolor);
|
||||
PHP_FUNCTION(imageistruecolor);
|
||||
PHP_FUNCTION(imagetruecolortopalette);
|
||||
PHP_FUNCTION(imagesetthickness);
|
||||
PHP_FUNCTION(imageellipse);
|
||||
PHP_FUNCTION(imagefilledellipse);
|
||||
PHP_FUNCTION(imagefilledarc);
|
||||
PHP_FUNCTION(imagealphablending);
|
||||
PHP_FUNCTION(imagesavealpha);
|
||||
PHP_FUNCTION(imagecolorallocatealpha);
|
||||
PHP_FUNCTION(imagecolorresolvealpha);
|
||||
PHP_FUNCTION(imagecolorclosestalpha);
|
||||
PHP_FUNCTION(imagecolorexactalpha);
|
||||
PHP_FUNCTION(imagecopyresampled);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GD_BUNDLED
|
||||
PHP_FUNCTION(imagerotate);
|
||||
PHP_FUNCTION(imageantialias);
|
||||
#endif
|
||||
|
||||
PHP_FUNCTION(imagesetthickness);
|
||||
PHP_FUNCTION(imagesettile);
|
||||
PHP_FUNCTION(imagecopymergegray);
|
||||
PHP_FUNCTION(imagesetbrush);
|
||||
PHP_FUNCTION(imagesettile);
|
||||
@@ -168,6 +172,7 @@ PHP_FUNCTION(image2wbmp);
|
||||
#if HAVE_GD_BUNDLED
|
||||
PHP_FUNCTION(imagelayereffect);
|
||||
PHP_FUNCTION(imagecolormatch);
|
||||
PHP_FUNCTION(imagefilter);
|
||||
#endif
|
||||
|
||||
PHP_GD_API int phpi_get_le_gd(void);
|
||||
|
||||
Reference in New Issue
Block a user