mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
Merge pull request #5274 from radarhere/gradient
Fixed linear_gradient and radial_gradient I and F modes
This commit is contained in:
commit
9a683db339
|
@ -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)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user