TiffIO 1.4.0
Jean-Dominique <dot> Gascuel <at> inrialpes.fr
TiffIO is a plugin that add TIFF images read/write capabilities to all Qt3 and Qt4 applications using the QImage class.
TiffIO come with a self-test suite (test.pro), and have been compiled and used successfully on a wide variety of systems, compilers and Qt version combination. A demo application (demo.pro) enables to quickly test image loading & viewing on any platform.
All TIFF operations are based on libtiff 3.9.4, this plugin is just a wrapper that enable to use it transparently from the QImage class, and the architecture defined by Qt.
[Home]
[Documentation]
[Download]
[Status]
[History]
[Installation]
Documentation
Adding the plugin in the Qt's tree (or linking it witinh your own application) is sufficient to enable any Qt application to manipulate TIFF images transparently along with all other formats already managed by Qt.
Code snipets to reading TIFF images from a Qt application
To load a TIFF image from Qt, you can simply use the strainforward approche, as with any other image type supported :QImage img("Examples/rgb8-zip-mac.tif"); if( ! img.isNull() ) // Load succeded ? ...A slightly more complex example (see the demo app), uses an image handler to get access to the description string (in Qt3) :
QImageIO io("Examples/rgb8-zip-mac.tif"); if( io.read() ) //Load succeeded ? { QString ... = io.format() // Should be "TIFF" QImage ... = io.image(); QString ... = io.description(); }Or using the new Qt4 dialect :
QImageReader reader("Examples/rgb8-zip-mac.tif"); QImage img = reader.read(); if( !img.isNull() ) //Load succceded ? { QString ... = reader.format() // Should be "TIFF" QString ... = reader.text("description"); }
Code snipets to write TIFF images from a Qt application
Saving TIFF images can be as strainforward too :QImage img = ... if( ! img.save("Temp/snapshot.tif", "TIFF") ) qWarning("save failed !");Most probably, you should stop reading here. You know whatever you really need to save portable TIFF images...
But if you are sure you really need it, you can also use hints to request particular flavours of TIFF images to be created. Beware not all of the combinations will by obyed by TiffIO, and worst : some rare combination (while perfectly legal TIFF formats) won't be understood by other TIFF readers... Hints are provided a parameters string to the Qt library. Saving a 10-bit RGB lossless compressed image, with Qt3 :
QImage img(100, 100, 32); ... QImageIO io("Temp/snapshot.tif", "TIFF"); io.setParameters("lzw bps=10"); if( ! io.write() ) qWarning("TIFF image save failed");Or a 64 colors image, uncompressed, using 6 bit indexes, using the Qt4 dialect:
QImage img(100, 100, QImage::Format_Indexed8); img.setNumColors(64); ... QImageWriter writer("Temp/snapsho.tif", "TIFF"); writer.setText("parameters", "none bps=6"); if( ! writer.write(img) ) ... // FailedThis parameter string is a blank separated list of words. Recognized words are :
- none or uncompressed
- Don't compress the saved TIFF image.
- rle or packbits
- Use the tiff's PackBit lossless codec. Should be understood by any modern TIFF application.
- fax or fax=3 or fax=4
- Use the CCITT fax Group 4 (default) or fax Group 3 compression. Valid Only for bitmap images.
- lzw
- Use the tiff's Lempel-Ziv-Welch lossless codec.
Note there is the Unisys pattent problem with this codec, and some platform may refuse to write (or even read) TIFF files using this format. - zip or zip=level
- Use the tiff's deflate lossless codec.
The level can be used to balance between fast save (zip=1) and tighter file (zip=9).
The default level is 6.
This codec is based on zlib sources from the Qt tree, and should be working on all platforms. - pixarlog
- Use PixarLog (aka 11-bit, non-linear, ZIP-compressed RGB or RGBA) format. This format enables to manage over-whites up to 2500% (now so-called HDR images), and to have a better accuracy (10bits) in the normal 0..100% range. Please note that because Qt is handling 8-bit components, those features won't be very usefull anyway.
- jpeg or jpeg=quality
- Use the tiff's JPEG lossly codec.
Quality balance between very compact file (eg. jpeg=50) or images with very few compression artefacts
(eg. jpeg=95).
This is based on some external library, or sources from the Qt source tree. - bps=bits
- Specify how many bits to use per sample channel (from 1 to 16).
This option does not work with JPEG compressed files, and enables to produce tighter files.
Using values bigger than 8 bits is useless, because the corresponding bits won't come from your QImage data.
Note: it is not wise to use fancy bits value. Although they are indeed TIFF compliant and libtiff supported, most software won't be able to read produced files (eg. within Adobe's Photoshop CS2, reads are limited to paletted on 4 or 8 bits, and Gray/RGB/RGBA/Lab on 1, 2, 4, 8, 12, or 16 bits. Writes are limited to 1, 8 or 16 bits).
TIFF support
Current support for reading .tif into a QImage :- Images created on any architecture (big endians or little endians byte ordering, LSB or MSB bit ordering for bitmaps)
- Uncompressed, or compressed images (lossless Packbits, LZW, ZIP, PixarLog, JPEG, bitmap FaxG4, etc.).
- Various color schemes (RGB, RGBA, Lab, Luv, CYMK, CIE XYZ, ...), with optional reference white for conversion to RGB.
- up to 32 bits signed/unsigned components RGB, RGBA and CIE Lab images (automatically converted to 8 bits RGB/RGBA images, as required by Qt).
- up to 16 bits paletted images with RGB colors (always loaded as 8 bits images, with color table truncated to 8 bits because of Qt).
- up to 8 bits per components for all the other color schemes (CYMK, Luv, etc.).
- up to 32 bits signed/unsigned gray images (always converted to 8 bits images, with an allGray() linear color table).
- Bitmap (1-bit images), loaded as a QImage bitmap (depth= 1), with a colortable.
- Accepts TIFF multi-layered images (eg. layers from Photoshop).
- Accepts scan-line based or tile-based images.
- Accepts image with any storage orientation.
- Accepts huge image size (limits from Qt and libtiff : 64k*64k ?).
Current support for writting a QImage :
- Always store planar, scan-line based, top-left oriented images, andhost-optimized architecture.
- various compression schemes (uncompressed, PackBits (aka RLE), CCITT group3 or 4 (aka fax, for bitmaps only), ZIP, LZW,PixarLog, and JPEG), and compression quality.
- output hints string, aka QImageIO::setParameters("jpeg=95") [Qt3].
- Bitmaps (depth=1) as one-chanel TIFF, with BPS=1, and MINISBLACK mode.
- Gray images (depth=8 bit/pixel) as one-chanel TIFF, in MINISBLACK mode.
- Other 8 bit/pixel images are saved as PALETTE images, with up to 256 RGB colors.
- True color images (24 or 32 bit/pixels) are saved as 3x8 bits RGB images, or 4x8 bits RGBA images if there is a Qt alpha channel.
Experimental :
- Support for reading 32-bit float componants (RGB, RGBA, CIELab and gray images) is not tested yet... I do need examples !
What is not supported at the time :
- Transparency (alpha channel), except when combined with a 3x8-bit RGB image.
- Fancy capabilities of Qt4 (eg. animations, fast scaled/cropped read, etc.).
-
JPEG compression/uncompression within TIFF on win32 platform (except if you
hack the Qt distribution, or provide your own libjpeg).
See comments in TiffIO.pri for details on how to proceed.
[Home]
[Documentation]
[Download]
[Status]
[History]
[Installation]
Source download
-
The latest sources and .pro, packaged for Qt' style qmake installation,
either on Windows or Unix platforms, and also RPM package of the same files,
for easy rebuild on linux platforms:
- Windows : TiffIO-140a.zip
- Unix TAR: TiffIO-140a.tgz
- Unix RPM: TiffIO-140-a.src.rpm
- Latest 1.3.0 version is 1.3.0e, based on libtiff 3.8.0 beta:
- Windows : TiffIO-130e.zip
- Unix TAR: TiffIO-130e.tgz
- Unix RPM: TiffIO-130-e.src.rpm
Nevertheless, this version do pass all internal tests. - Other sources are here
Pre-compiled download
None at that time: because there is too many combination of versions of Qt, versions of compiler, and systems flavors...
[Home]
[Documentation]
[Download]
[Status]
[History]
[Installation]
Status
- The plugin have been compiled and tested with Qt 3.2.3, Qt 3.3.6, Qt 3.3.8b, Qt 4.0.1, Qt 4.1 and Qt 4.5.3.
- The plugin have beed compiled and tested on MacOSX, Solaris, Irix, Tru64, AIX, Linux, HP-UX, and Windows XP (SP1 & SP2), and Windows Seven.
- The plugin have been compiled and tested with MS Visual C++ (6, .NET, .NET 2003, 2005 and 2008), with g++ (3.2, 3.3 and 4.2), and mingw++.
I am using TiffIO on Win32/Qt 3.3.8b and 4.5.3, ``every days'', and I am not aware of any bugs. The self-test suite (just compile and execute the provided test.pro project) enable a quick checking of the plugin consistency for a given platform. If you have a doubt, you can also compile the demo.pro micro-application to have a look at any dubious .tiff file.
Known Bugs
-
On some version of borland bcc, you will need to ignore
hundreds of spurious warnings araising from the libtiff sources, that abort
compiling somewhere in the installation.
One should be able to shut warnings off, and finish compiling. Please e-mail me the right bcc options ! - Alpha channels under Qt3 are alway considered post-multiplied. With Qt4, we are able to handle both pre- and post-multiplied alphas correctly.
I you find some bugs, or need support never encountered before TIFF variant, send e-mails to Jean-Dominique.Gascuel at imag.fr.
[Home]
[Documentation]
[Download]
[Status]
[History]
[Installation]
History
- 2010-06-25 / 1.4.0a :
- NEW Upgraded to libtiff 3.9.4 (Latest stable version, as of June 2010).
- NEW Tested under Visual 2008, gcc 4.2, Qt 4.5.3 and Windows Seven.
- FIX Qt4 bug in test.cpp when saving to an already existing image file.
- 2006-11-20 / 1.3.0e :
- NEW hints fax{=3|4} for CCITT Group 3/4 codecs.
- FIX test to test for fax, and PixarLog read/writes possible or not.
- FIX compile to accept no-fax, no-pixar-log qmake's CONFIG options.
- FIX bit order when reading FILLORDER=2 bitmaps (Thanks to Sebastian Kirsche).
- 2006-08-30 / 1.3.0c :
- NEW more installation documentation
- FIX crash when compiling test.pro before demo.pro (static and dynamic TiffIO_Qt3.obj mixed-up).
- FIX passing parameter string for Qt4.
- NEW check reading for pre/post multiplied alpha on Qt4.
- FIX bps default to 1 (bitmaps), as in PhotoShop CS2.
- 2006-04-13 / 1.3.0 :
- NEW support for hint string (QImageIO::parameters()).
- NEW description string when reading TIFF, shown in the demo app.
- NEW support for strange bit per samples (eg. 10-bits signed RGB).
- NEW support for PixarLog codec (which uses 11 bits HDR samples).
- FIX Configuration of the alpha channel flag when reading Qt3 images.
- NEW Demo app now use a checkboard background, so we can see transparency.
- NEW Test app updated to check alpha values of test images with alpha channel, and to test new write hints.
- 2006-02-10 / 1.2.0e :
- NEW support for Lab up to 3x16bits and RGB/RGBA up to 4x32bits.
- FIX demo.pro was compiled in debug, and TiffIO.pro in release. So when using Qt4.x, they would never met...
- 2006-02-06 / 1.2.0d :
- NEW Upgrade to beta libtiff 3.8.0 (CVS), because brand 380 crash on some uncommon TIFF features (eg. uncompressed YCrCb color space) crashes and other compile errors.
- FIX demo for Qt4.
- FIX bug preventing tiff to be in the list of Qt4.1 recognized formats.
- 2006-01-11 / 1.2.0 :
- FIX linux-g++-64 compile (Thanks to Michael Kettner).
- NEW allow (but discourage) compiling with a pre-compiled libtiff.
- FIX bit order is different from byte order. So don't messup endianness with LSBfirst in bitmaps (Thanks to Frank Warmerdam).
- FIX bug in Qt4 QIODevice API preventing writting TIFF.
- NEW Upgrade to libtiff 3.8.0, with some patches to avoid crashes and compile errors.
-
2005-09-29 / 1.1.0 :
- FIX missing checking of libtiff error code while reading/writting scan-lines.
- FIX TiffIO generates qWarning() on fatal libtiff error, to avoid crashing the application.
- FIX support for compiling with no-jpeg, no-lzw, no-zlib qmake config options.
- NEW remove depedancy to GetFocus and MessageBox on win32 build.
- NEW Save 32 bits QImage 24 bits TIFF when no alpha, and 32 bits TIFF when the image have an alpha channel.
- NEW support for statically linked code (see test.pro for an example).
-
NEW add support for Qt 4.x image IO architecture.
-
2005-06-17 / 1.0.7:
- FIX Upgraded to libTiff 3.7.2, due to security alerts.
- FIX 16/32bits truncation warnings (that turns to compile errors on Boreland bcc32.
-
NEW handler to redirect TIFF errors/warnings to Qt's qFatal() and
qWarning().
This enables uniform application-wide policy using Qt's installMsgHandler(). - NEW Test suite now checks that unsupported files don't crash and do generate Qt style errors/warnings.
- NEW Experimental support for reading 2 bits and 4 bits gray or color mapped images.
- FIX crash when reading bitmaps to hardware that needs a swap-bits.
- FIX byte swapping problem when writting 24/32 bit images on SGI.
- NEW support for JPEG-in-TIFF when the Qt installation contains sources, or on unix with libjpeg 6.2 devel package.
-
2005-03-22 / 1.0.6:
-
NEW Added support (and self-test) for bitmaps i/o, and FaxG4 reading.
-
NEW Added support (and self-test) for bitmaps i/o, and FaxG4 reading.
-
2005-02-01 / 1.0.5:
- NEW self-test program and examples files.
-
FIX compiler issues on HP-UX and AIX, thanks to Till Oliver Knoll.
-
2005-01-14 / 1.0.4:
- FIX Upgrade to libtiff 3.7.1, because of security alert.
- FIX libtiff 3.7.1 not to crash when displaying warnings or error messages.
-
FIX libtiff 3.7.1 to have readable error message when reading
unsupported pixel formats (eg. CYMK 16 bits).
-
2004-12-17 / 1.0.3:
- FIX Add "TIFF" as recognized format (as well as TIF).
-
FIX RGBA/ABGR color inversion on win32 platforms.
-
2004-11-22 / 1.0.2:
-
FIX a minor bug about the regexp to recognize TIFF formats.
-
FIX a minor bug about the regexp to recognize TIFF formats.
- 2004-11-08 : Creation
[Home]
[Documentation]
[Download]
[Status]
[History]
[Installation]
Installation
Pre-requisite
You should have Qt installed, and the QTDIR environement variable correctly defined. In particular, having several installation of Qt (eg. Qt3 and Qt4) installed works only if QTDIR/include, QTDIR/bin, QTDIR/lib etc. goes to the right places (eg. QTDIR=/usr/share/qt3 or QTDIR=/usr/share/qt4 under some linuxes).Let's do it.
-
On unix :
qmake TiffIO.pro
make
sudo make install -
On windows command line :
qmake TiffIO.pro
nmake
- On MS Visual Studio (6, .NET and .NET2003) :
-
Generate the .vcproj with the IDE Qt icon, or with the command:
qmake -tp vc TiffIO.pro
- Exit any Qt application (including Designer or Assistant), because they lock the QTDIR/plugin/imageformats directory.
- Open the project file, and build the solution.
- On MS Visual Studio (6, .NET and .NET2003) :
Qt4 plugin management
Among the changes introduced by Qt4, there is a change in the policy when loading plugins. Now, the rules specify that a plugin is suitable to load only if it has been compiled with the same version and compile options that the main app loading it. It means that in order to have the plugin running both in release and in debug mode, you should compile and install both TiffIO.pro and TiffIO_DBG.pro.Support of ZIP compression scheme inside TIFF images
If available, the Tiff library (and the TiffIO plugin), will automatically compile with the ZIP compression scheme to read or write more compact images.This is an important feature, because many TIFF files available around are ZIP compressed.
- Qt source tree contains a zlib distribition. TiffIO build process automatically tries to use it. But it means that you should have installed Qt with internal zlib support (eg. configure with option -qt-zlib).
- On unix systems, TiffIO looks into /usr/local/include and /usr/include for a suitable zlib.
- If you have trouble, you may choose your own zlib sources by providing option ZLIB=pathToIncludeAndLib to any qmake call.
- Or you can disable zlib support by using the CONFIG+=no-zlib option to any qmake call.
Support of JPEG compression scheme inside TIFF images
The Tiff library also propose the JPEG lossy compression scheme embebed in TIFF images.This is more exotic than ZIP compression, but may be needed in some rare cases.
- Under Unix/Linux, there is usually a jpeg lib installed in /usr, or /usr/local which TiffIO automatically detect.
-
Under MacOSX, there is no (by defaults) jpeg lib in the system, hence
you need either to install Qt with internal support for JPEG,
(ie. configure with option -qt-imgfmt-jpeg),
either to run make in QTDIR/src/3rdparty/libjpeg to create there a libjpeg.a,
either to disable jpeg support from TiffIO using the qmake's option CONFIG+=no-jpeg. -
Under Windows, you can't link against a DLL without exporting the
symbols, so you can't use the above method.
To use the $QTDIR/src/3rdparty/libjpeg, a solution is to compile that library separatly, then to link your plugin against it. See comments inside TiffIO.pri for details.
Support for another TIFF library source
TiffIO is packaged with its own TIFF source distribution. This is important for stability and to make sure it is compiled with options compatible with Qt accross various platforms.I strongly urge you not to compile with a different version of LibTiff... Nevertheless, some of your folks have to live dangerously for whatever reason, so the .pro files enable you to do that :
- qmake TIFF=/home/me/libtiff-3.8.2/libtiff TiffIO.pro
compiles using a different directory to look for tiff's sources. - qmake CONFIG+=libtiff TiffIO.pro
links using a precompiled tiff library, located in the TIFF_ROOT (command line argument, or env var) directory. TIFF_ROOT defaults to "/usr", hence using the unix standard "/usr/include/tiffio.h" and "/usr/lib/libtiff.so" (or .a) files.
Testing
To run the self-test program, use the test.pro and run the generated executable. It should end saying All xxx the images checked ok. The corresponding cases are in the Example/ subdirectory.
You can also see samples, by compiling the demo.pro demo viewer.