CVS update: php3/functions
| From: | shane | Date: | Sun, 13 Sep 1998 04:58:03 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-1023@lists.php.net to get a copy of this message | ||
Date: Sunday September 13, 1998 @ 0:58
Author: shane
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv13876/functions
Modified Files:
gdttf.c
Log Message:
a couple fixes. Where did gdImageColorResolve go?
Index: php3/functions/gdttf.c
diff -c php3/functions/gdttf.c:1.13 php3/functions/gdttf.c:1.14
*** php3/functions/gdttf.c:1.13 Thu Sep 3 11:44:28 1998
--- php3/functions/gdttf.c Sun Sep 13 00:58:03 1998
***************
*** 135,141 ****
--- 135,193 ----
char *gdttfchar(gdImage *im, int fg, font_t *font, int x, int y, TT_F26Dot6 x1, TT_F26Dot6 y1,
TT_F26Dot6 *advance, TT_BBox **bbox, char **next);
/* This prototype is missing from gd.h */
+ /* FIXME Since when does GD have this function??? My copy of 1.3 doesnt
int gdImageColorResolve(gdImagePtr im, int r, int g, int b);
+ */
+
+ /********************************************************************/
+ /* gdImageColorResolve is a replacement for the old fragment: */
+ /* */
+ /* if ((color=gdImageColorExact(im,R,G,B)) < 0) */
+ /* if ((color=gdImageColorAllocate(im,R,G,B)) < 0) */
+ /* color=gdImageColorClosest(im,R,G,B); */
+ /* */
+ /* in a single function */
+
+ static int
+ gdImageColorResolve(gdImagePtr im, int r, int g, int b)
+ {
+ int c;
+ int ct = -1;
+ int op = -1;
+ long rd, gd, bd, dist;
+ long mindist = 3*255*255; /* init to max poss dist */
+
+ for (c = 0; c < im->colorsTotal; c++) {
+ if (im->open[c]) {
+ op = c; /* Save open slot */
+ continue; /* Color not in use */
+ }
+ rd = (long)(im->red [c] - r);
+ gd = (long)(im->green[c] - g);
+ bd = (long)(im->blue [c] - b);
+ dist = rd * rd + gd * gd + bd * bd;
+ if (dist < mindist) {
+ if (dist == 0) {
+ return c; /* Return exact match color */
+ }
+ mindist = dist;
+ ct = c;
+ }
+ }
+ /* no exact match. We now know closest, but first try to allocate exact */
+ if (op == -1) {
+ op = im->colorsTotal;
+ if (op == gdMaxColors) { /* No room for more colors */
+ return ct; /* Return closest available color */
+ }
+ im->colorsTotal++;
+ }
+ im->red [op] = r;
+ im->green[op] = g;
+ im->blue [op] = b;
+ im->open [op] = 0;
+ return op; /* Return newly allocated color */
+ }
/********************************************************************
* gdTcl_UtfToUniChar is borrowed from ...
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net