How to Customize QTiffHandler
-
My application makes use of image thumbnails to improve performance. Tiff files can contain multiple images in subfiles or directories. QTiffHandler reads the first directory, but I want to scan all available directories and choose which one to read. Is there a way for me to "subclass" QTiffHandler? If not, I could create my own routines to read a tiff directory into a QImage. If I take that approach can I access the libtiff source in the Qt distribution safely, or do I need to independently keep it in my project?
Any recommendations on the best approach and suggested reading material is greatly appreciated.
-
Hi
First, i would look at the source.
https://code.woboq.org/qt5/qtimageformats/src/plugins/imageformats/tiff/qtiffhandler.cpp.html#852
It seems to have support for Tiff Directories.bool QTiffHandler::jumpToNextImage() bool QTiffHandler::jumpToImage(int imageNumber) int QTiffHandler::imageCount() const int QTiffHandler::currentImageNumber() const
However, its unclear to me if those are avialable to use from App.
Since its being a plugin, i would check if i could upgrade the existing code to support the feature needed and
simply use this new plugin instead of the old. After all that is the benefit with plugins.
However, the image plugins might not offer easy way to use these new features as its
used by Qt internally and might not be super easy to surface. However its worth checking out
before starting to use the lib directly. IMHO. -
@mrjj Thanks for the response! I see that QImageReader supports jumpToNextImage. I'll see if that works. I already have code that walks the tiff IFDs so I know in advance which directory I want to use. If this works then I will mark the topic as solved, although I really would like to know how to customize QTiffHandler ;*)
-
@mrjj Thanks for the response! I see that QImageReader supports jumpToNextImage. I'll see if that works. I already have code that walks the tiff IFDs so I know in advance which directory I want to use. If this works then I will mark the topic as solved, although I really would like to know how to customize QTiffHandler ;*)
-
Unfortunately QImageReader::imageCount() is returning 1 for a tiff file with 4 directories (created in photoshop with save image pyramid), so this approach does not appear to be workable. It might be a failure of libtiff since QTiffHandler does have an imageCount function.
-
Unfortunately QImageReader::imageCount() is returning 1 for a tiff file with 4 directories (created in photoshop with save image pyramid), so this approach does not appear to be workable. It might be a failure of libtiff since QTiffHandler does have an imageCount function.
@rory_1
Ok, good digging
it seems it does call the handlers function so i agree it might be related to the libTiffint QImageReader::imageCount() const { if (!d->initHandler()) return -1; return d->handler->imageCount(); }
However, reading the docs, it seems that function is for animation support so
im not sure its what we want even the actual code seems to be related to TIFF dirs. -
I'm going to try implementing libtiff in my own project. Can I use the libtiff source included with Qt? If so what is the suggested way of supplying the path in the includes. The folder is at C:\Qt\5.13.0\Src\qtimageformats\src\3rdparty\libtiff\libtiff on my windows machine.
-
I'm going to try implementing libtiff in my own project. Can I use the libtiff source included with Qt? If so what is the suggested way of supplying the path in the includes. The folder is at C:\Qt\5.13.0\Src\qtimageformats\src\3rdparty\libtiff\libtiff on my windows machine.