From e3954aa4eaa3746dea3408fb0e6d4a1b8c3cd11f Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 15 Sep 2017 00:22:26 +0300 Subject: [PATCH 01/18] remove unnecessary ImagingCopyInfos --- libImaging/AlphaComposite.c | 2 -- libImaging/Blend.c | 9 +++++---- libImaging/Point.c | 2 -- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/libImaging/AlphaComposite.c b/libImaging/AlphaComposite.c index 00d28f95696..4fee3cecdb5 100644 --- a/libImaging/AlphaComposite.c +++ b/libImaging/AlphaComposite.c @@ -46,8 +46,6 @@ ImagingAlphaComposite(Imaging imDst, Imaging imSrc) if (!imOut) return NULL; - ImagingCopyInfo(imOut, imDst); - for (y = 0; y < imDst->ysize; y++) { rgba8* dst = (rgba8*) imDst->image[y]; diff --git a/libImaging/Blend.c b/libImaging/Blend.c index 91985671411..19a080d6d5b 100644 --- a/libImaging/Blend.c +++ b/libImaging/Blend.c @@ -26,8 +26,11 @@ ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) int x, y; /* Check arguments */ - if (!imIn1 || !imIn2 || imIn1->type != IMAGING_TYPE_UINT8) - return ImagingError_ModeError(); + if (!imIn1 || !imIn2 || imIn1->type != IMAGING_TYPE_UINT8 + || imIn1->palette || strcmp(imIn1->mode, "1") == 0 + || imIn2->palette || strcmp(imIn2->mode, "1") == 0) + return ImagingError_ModeError(); + if (imIn1->type != imIn2->type || imIn1->bands != imIn2->bands || imIn1->xsize != imIn2->xsize || @@ -44,8 +47,6 @@ ImagingBlend(Imaging imIn1, Imaging imIn2, float alpha) if (!imOut) return NULL; - ImagingCopyInfo(imOut, imIn1); - if (alpha >= 0 && alpha <= 1.0) { /* Interpolate between bands */ for (y = 0; y < imIn1->ysize; y++) { diff --git a/libImaging/Point.c b/libImaging/Point.c index 53d797e58e8..fc0b1d78768 100644 --- a/libImaging/Point.c +++ b/libImaging/Point.c @@ -216,8 +216,6 @@ ImagingPointTransform(Imaging imIn, double scale, double offset) if (!imOut) return NULL; - ImagingCopyInfo(imOut, imIn); - switch (imIn->type) { case IMAGING_TYPE_INT32: ImagingSectionEnter(&cookie); From f6a05fd22c5f90e03c27fca8de4e63e25c0bfea9 Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 15 Sep 2017 00:33:04 +0300 Subject: [PATCH 02/18] Rename ImagingCopyInfo to ImagingCopyPaletteInfo --- libImaging/Copy.c | 2 +- libImaging/Crop.c | 2 +- libImaging/Effects.c | 2 +- libImaging/Filter.c | 2 +- libImaging/Geometry.c | 20 ++++++++++---------- libImaging/Imaging.h | 2 +- libImaging/ModeFilter.c | 2 +- libImaging/Offset.c | 2 +- libImaging/Point.c | 2 +- libImaging/RankFilter.c | 2 +- libImaging/Storage.c | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libImaging/Copy.c b/libImaging/Copy.c index 992b8b5057a..d0a45ef1552 100644 --- a/libImaging/Copy.c +++ b/libImaging/Copy.c @@ -32,7 +32,7 @@ _copy(Imaging imOut, Imaging imIn) if (!imOut) return NULL; - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); ImagingSectionEnter(&cookie); if (imIn->block != NULL && imOut->block != NULL) diff --git a/libImaging/Crop.c b/libImaging/Crop.c index 893cdb5bac0..8819ef12c18 100644 --- a/libImaging/Crop.c +++ b/libImaging/Crop.c @@ -41,7 +41,7 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) if (!imOut) return NULL; - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); if (sx0 < 0 || sy0 < 0 || sx1 > imIn->xsize || sy1 > imIn->ysize) (void) ImagingFill(imOut, &zero); diff --git a/libImaging/Effects.c b/libImaging/Effects.c index 899fbe637ad..53fdda36e4d 100644 --- a/libImaging/Effects.c +++ b/libImaging/Effects.c @@ -144,7 +144,7 @@ ImagingEffectSpread(Imaging imIn, int distance) SPREAD(INT32, image32); } - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); return imOut; } diff --git a/libImaging/Filter.c b/libImaging/Filter.c index aab9cdce7a7..47599c9dde9 100644 --- a/libImaging/Filter.c +++ b/libImaging/Filter.c @@ -85,7 +85,7 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode) } ImagingSectionLeave(&cookie); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); return imOut; } diff --git a/libImaging/Geometry.c b/libImaging/Geometry.c index 2b3b1d5efe9..336321ed0f8 100644 --- a/libImaging/Geometry.c +++ b/libImaging/Geometry.c @@ -24,7 +24,7 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); ImagingSectionEnter(&cookie); @@ -65,7 +65,7 @@ ImagingFlipTopBottom(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); ImagingSectionEnter(&cookie); @@ -90,7 +90,7 @@ ImagingRotate90(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); #define ROTATE_90(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -132,7 +132,7 @@ ImagingTranspose(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); #define TRANSPOSE(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -173,7 +173,7 @@ ImagingRotate180(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); #define ROTATE_180(image)\ for (y = 0; y < imIn->ysize; y++, yr--) {\ @@ -209,7 +209,7 @@ ImagingRotate270(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); #define ROTATE_270(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -641,7 +641,7 @@ ImagingGenericTransform( if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); ImagingSectionEnter(&cookie); @@ -688,7 +688,7 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn, if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); if (x0 < 0) x0 = 0; @@ -778,7 +778,7 @@ affine_fixed(Imaging imOut, Imaging imIn, int xx, yy; int a0, a1, a2, a3, a4, a5; - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; @@ -880,7 +880,7 @@ ImagingTransformAffine(Imaging imOut, Imaging imIn, following code is used. maybe we should fall back on the slow generic transform engine in this case? */ - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index a48d373eed6..9dc899bead0 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -173,7 +173,7 @@ extern Imaging ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int structure_size); -extern void ImagingCopyInfo(Imaging destination, Imaging source); +extern void ImagingCopyPaletteInfo(Imaging destination, Imaging source); extern void ImagingHistogramDelete(ImagingHistogram histogram); diff --git a/libImaging/ModeFilter.c b/libImaging/ModeFilter.c index b1fc7e8e652..8e2fdc1fa34 100644 --- a/libImaging/ModeFilter.c +++ b/libImaging/ModeFilter.c @@ -72,7 +72,7 @@ ImagingModeFilter(Imaging im, int size) } - ImagingCopyInfo(imOut, im); + ImagingCopyPaletteInfo(imOut, im); return imOut; } diff --git a/libImaging/Offset.c b/libImaging/Offset.c index 7d69f38a71d..d89db9eb9c1 100644 --- a/libImaging/Offset.c +++ b/libImaging/Offset.c @@ -31,7 +31,7 @@ ImagingOffset(Imaging im, int xoffset, int yoffset) if (!imOut) return NULL; - ImagingCopyInfo(imOut, im); + ImagingCopyPaletteInfo(imOut, im); /* make offsets positive to avoid negative coordinates */ xoffset %= im->xsize; diff --git a/libImaging/Point.c b/libImaging/Point.c index fc0b1d78768..1d3c106290f 100644 --- a/libImaging/Point.c +++ b/libImaging/Point.c @@ -180,7 +180,7 @@ ImagingPoint(Imaging imIn, const char* mode, const void* table) } else point = im_point_32_8; - ImagingCopyInfo(imOut, imIn); + ImagingCopyPaletteInfo(imOut, imIn); ImagingSectionEnter(&cookie); diff --git a/libImaging/RankFilter.c b/libImaging/RankFilter.c index cfcc7ef3839..c60934f284a 100644 --- a/libImaging/RankFilter.c +++ b/libImaging/RankFilter.c @@ -103,7 +103,7 @@ ImagingRankFilter(Imaging im, int size, int rank) return (Imaging) ImagingError_ModeError(); } - ImagingCopyInfo(imOut, im); + ImagingCopyPaletteInfo(imOut, im); return imOut; diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 615c5fa2016..fc173359f58 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -24,7 +24,7 @@ * 1998-10-26 fl Added "I;16" and "I;16B" storage modes (experimental) * 1998-12-29 fl Fixed allocation bug caused by previous fix * 1999-02-03 fl Added "RGBa" and "BGR" modes (experimental) - * 2001-04-22 fl Fixed potential memory leak in ImagingCopyInfo + * 2001-04-22 fl Fixed potential memory leak in ImagingCopyPaletteInfo * 2003-09-26 fl Added "LA" and "PA" modes (experimental) * 2005-10-02 fl Added image counter * @@ -458,7 +458,7 @@ ImagingNew2Dirty(const char* mode, Imaging imOut, Imaging imIn) } void -ImagingCopyInfo(Imaging destination, Imaging source) +ImagingCopyPaletteInfo(Imaging destination, Imaging source) { if (source->palette) { if (destination->palette) From bda6d1e58852b70eb4942cf452f700c28b526795 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 19 Sep 2017 20:42:13 +0300 Subject: [PATCH 03/18] rename ImagingCopyPaletteInfo to ImagingCopyPalette --- libImaging/Copy.c | 2 +- libImaging/Crop.c | 2 +- libImaging/Effects.c | 2 +- libImaging/Filter.c | 2 +- libImaging/Geometry.c | 20 ++++++++++---------- libImaging/Imaging.h | 2 +- libImaging/ModeFilter.c | 2 +- libImaging/Offset.c | 2 +- libImaging/Point.c | 2 +- libImaging/RankFilter.c | 2 +- libImaging/Storage.c | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libImaging/Copy.c b/libImaging/Copy.c index d0a45ef1552..1bc9b1a709a 100644 --- a/libImaging/Copy.c +++ b/libImaging/Copy.c @@ -32,7 +32,7 @@ _copy(Imaging imOut, Imaging imIn) if (!imOut) return NULL; - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); if (imIn->block != NULL && imOut->block != NULL) diff --git a/libImaging/Crop.c b/libImaging/Crop.c index 8819ef12c18..4407c1b1d2d 100644 --- a/libImaging/Crop.c +++ b/libImaging/Crop.c @@ -41,7 +41,7 @@ ImagingCrop(Imaging imIn, int sx0, int sy0, int sx1, int sy1) if (!imOut) return NULL; - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); if (sx0 < 0 || sy0 < 0 || sx1 > imIn->xsize || sy1 > imIn->ysize) (void) ImagingFill(imOut, &zero); diff --git a/libImaging/Effects.c b/libImaging/Effects.c index 53fdda36e4d..5b58fddbb53 100644 --- a/libImaging/Effects.c +++ b/libImaging/Effects.c @@ -144,7 +144,7 @@ ImagingEffectSpread(Imaging imIn, int distance) SPREAD(INT32, image32); } - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); return imOut; } diff --git a/libImaging/Filter.c b/libImaging/Filter.c index 47599c9dde9..e6b1a4966ac 100644 --- a/libImaging/Filter.c +++ b/libImaging/Filter.c @@ -85,7 +85,7 @@ ImagingExpand(Imaging imIn, int xmargin, int ymargin, int mode) } ImagingSectionLeave(&cookie); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); return imOut; } diff --git a/libImaging/Geometry.c b/libImaging/Geometry.c index 336321ed0f8..dee2b899cbe 100644 --- a/libImaging/Geometry.c +++ b/libImaging/Geometry.c @@ -24,7 +24,7 @@ ImagingFlipLeftRight(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); @@ -65,7 +65,7 @@ ImagingFlipTopBottom(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); @@ -90,7 +90,7 @@ ImagingRotate90(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); #define ROTATE_90(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -132,7 +132,7 @@ ImagingTranspose(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); #define TRANSPOSE(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -173,7 +173,7 @@ ImagingRotate180(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->xsize || imIn->ysize != imOut->ysize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); #define ROTATE_180(image)\ for (y = 0; y < imIn->ysize; y++, yr--) {\ @@ -209,7 +209,7 @@ ImagingRotate270(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); #define ROTATE_270(image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ @@ -641,7 +641,7 @@ ImagingGenericTransform( if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); @@ -688,7 +688,7 @@ ImagingScaleAffine(Imaging imOut, Imaging imIn, if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) return (Imaging) ImagingError_ModeError(); - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); if (x0 < 0) x0 = 0; @@ -778,7 +778,7 @@ affine_fixed(Imaging imOut, Imaging imIn, int xx, yy; int a0, a1, a2, a3, a4, a5; - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; @@ -880,7 +880,7 @@ ImagingTransformAffine(Imaging imOut, Imaging imIn, following code is used. maybe we should fall back on the slow generic transform engine in this case? */ - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); xsize = (int) imIn->xsize; ysize = (int) imIn->ysize; diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 9dc899bead0..145cc62feb6 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -173,7 +173,7 @@ extern Imaging ImagingNewPrologueSubtype(const char *mode, int xsize, int ysize, int structure_size); -extern void ImagingCopyPaletteInfo(Imaging destination, Imaging source); +extern void ImagingCopyPalette(Imaging destination, Imaging source); extern void ImagingHistogramDelete(ImagingHistogram histogram); diff --git a/libImaging/ModeFilter.c b/libImaging/ModeFilter.c index 8e2fdc1fa34..1cdb6300dcc 100644 --- a/libImaging/ModeFilter.c +++ b/libImaging/ModeFilter.c @@ -72,7 +72,7 @@ ImagingModeFilter(Imaging im, int size) } - ImagingCopyPaletteInfo(imOut, im); + ImagingCopyPalette(imOut, im); return imOut; } diff --git a/libImaging/Offset.c b/libImaging/Offset.c index d89db9eb9c1..b3d9425fb65 100644 --- a/libImaging/Offset.c +++ b/libImaging/Offset.c @@ -31,7 +31,7 @@ ImagingOffset(Imaging im, int xoffset, int yoffset) if (!imOut) return NULL; - ImagingCopyPaletteInfo(imOut, im); + ImagingCopyPalette(imOut, im); /* make offsets positive to avoid negative coordinates */ xoffset %= im->xsize; diff --git a/libImaging/Point.c b/libImaging/Point.c index 1d3c106290f..426c410c961 100644 --- a/libImaging/Point.c +++ b/libImaging/Point.c @@ -180,7 +180,7 @@ ImagingPoint(Imaging imIn, const char* mode, const void* table) } else point = im_point_32_8; - ImagingCopyPaletteInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); ImagingSectionEnter(&cookie); diff --git a/libImaging/RankFilter.c b/libImaging/RankFilter.c index c60934f284a..0164861bb07 100644 --- a/libImaging/RankFilter.c +++ b/libImaging/RankFilter.c @@ -103,7 +103,7 @@ ImagingRankFilter(Imaging im, int size, int rank) return (Imaging) ImagingError_ModeError(); } - ImagingCopyPaletteInfo(imOut, im); + ImagingCopyPalette(imOut, im); return imOut; diff --git a/libImaging/Storage.c b/libImaging/Storage.c index fc173359f58..72285970aca 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -24,7 +24,7 @@ * 1998-10-26 fl Added "I;16" and "I;16B" storage modes (experimental) * 1998-12-29 fl Fixed allocation bug caused by previous fix * 1999-02-03 fl Added "RGBa" and "BGR" modes (experimental) - * 2001-04-22 fl Fixed potential memory leak in ImagingCopyPaletteInfo + * 2001-04-22 fl Fixed potential memory leak in ImagingCopyPalette * 2003-09-26 fl Added "LA" and "PA" modes (experimental) * 2005-10-02 fl Added image counter * @@ -458,7 +458,7 @@ ImagingNew2Dirty(const char* mode, Imaging imOut, Imaging imIn) } void -ImagingCopyPaletteInfo(Imaging destination, Imaging source) +ImagingCopyPalette(Imaging destination, Imaging source) { if (source->palette) { if (destination->palette) From ecfc10d002bc929833b0124ecc8ece3092abd56d Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 19 Sep 2017 21:01:34 +0300 Subject: [PATCH 04/18] oops --- libImaging/Geometry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libImaging/Geometry.c b/libImaging/Geometry.c index bc63ac413a9..1d08728dad5 100644 --- a/libImaging/Geometry.c +++ b/libImaging/Geometry.c @@ -188,7 +188,7 @@ ImagingTransverse(Imaging imOut, Imaging imIn) if (imIn->xsize != imOut->ysize || imIn->ysize != imOut->xsize) return (Imaging) ImagingError_Mismatch(); - ImagingCopyInfo(imOut, imIn); + ImagingCopyPalette(imOut, imIn); #define TRANSVERSE(INT, image) \ for (y = 0; y < imIn->ysize; y += ROTATE_CHUNK) { \ From 973787e240c19b3d6573c91fc0772805afa5fcce Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Tue, 19 Sep 2017 12:44:56 +0000 Subject: [PATCH 05/18] flags to fix building on mingw --- setup.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index f378362e686..579553f645e 100755 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ import subprocess from distutils.command.build_ext import build_ext -from distutils import sysconfig +from distutils import sysconfig, ccompiler from setuptools import Extension, setup, find_packages # monkey patch import hook. Even though flake8 says it's not used, it is. @@ -44,6 +44,9 @@ class DependencyException(Exception): pass class RequiredDependencyException(Exception): pass +PLATFORM_MINGW = 'mingw' in ccompiler.get_default_compiler() +PLATFORM_PYPY = hasattr(sys, 'pypy_version_info') + def _dbg(s, tp=None): if DEBUG: if tp: @@ -607,7 +610,7 @@ def build_extensions(self): if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1: defs.append(("WORDS_BIGENDIAN", None)) - if sys.platform == "win32" and not hasattr(sys, 'pypy_version_info'): + if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW): defs.append(("PILLOW_VERSION", '"\\"%s\\""'%PILLOW_VERSION)) else: defs.append(("PILLOW_VERSION", '"%s"'%PILLOW_VERSION)) @@ -781,7 +784,7 @@ def debug_build(): test_suite='nose.collector', keywords=["Imaging", ], license='Standard PIL License', - zip_safe=not debug_build(), ) + zip_safe=not (debug_build() or PLATFORM_MINGW), ) except RequiredDependencyException as err: msg = """ From 5c77fbb29f8df09993461c91c153feb636d9766b Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Tue, 19 Sep 2017 12:45:09 +0000 Subject: [PATCH 06/18] test mingw --- appveyor.yml | 42 ++++++++++++++++++++----- winbuild/appveyor_build_msys2.sh | 3 ++ winbuild/appveyor_install_msys2_deps.sh | 11 +++++++ 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 winbuild/appveyor_build_msys2.sh create mode 100644 winbuild/appveyor_install_msys2_deps.sh diff --git a/appveyor.yml b/appveyor.yml index 18c179983cf..c37b6b61335 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,6 +10,8 @@ environment: EXECUTABLE: python.exe PIP_DIR: Scripts VENV: NO + TEST_OPTIONS: + DEPLOY: YES matrix: - PYTHON: C:/vp/pypy2 EXECUTABLE: bin/pypy.exe @@ -21,6 +23,11 @@ environment: - PYTHON: C:/Python34-x64 - PYTHON: C:/Python33 - PYTHON: C:/Python33-x64 + - PYTHON: C:/msys64/mingw32 + EXECUTABLE: bin/python3 + PIP_DIR: bin + TEST_OPTIONS: --processes=0 + DEPLOY: NO install: @@ -36,19 +43,38 @@ install: { c:\pillow\winbuild\appveyor_install_pypy.cmd } -- c:\python34\python.exe c:\pillow\winbuild\build_dep.py -- c:\pillow\winbuild\build_deps.cmd - +- ps: | + if ($env:PYTHON -eq "c:/msys64/mingw32") + { + c:\msys64\usr\bin\bash -l -c c:\\pillow\\winbuild\\appveyor_install_msys2_deps.sh + } + else + { + c:\python34\python.exe c:\pillow\winbuild\build_dep.py + c:\pillow\winbuild\build_deps.cmd + $host.SetShouldExit(0) + } + build_script: -- '%PYTHON%\%EXECUTABLE% c:\pillow\winbuild\build.py' +- ps: | + if ($env:PYTHON -eq "c:/msys64/mingw32") + { + c:\msys64\usr\bin\bash -l -c c:\\pillow\\winbuild\\appveyor_build_msys2.sh + Write-Host "through install" + $host.SetShouldExit(0) + } + else + { + & $env:PYTHON/$env:EXECUTABLE c:\pillow\winbuild\build.py + $host.SetShouldExit(0) + } - cd c:\pillow -- dir dist\*.egg - '%PYTHON%\%EXECUTABLE% selftest.py --installed' test_script: - cd c:\pillow - '%PYTHON%\%PIP_DIR%\pip.exe install nose' -- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s' +- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s %TEST_OPTIONS%' matrix: fast_finish: true @@ -59,7 +85,7 @@ artifacts: - path: pillow\dist\*.wheel name: wheel -after_test: +before_deploy: - '%PYTHON%\%PIP_DIR%\pip.exe install wheel' - cd c:\pillow\winbuild\ - '%PYTHON%\%EXECUTABLE% c:\pillow\winbuild\build.py --wheel' @@ -77,6 +103,8 @@ deploy: artifact: /.*egg|wheel/ on: branch: master + deploy: YES + # Uncomment the following line to get RDP access after the build/test and block for # up to the timeout limit (~1hr) diff --git a/winbuild/appveyor_build_msys2.sh b/winbuild/appveyor_build_msys2.sh new file mode 100644 index 00000000000..489f9411eac --- /dev/null +++ b/winbuild/appveyor_build_msys2.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cd /c/pillow && /mingw32/$EXECUTABLE setup.py install diff --git a/winbuild/appveyor_install_msys2_deps.sh b/winbuild/appveyor_install_msys2_deps.sh new file mode 100644 index 00000000000..52b81443324 --- /dev/null +++ b/winbuild/appveyor_install_msys2_deps.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +pacman -S --noconfirm mingw32/mingw-w64-i686-python3 \ + mingw32/mingw-w64-i686-python3-pip \ + mingw32/mingw-w64-i686-python3-setuptools \ + mingw32/mingw-w64-i686-python2-pip \ + mingw32/mingw-w64-i686-python2-setuptools \ + mingw-w64-i686-libjpeg-turbo + +/mingw32/bin/pip install nose olefile +/mingw32/bin/pip3 install nose olefile From fd67647901e36f0a4c48e43e8dd41c047ea2c5af Mon Sep 17 00:00:00 2001 From: wiredfool Date: Wed, 20 Sep 2017 09:58:01 +0100 Subject: [PATCH 07/18] Updage CHANGES.rst [ci skip] --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index e26794af6fb..4c217103716 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,9 @@ Changelog (Pillow) 4.3.0 (unreleased) ------------------ +- Fixed support for building on Windows/msys2. Added Appveyor CI coverage for python3 on msys2 #2476 + [wiredfool] + - Fix ValueError in Exif/Tiff IFD #2719 [wiredfool] From 0c248c68f2001071fdd9d9e00be4b04be15c0051 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:08:53 +0000 Subject: [PATCH 08/18] platform changes --- docs/installation.rst | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index f1029ae82ff..6a6a80fcb3a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -339,6 +339,20 @@ Prerequisites are installed on **Fedora 23** with:: $ sudo dnf install libtiff-devel libjpeg-devel zlib-devel freetype-devel \ lcms2-devel libwebp-devel tcl-devel tk-devel libraqm-devel +See also the ``Dockerfile``s in the Test Infrastructure repo +(https://github.com/python-pillow/docker-images) for a known working +install process for other tested distros. + +Building on Android +^^^^^^^^^^^^^^^^^^^ + +Basic Android support has been added for compilation within the Termux +environment. The dependencies can be installed by:: + + $ pkg -y install python python-dev ndk-sysroot clang make \ + libjpeg-turbo-dev + +This has been tested within the Termux app on ChromeOS, on x86. Platform Support @@ -348,8 +362,7 @@ Current platform support for Pillow. Binary distributions are contributed for each release on a volunteer basis, but the source should compile and run everywhere platform support is listed. In general, we aim to support all current versions of Linux, macOS, and -Windows. Note that Android is not currently supported, but there have -been reports of success. +Windows. Continuous Integration Targets ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -369,6 +382,10 @@ These platforms are built and tested for every change. +----------------------------------+-------------------------------+-----------------------+ | Debian Stretch | 2.7 |x86 | +----------------------------------+-------------------------------+-----------------------+ +| Fedora 24 | 2.7 |x86-64 | ++----------------------------------+-------------------------------+-----------------------+ +| Fedora 26 | 2.7 |x86-64 | ++----------------------------------+-------------------------------+-----------------------+ | Mac OS X 10.10 Yosemite* | 2.7, 3.3, 3.4, 3.5, 3.6 |x86-64 | +----------------------------------+-------------------------------+-----------------------+ | Ubuntu Linux 16.04 LTS | 2.7 |x86-64 | @@ -380,7 +397,8 @@ These platforms are built and tested for every change. +----------------------------------+-------------------------------+-----------------------+ | Ubuntu Linux 12.04 LTS | 2.7 |x86-64 | +----------------------------------+-------------------------------+-----------------------+ -| Windows Server 2012 R2 | 2.7,3.3,3.4,pypy |x86, x86-64 | +| Windows Server 2012 R2 | 2.7,3.3,3.4 |x86, x86-64 | +| | pypy, 3.5/mingw |x86 | +----------------------------------+-------------------------------+-----------------------+ \* Mac OS X CI is not run for every commit, but is run for every release. From 997e10894686a8a3cbf2a29cec3cd8a712d93ae7 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:09:15 +0000 Subject: [PATCH 09/18] Deprecated easy_install in instructions --- docs/installation.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 6a6a80fcb3a..49788d6334c 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -32,12 +32,6 @@ Install Pillow with :command:`pip`:: $ pip install Pillow -Or use :command:`easy_install` for installing `Python Eggs -`_ as -:command:`pip` does not support them:: - - $ easy_install Pillow - Windows Installation ^^^^^^^^^^^^^^^^^^^^ @@ -49,10 +43,6 @@ libraries included:: > pip install Pillow -or:: - - > easy_install Pillow - macOS Installation ^^^^^^^^^^^^^^^^^^ From 505eb799baa5e9f7db11394ef2d076014b42471a Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:47:35 +0000 Subject: [PATCH 10/18] fixed doc formatting error --- PIL/GifImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 75158809d3b..a08063bfbd8 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -767,7 +767,7 @@ def getdata(im, offset=(0, 0), **params): :param im: Image object :param offset: Tuple of (x, y) pixels. Defaults to (0,0) - :param **params: E.g. duration or other encoder info parameters + :param \**params: E.g. duration or other encoder info parameters :returns: List of Bytes containing gif encoded frame data """ From ba101e4e62bdac21504fa08e9244801e3e1ae840 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:49:14 +0000 Subject: [PATCH 11/18] Fix docstring error --- PIL/ContainerIO.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PIL/ContainerIO.py b/PIL/ContainerIO.py index 609aa33e308..496ed68263d 100644 --- a/PIL/ContainerIO.py +++ b/PIL/ContainerIO.py @@ -72,8 +72,7 @@ def read(self, n=0): """ Read data. - @def read(bytes=0) - :param bytes: Number of bytes to read. If omitted or zero, + :param n: Number of bytes to read. If omitted or zero, read until end of region. :returns: An 8-bit string. """ From dc327121f1f0ceba521016937bba385afad1cd05 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:49:47 +0000 Subject: [PATCH 12/18] formatting --- docs/installation.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/installation.rst b/docs/installation.rst index 49788d6334c..95588de34df 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -329,7 +329,7 @@ Prerequisites are installed on **Fedora 23** with:: $ sudo dnf install libtiff-devel libjpeg-devel zlib-devel freetype-devel \ lcms2-devel libwebp-devel tcl-devel tk-devel libraqm-devel -See also the ``Dockerfile``s in the Test Infrastructure repo +See also the ``Dockerfile``\s in the Test Infrastructure repo (https://github.com/python-pillow/docker-images) for a known working install process for other tested distros. @@ -388,6 +388,7 @@ These platforms are built and tested for every change. | Ubuntu Linux 12.04 LTS | 2.7 |x86-64 | +----------------------------------+-------------------------------+-----------------------+ | Windows Server 2012 R2 | 2.7,3.3,3.4 |x86, x86-64 | +| | | | | | pypy, 3.5/mingw |x86 | +----------------------------------+-------------------------------+-----------------------+ From 8172fa710b70dccef60fc5e47a4c26d442b46f29 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 10:54:59 +0000 Subject: [PATCH 13/18] Updated release notes --- docs/releasenotes/4.3.0.rst | 113 +++++++++++++++++++++++------------- 1 file changed, 73 insertions(+), 40 deletions(-) diff --git a/docs/releasenotes/4.3.0.rst b/docs/releasenotes/4.3.0.rst index e9ac8d936d4..f2e0f42b565 100644 --- a/docs/releasenotes/4.3.0.rst +++ b/docs/releasenotes/4.3.0.rst @@ -1,30 +1,89 @@ 4.3.0 ----- +API Changes +=========== + +Deprecations +^^^^^^^^^^^^ + +Several undocumented functions in ImageOps have been deprecated: +``gaussian_blur``, ``gblur``, ``unsharp_mask``, ``usm`` and +``box_blur``. Use the equivalent operations in ImageFilter +instead. These functions will be removed in a future release. + +TIFF Metadata Changes +^^^^^^^^^^^^^^^^^^^^^ + +* TIFF tags with unknown type/quantity now default to being bare + values if they are 1 element, where previously they would be a + single element tuple. This is only with the new api, not the legacy + api. This normalizes the handling of fields, so that the metadata + with inferred or image specified counts are handled the same as + metadata with count specified in the TIFF spec. +* The ``PhotoshopInfo``, ``XMP``, and ``JPEGTables`` tags now have a + defined type (bytes) and a count of 1. +* The ``ImageJMetaDataByteCounts`` tag now has an arbitrary number of + items, as there can be multiple items, one for UTF-8, and one for + UTF-16. + +Core Image API Changes +^^^^^^^^^^^^^^^^^^^^^^ + +These are internal functions that should not have been used by user +code, but they were accessible from the python layer. + +Debugging code within ``Image.core.grabclipboard`` was removed. It had been +marked as ``will be removed in future versions`` since PIL. When enabled, it +identified the format of the clipboard data. + +The ``PIL.Image.core.copy`` and ``PIL.Image.Image.im.copy2`` methods +have been removed. + + +API Additions +============= + Get One Channel From Image -========================== +^^^^^^^^^^^^^^^^^^^^^^^^^^ -New method :py:meth:`PIL.Image.Image.getchannel` is added. -It returns single channel by index or name. For example, +A new method :py:meth:`PIL.Image.Image.getchannel` has been added to +return a single channel by index or name. For example, ``image.getchannel("A")`` will return alpha channel as separate image. -``getchannel`` should work up to 6 times faster than ``image.split()[0]`` -in previous Pillow versions. - +``getchannel`` should work up to 6 times faster than +``image.split()[0]`` in previous Pillow versions. Box Blur -======== - -New filter :py:class:`PIL.ImageFilter.BoxBlur` is added. +^^^^^^^^ +A new filter, :py:class:`PIL.ImageFilter.BoxBlur`, has been +added. This is a filter with similar results to a Gaussian blur, but +is much faster. Partial Resampling -================== +^^^^^^^^^^^^^^^^^^ Added new argument ``box`` for :py:meth:`PIL.Image.Image.resize`. This argument defines a source rectangle from within the source image to be resized. This is very similar to the ``image.crop(box).resize(size)`` sequence except that ``box`` can be specified with subpixel accuracy. +New Transpose Operation +^^^^^^^^^^^^^^^^^^^^^^^ + +The ``Image.TRANSVERSE`` operation has been added to +:py:meth:`PIL.Image.Image.transpose`. This is equvalent to a transpose +operation about the opposite diagonal. + +Multiband Filters +^^^^^^^^^^^^^^^^^ + +There is a new :py:class:`PIL.ImageFilter.MultibandFilter` base class +for image filters that can run on all channels of an image in one +operation. The original :py:class:`PIL.ImageFilter.Filter` class +remains for image filters that can process only single band images, or +require splitting of channels prior to filtering. + Loading 16-bit TIFF Images ========================== @@ -33,7 +92,6 @@ Pillow now can read 16-bit multichannel TIFF files including files with alpha transparency. The image data is truncated to 8-bit precision. - Performance =========== @@ -44,33 +102,8 @@ This release contains several performance improvements: * Upscaling of multichannel images (such as RGB) is accelerated by 5-10% * JPEG loading is accelerated up to 15% and JPEG saving up to 20% when using a recent version of libjpeg-turbo. +* ``Image.transpose`` has been accelerated 15% or more by using a cache + friendly algorithm. +* ImageFilters based on Kernel convolution are significantly faster + due to the new MultibandFilter feature. - -TIFF Metadata Changes -===================== - -* TIFF tags with unknown type/quantity now default to being bare - values if they are 1 element, where previously they would be a - single element tuple. This is only with the new api, not the legacy - api. This normalizes the handling of fields, so that the metadata - with inferred or image specified counts are handled the same as - metadata with count specified in the TIFF spec. -* The ``PhotoshopInfo``, ``XMP``, and ``JPEGTables`` tags now have a - defined type (bytes) and a count of 1. -* The ``ImageJMetaDataByteCounts`` tag now has an arbitrary number of - items, as there can be multiple items, one for UTF-8, and one for - UTF-16. - - -Core Image API Changes -====================== - -These are internal functions that should not have been used by user -code, but they were accessible from the python layer. - -Debugging code within ``Image.core.grabclipboard`` was removed. It had been -marked as ``will be removed in future versions`` since PIL. When enabled, it -identified the format of the clipboard data. - -The ``PIL.Image.core.copy`` and ``PIL.Image.Image.im.copy2`` methods -have been removed. From 6e2010e7fd36110baee086d86a8de5e333243e91 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Wed, 20 Sep 2017 11:17:46 +0000 Subject: [PATCH 14/18] speling --- docs/releasenotes/4.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/releasenotes/4.3.0.rst b/docs/releasenotes/4.3.0.rst index f2e0f42b565..1463b34d6e2 100644 --- a/docs/releasenotes/4.3.0.rst +++ b/docs/releasenotes/4.3.0.rst @@ -72,7 +72,7 @@ New Transpose Operation ^^^^^^^^^^^^^^^^^^^^^^^ The ``Image.TRANSVERSE`` operation has been added to -:py:meth:`PIL.Image.Image.transpose`. This is equvalent to a transpose +:py:meth:`PIL.Image.Image.transpose`. This is equivalent to a transpose operation about the opposite diagonal. Multiband Filters From 6a435793d885bc9d5289713216fe4f8635075c43 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 23 Sep 2017 04:15:19 +0300 Subject: [PATCH 15/18] fallback to small block size on memory error increase default block size to previous value --- libImaging/Imaging.h | 18 +++++++++--------- libImaging/Storage.c | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/libImaging/Imaging.h b/libImaging/Imaging.h index 5b8dc2c8388..c1a04124870 100644 --- a/libImaging/Imaging.h +++ b/libImaging/Imaging.h @@ -159,16 +159,16 @@ struct ImagingPaletteInstance { }; typedef struct ImagingMemoryArena { - int alignment; - int block_size; - int blocks_max; - int blocks_cached; + int alignment; /* Alignment in memory of each line of an image */ + int block_size; /* Preferred block size */ + int blocks_max; /* Maximum number of cached blocks */ + int blocks_cached; /* Current number of block not accociated with images */ ImagingMemoryBlock *blocks; - int stats_new_count; - int stats_allocated_blocks; - int stats_reused_blocks; - int stats_reallocated_blocks; - int stats_freed_blocks; + int stats_new_count; /* Number of new allocated images */ + int stats_allocated_blocks; /* Number of allocated blocks */ + int stats_reused_blocks; /* Number of blocks which was retrieved from pool */ + int stats_reallocated_blocks; /* Number of blocks which was actually reallocated after retrieving */ + int stats_freed_blocks; /* Number of freed blocks */ } *ImagingMemoryArena; diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 89ed81d2397..04a365ea82d 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -264,9 +264,11 @@ ImagingDelete(Imaging im) /* ------------------ */ /* Allocate image as an array of line buffers. */ +#define IMAGING_PAGE_SIZE (4096) + struct ImagingMemoryArena ImagingDefaultArena = { 1, // alignment - 1*1024*1024, // block_size + 16*1024*1024, // block_size 0, // blocks_max 0, // blocks_cached NULL, // blocks @@ -382,7 +384,7 @@ ImagingDestroyArray(Imaging im) } Imaging -ImagingAllocateArray(Imaging im, int dirty) +ImagingAllocateArray(Imaging im, int dirty, int block_size) { int y, line_in_block, current_block; ImagingMemoryArena arena = &ImagingDefaultArena; @@ -395,14 +397,13 @@ ImagingAllocateArray(Imaging im, int dirty) } linesize = (im->linesize + arena->alignment - 1) & -arena->alignment; - lines_per_block = arena->block_size / linesize; + lines_per_block = block_size / linesize; if (lines_per_block == 0) lines_per_block = 1; blocks_count = (im->ysize + lines_per_block - 1) / lines_per_block; // printf("NEW size: %dx%d, ls: %d, lpb: %d, blocks: %d\n", // im->xsize, im->ysize, linesize, lines_per_block, blocks_count); - im->destroy = ImagingDestroyArray; /* One extra ponter is always NULL */ im->blocks = calloc(sizeof(*im->blocks), blocks_count + 1); if ( ! im->blocks) { @@ -421,6 +422,7 @@ ImagingAllocateArray(Imaging im, int dirty) } block = memory_get_block(arena, lines_remained * linesize, dirty); if ( ! block.ptr) { + ImagingDestroyArray(im); return (Imaging) ImagingError_MemoryError(); } im->blocks[current_block] = block; @@ -436,6 +438,8 @@ ImagingAllocateArray(Imaging im, int dirty) } } + im->destroy = ImagingDestroyArray; + return im; } @@ -503,7 +507,14 @@ ImagingNewInternal(const char* mode, int xsize, int ysize, int dirty) if ( ! im) return NULL; - if (ImagingAllocateArray(im, dirty)) { + if (ImagingAllocateArray(im, dirty, ImagingDefaultArena.block_size)) { + return im; + } + + ImagingError_Clear(); + + // Try to allocate the image once more with smallest possible block size + if (ImagingAllocateArray(im, dirty, IMAGING_PAGE_SIZE)) { return im; } From 4b85230726db5c56fb603db1aa3b5a0a762a3896 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 23 Sep 2017 04:20:53 +0300 Subject: [PATCH 16/18] clear_cache: number or blocks to keep --- Tests/test_core_resources.py | 7 ++++--- _imaging.c | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Tests/test_core_resources.py b/Tests/test_core_resources.py index 30bea3e802c..11f26d38e80 100644 --- a/Tests/test_core_resources.py +++ b/Tests/test_core_resources.py @@ -129,14 +129,15 @@ def test_clear_cache_stats(self): Image.core.set_block_size(4096) Image.new('RGB', (256, 256)) Image.new('RGB', (256, 256)) - Image.core.clear_cache() + # Keep 16 blocks in cache + Image.core.clear_cache(16) stats = Image.core.get_stats() self.assertGreaterEqual(stats['new_count'], 2) self.assertGreaterEqual(stats['allocated_blocks'], 64) self.assertGreaterEqual(stats['reused_blocks'], 64) - self.assertGreaterEqual(stats['freed_blocks'], 64) - self.assertEqual(stats['blocks_cached'], 0) + self.assertGreaterEqual(stats['freed_blocks'], 48) + self.assertEqual(stats['blocks_cached'], 16) def test_large_images(self): Image.core.reset_stats() diff --git a/_imaging.c b/_imaging.c index be612c1b77e..b7d1ec09b6d 100644 --- a/_imaging.c +++ b/_imaging.c @@ -3466,10 +3466,12 @@ _set_blocks_max(PyObject* self, PyObject* args) static PyObject* _clear_cache(PyObject* self, PyObject* args) { - if (!PyArg_ParseTuple(args, ":clear_cache")) + int i = 0; + + if (!PyArg_ParseTuple(args, "|i:clear_cache", &i)) return NULL; - ImagingMemoryClearCache(&ImagingDefaultArena, 0); + ImagingMemoryClearCache(&ImagingDefaultArena, i); Py_INCREF(Py_None); return Py_None; From 145180a105a751c2359fa9d67873fa2956c68e14 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 23 Sep 2017 04:44:01 +0300 Subject: [PATCH 17/18] fix alignment --- libImaging/Storage.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 04a365ea82d..0f3ed639ec6 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -389,20 +389,21 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) int y, line_in_block, current_block; ImagingMemoryArena arena = &ImagingDefaultArena; ImagingMemoryBlock block = {NULL, 0}; - int linesize, lines_per_block, blocks_count; + int aligned_linesize, lines_per_block, blocks_count; + void *aligned_ptr; /* 0-width or 0-height image. No need to do anything */ if ( ! im->linesize || ! im->ysize) { return im; } - linesize = (im->linesize + arena->alignment - 1) & -arena->alignment; - lines_per_block = block_size / linesize; + aligned_linesize = (im->linesize + arena->alignment - 1) & -arena->alignment; + lines_per_block = block_size / aligned_linesize; if (lines_per_block == 0) lines_per_block = 1; blocks_count = (im->ysize + lines_per_block - 1) / lines_per_block; // printf("NEW size: %dx%d, ls: %d, lpb: %d, blocks: %d\n", - // im->xsize, im->ysize, linesize, lines_per_block, blocks_count); + // im->xsize, im->ysize, aligned_linesize, lines_per_block, blocks_count); /* One extra ponter is always NULL */ im->blocks = calloc(sizeof(*im->blocks), blocks_count + 1); @@ -416,19 +417,25 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) current_block = blocks_count - 1; for (y = 0; y < im->ysize; y++) { if (line_in_block == 0) { + int block_size; int lines_remained = lines_per_block; if (lines_remained > im->ysize - y) { lines_remained = im->ysize - y; } - block = memory_get_block(arena, lines_remained * linesize, dirty); + block_size = lines_remained * aligned_linesize + arena->alignment - 1; + block = memory_get_block(arena, block_size, dirty); if ( ! block.ptr) { ImagingDestroyArray(im); return (Imaging) ImagingError_MemoryError(); } im->blocks[current_block] = block; + /* This is copied from libc _int_memalign */ + aligned_ptr = (void *)( + ((unsigned long) (block.ptr + arena->alignment - 1)) & + -((signed long) arena->alignment)); } - im->image[y] = block.ptr + linesize * line_in_block; + im->image[y] = aligned_ptr + aligned_linesize * line_in_block; line_in_block += 1; if (line_in_block >= lines_per_block) { From 385963928f36fbf81d4742fc744b7b16291f4be0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sat, 23 Sep 2017 04:56:18 +0300 Subject: [PATCH 18/18] make MS C compiler happy --- libImaging/Storage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libImaging/Storage.c b/libImaging/Storage.c index 0f3ed639ec6..eca652727ed 100644 --- a/libImaging/Storage.c +++ b/libImaging/Storage.c @@ -390,7 +390,7 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) ImagingMemoryArena arena = &ImagingDefaultArena; ImagingMemoryBlock block = {NULL, 0}; int aligned_linesize, lines_per_block, blocks_count; - void *aligned_ptr; + char *aligned_ptr; /* 0-width or 0-height image. No need to do anything */ if ( ! im->linesize || ! im->ysize) { @@ -430,7 +430,7 @@ ImagingAllocateArray(Imaging im, int dirty, int block_size) } im->blocks[current_block] = block; /* This is copied from libc _int_memalign */ - aligned_ptr = (void *)( + aligned_ptr = (char *)( ((unsigned long) (block.ptr + arena->alignment - 1)) & -((signed long) arena->alignment)); }