make affine transform arguments order more common

This commit is contained in:
homm 2016-06-02 21:58:42 +03:00
parent 4cfc791a5b
commit 2b77b1cec7
3 changed files with 26 additions and 28 deletions

View File

@ -1869,9 +1869,7 @@ class Image(object):
h = box[3] - box[1] h = box[3] - box[1]
if method == AFFINE: if method == AFFINE:
# change argument order to match implementation data = data[0:6]
data = (data[2], data[0], data[1],
data[5], data[3], data[4])
elif method == EXTENT: elif method == EXTENT:
# convert extent to an affine transform # convert extent to an affine transform
@ -1879,7 +1877,7 @@ class Image(object):
xs = float(x1 - x0) / w xs = float(x1 - x0) / w
ys = float(y1 - y0) / h ys = float(y1 - y0) / h
method = AFFINE method = AFFINE
data = (x0 + xs/2, xs, 0, y0 + ys/2, 0, ys) data = (xs, 0, x0 + xs/2, 0, ys, y0 + ys/2)
elif method == PERSPECTIVE: elif method == PERSPECTIVE:
# change argument order to match implementation # change argument order to match implementation

View File

@ -1544,12 +1544,12 @@ _resize(ImagingObject* self, PyObject* args)
if (imIn->xsize == xsize && imIn->ysize == ysize) { if (imIn->xsize == xsize && imIn->ysize == ysize) {
imOut = ImagingCopy(imIn); imOut = ImagingCopy(imIn);
} }
else if ( ! filter) { else if (filter == IMAGING_TRANSFORM_NEAREST) {
double a[6]; double a[6];
memset(a, 0, sizeof a); memset(a, 0, sizeof a);
a[1] = (double) imIn->xsize / xsize; a[0] = (double) imIn->xsize / xsize;
a[5] = (double) imIn->ysize / ysize; a[4] = (double) imIn->ysize / ysize;
imOut = ImagingNew(imIn->mode, xsize, ysize); imOut = ImagingNew(imIn->mode, xsize, ysize);

View File

@ -250,8 +250,8 @@ affine_transform(double* xin, double* yin, int x, int y, void* data)
double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a0 = a[0]; double a1 = a[1]; double a2 = a[2];
double a3 = a[3]; double a4 = a[4]; double a5 = a[5]; double a3 = a[3]; double a4 = a[4]; double a5 = a[5];
xin[0] = a0 + a1*x + a2*y; xin[0] = a0*x + a1*y + a2;
yin[0] = a3 + a4*x + a5*y; yin[0] = a3*x + a4*y + a5;
return 1; return 1;
} }
@ -690,8 +690,8 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn,
return (Imaging) ImagingError_MemoryError(); return (Imaging) ImagingError_MemoryError();
} }
xo = a[0]; xo = a[2];
yo = a[3]; yo = a[5];
xmin = x1; xmin = x1;
xmax = x0; xmax = x0;
@ -705,7 +705,7 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn,
xmin = x; xmin = x;
xintab[x] = xin; xintab[x] = xin;
} }
xo += a[1]; xo += a[0];
} }
#define AFFINE_SCALE(pixel, image)\ #define AFFINE_SCALE(pixel, image)\
@ -720,7 +720,7 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn,
for (x = xmin; x < xmax; x++)\ for (x = xmin; x < xmax; x++)\
out[x] = in[xintab[x]];\ out[x] = in[xintab[x]];\
}\ }\
yo += a[5];\ yo += a[4];\
} }
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
@ -743,8 +743,8 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn,
static inline int static inline int
check_fixed(double a[6], int x, int y) check_fixed(double a[6], int x, int y)
{ {
return (fabs(a[0] + x*a[1] + y*a[2]) < 32768.0 && return (fabs(x*a[0] + y*a[1] + a[2]) < 32768.0 &&
fabs(a[3] + x*a[4] + y*a[5]) < 32768.0); fabs(x*a[3] + y*a[4] + a[5]) < 32768.0);
} }
static inline Imaging static inline Imaging
@ -778,8 +778,8 @@ affine_fixed(Imaging imOut, Imaging imIn,
#define AFFINE_TRANSFORM_FIXED(pixel, image)\ #define AFFINE_TRANSFORM_FIXED(pixel, image)\
for (y = y0; y < y1; y++) {\ for (y = y0; y < y1; y++) {\
pixel *out;\ pixel *out;\
xx = a0;\ xx = a2;\
yy = a3;\ yy = a5;\
out = imOut->image[y];\ out = imOut->image[y];\
if (fill && x1 > x0)\ if (fill && x1 > x0)\
memset(out+x0, 0, (x1-x0)*sizeof(pixel));\ memset(out+x0, 0, (x1-x0)*sizeof(pixel));\
@ -790,11 +790,11 @@ affine_fixed(Imaging imOut, Imaging imIn,
if (yin >= 0 && yin < ysize)\ if (yin >= 0 && yin < ysize)\
*out = imIn->image[yin][xin];\ *out = imIn->image[yin][xin];\
}\ }\
xx += a1;\ xx += a0;\
yy += a4;\ yy += a3;\
}\ }\
a0 += a2;\ a2 += a1;\
a3 += a5;\ a5 += a4;\
} }
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);
@ -834,7 +834,7 @@ ImagingTransformAffine(Imaging imOut, Imaging imIn,
filterid, fill); filterid, fill);
} }
if (a[2] == 0 && a[4] == 0) if (a[1] == 0 && a[3] == 0)
/* Scaling */ /* Scaling */
return ImagingScaleAffine(imOut, imIn, x0, y0, x1, y1, a, fill); return ImagingScaleAffine(imOut, imIn, x0, y0, x1, y1, a, fill);
@ -866,8 +866,8 @@ ImagingTransformAffine(Imaging imOut, Imaging imIn,
xsize = (int) imIn->xsize; xsize = (int) imIn->xsize;
ysize = (int) imIn->ysize; ysize = (int) imIn->ysize;
xo = a[0]; xo = a[2];
yo = a[3]; yo = a[5];
#define AFFINE_TRANSFORM(pixel, image)\ #define AFFINE_TRANSFORM(pixel, image)\
for (y = y0; y < y1; y++) {\ for (y = y0; y < y1; y++) {\
@ -884,11 +884,11 @@ ImagingTransformAffine(Imaging imOut, Imaging imIn,
if (yin >= 0 && yin < ysize)\ if (yin >= 0 && yin < ysize)\
*out = imIn->image[yin][xin];\ *out = imIn->image[yin][xin];\
}\ }\
xx += a[1];\ xx += a[0];\
yy += a[4];\ yy += a[3];\
}\ }\
xo += a[2];\ xo += a[1];\
yo += a[5];\ yo += a[4];\
} }
ImagingSectionEnter(&cookie); ImagingSectionEnter(&cookie);