Merge pull request #5274 from radarhere/gradient

Fixed linear_gradient and radial_gradient I and F modes
This commit is contained in:
wiredfool 2021-03-28 14:35:22 +01:00 committed by GitHub
commit 9a683db339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -524,7 +524,7 @@ class TestImage:
# Arrange # Arrange
target_file = "Tests/images/linear_gradient.png" target_file = "Tests/images/linear_gradient.png"
for mode in ["L", "P"]: for mode in ["L", "P", "I", "F"]:
# Act # Act
im = Image.linear_gradient(mode) im = Image.linear_gradient(mode)
@ -550,7 +550,7 @@ class TestImage:
# Arrange # Arrange
target_file = "Tests/images/radial_gradient.png" target_file = "Tests/images/radial_gradient.png"
for mode in ["L", "P"]: for mode in ["L", "P", "I", "F"]:
# Act # Act
im = Image.radial_gradient(mode) im = Image.radial_gradient(mode)

View File

@ -76,9 +76,22 @@ ImagingFillLinearGradient(const char *mode) {
return NULL; return NULL;
} }
if (im->image8) {
for (y = 0; y < 256; y++) { for (y = 0; y < 256; y++) {
memset(im->image8[y], (unsigned char)y, 256); memset(im->image8[y], (unsigned char)y, 256);
} }
} else {
int x;
for (y = 0; y < 256; y++) {
for (x = 0; x < 256; x++) {
if (im->type == IMAGING_TYPE_FLOAT32) {
IMAGING_PIXEL_FLOAT32(im, x, y) = y;
} else {
IMAGING_PIXEL_INT32(im, x, y) = y;
}
}
}
}
return im; return im;
} }
@ -103,9 +116,16 @@ ImagingFillRadialGradient(const char *mode) {
d = (int)sqrt( d = (int)sqrt(
(double)((x - 128) * (x - 128) + (y - 128) * (y - 128)) * 2.0); (double)((x - 128) * (x - 128) + (y - 128) * (y - 128)) * 2.0);
if (d >= 255) { if (d >= 255) {
im->image8[y][x] = 255; d = 255;
} else { }
if (im->image8) {
im->image8[y][x] = d; im->image8[y][x] = d;
} else {
if (im->type == IMAGING_TYPE_FLOAT32) {
IMAGING_PIXEL_FLOAT32(im, x, y) = d;
} else {
IMAGING_PIXEL_INT32(im, x, y) = d;
}
} }
} }
} }