Commit Graph

189 Commits

Author SHA1 Message Date
Andrew Murray
34d04d3e82 Replaced distutils with C version check 2019-12-28 09:57:49 +11:00
Andrew Murray
c0048ad7de Use context managers 2019-11-26 07:03:23 +11: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
Andrew Murray
6cd99fc3cf
Merge branch 'master' into rm-2.7 2019-10-08 18:57:27 +11:00
Jon Dufresne
64032061c0 Move several imports to the top-level of the file
This better follows PEP 8 style guide:

https://www.python.org/dev/peps/pep-0008/#imports

> Imports are always put at the top of the file, just after any module
> comments and docstrings, and before module globals and constants.

This also avoids duplicate import code within the same file.
2019-10-07 06:28:36 -07:00
Hugo
74d2767c57 Remove duplicate line 2019-10-07 14:30:59 +03:00
Hugo
538d9e2e5d Upgrade Python syntax with pyupgrade --py3-plus 2019-10-07 14:30:59 +03:00
Hugo
af770a6c55 Drop support for EOL Python 2.7 2019-10-07 14:30:59 +03:00
Andrew Murray
fb8470187a
Merge pull request #4034 from cgohlke/patch-1
Initialize rows_per_strip when RowsPerStrip tag is missing
2019-09-30 22:32:34 +10:00
Andrew Murray
4de10089f0 Moved libtiff test into libtiff test file 2019-09-29 21:06:11 +10:00
Hugo van Kemenade
f5aed1a254
Merge branch 'master' into patch-1 2019-09-20 22:59:29 +03:00
Andrew Murray
19ab3c36e6 Added test 2019-09-18 22:07:17 +10:00
Andrew Murray
1b70a4c6b5 Use TIFF orientation 2019-09-13 22:36:26 +10:00
chadawagner
34330a7aa0
Update Tests/test_file_libtiff.py
Co-Authored-By: Andrew Murray <3112309+radarhere@users.noreply.github.com>
2019-08-19 09:46:07 -07:00
chadawagner
457a97dde8 added test for reading TIFF from non-disk file obj 2019-08-12 18:56:34 +10: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
Hugo
f5a89a0e9a Use unittest asserts for consistency 2019-06-30 11:13:02 +03:00
Andrew Murray
c994b783ec
Merge branch 'master' into tiff-jpeg-quality 2019-06-30 14:03:09 +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
d00e18b017 Updated test result 2019-06-23 14:01:51 +10:00
David Nisson
ddb61cfbd2 updated tests to match new tile descriptors 2019-06-23 13:59:20 +10:00
Hugo
f87821e010 Format with Black 2019-06-13 18:54:11 +03:00
Konstantin Kopachev
5e5ff10f09 Fix bits value for RGB;16N unpackers 2019-05-10 08:07:01 +10:00
Andrew Murray
ca0d28eae5 Added reading of CMYK;16L TIFF images 2019-05-01 00:42:30 +10:00
Konstantin Kopachev
28c6f555a2
Merge remote-tracking branch 'remotes/upstream/master' into tiff-old-jpeg 2019-03-11 10:38:02 -07:00
Andrew Murray
dd0e4ac0a1 Corrected length of Tiff BYTE tags 2019-02-22 23:17:26 +11:00
Andrew Murray
b0f429adca
Line too long 2019-02-15 22:12:40 +11:00
Andrew Murray
6fc7460f9e
Restored newline at end of file 2019-02-15 20:47:00 +11:00
Andrew Murray
1a7a1123e6
Merge branch 'master' into tiff-old-jpeg 2019-02-15 19:56:17 +11:00
Jon Dufresne
4de5477b61 Remove unnecessary unittest.main() boilerplate from test files
With the introduction and use of pytest, it is simple and easy to
execute specific tests in isolation through documented command line
arguments. Either by specifying the module path or through the `-k
EXPRESSION` argument. There is no longer any need to provide the
boilerplate:

    if __name__ == '__main__':
        unittest.main()

To every test file. It is simply noise.

The pattern remains in test files that aren't named with `test_*` as
those files are not discovered and executed by pytest by default.
2019-02-03 10:10:16 -08:00
Hugo
1885a2cef5
Merge pull request #3579 from jdufresne/run-one-test
Improve pytest configuration to allow specific tests as CLI args
2019-02-03 11:30:57 +02:00
Hugo
187ba3f6e8 Flake8: Fix F723 syntax error in type comment 'dummy value'; it's just a comment, not a Mypy type 2019-01-30 11:53:26 +02:00
Jon Dufresne
7da17ad41e Improve pytest configuration to allow specific tests as CLI args
The previous test configuration made it difficult to run a single test
with the pytest CLI. There were two major issues:

- The Tests directory was not a package. It now includes a __init__.py
  file and imports from other tests modules are done with relative
  imports.

- setup.cfg always specified the Tests directory. So even if a specific
  test were specified as a CLI arg, this configuration would also always
  include all tests. This configuration has been removed to allow
  specifying a single test on the command line.

Contributors can now run specific tests with a single command such as:

  $ tox -e py37 -- Tests/test_file_pdf.py::TestFilePdf.test_rgb

This makes it easy and faster to iterate on a single test failure and is
very familiar to those that have previously used tox and pytest.

When running tox or pytest with no arguments, they still discover and
runs all tests in the Tests directory.
2019-01-13 09:00:12 -08:00
Jon Dufresne
3e28ba3b7d Python del is a statement not a function
https://docs.python.org/3/reference/simple_stmts.html#the-del-statement
2019-01-12 18:28:35 -08:00
Andrew Murray
6ead422e91 Added custom string TIFF tags 2018-12-29 16:14:52 +11:00
Konstantin Kopachev
e91b851fdc
Add reading old-JPEG compressed TIFFs
Old-style JPEG compression in TIFFs are able to be read using Strip/Tile APIs. Although, it should be possible to read them using Scanline API, it does not work for some reason.  Anyway, reading subsampled YCbCr formats through Strip/Tile/Scanline libtiff API does not de-subsample the data, so caller should unpack data to whatever format is appropriate.  New-style JPEG compressed images were already read through libtiff as RGB images (https://github.com/python-pillow/Pillow/pull/3227). Unfortunately, there is no flag to ask libtiff to de-subsample old jpeg, but it provides a way to read any image as 32bit RGBA.  This commit adds ability to read old-style JPEG TIFFs through reading *all* YCbCr images as RGBX using Tile and Strip reading API. This supersedes previous work (PR #3227) to read new-style JPEG-TIFFs.
2018-12-10 10:07:41 -08:00
Andrew Murray
ddf8593e7b Do not write custom tags with libtiff < 4 2018-11-12 06:14:04 +11:00
Andrew Murray
a3d45e9cef Added custom int and float TIFF tags 2018-11-12 06:14:04 +11:00
Hugo
a3b0659790 flake8 2018-10-24 22:29:01 +03:00
Hugo
d1ca4916e0 Use more specific assertions 2018-10-24 22:29:01 +03:00
Andrew Murray
c7d924fd85 Too many blank lines 2018-10-21 18:11:50 +11:00
Hugo
d36365f4fb
Merge pull request #3227 from kkopachev/master
Adding support to reading tiled and YcbCr jpeg tiffs through libtiff
2018-09-29 19:45:29 +03:00
Hugo
84b4905a94
Merge pull request #3310 from radarhere/compression
Fixed None as TIFF compression argument
2018-09-29 19:44:43 +03:00
Hugo
b9b4c03957
Merge pull request #2203 from jdufresne/test-exceptions
Avoid catching unexpected exceptions in tests
2018-09-26 15:43:41 +03:00
Konstantin Kopachev
b0e5e5fb11
Update test files to be closer match of originals 2018-09-18 12:05:51 -07:00
Konstantin Kopachev
52637a4268
move libtiff-related tests into libtiff test file 2018-09-18 12:05:50 -07:00
wiredfool
4cfcc3b010 Tests for issue #1765 2018-09-07 20:32:54 +10:00
Jon Dufresne
875e8c4bda Avoid catching unexpected exceptions in tests
Instead, allow exceptions to bubble up to the unittest exception
handler.

Prevents replacing the exception trace with a less informative
message. As the exceptions are always unexpected, should not need to
catch them explicitly in tests.
2018-09-04 19:43:20 -07:00
Andrew Murray
36b1afff26 Fixed None as TIFF compression argument 2018-08-25 08:21:43 +10:00
Andrew Murray
c2189235af Line too long 2018-07-02 19:26:02 +10:00
Andrew Murray
0e61d4be9f Removed unused variables 2018-07-02 19:21:44 +10:00
Andrew Murray
dcf6bc047b Do not use bare except 2018-07-02 19:21:44 +10:00
Andrew Murray
b4e6cdadac Added py3 variable to _util 2018-04-20 09:19:13 +10:00
Eric Soroos
768668c1d7 Added RGB*;16N Unpackers 2017-12-20 13:53:14 +00:00
Eric Soroos
e617d05b9e These tests/features now require libtiff 2017-12-20 12:22:28 +00:00
Eric Soroos
4b4f7d6a2c Refactor to use features 2017-12-20 12:21:33 +00:00
Eric Soroos
d698d522ef Added end to end tests in test_file_libtiff 2017-12-20 12:09:26 +00:00
Andrew Murray
9e843a2d9b Changed format of lambda calls 2017-09-01 21:05:40 +10:00
wiredfool
c16ba722f2 Merge pull request #2551 from jdufresne/keys
Remove unnecessary calls to dict.keys()
2017-06-13 13:12:48 +01:00
Andrew Murray
e8cba27bb1 Changed assert checks to more specific versions 2017-06-03 14:04:54 +10:00
Jon Dufresne
d244fbb299 Remove unnecessary calls to dict.keys()
iter(dict) is equivalent to iter(dict.keys()), so simply act on the dict
instead of adding the extra call.

Inspired by Lennart Regebro's PyCon 2017 presentation "Prehistoric
Patterns in Python". Available at:

https://www.youtube.com/watch?v=V5-JH23Vk0I
2017-05-28 09:55:38 -07:00
Andrew Murray
37b293f593 Flake8 fixes 2017-04-20 21:14:23 +10:00
Marcus Brinkmann
5bdf1e4998 Test for libtiff, n_frames and seek. 2017-03-14 23:17:22 +00:00
Andrew Murray
1fcdf6a2db Removed duplicate test 2017-03-03 21:38:19 +11:00
Hugo
e83479edf0 Merge pull request #2263 from wiredfool/tiff_bytesio
Fix for writing Tiff to BytesIO using libtiff
2016-12-09 11:04:41 +02:00
wiredfool
aa247dbb60 Moving tests requiring libtiff to test_file_libtiff 2016-12-05 08:25:10 -08:00
wiredfool
86606022c5 Merge pull request #2193 from SemanticsOS/lambdafu/libtiff-icc
Update info.icc_profile when using libtiff reader.
2016-12-03 13:44:26 +00:00
wiredfool
ce3432f5f4 Test for issue #2206 2016-11-23 06:24:40 -08:00
Jon Dufresne
dbe9f85c7d Drop support for Python 2.6
* Drop unittest2 requirement
* Use set literals
* Use dict/set comprehension
* Use str.format() automatic numbering
2016-11-22 04:23:55 -08:00
Marcus Brinkmann
66de02685f Update info.icc_profile when using libtiff reader. 2016-11-04 16:37:49 +01:00
wiredfool
b81da5a322 Tests for issue #1651 2016-09-29 22:29:19 +01:00
hugovk
2c4a1209f4 flake8 2016-08-04 09:40:12 +03:00
homm
1ba4e9e5ba remove end of file banner from all files 2016-07-10 14:11:28 +03:00
wiredfool
be2100be7b Skip tests that require libtiff if it is not installed, fixes #1866 2016-05-06 09:07:00 -07:00
wiredfool
14f3b45f46 Merge pull request #1789 from zwhfly/tiff
Add Support for 2/4 bpp Tiff Grayscale Images
2016-04-03 12:07:48 -07:00
Andrew Murray
677b958a7f Health fixes 2016-04-01 21:49:30 +11:00
zwhfly
124bee0485 Add Tests for 2/4 bpp Tiff Grayscale Images
Including inverted and/or bit-order-reversed formats.
2016-03-29 20:19:22 +08:00
wiredfool
e5076a3278 Merge pull request #1620 from wiredfool/issue_1597
Partial fix for #1597
2016-01-01 07:47:58 -08:00
wiredfool
36d4f5a9b4 Tests for permitted libtiff metadata 2016-01-01 05:30:40 -08:00
Andrew Murray
a83bcec169 Flake8 fixes 2015-12-31 07:27:27 +11:00
wiredfool
9fa6634f4d Partial fix for #1597
Haven't excercized all of the metadata that we're allowing yet,
and there's clearly still something up with Arrays, as one
of them is still crashing and making it impossible to save a
palette with a libtiff image.
2015-12-30 07:54:14 -08:00
wiredfool
b68bb56b64 test for issue #1561 2015-12-14 20:24:01 +00:00
wiredfool
05348d4f8f Reenabling failing/crashing tests, with fixes 2015-09-14 03:03:24 -07:00
wiredfool
c2818ee09e Add versioned api to tests 2015-09-13 16:19:40 +01:00
wiredfool
f3ab9b9f81 temp removing segfaulting test on travis 2015-09-13 14:38:51 +01:00
wiredfool
2636679868 updating tests for legacy_api api change 2015-09-13 14:08:49 +01:00
wiredfool
0c942911d9 fixed the rebase 2015-09-11 22:39:37 +01:00
Antony Lee
c113e8f7cd libtiff's rational precision is limited to C floats. 2015-09-11 22:39:37 +01:00
Antony Lee
93abbd0caa Restore legacy TIFF API.
To have the old API that always returns tuples, and fractions as pairs,
set the `legacy_api` attribute of the IFD to True.

This should alleviate concerns about backwards compatibility.
2015-09-11 22:39:37 +01:00
Antony Lee
974bcc074b Major rewrite of TIFF ImageFileDirectory.
Do not represent scalar tags as 1-element tuples.  Keep tag
type and count information in TiffTags.TAGS.  Normalize data in
ImageFileDirectory.__setitem__: wrap and unwrap tuples as needed,
convert rationals to floats.  (To ensure consistency, make the "tags"
attribute private.)  Interpret byte data as a series of integers rather
than a bytearray (which should only map to the "undefined" type).  On
Python3, if a str is assigned to an "undefined" tag, encode it as ASCII.

Note that a large number of tags have been removed from TiffTags.TAGS
because I do not have time to figure out the type and count of each of
them.  They should be restored before this gets merged in.

This obviously breaks backwards compatibility in a lot of ways...
2015-09-11 22:34:50 +01:00
Antony Lee
4e754e9c55 Use logging instead of print.
cf. #1191.

Only TiffImagePlugin and OLEFileIO still rely on (their own) DEBUG flag.
I left TiffImagePlugin as it is because I hope #1059 gets merged in
first, and OLEFileIO because it uses its own logic.

Untested, as usual.
2015-06-29 12:39:50 -07:00
Andrew Murray
4e2de9d9ed Added missing future print imports and removed unnecessary imports 2015-05-23 20:28:41 +10:00
Andrew Murray
ee34d6843b Further health fixes 2015-04-24 18:24:52 +10:00
Andrew Murray
7f414057c9 Fixed redefinition of built-in 2015-04-24 16:02:39 +10:00
Andrew Murray
d1c182cadc Various Flake8 fixes 2015-04-24 09:26:52 +10:00
Hugo
02476b7689 Remove unused variable, and other minor flake8 warnings 2014-11-17 10:33:31 +02:00
wiredfool
9a2cc7df83 hoist import, move test to libtiff 2014-11-15 20:38:52 -08:00
wiredfool
2d2474685a Added 4bit test to libtiff as well 2014-10-29 11:07:20 -07:00