Commit Graph

61 Commits

Author SHA1 Message Date
Andrew Murray
4d0e8e74b4 Use im property 2024-08-10 10:20:08 +10:00
Andrew Murray
b17f1e507b Use f-strings 2024-05-07 14:01:08 +10:00
Andrew Murray
3a92d4af01 Replace ImageMath.eval with ImageMath.lambda_eval 2024-04-09 07:34:52 +10:00
Andrew Murray
bc5ec2268a Added type hints 2023-12-26 22:26:11 +11:00
Hugo van Kemenade
43b2f61e79 Add 'from __future__ import annotations' using Ruff/isort 2023-12-21 13:13:31 +02:00
Hugo van Kemenade
ee85e387ba Remove redundant parentheses 2022-04-10 23:39:54 +03:00
Andrew Murray
f8e4e9c2dd Added enums 2022-01-15 09:02:31 +11:00
Andrew Murray
84ee93f7bf Moved _info function into docstring 2021-09-13 17:14:59 +10:00
Andrew Murray
b8c8375d0c Use python3 in shebang line 2021-04-09 19:10:36 +10:00
Andrew Murray
eb2a0622a3 Removed broken link 2021-01-10 08:26:45 +11:00
Hugo
dda6145fce Since Python 3.3 IOError and WindowsError have been merged into OSError 2020-04-10 12:57:29 +03:00
Hugo van Kemenade
5006401d0b
Merge branch 'master' into rm-2.7 2019-11-03 22:48:26 +02:00
Hugo van Kemenade
6060ed3d14
Merge pull request #4091 from nulano/libimagequant-features
Add libimagequant to features.py
2019-11-02 21:31:09 +02:00
Hugo
cc63f66575 Merge remote-tracking branch 'upstream/master' into rm-2.7 2019-11-01 13:22:56 +02:00
Jon Dufresne
4cd4adddc3 Improve handling of file resources
Follow Python's file object semantics. User code is responsible for
closing resources (usually through a context manager) in a deterministic
way.

To achieve this, remove __del__ functions. These functions used to
closed open file handlers in an attempt to silence Python
ResourceWarnings. However, using __del__ has the following drawbacks:

- __del__ isn't called until the object's reference count reaches 0.
  Therefore, resource handlers remain open or in use longer than
  necessary.

- The __del__ method isn't guaranteed to execute on system exit. See the
  Python documentation:

  https://docs.python.org/3/reference/datamodel.html#object.__del__

  > It is not guaranteed that __del__() methods are called for objects
  > that still exist when the interpreter exits.

- Exceptions that occur inside __del__ are ignored instead of raised.
  This has the potential of hiding bugs. This is also in the Python
  documentation:

  > Warning: Due to the precarious circumstances under which __del__()
  > methods are invoked, exceptions that occur during their execution
  > are ignored, and a warning is printed to sys.stderr instead.

Instead, always close resource handlers when they are no longer in use.
This will close the file handler at a specified point in the user's code
and not wait until the interpreter chooses to. It is always guaranteed
to run. And, if an exception occurs while closing the file handler, the
bug will not be ignored.

Now, when code receives a ResourceWarning, it will highlight an area
that is mishandling resources. It should not simply be silenced, but
fixed by closing resources with a context manager.

All warnings that were emitted during tests have been cleaned up. To
enable warnings, I passed the `-Wa` CLI option to Python. This exposed
some mishandling of resources in ImageFile.__init__() and
SpiderImagePlugin.loadImageSeries(), they too were fixed.
2019-10-12 08:27:17 -07:00
nulano
accbe58b5e add Python version to selftest, rename brief parameter 2019-10-12 15:40:12 +01:00
Hugo
538d9e2e5d Upgrade Python syntax with pyupgrade --py3-plus 2019-10-07 14:30:59 +03:00
nulano
5f4c1e113c add libimagequant to features.py 2019-09-27 00:34:45 +02:00
Jon Dufresne
d50445ff30 Introduce isort to automate import ordering and formatting
Similar to the recent adoption of Black. isort is a Python utility to
sort imports alphabetically and automatically separate into sections. By
using isort, contributors can quickly and automatically conform to the
projects style without thinking. Just let the tool do it.

Uses the configuration recommended by the Black to avoid conflicts of
style.

Rewrite TestImageQt.test_deprecated to no rely on import order.
2019-07-06 16:11:35 -07:00
Alexander Böhn
7b815a5f1d Added an image.entropy() method
This calculates the entropy for the image, based on the histogram.

Because this uses image histogram data directly, the existing C
function underpinning the `image.histogram()` method was abstracted
into a static function to parse extrema tuple arguments, and a new
C function was added to calculate image entropy, making use of the
new static extrema function.

The extrema-parsing function was written by @homm, based on the
macro abstraction I wrote, during the discussion of my first
entropy-method pull request: https://git.io/fhodS

The new `image.entropy()` method is based on `image.histogram()`,
and will accept the same arguments to calculate the histogram data
it will use to assess the entropy of the image.

The algorithm and methodology is based on existing Python code:

* https://git.io/fhmIU

... A test case in the `Tests/` directory, and doctest lines in
`selftest.py`, have both been added and checked.

Changes proposed in this pull request:

* Added “math.h” include to _imaging.c
* The addition of an `image.entropy()` method to the `Image`
  Python class,
* The abstraction of the extrema-parsing logic of of the C
  function `_histogram` into a static function, and
* The use of that static function in both the `_histogram` and
  `_entropy` C functions.
* Minor documentation addenda in the docstrings for both the
  `image.entropy()` and `image.histogram()` methods were also
  added.
* Removed outdated boilerplate from testing code
* Removed unused “unittest” import
2019-06-26 19:15:47 +10:00
Hugo
471220093b Format with Black 2019-06-13 18:54:57 +03:00
Hugo
91da8ff31d flake8: F401 imported but unused 2018-11-11 19:01:10 +02:00
Hugo
e33dd498f5 Prefer more conventional __version__ rather than PILLOW_VERSION 2018-04-25 11:21:38 +03:00
wiredfool
7619018257 remove --installed tweaking in selftest.py 2017-12-28 14:51:55 +00:00
Jason Douglas
c18d26b04b - Conditonally compile animation support, only if the mux.h and demux.h headers meet the ABI version requirements
- Add WEBPMUX support back to WebPDecode_wrapper (to support older versions of libwebp that have mux support, but not animation)
- Add HAVE_WEBPANIM flag, and use it appropriately
- Update documentation / tests
2017-09-27 19:04:24 -07:00
wiredfool
42831098ac Fix RAQM feature detection 2017-06-21 14:00:15 -07:00
shamsa
fcd20da3cb Testing complex text layout. 2017-06-21 14:00:14 -07:00
Eric Soroos
d012f50975 Simplify feature checking, fix transparent webp detection, add webpmux detection 2017-06-13 04:20:21 -07:00
Andrew Murray
57bab081b9 Set executable flag on selftest.py and added shebang line 2016-12-11 12:30:11 +11:00
Andrew Murray
86828ffd2a Replaced del with pop 2016-06-18 11:25:39 +10:00
Andrew Murray
0907f423ca Removed unused variable from selftest 2016-03-29 22:53:48 +11:00
Andrew Murray
a9efd7ad98 Stopped modules from importing themselves 2015-12-02 16:37:50 +11:00
Andrew Murray
aed878e7d1 Adjusted selftest feature label to be in sync with setup 2015-05-15 07:42:22 +10:00
Andrew Murray
98fa49ea37 Changed module and codec names 2015-05-14 20:57:01 +10:00
Andrew Murray
799e8312cb Separated out feature checking from selftest 2015-05-14 19:43:28 +10:00
hugovk
699b662511 Update selftest.py for hopper 2014-09-04 09:50:47 +03:00
Hugo
d7f7965aa2 Replace lena.gif with hopper.gif 2014-09-04 08:44:46 +03:00
hugovk
78003ca473 Update paths to Tests/images/ instead of Images/ 2014-06-23 09:19:29 +03:00
Alastair Houghton
ac8ebccfa6 Added tests and fixed a few bugs that the tests threw up. 2014-03-19 12:16:14 +00:00
cgohlke
e06a0d6139 Report availability of LIBTIFF during selftest 2013-12-29 19:12:06 -08:00
wiredfool
e9e5599412 buildable, selftest registers properly 2013-10-01 23:05:56 -07:00
Alex Clark
26995d7b02 Support selftest.py --installed, fixes #263
Courtesy of @Arfrever
2013-06-30 19:16:27 -04:00
Christoph Gohlke
c48590bfba Fix ImportError during selftest. Remove path silliness.
Also apply PEP8 and print Pillow version during test.
2013-06-29 19:13:55 -07:00
wiredfool
b3752ca053 merge from master 2013-05-21 21:29:58 -07:00
Alex Clark
cb28745049 Wording 2013-05-21 17:44:21 -04:00
wiredfool
a5499170f9 Feature for transparent webp 2013-05-15 17:22:41 -07:00
wiredfool
7f178bc0b6 selftests pass with namespaces on py2.7/3.2 2013-04-08 22:42:49 -07:00
wiredfool
517e0210ab webp to PIL in selftest 2013-04-08 22:41:31 -07:00
wiredfool
c774f9ab4c merged pull request #88 to master, resolved conflicts 2013-04-08 20:31:28 -07:00
Christoph Gohlke
8b440811b5 Fix support not installed messages during selftest
The extension modules are currently not installed in PIL but sys.path.
2013-03-14 12:34:56 -07:00