Skip to content

Tiled tif write support #672

Description

@jamesra

I would like to write some BigTiff 4GB+ images as tiled tiffs to export data to an Omero server. Pillow appears to support reading tiled tiff but not writing.

Being optimistic I naively added the TileWidth and TileLength tags to a tifinfo dictionary passed to the save function the result is an invalid tif file. My test code can be found on github here:

https://github.com/jamesra/random/blob/master/pillow_tif_tiles.py

TiffInfo shows the tags correctly in the resulting tif file, but it fails to load in Photoshop or any of the built-in Windows viewers I tried.

Activity

  1. wiredfool commented on May 22, 2014

    @wiredfool
    Member

    The libtiff support is pretty much only for writing a single tile. IIRC, It's going to take working on some of the low level code to make it work with tiles.

  2. jamesra commented on May 23, 2014

    @jamesra
    Author

    There appear to be write functions in libtiff:
    http://www.libtiff.org/man/TIFFWriteTile.3t.html

    I may play with a crude implementation tomorrow if I can reach that function from Pillow. I'm still trying to wrap my head around what needs to be done.

  3. wiredfool commented on May 23, 2014

    @wiredfool
    Member

    The encoding is (helpfully enough) in TiffDecode.c, with the setup at the bottom of encode.c.

    The setup code is in TiffImagePlugin.py -- if you're running with libtiff it actually does the save in _save instead of calling out to ImageFile._save. ImageFile._save does the tiles, save is hardwired for one.

    TiffWriteTile may be a near drop in replacement to the shuffle and TiffWriteScanline function call in TiffDecode.c:ImagingLibTiffEncode. If that's the case, and it works in the single tile case, then it may just be a case of removing the hardwired encode call in TiffImagePlugin and using ImageFile._save instead.

    I've meant to go back and clean up some of the tiff support for a while, If you can't get your head around it, I'll take a look at it at some point.

  4. jamesra commented on May 28, 2014

    @jamesra
    Author

    Do all paths lead to LibTiff eventually? I'm trying to setup a debug environment for VS 2008. I'd like my system to work without installing additional dependencies. My users and I utilize the Gohlke installer to obtain Pillow for Windows. When I debug python the trace indicates that libtiff is not installed. However when I follow the chain through ImageFile._save the encoder seems to reach TiffDecode.c:LibTiffEncoderNew both paths appear to use libitff.

    Thanks for offering to look. If you have npt seen a pull request by about 6/6/2014 I've probably had to work on other projects for a bit. I would still love and use a fix.

  5. wiredfool commented on May 28, 2014

    @wiredfool
    Member

    More and more roads are leading to libtiff. I think cgohilke's installers use statically linked libraries, so you'll have the tiff that it's compiled against.

    And I do seem to remember that it's a pain to setup the debugging libs on windows.

  6. jamesra commented on May 28, 2014

    @jamesra
    Author

    Yes it is. I've made it close to a semi-functional debug setup. I can pass selftest.py and the libtiff tests are either slow or frozen. Others such as JPeg seem to be passing.

    One change change to the source of TiffDecode.h to compile on Windows was changing unistd.h to io.h

    #ifndef _UNISTD_H
        #if defined(_MSC_VER)
            #include \<io.h>
            #define _UNISTD_H
        #else
            #include \<unistd.h>
        #endif  
    #endif
    

    Would you like that as a separate pull request? Is there a better way for me to structure that #if test to be cross-platform?

  7. aclark4life commented on Jun 7, 2014

    @aclark4life
    Member

    Is there any associated PR for this one yet?

  8. added this to the 2.5.0 milestone on Jun 7, 2014
  9. jamesra commented on Jun 7, 2014

    @jamesra
    Author

    No sorry. I got stuck on the Windows dev environment and had to set it aside to work on something else for a bit. If you want to take a shot at it that would be great.

  10. jamesra commented on Jun 7, 2014

    @jamesra
    Author

    Oh... I didn't read the post above yours. If you are asking about the #include change I didn't create a pull request yet because even though the alteration allows the build to complete I am not able to pass the tif tests with the resulting build. Some of the other tests do pass though.

    The change in my branch is here:
    jamesra@13c39cb

    It would be easy to create the pull if it is wanted.

  11. aclark4life commented on Jun 8, 2014

    @aclark4life
    Member

    Sure please do send, thanks

  12. modified the milestones: Future, 2.5.0 on Jun 22, 2014
  13. jamesra commented on Jun 23, 2015

    @jamesra
    Author

    I haven’t had a chance to make progress.

    It has been a while but I vaguely remember a Pillow API issue where I could not read/write specific tiles. I believe Pillow wanted to read or write the entire file. I need a method where I can update individual tiles. Like many BigTIFF users our images are too large to entirely load into memory and get decent performance.

  14. radarhere commented on Sep 30, 2018

    @radarhere
    Member

    Does the image size limit imposed by #2583 mean that this scenario is no longer viable?

  15. bthorsted commented on Jun 2, 2021

    @bthorsted

    Will this ever be implemented in Pillow?

  16. aclark4life commented on Jun 2, 2021

    @aclark4life
    Member

    @bjtho08 Probably no time soon, unfortunately, unless you are offering to do it for us 😄 And it also may be a "wontfix" according to @radarhere 3 years ago, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions