Fix setting of TIFF ExtraSamples tag#1059
Fix setting of TIFF ExtraSamples tag#1059anntzer wants to merge 10 commits intopython-pillow:masterfrom
Conversation
|
ok, will check |
|
We're going to need more than this to conform to the spec when writing tags. (ref: http://www.remotesensing.org/libtiff/man/TIFFSetField.3tiff.html) This winds up calling TIFFVSetField with variable args -- with the arguments for specific tags being the correct types as listed in the doc referenced. Unfortunately, it's not consistent where arrays are represented as ct, [number]. Some of them are [number] with a fixed length (e.g. TIFFTAG_PRIMARYCHROMATICITIES), some are ct, [number]* (e.g. TIFFTAG_EXTRASAMPLES). What we're going to need to do to do this properly is to list the known tags & types, and make sure that we're emitting the right types and data for those. Additionally, we'd then know which are the unknown tags, which would then need to be dealt with separately by adding them to the tiff types dictionary prior to adding the tag. (#983, #660) |
8968a85 to
4da52b7
Compare
|
I gave in and just rewrote the whole thing. |
|
Wow, that you did. |
|
|
|
I just noticed your comment on #520 about incompatibilities. Do you have any specific suggestions? It is not clear to me how to keep full backwards compatibility there... |
|
I don't have specific suggestions yet -- I haven't gotten in the headspace to go through and see what all is failing from the tests (since right now, they're fail fast, there could be many hiding behind the one failure), and even if the tests are actually covering what needs to be covered. Breaking user's code is something that I don't want to do, at least without some deprecation warnings and a phase in over some time. (From a quick look, the two things that concern me are changing some of the test items -- but I need to look closer to see if that's changing internal implementation details, or changing the only way people had to get that information, and the changes in the way that the TiffTags are done, especially removing a huge chunk of tags that we did have in there. ) I think what I'd probably look at doing is building up the IFD info in whatever api and structure works for it, including supporting EXIF (since it's the same thing), then blessing the new api as the way to do it. I'd then go back and make the old api work in a best-effort / best-guess approach, building on the new, working core. |
|
|
b58fdaa to
c3be6d4
Compare
|
The removal of a huge chunk of tags is simply due to the fact that I was too lazy to figure out the type of each of the tags, as this is now needed. This can easily be added back once we have decided on the actual API, which I agree is the main issue. |
c3be6d4 to
d1e2db6
Compare
|
Changes Unknown when pulling d1e2db6 on anntzer:tiff-extra-samples into * on python-pillow:master*. |
|
@anntzer Some tips. Make full use of Travis CI to run the full test suite on all Python versions. I recommend enabling Travis (and Coveralls, seeing as you're making a big change) for your own account, so you can have your own branches fully tested. They're free for open source. See https://github.com/python-pillow/Pillow/blob/master/CONTRIBUTING.md for guidelines. If you want to temporarily disable fail-first and see all test failures, remove the
It'll need to be re-enabled when everything is all done and the PR is ready for merging. Ideally all changed code should be covered by tests, and especially for big changes, it's wise to make sure there are specific tests for the functionality being changed. |
d1e2db6 to
3b0e0bf
Compare
|
|
|
I don't really want to shoehorn the old API on top of the new one, so what about the following: have a global tag (e.g., |
|
@anntzer Any progress on this? |
|
Did you see the Feb 25th commits? I was waiting for your opinion on the approach (providing a |
|
Ah, thanks. We probably need @wiredfool or @hugovk to review. |
cf. python-pillow#1191. Only TiffImagePlugin and OLEFileIO still rely on a DEBUG flag. I left TiffImagePlugin as it is because I hope python-pillow#1059 gets merged in first, and OLEFileIO because it uses its own logic. Untested, as usual.
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.
Some programs generate SamplesPerPixel entries in ExtraSamples instead of SamplesPerPixel-3, cf. python-pillow#1227. This is a stopgap measure to support them. One could also decide to add generic code to always support having SamplesPerPixel entries (by dropping the first 3).
By interleaving little and big-endian entries we make sure entries exist for both cases. Some additional entries created when the big-endian was missing. I am not sure of what entry to create for the big-endian, 4-bit case (what is the order of the two entries within the byte?).
662e815 to
752d463
Compare
|
Sorry, I rebased mostly just to get a new appveyor build (I guess something went wrong during the transition). |
309984e to
d27cddd
Compare
|
Can someone reproduce Travis's failures locally? Despite my best attempts I cannot reproduce them (on Linux 64bit). In theory I could "fix" the failures by replacing calls to |
|
I am unable to reproduce on OS X. |
|
I can reproduce on Ubuntu 12.04/x64. Changing the assert to yields: They are roughly equivalent, but different representations. |
|
Sorry, I won't have the time to work on this in the next few days. We could switch back to assertAlmostEqual (which as I mentioned earlier was already used by the earlier tests) for now... |
|
The problem is that I have no idea of where (634011008, 16777216) comes from. It is not that hard to see that the value actually stored in the file is (4294967295, 113653537) (hex dump |
f6e453a to
95d619a
Compare
|
Half-fudging it, but not really: libtiff's precision for "rationals" is limited to C floats, not C doubles, so it should be enough to require roundtripping up to that precision. |
|
Sad. |
|
See #1419 |
|
Closing, merged #1419 which contains this branch. |

(cf. PIL fails to roundtrip some TIFF images #1039, Fix incorrect TIFF SAVE_INFO. #1045)