mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 18:06:18 +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.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__':
|
||||
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.
|
||||
* Files that are valid with 0.3 are reported as being invalid.
|
||||
*/
|
||||
int WebPDecoderBuggyAlpha() {
|
||||
int WebPDecoderBuggyAlpha(void) {
|
||||
return WebPGetDecoderVersion()==0x0103;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ ImagingGetBand(Imaging imIn, int band)
|
|||
|
||||
/* Check arguments */
|
||||
if (!imIn || imIn->type != IMAGING_TYPE_UINT8)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
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 */
|
||||
if (imIn->bands == 1)
|
||||
return ImagingCopy(imIn);
|
||||
return ImagingCopy(imIn);
|
||||
|
||||
/* Special case for LXXA etc */
|
||||
if (imIn->bands == 2 && band == 1)
|
||||
|
@ -45,16 +45,16 @@ ImagingGetBand(Imaging imIn, int band)
|
|||
|
||||
imOut = ImagingNew("L", imIn->xsize, imIn->ysize);
|
||||
if (!imOut)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
/* Extract band from image */
|
||||
for (y = 0; y < imIn->ysize; y++) {
|
||||
UINT8* in = (UINT8*) imIn->image[y] + band;
|
||||
UINT8* out = imOut->image8[y];
|
||||
for (x = 0; x < imIn->xsize; x++) {
|
||||
out[x] = *in;
|
||||
in += 4;
|
||||
}
|
||||
UINT8* in = (UINT8*) imIn->image[y] + band;
|
||||
UINT8* out = imOut->image8[y];
|
||||
for (x = 0; x < imIn->xsize; x++) {
|
||||
out[x] = *in;
|
||||
in += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return imOut;
|
||||
|
@ -67,19 +67,19 @@ ImagingPutBand(Imaging imOut, Imaging imIn, int band)
|
|||
|
||||
/* Check arguments */
|
||||
if (!imIn || imIn->bands != 1 || !imOut)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
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 ||
|
||||
imIn->xsize != imOut->xsize ||
|
||||
imIn->ysize != imOut->ysize)
|
||||
return (Imaging) ImagingError_Mismatch();
|
||||
imIn->xsize != imOut->xsize ||
|
||||
imIn->ysize != imOut->ysize)
|
||||
return (Imaging) ImagingError_Mismatch();
|
||||
|
||||
/* Shortcuts */
|
||||
if (imOut->bands == 1)
|
||||
return ImagingCopy2(imOut, imIn);
|
||||
return ImagingCopy2(imOut, imIn);
|
||||
|
||||
/* Special case for LXXA etc */
|
||||
if (imOut->bands == 2 && band == 1)
|
||||
|
@ -87,12 +87,12 @@ ImagingPutBand(Imaging imOut, Imaging imIn, int band)
|
|||
|
||||
/* Insert band into image */
|
||||
for (y = 0; y < imIn->ysize; y++) {
|
||||
UINT8* in = imIn->image8[y];
|
||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||
for (x = 0; x < imIn->xsize; x++) {
|
||||
*out = in[x];
|
||||
out += 4;
|
||||
}
|
||||
UINT8* in = imIn->image8[y];
|
||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||
for (x = 0; x < imIn->xsize; x++) {
|
||||
*out = in[x];
|
||||
out += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return imOut;
|
||||
|
@ -105,10 +105,10 @@ ImagingFillBand(Imaging imOut, int band, int color)
|
|||
|
||||
/* Check arguments */
|
||||
if (!imOut || imOut->type != IMAGING_TYPE_UINT8)
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
return (Imaging) ImagingError_ModeError();
|
||||
|
||||
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 */
|
||||
if (imOut->bands == 2 && band == 1)
|
||||
|
@ -118,11 +118,11 @@ ImagingFillBand(Imaging imOut, int band, int color)
|
|||
|
||||
/* Insert color into image */
|
||||
for (y = 0; y < imOut->ysize; y++) {
|
||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||
for (x = 0; x < imOut->xsize; x++) {
|
||||
*out = (UINT8) color;
|
||||
out += 4;
|
||||
}
|
||||
UINT8* out = (UINT8*) imOut->image[y] + band;
|
||||
for (x = 0; x < imOut->xsize; x++) {
|
||||
*out = (UINT8) color;
|
||||
out += 4;
|
||||
}
|
||||
}
|
||||
|
||||
return imOut;
|
||||
|
|
|
@ -136,6 +136,9 @@ ImagingFilter(Imaging im, int xsize, int ysize, const FLOAT32* kernel,
|
|||
if (!imOut)
|
||||
return NULL;
|
||||
|
||||
// Add one time for rounding
|
||||
offset += 0.5;
|
||||
|
||||
#define KERNEL5x5(image, kernel, d) ( \
|
||||
(int) image[y+2][x-d-d] * kernel[0] + \
|
||||
(int) image[y+2][x-d] * kernel[1] + \
|
||||
|
|
Loading…
Reference in New Issue
Block a user