mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-08 13:53:21 +03:00
Merge branch 'master' into fast-filters
# Conflicts: # libImaging/Filter.c
This commit is contained in:
commit
49492def9b
BIN
Tests/images/hopper_emboss.bmp
Normal file
BIN
Tests/images/hopper_emboss.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
Tests/images/hopper_emboss_more.bmp
Normal file
BIN
Tests/images/hopper_emboss_more.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
|
@ -94,6 +94,28 @@ class TestImageFilter(PillowTestCase):
|
||||||
self.assertEqual(rankfilter.size, 1)
|
self.assertEqual(rankfilter.size, 1)
|
||||||
self.assertEqual(rankfilter.rank, 2)
|
self.assertEqual(rankfilter.rank, 2)
|
||||||
|
|
||||||
|
def test_consistency_3x3(self):
|
||||||
|
im = Image.open("Tests/images/hopper.bmp")
|
||||||
|
emboss = im.filter(ImageFilter.Kernel((3, 3),
|
||||||
|
(-1, -1, 0,
|
||||||
|
-1, 0, 1,
|
||||||
|
0, 1, 1), .3))
|
||||||
|
|
||||||
|
self.assert_image_equal(
|
||||||
|
emboss, Image.open("Tests/images/hopper_emboss.bmp"))
|
||||||
|
|
||||||
|
def test_consistency_5x5(self):
|
||||||
|
im = Image.open("Tests/images/hopper.bmp")
|
||||||
|
emboss = im.filter(ImageFilter.Kernel((5, 5),
|
||||||
|
(-1, -1, -1, -1, 0,
|
||||||
|
-1, -1, -1, 0, 1,
|
||||||
|
-1, -1, 0, 1, 1,
|
||||||
|
-1, 0, 1, 1, 1,
|
||||||
|
0, 1, 1, 1, 1), 0.3))
|
||||||
|
|
||||||
|
self.assert_image_equal(
|
||||||
|
emboss, Image.open("Tests/images/hopper_emboss_more.bmp"))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
2
_webp.c
2
_webp.c
|
@ -247,7 +247,7 @@ PyObject* WebPDecoderVersion_wrapper(PyObject* self, PyObject* args){
|
||||||
* The version of webp that ships with (0.1.3) Ubuntu 12.04 doesn't handle alpha well.
|
* The version of webp that ships with (0.1.3) Ubuntu 12.04 doesn't handle alpha well.
|
||||||
* Files that are valid with 0.3 are reported as being invalid.
|
* Files that are valid with 0.3 are reported as being invalid.
|
||||||
*/
|
*/
|
||||||
int WebPDecoderBuggyAlpha() {
|
int WebPDecoderBuggyAlpha(void) {
|
||||||
return WebPGetDecoderVersion()==0x0103;
|
return WebPGetDecoderVersion()==0x0103;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,14 +30,14 @@ ImagingGetBand(Imaging imIn, int band)
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (!imIn || imIn->type != IMAGING_TYPE_UINT8)
|
if (!imIn || imIn->type != IMAGING_TYPE_UINT8)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
if (band < 0 || band >= imIn->bands)
|
if (band < 0 || band >= imIn->bands)
|
||||||
return (Imaging) ImagingError_ValueError("band index out of range");
|
return (Imaging) ImagingError_ValueError("band index out of range");
|
||||||
|
|
||||||
/* Shortcuts */
|
/* Shortcuts */
|
||||||
if (imIn->bands == 1)
|
if (imIn->bands == 1)
|
||||||
return ImagingCopy(imIn);
|
return ImagingCopy(imIn);
|
||||||
|
|
||||||
/* Special case for LXXA etc */
|
/* Special case for LXXA etc */
|
||||||
if (imIn->bands == 2 && band == 1)
|
if (imIn->bands == 2 && band == 1)
|
||||||
|
@ -45,16 +45,16 @@ ImagingGetBand(Imaging imIn, int band)
|
||||||
|
|
||||||
imOut = ImagingNew("L", imIn->xsize, imIn->ysize);
|
imOut = ImagingNew("L", imIn->xsize, imIn->ysize);
|
||||||
if (!imOut)
|
if (!imOut)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Extract band from image */
|
/* Extract band from image */
|
||||||
for (y = 0; y < imIn->ysize; y++) {
|
for (y = 0; y < imIn->ysize; y++) {
|
||||||
UINT8* in = (UINT8*) imIn->image[y] + band;
|
UINT8* in = (UINT8*) imIn->image[y] + band;
|
||||||
UINT8* out = imOut->image8[y];
|
UINT8* out = imOut->image8[y];
|
||||||
for (x = 0; x < imIn->xsize; x++) {
|
for (x = 0; x < imIn->xsize; x++) {
|
||||||
out[x] = *in;
|
out[x] = *in;
|
||||||
in += 4;
|
in += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imOut;
|
return imOut;
|
||||||
|
@ -67,19 +67,19 @@ ImagingPutBand(Imaging imOut, Imaging imIn, int band)
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (!imIn || imIn->bands != 1 || !imOut)
|
if (!imIn || imIn->bands != 1 || !imOut)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
if (band < 0 || band >= imOut->bands)
|
if (band < 0 || band >= imOut->bands)
|
||||||
return (Imaging) ImagingError_ValueError("band index out of range");
|
return (Imaging) ImagingError_ValueError("band index out of range");
|
||||||
|
|
||||||
if (imIn->type != imOut->type ||
|
if (imIn->type != imOut->type ||
|
||||||
imIn->xsize != imOut->xsize ||
|
imIn->xsize != imOut->xsize ||
|
||||||
imIn->ysize != imOut->ysize)
|
imIn->ysize != imOut->ysize)
|
||||||
return (Imaging) ImagingError_Mismatch();
|
return (Imaging) ImagingError_Mismatch();
|
||||||
|
|
||||||
/* Shortcuts */
|
/* Shortcuts */
|
||||||
if (imOut->bands == 1)
|
if (imOut->bands == 1)
|
||||||
return ImagingCopy2(imOut, imIn);
|
return ImagingCopy2(imOut, imIn);
|
||||||
|
|
||||||
/* Special case for LXXA etc */
|
/* Special case for LXXA etc */
|
||||||
if (imOut->bands == 2 && band == 1)
|
if (imOut->bands == 2 && band == 1)
|
||||||
|
@ -87,12 +87,12 @@ ImagingPutBand(Imaging imOut, Imaging imIn, int band)
|
||||||
|
|
||||||
/* Insert band into image */
|
/* Insert band into image */
|
||||||
for (y = 0; y < imIn->ysize; y++) {
|
for (y = 0; y < imIn->ysize; y++) {
|
||||||
UINT8* in = imIn->image8[y];
|
UINT8* in = imIn->image8[y];
|
||||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||||
for (x = 0; x < imIn->xsize; x++) {
|
for (x = 0; x < imIn->xsize; x++) {
|
||||||
*out = in[x];
|
*out = in[x];
|
||||||
out += 4;
|
out += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imOut;
|
return imOut;
|
||||||
|
@ -105,10 +105,10 @@ ImagingFillBand(Imaging imOut, int band, int color)
|
||||||
|
|
||||||
/* Check arguments */
|
/* Check arguments */
|
||||||
if (!imOut || imOut->type != IMAGING_TYPE_UINT8)
|
if (!imOut || imOut->type != IMAGING_TYPE_UINT8)
|
||||||
return (Imaging) ImagingError_ModeError();
|
return (Imaging) ImagingError_ModeError();
|
||||||
|
|
||||||
if (band < 0 || band >= imOut->bands)
|
if (band < 0 || band >= imOut->bands)
|
||||||
return (Imaging) ImagingError_ValueError("band index out of range");
|
return (Imaging) ImagingError_ValueError("band index out of range");
|
||||||
|
|
||||||
/* Special case for LXXA etc */
|
/* Special case for LXXA etc */
|
||||||
if (imOut->bands == 2 && band == 1)
|
if (imOut->bands == 2 && band == 1)
|
||||||
|
@ -118,11 +118,11 @@ ImagingFillBand(Imaging imOut, int band, int color)
|
||||||
|
|
||||||
/* Insert color into image */
|
/* Insert color into image */
|
||||||
for (y = 0; y < imOut->ysize; y++) {
|
for (y = 0; y < imOut->ysize; y++) {
|
||||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||||
for (x = 0; x < imOut->xsize; x++) {
|
for (x = 0; x < imOut->xsize; x++) {
|
||||||
*out = (UINT8) color;
|
*out = (UINT8) color;
|
||||||
out += 4;
|
out += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return imOut;
|
return imOut;
|
||||||
|
|
|
@ -136,6 +136,9 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
||||||
if (!imOut)
|
if (!imOut)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
// Add one time for rounding
|
||||||
|
offset += 0.5;
|
||||||
|
|
||||||
#define KERNEL5x5(image, kernel, d) ( \
|
#define KERNEL5x5(image, kernel, d) ( \
|
||||||
(int) image[y+2][x-d-d] * kernel[0] + \
|
(int) image[y+2][x-d-d] * kernel[0] + \
|
||||||
(int) image[y+2][x-d] * kernel[1] + \
|
(int) image[y+2][x-d] * kernel[1] + \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user