Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PerspectiveTransform #7699

Merged
merged 4 commits into from
Jan 9, 2024
Merged

Conversation

radarhere
Copy link
Member

Furthers the work of #7684 to help clarify ImageTransform for #7683, by adding code and documentation for the missing ImageTransform - PerspectiveTransform.

This is based on AffineTransform, since it is similar.

static int
affine_transform(double *xout, double *yout, int x, int y, void *data) {
/* full moon tonight. your compiler will generate bogus code
for simple expressions, unless you reorganize the code, or
install Service Pack 3 */
double *a = (double *)data;
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 xin = x + 0.5;
double yin = y + 0.5;
xout[0] = a0 * xin + a1 * yin + a2;
yout[0] = a3 * xin + a4 * yin + a5;
return 1;
}
static int
perspective_transform(double *xout, double *yout, int x, int y, void *data) {
double *a = (double *)data;
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 a6 = a[6];
double a7 = a[7];
double xin = x + 0.5;
double yin = y + 0.5;
xout[0] = (a0 * xin + a1 * yin + a2) / (a6 * xin + a7 * yin + 1);
yout[0] = (a3 * xin + a4 * yin + a5) / (a6 * xin + a7 * yin + 1);
return 1;
}

If the 7th (g) and 8th (h) values are 0, then perspective_transform is identical to affine_transform, soPERSPECTIVE should be able to do everything that AFFINE can.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add to release notes?

@radarhere
Copy link
Member Author

Ok, sure, I've added release notes.

@hugovk hugovk merged commit 35d6a66 into python-pillow:main Jan 9, 2024
57 checks passed
@radarhere radarhere deleted the perspective branch January 9, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants