Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ws and comment for recommended aa method

  • Loading branch information...
commit 83500123d02789781c25691527ae720ba1587948 1 parent ec136c2
@pierrejoye pierrejoye authored
Showing with 31 additions and 21 deletions.
  1. +31 −21 ext/gd/libgd/gd_interpolation.c
View
52 ext/gd/libgd/gd_interpolation.c
@@ -35,6 +35,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
- Add scale support for a portion only of an image (equivalent of copyresized/resampled)
@@ -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;
}
/*
Please sign in to comment.
Something went wrong with that request. Please try again.