Commit Graph

215 Commits

Author SHA1 Message Date
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
Andrew Murray
a8c07e3d5f Added orientation note [ci skip] 2019-10-11 22:40:31 +11:00
Andrew Murray
ecb3a30487 Clarified documentation [ci skip] 2019-10-06 13:52:58 +11:00
Hugo
f792ab6c02 RST uses double backticks for code (MD uses 1) 2019-09-13 08:56:33 +03:00
Andrew Murray
5ad5be4a32 Reference Pillow not PIL [ci skip] 2019-09-06 06:13:12 +10:00
Andrew Murray
51457311de
Reference Pillow not PIL [ci skip]
Co-Authored-By: Hugo van Kemenade <hugovk@users.noreply.github.com>
2019-09-06 06:10:40 +10:00
Andrew Murray
2a7ad14172 Added more limited support modes [ci skip] 2019-09-05 20:10:43 +10:00
Andrew Murray
0527efd593 Corrected documentation of TIFF saving arguments [ci skip] 2019-08-07 19:53:35 +10:00
Oliver Tonnhofer
2b7d8be536 tiff: add support for JPEG quality
Uses JPEGQUALITY pseudo-tag from libtiff.

Also changes the way tags are passed to PyImaging_LibTiffEncoderNew from
dict to list to ensure that COMPRESSION tag is added before JPEGQUALITY.
This is required as the COMPRESSION tag registers the JPEGQUALITY
pseudo-tag.
2019-06-26 06:33:54 +10:00
Oliver Tonnhofer
61add9d6b0 Improve encoding of TIFF tags
- Pass tagtype from v2 directory to libtiff encoder, instead of
autodetecting type.
- Use explicit types. E.g. uint32_t for TIFF_LONG to fix issues on
platforms with 64bit longs.
- Add support for multiple values (arrays). Requires type in v2
directory and values must be passed as a tuple.
- Add support for signed types (e.g. TIFFTypes.TIFF_SIGNED_SHORT).
2019-06-26 06:33:19 +10:00
Andrew Murray
0a73e31415 Added note about RGBX padding 2019-06-21 19:37:43 +10:00
Andrew Murray
231fe4d62a Revert "Merge pull request #3838 from radarhere/i_conversion"
This reverts commit 41f3e7c8bd, reversing
changes made to 2f84482871.
2019-06-11 19:28:31 +10:00
Hugo
41f3e7c8bd
Merge pull request #3838 from radarhere/i_conversion
Improved I mode conversion
2019-06-05 22:23:35 +03:00
Andrew Murray
e1df2118b3 Link method [ci skip] 2019-06-02 13:34:18 +10:00
Andrew Murray
a258b8dcdc
Apply suggestions from code review [ci skip]
Co-Authored-By: Hugo <hugovk@users.noreply.github.com>
2019-05-09 19:05:06 +10:00
Andrew Murray
64eff66ee7 Updated pixel range documentation [ci skip] 2019-05-09 14:32:14 +10:00
Andrew Murray
f9f235ac2e Corrected use of function [ci skip] 2019-05-06 08:40:32 +10:00
Andrew Murray
38df9bef09 Added import [ci skip] 2019-05-06 08:38:43 +10:00
Andrew Murray
1d67bf0539 Document pixel range [ci skip] 2019-05-04 16:11:16 +10:00
Andrew Murray
d31de47768 Added release notes [ci skip] 2019-04-01 21:16:52 +11:00
Andrew Murray
9699ac40c7 n_frames is not an info key [ci skip] 2019-03-31 12:44:39 +11:00
Andrew Murray
7a845ee2e7 Corrected seek documentation [ci skip] 2019-03-31 12:43:09 +11:00
Andrew Kuchling
7ca0c189e3 Various documentation fixes [ci skip]
* TIFF: describe num_frames and seek()/tell()
* Link methods to PIL.Image class instead of the Python file object
* It doesn't seem like the Spider plug-in actually has an 'nimages' attribute
* Fix markup for exception name
2019-03-31 12:14:53 +11:00
Andrew Murray
4a5666f1f4 Added transparency for all PNG greyscale modes 2019-03-27 07:41:33 +11:00
Andrew Murray
fa8ecffff2 Corrected seek documentation 2019-03-17 00:00:10 +11:00
Andrew Murray
0ad09f7386
Merge branch 'master' into mime-types 2019-03-15 07:06:59 +11:00
Andrew Murray
ebdb1ffc54 Added PNM to the list of PPM files [ci skip] 2019-03-14 08:35:27 +11:00
Andrew Murray
f06056cc1f Updated PNG modes [ci skip] 2019-03-12 21:10:59 +11:00
Andrew Murray
8ddcc1de52 Load EXIF from PNG where eXIf chunk is after first IDAT chunk 2019-03-11 21:20:18 +11:00
Hugo
5da0d5beee
Merge pull request #3673 from radarhere/dds
Add reading of DDS uncompressed RGB data
2019-03-11 12:04:47 +02:00
Andrew Murray
2764031762 Changed PIL references to Pillow [ci skip] 2019-03-08 21:04:23 +11:00
Andrew Murray
1c1bad3186 Document the DIB image format [ci skip] 2019-03-08 21:04:01 +11:00
Andrew Murray
148d320b40 Added reading of uncompressed RGB data 2019-02-23 06:44:06 +11:00
Andrew Murray
828a6f947c Fixed typo [ci skip] 2019-02-12 20:35:23 +11:00
Andrew Murray
95d80a7e5d Corrected data type [ci skip] 2018-12-24 17:05:38 +11:00
Andrew Murray
cea6ecfdbb Updated example decoders [ci skip] 2018-09-30 14:07:55 +10:00
Hugo
e2deb07608
Merge pull request #3274 from radarhere/pdf
Improve PDF document info
2018-09-29 17:43:05 +03:00
Andrew Murray
bd600c6966 Crop is no longer lazy [ci skip] 2018-09-29 15:31:10 +10:00
Andrew Murray
6072e2e595 Changed note to be more generic [ci skip] 2018-09-29 15:12:48 +10:00
Andrew Murray
f4fd517373 Removed blank line after heading for consistency [ci skip] 2018-09-05 21:05:09 +10:00
Andrew Murray
d86fa316ca Fixed typo [ci skip] 2018-09-05 21:02:32 +10:00
Andrew Murray
fc57658635 Added PDF creation and modification date info 2018-08-25 00:58:49 +10:00
Andrew Murray
af817c83ad Corrected links for Read The Docs [ci skip] 2018-08-23 21:07:25 +10:00
Andrew Murray
de7b43397a Added links to installation documentation [ci skip] 2018-08-23 20:36:05 +10:00
Andrew Murray
a91cb4b24a Improved GIF documentation [ci skip] 2018-08-04 22:35:48 +10:00
Hugo
a2c6a5a38e Update CHANGES, image-file-formats and release notes [CI skip] 2018-07-01 22:24:35 +03:00
Hugo
80d399a485
Merge pull request #3178 from danpla/tga-la
TGA: Read and write LA data
2018-07-01 21:57:10 +03:00
Alex Clark
eafbb395a9
Merge pull request #1817 from radarhere/gd
Added GD tests
2018-06-30 18:01:36 -04:00
Andrew Murray
7274636a7e Added coordinate system links in documentation 2018-06-24 14:34:01 +10:00
Andrew Murray
6b224bed34 Updated documentation [ci skip] 2018-06-16 22:29:34 +10:00