[PyQt] creating TIFF with CCITT FAX group 4 compression

David Boddie david at boddie.org.uk
Fri Jul 18 00:37:47 BST 2008


Glenn,

> > http://www.riverbankcomputing.com/static/Docs/PyQt4/html/qimagewriter.htm
> >l#setCompression
>
> That'd be better than nothing, but still in color, so still much huger
> than necessary.  I totally missed this.  Being a Python newbie is tough,
> after getting to be pretty experienced with Perl.

Yes, and there's a problem with Qt's TIFF writer, as we'll see later.

> The ImageMagick people say they support PerlMagick, but that
> PythonMagick was user-contributed, and they don't support it --
> apparently, neither does the original contributor, as far as I can tell
> from timestamps on things...

I guess people didn't see the need for a Python wrapper.

> Hmm.  In 2004 or 2005 Oliver M. Haynold talks about a "next release"
> containing "toString" and "fromString", which would likely work-around
> the file names issue.  With the FAQ (I had found pytiff, but not the
> FAQ), it looks like the compression is possible.  But the remaining
> problem is "fromString".  And the dates... it is 2008 now, why can't we
> find pytiff 0.2?  And where is Oliver M. Haynold?  Likely on to other
> things... yep, graduated 2005, busy with a real job, maybe even a life.
> Inquiry will be sent.  This looks promising, if it can be tweaked to
> accept input from strings in addition to files.

That's certainly one option.

> Hmm.  Tried to install it, needs M$ VC 7.1 (that is what Python 2.5 was
> compiled with, I guess), I have VC 6.0 and VC 8.0 installed...  Aargh!
> Not another version of VC to have to be installed :(  So this experiment
> will have to be deferred a bit.  I wonder which would be easier -- to
> install VC 7.1, or recompile Python, PyQt, and the other extensions,
> with VC 8.0...

Anything that needs to be specially compiled one at least one platform
isn't going to be fun.

> > Perhaps the FreeImagePy project mentioned will be useful:
> >
> > http://freeimagepy.sourceforge.net/
>
> Sounds useful, my other message responding to the other person that
> pointed this one out mentions out that it is pretty daunting for a
> Python newbie an Qt newbie to think about compiling this on 3 different
> platforms...  maybe in 6 months it will seem simpler.  And see compiler
> woes above on the first platform I tried PyTIFF on :(

Another idea came to me when looking at the code for TIFF writing in Qt.

The C++ QTiffHandler class uses libtiff to read and write images and,
according to the libtiff Web site, CCITT Group 4 support is enabled if
the library is configured appropriately. In theory, this could be
used if you called setCompression() with 2, 3, 4 or 32771 (depending on
which one corresponds to Group 4 compression).

  http://www.libtiff.org/internals.html

Unfortunately, the handler converts the image to ARGB format before saving,
and unhelpfully restricts the choice of compression to either none or LZW.

If I was comfortable with the Python ctypes module for interacting with
C libraries (or the equivalent Qt class), I would suggest writing a
Python function to replace QTiffHandler.write(), but it might be tricky.

An alternative would be to write a helper function to write the file,
but I'm thinking that it might be easier just to create a new version of
the Qt TIFF plugin just to write files in the format you want. Once
installed, it should just work with PyQt.

> Thanks, appreciate the pointers, you'd found some stuff I'd overlooked,
> even about packages I found.

No problem. File handling is a subject I'm interested in, so it's good to
take a look around to see what's on offer every now and again.

David


More information about the PyQt mailing list