From: Pierre Joye Date: Tue, 9 Apr 2013 05:04:52 +0000 (+0200) Subject: ws and comment for recommended aa method X-Git-Tag: php-5.5.0beta3~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83500123d02789781c25691527ae720ba1587948;p=php ws and comment for recommended aa method --- diff --git a/ext/gd/libgd/gd_interpolation.c b/ext/gd/libgd/gd_interpolation.c index a1916a13d4..ccdefb9b46 100644 --- a/ext/gd/libgd/gd_interpolation.c +++ b/ext/gd/libgd/gd_interpolation.c @@ -34,6 +34,17 @@ */ +/* + Additional functions are available for simple rotation or up/downscaling. + downscaling using the fixed point implementations are usually much faster + than the existing gdImageCopyResampled while having a similar or better + quality. + + For image rotations, the optimized versions have a lazy antialiasing for + the edges of the images. For a much better antialiased result, the affine + function is recommended. +*/ + /* TODO: - Optimize pixel accesses and loops once we have continuous buffer @@ -1004,24 +1015,24 @@ static inline void _gdScaleHoriz(gdImagePtr pSrc, unsigned int src_width, unsign static inline void _gdScaleCol (gdImagePtr pSrc, unsigned int src_width, gdImagePtr pRes, unsigned int dst_width, unsigned int dst_height, unsigned int uCol, LineContribType *contrib) { unsigned int y; - for (y = 0; y < dst_height - 1; y++) { - register unsigned char r = 0, g = 0, b = 0, a = 0; - const int iLeft = contrib->ContribRow[y].Left; - const int iRight = contrib->ContribRow[y].Right; + for (y = 0; y < dst_height - 1; y++) { + register unsigned char r = 0, g = 0, b = 0, a = 0; + const int iLeft = contrib->ContribRow[y].Left; + const int iRight = contrib->ContribRow[y].Right; int i; int *row = pRes->tpixels[y]; /* Accumulate each channel */ - for (i = iLeft; i <= iRight; i++) { - const int pCurSrc = pSrc->tpixels[i][uCol]; + for (i = iLeft; i <= iRight; i++) { + const int pCurSrc = pSrc->tpixels[i][uCol]; const int i_iLeft = i - iLeft; - r += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetRed(pCurSrc))); - g += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetGreen(pCurSrc))); - b += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetBlue(pCurSrc))); + r += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetRed(pCurSrc))); + g += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetGreen(pCurSrc))); + b += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetBlue(pCurSrc))); a += (unsigned char)(contrib->ContribRow[y].Weights[i_iLeft] * (double)(gdTrueColorGetAlpha(pCurSrc))); - } + } pRes->tpixels[y][uCol] = gdTrueColorAlpha(r, g, b, a); - } + } } static inline void _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_width, const unsigned int src_height, const gdImagePtr pDst, const unsigned int dst_width, const unsigned int dst_height) @@ -1030,12 +1041,12 @@ static inline void _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_w LineContribType * contrib; /* same height, copy it */ - if (src_height == dst_height) { + if (src_height == dst_height) { unsigned int y; for (y = 0; y < src_height - 1; ++y) { memcpy(pDst->tpixels[y], pSrc->tpixels[y], src_width); } - } + } contrib = _gdContributionsCalc(dst_height, src_height, (double)(dst_height) / (double)(src_height), pSrc->interpolation); /* scale each column */ @@ -1047,14 +1058,14 @@ static inline void _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_w gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_width, const unsigned int src_height, const unsigned int new_width, const unsigned int new_height) { - gdImagePtr tmp_im; + gdImagePtr tmp_im; gdImagePtr dst; tmp_im = gdImageCreateTrueColor(new_width, src_height); if (tmp_im == NULL) { return NULL; } - _gdScaleHoriz (src, src_width, src_height, tmp_im, new_width, src_height); + _gdScaleHoriz(src, src_width, src_height, tmp_im, new_width, src_height); dst = gdImageCreateTrueColor(new_width, new_height); if (dst == NULL) { @@ -1064,24 +1075,23 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt _gdScaleVert(tmp_im, new_width, src_height, dst, new_width, new_height); gdFree(tmp_im); - - return dst; + return dst; } gdImagePtr Scale(const gdImagePtr src, const unsigned int src_width, const unsigned int src_height, const gdImagePtr dst, const unsigned int new_width, const unsigned int new_height) { - gdImagePtr tmp_im; + gdImagePtr tmp_im; tmp_im = gdImageCreateTrueColor(new_width, src_height); if (tmp_im == NULL) { return NULL; } - _gdScaleHoriz(src, src_width, src_height, tmp_im, new_width, src_height); + _gdScaleHoriz(src, src_width, src_height, tmp_im, new_width, src_height); - _gdScaleVert(tmp_im, new_width, src_height, dst, new_width, new_height); + _gdScaleVert(tmp_im, new_width, src_height, dst, new_width, new_height); gdFree(tmp_im); - return dst; + return dst; } /*