From: Wez Furlong Date: Sun, 21 Apr 2002 13:48:22 +0000 (+0000) Subject: Apply that patch I wrote ages ago that fixes some problems with true-color X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~515 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d1dc8141ce9a30d0fa5d04c76bb78c19f3c3b7b;p=php Apply that patch I wrote ages ago that fixes some problems with true-color vs palette based handling. Also implements the gdImageStringFTEx function. --- diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index 36413512d6..ec534855d6 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -1651,18 +1651,37 @@ gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int s if (dst->trueColor) { /* 2.0: much easier when the destination is truecolor. */ + + if (src->trueColor) { for (y = 0; (y < h); y++) { for (x = 0; (x < w); x++) { int c = gdImageGetTrueColorPixel (src, srcX + x, srcY + y); + gdImageSetPixel (dst, + dstX + x, + dstY + y, + c); + } + } + + } + else { + /* source is palette based */ + for (y = 0; (y < h); y++) + { + for (x = 0; (x < w); x++) + { + int c = gdImageGetPixel (src, srcX + x, + srcY + y); if (c != src->transparent) { gdImageSetPixel (dst, dstX + x, dstY + y, - c); + gdTrueColor(src->red[c], src->green[c], src->blue[c])); + } } } } diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h index 97cc9ad621..8dfb301e02 100644 --- a/ext/gd/libgd/gd.h +++ b/ext/gd/libgd/gd.h @@ -251,6 +251,19 @@ char *gdImageStringTTF(gdImage *im, int *brect, int fg, char *fontlist, char *gdImageStringFT(gdImage *im, int *brect, int fg, char *fontlist, double ptsize, double angle, int x, int y, char *string); +typedef struct { + int flags; /* for future expansion logical OR of gdFTEX_ values */ + double linespacing; /* fine tune line spacing for '\n' */ +} gdFTStringExtra, *gdFTStringExtraPtr; +#define gdFTEX_LINESPACE 1 + +/* FreeType 2 text output with fine tuning */ +char * +gdImageStringFTEx(gdImage * im, int *brect, int fg, char * fontlist, + double ptsize, double angle, int x, int y, char * string, + gdFTStringExtraPtr strex); + + /* Point type for use in polygon drawing. */ typedef struct { int x, y; diff --git a/ext/gd/libgd/gd_png.c b/ext/gd/libgd/gd_png.c index 4b281a08db..4cdbea44e6 100644 --- a/ext/gd/libgd/gd_png.c +++ b/ext/gd/libgd/gd_png.c @@ -225,7 +225,7 @@ gdImageCreateFromPngCtx (gdIOCtx * infile) im->alpha[i] = gdAlphaMax - (trans[i] >> 1); if ((trans[i] == 0) && (firstZero)) { - im->transparent = i; + transparent = i; firstZero = 0; } } diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c index d3dea0caa8..f2937b45d7 100644 --- a/ext/gd/libgd/gdft.c +++ b/ext/gd/libgd/gdft.c @@ -513,7 +513,8 @@ tweenColorFetch (char **error, void *key) gdTrueColorGetRed (fg), gdTrueColorGetGreen (fg), gdTrueColorGetBlue (fg), - gdAlphaMax - (gdTrueColorGetAlpha (fg) * pixel / NUMCOLORS)); + gdAlphaMax - ((gdAlphaMax - gdTrueColorGetAlpha (fg)) * pixel / NUMCOLORS) + ); } else { @@ -566,76 +567,53 @@ gdft_draw_bitmap (gdImage * im, int fg, FT_Bitmap bitmap, int pen_x, int pen_y) for (col = 0; col < bitmap.width; col++, pc++) { - if (bitmap.pixel_mode == ft_pixel_mode_grays) - { + x = pen_x + col; + + /* clip if out of bounds */ + if (x >= im->sx || x < 0) + continue; + + switch(bitmap.pixel_mode) { + case ft_pixel_mode_grays: /* * Round to NUMCOLORS levels of antialiasing for * index color images since only 256 colors are * available. */ + tc_key.pixel = ((bitmap.buffer[pc] * NUMCOLORS) + bitmap.num_grays / 2) / (bitmap.num_grays - 1); - } - else if (bitmap.pixel_mode == ft_pixel_mode_mono) - { + break; + case ft_pixel_mode_mono: tc_key.pixel = ((bitmap.buffer[pc / 8] << (pc % 8)) & 128) ? NUMCOLORS : 0; - } - else - { + break; + default: return "Unsupported ft_pixel_mode"; } if (tc_key.pixel > 0) - { /* if not background */ - x = pen_x + col; - - /* clip if out of bounds */ - if (x >= im->sx || x < 0) - continue; - /* get pixel location in gd buffer */ - if (im->trueColor) { - tpixel = &im->tpixels[y][x]; + + if (im->trueColor) { + tc_elem = (tweencolor_t *) gdCacheGet ( + tc_cache, &tc_key); + + gdImageSetPixel(im, x, y, tc_elem->tweencolor); } - else - { + else { pixel = &im->pixels[y][x]; - } if (tc_key.pixel == NUMCOLORS) - { - /* use fg color directly */ - if (im->trueColor) - { - *tpixel = fg; - } - else - { *pixel = fg; - } - } - else - { - /* find antialised color */ - if (im->trueColor) - { - tc_key.bgcolor = *tpixel; - } - else - { + else { tc_key.bgcolor = *pixel; - } tc_elem = (tweencolor_t *) gdCacheGet ( tc_cache, &tc_key); - if (im->trueColor) - { - *tpixel = tc_elem->tweencolor; - } - else - { *pixel = tc_elem->tweencolor; + } + } } } @@ -647,10 +625,17 @@ extern int any2eucjp (char *, char *, unsigned int); /********************************************************************/ /* 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) +{ + return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, NULL); +} + +char * +gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, + double ptsize, double angle, int x, int y, char *string, + gdFTStringExtra * strex) { FT_BBox bbox, glyph_bbox; FT_Matrix matrix; @@ -672,6 +657,9 @@ gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, int render = (im && (im->trueColor || (fg <= 255 && fg >= -255))); FT_BitmapGlyph bm; + /* fine tuning */ + double linespace = LINESPACE; + /***** initialize font library and font cache on first call ******/ static gdCache_head_t *fontCache; static FT_Library library; @@ -704,6 +692,14 @@ gdImageStringFT (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; @@ -754,7 +750,7 @@ gdImageStringFT (gdImage * im, int *brect, int fg, char *fontlist, /* newlines */ if (ch == '\n') { - penf.y -= face->size->metrics.height * LINESPACE; + penf.y -= face->size->metrics.height * linespace; penf.y = (penf.y - 32) & -64; /* round to next pixel row */ x1 = (penf.x * cos_a - penf.y * sin_a + 32) / 64; y1 = (penf.x * sin_a + penf.y * cos_a + 32) / 64; diff --git a/ext/gd/libgd/webpng.c b/ext/gd/libgd/webpng.c index 8065acc5cd..f3c35e306f 100644 --- a/ext/gd/libgd/webpng.c +++ b/ext/gd/libgd/webpng.c @@ -168,12 +168,12 @@ main (int argc, char **argv) t = gdImageGetTransparent (im); if (t != (-1)) { - printf ("First 100% transparent index: %d\n", t); + printf ("First 100%% transparent index: %d\n", t); } else { /* -1 means the image is not transparent. */ - printf ("First 100% transparent index: none\n"); + printf ("First 100%% transparent index: none\n"); } if (gdImageGetInterlaced (im)) { @@ -185,6 +185,40 @@ main (int argc, char **argv) } no = 0; } + else if (!strcmp(argv[i], "-a")) + { + int maxx, maxy, x, y, alpha, pix, nalpha = 0; + + maxx = gdImageSX(im); + maxy = gdImageSY(im); + + printf("alpha channel information:\n"); + + if (im->trueColor) { + for (y = 0; y < maxy; y++) { + for (x = 0; x < maxx; x++) { + pix = gdImageGetPixel(im, x, y); + alpha = gdTrueColorGetAlpha(pix); + + if (alpha > gdAlphaOpaque) { + /* Use access macros to learn colors. */ + printf ("%d %d %d %d\n", + gdTrueColorGetRed(pix), + gdTrueColorGetGreen(pix), + gdTrueColorGetBlue(pix), + alpha); + nalpha++; + } + + } + } + } + else + printf("NOT a true color image\n"); + no = 0; + printf("%d alpha channels\n", nalpha); + + } else { fprintf (stderr, "Unknown argument: %s\n", argv[i]); @@ -202,6 +236,7 @@ usage: " -l Prints the table of color indexes\n" " -t [index] Set the transparent color to the specified index (0-255 or \"none\")\n" " -d Reports the dimensions and other characteristics of the image.\n" + " -a Prints all alpha channels that are not 100%% opaque.\n" "\n" "If you specify '-' as the input file, stdin/stdout will be used input/output.\n" );