static void
gdImageBrushApply (gdImagePtr im, int x, int y)
{
- int lx, ly;
- int hy;
- int hx;
- int x1, y1, x2, y2;
- int srcx, srcy;
- if (!im->brush)
- {
- return;
- }
- hy = gdImageSY (im->brush) / 2;
- y1 = y - hy;
- y2 = y1 + gdImageSY (im->brush);
- hx = gdImageSX (im->brush) / 2;
- x1 = x - hx;
- x2 = x1 + gdImageSX (im->brush);
- srcy = 0;
- if (im->trueColor)
- {
- for (ly = y1; (ly < y2); ly++)
- {
- srcx = 0;
- for (lx = x1; (lx < x2); lx++)
- {
- int p;
- p = gdImageGetTrueColorPixel (
- im->brush, srcx, srcy);
- gdImageSetPixel (im, lx, ly,
- p);
- srcx++;
- }
- srcy++;
+ int lx, ly;
+ int hy, hx;
+ int x1, y1, x2, y2;
+ int srcx, srcy;
+
+ if (!im->brush) {
+ return;
}
- }
- else
- {
- for (ly = y1; (ly < y2); ly++)
- {
- srcx = 0;
- for (lx = x1; (lx < x2); lx++)
- {
- int p;
- p = gdImageGetPixel (im->brush, srcx, srcy);
- /* Allow for non-square brushes! */
- if (p != gdImageGetTransparent (im->brush))
- {
- /* Truecolor brush. Very slow
- on a palette destination. */
- if (im->brush->trueColor)
- {
- gdImageSetPixel (im, lx, ly,
- gdImageColorResolveAlpha (
- im,
- gdTrueColorGetRed (p),
- gdTrueColorGetGreen (p),
- gdTrueColorGetBlue (p),
- gdTrueColorGetAlpha (p)));
- }
- else
- {
- gdImageSetPixel (im, lx, ly,
- im->brushColorMap[p]);
- }
+
+ hy = gdImageSY (im->brush) / 2;
+ y1 = y - hy;
+ y2 = y1 + gdImageSY (im->brush);
+ hx = gdImageSX (im->brush) / 2;
+ x1 = x - hx;
+ x2 = x1 + gdImageSX (im->brush);
+ srcy = 0;
+
+ if (im->trueColor) {
+ for (ly = y1; (ly < y2); ly++) {
+ srcx = 0;
+ for (lx = x1; (lx < x2); lx++) {
+ int p;
+ p = gdImageGetTrueColorPixel (im->brush, srcx, srcy);
+ /* 2.0.9, Thomas Winzig: apply simple full transparency */
+ if (p != gdImageGetTransparent (im->brush)) {
+ gdImageSetPixel (im, lx, ly, p);
+ }
+ srcx++;
+ }
+ srcy++;
+ }
+ } else {
+ for (ly = y1; (ly < y2); ly++) {
+ srcx = 0;
+ for (lx = x1; (lx < x2); lx++) {
+ int p;
+ p = gdImageGetPixel (im->brush, srcx, srcy);
+ /* Allow for non-square brushes! */
+ if (p != gdImageGetTransparent (im->brush)) {
+ /* Truecolor brush. Very slow on a palette destination. */
+ if (im->brush->trueColor) {
+ gdImageSetPixel(im, lx, ly, gdImageColorResolveAlpha(im, gdTrueColorGetRed(p),
+ gdTrueColorGetGreen(p),
+ gdTrueColorGetBlue(p),
+ gdTrueColorGetAlpha(p)));
+ } else {
+ gdImageSetPixel(im, lx, ly, im->brushColorMap[p]);
+ }
+ }
+ srcx++;
+ }
+ srcy++;
}
- srcx++;
- }
- srcy++;
}
- }
}
static void
void
gdImageCopyResized (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
{
- int c;
- int x, y;
- int tox, toy;
- int ydest;
- int i;
- int colorMap[gdMaxColors];
- /* Stretch vectors */
- int *stx;
- int *sty;
- /* We only need to use floating point to determine the correct
- stretch vector for one line's worth. */
- double accum;
- stx = (int *) gdMalloc (sizeof (int) * srcW);
- sty = (int *) gdMalloc (sizeof (int) * srcH);
- accum = 0;
- for (i = 0; (i < srcW); i++)
- {
- int got;
- accum += (double) dstW / (double) srcW;
- got = (int) floor (accum);
- stx[i] = got;
- accum -= got;
- }
- accum = 0;
- for (i = 0; (i < srcH); i++)
- {
- int got;
- accum += (double) dstH / (double) srcH;
- got = (int) floor (accum);
- sty[i] = got;
- accum -= got;
- }
- for (i = 0; (i < gdMaxColors); i++)
- {
- colorMap[i] = (-1);
- }
- toy = dstY;
- for (y = srcY; (y < (srcY + srcH)); y++)
- {
- for (ydest = 0; (ydest < sty[y - srcY]); ydest++)
- {
- tox = dstX;
- for (x = srcX; (x < (srcX + srcW)); x++)
- {
- int nc = 0;
- int mapTo;
- if (!stx[x - srcX])
- {
- continue;
- }
- if (dst->trueColor)
- {
- mapTo = gdImageGetTrueColorPixel (src, x, y);
- /* Added 7/24/95: support transparent copies */
- if (gdImageGetTransparent (src) == mapTo)
- {
- tox++;
- continue;
- }
- }
- else
- {
- c = gdImageGetPixel (src, x, y);
- /* Added 7/24/95: support transparent copies */
- if (gdImageGetTransparent (src) == c)
- {
- tox += stx[x - srcX];
- continue;
- }
- if (src->trueColor)
- {
- /* Remap to the palette available in the
- destination image. This is slow and
- works badly. */
- mapTo = gdImageColorResolveAlpha (dst,
- gdTrueColorGetRed (c),
- gdTrueColorGetGreen (c),
- gdTrueColorGetBlue (c),
- gdTrueColorGetAlpha (c));
- }
- else
- {
- /* Have we established a mapping for this color? */
- if (colorMap[c] == (-1))
- {
- /* If it's the same image, mapping is trivial */
- if (dst == src)
- {
- nc = c;
- }
- else
- {
- /* Find or create the best match */
- /* 2.0.5: can't use gdTrueColorGetRed, etc with palette */
- nc = gdImageColorResolveAlpha (dst,
- gdImageRed (src, c),
- gdImageGreen (src, c),
- gdImageBlue (src, c),
- gdImageAlpha (src, c));
- }
- colorMap[c] = nc;
+ int c;
+ int x, y;
+ int tox, toy;
+ int ydest;
+ int i;
+ int colorMap[gdMaxColors];
+ /* Stretch vectors */
+ int *stx, *sty;
+ /* We only need to use floating point to determine the correct stretch vector for one line's worth. */
+ double accum;
+ stx = (int *) gdMalloc (sizeof (int) * srcW);
+ sty = (int *) gdMalloc (sizeof (int) * srcH);
+ accum = 0;
+
+ for (i = 0; (i < srcW); i++) {
+ int got;
+ accum += (double) dstW / (double) srcW;
+ got = (int) floor (accum);
+ stx[i] = got;
+ accum -= got;
+ }
+ accum = 0;
+ for (i = 0; (i < srcH); i++) {
+ int got;
+ accum += (double) dstH / (double) srcH;
+ got = (int) floor (accum);
+ sty[i] = got;
+ accum -= got;
+ }
+ for (i = 0; (i < gdMaxColors); i++) {
+ colorMap[i] = (-1);
+ }
+ toy = dstY;
+ for (y = srcY; (y < (srcY + srcH)); y++) {
+ for (ydest = 0; (ydest < sty[y - srcY]); ydest++) {
+ tox = dstX;
+ for (x = srcX; (x < (srcX + srcW)); x++) {
+ int nc = 0;
+ int mapTo;
+ if (!stx[x - srcX]) {
+ continue;
+ }
+ if (dst->trueColor) {
+ /* 2.0.9: Thorben Kundinger: Maybe the source image is not a truecolor image */
+ if (!src->trueColor) {
+ int tmp = gdImageGetPixel (src, x, y);
+ mapTo = gdImageGetTrueColorPixel (src, x, y);
+ if (gdImageGetTransparent (src) == tmp) {
+ tox++;
+ continue;
+ }
+ } else {
+ /* TK: old code follows */
+ mapTo = gdImageGetTrueColorPixel (src, x, y);
+ /* Added 7/24/95: support transparent copies */
+ if (gdImageGetTransparent (src) == mapTo) {
+ tox++;
+ continue;
+ }
+ }
+ } else {
+ c = gdImageGetPixel (src, x, y);
+ /* Added 7/24/95: support transparent copies */
+ if (gdImageGetTransparent (src) == c) {
+ tox += stx[x - srcX];
+ continue;
+ }
+ if (src->trueColor) {
+ /* Remap to the palette available in the destination image. This is slow and works badly. */
+ mapTo = gdImageColorResolveAlpha(dst, gdTrueColorGetRed(c),
+ gdTrueColorGetGreen(c),
+ gdTrueColorGetBlue(c),
+ gdTrueColorGetAlpha (c));
+ } else {
+ /* Have we established a mapping for this color? */
+ if (colorMap[c] == (-1)) {
+ /* If it's the same image, mapping is trivial */
+ if (dst == src) {
+ nc = c;
+ } else {
+ /* Find or create the best match */
+ /* 2.0.5: can't use gdTrueColorGetRed, etc with palette */
+ nc = gdImageColorResolveAlpha(dst, gdImageRed(src, c),
+ gdImageGreen(src, c),
+ gdImageBlue(src, c),
+ gdImageAlpha(src, c));
+ }
+ colorMap[c] = nc;
+ }
+ mapTo = colorMap[c];
+ }
+ }
+ for (i = 0; (i < stx[x - srcX]); i++) {
+ gdImageSetPixel (dst, tox, toy, mapTo);
+ tox++;
+ }
}
- mapTo = colorMap[c];
- }
- }
- for (i = 0; (i < stx[x - srcX]); i++)
- {
- gdImageSetPixel (dst, tox, toy, mapTo);
- tox++;
+ toy++;
}
- }
- toy++;
}
- }
- gdFree (stx);
- gdFree (sty);
+ gdFree (stx);
+ gdFree (sty);
}
/* When gd 1.x was first created, floating point was to be avoided.
}
}
-
-
#ifdef ROTATE_PI
#undef ROTATE_PI
#endif /* ROTATE_PI */