From ecf359b8c9664b12c2b348a56cfb280334d02aa7 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Mon, 29 Dec 2014 10:50:03 -0500 Subject: [PATCH] Support for multipage decoding in BaseImageDecoder and implemented in TiffDecoder. --- modules/imgcodecs/src/grfmt_base.hpp | 3 +++ modules/imgcodecs/src/grfmt_tiff.cpp | 19 ++++++++++++++----- modules/imgcodecs/src/grfmt_tiff.hpp | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/imgcodecs/src/grfmt_base.hpp b/modules/imgcodecs/src/grfmt_base.hpp index 8a534da..dcb75b0 100644 --- a/modules/imgcodecs/src/grfmt_base.hpp +++ b/modules/imgcodecs/src/grfmt_base.hpp @@ -70,6 +70,9 @@ public: virtual bool readHeader() = 0; virtual bool readData( Mat& img ) = 0; + /// Called after readData to advance to the next page, if any. + virtual bool nextPage() { return false; } + virtual size_t signatureLength() const; virtual bool checkSignature( const String& signature ) const; virtual ImageDecoder newDecoder() const; diff --git a/modules/imgcodecs/src/grfmt_tiff.cpp b/modules/imgcodecs/src/grfmt_tiff.cpp index 7ec76c8..7046276 100644 --- a/modules/imgcodecs/src/grfmt_tiff.cpp +++ b/modules/imgcodecs/src/grfmt_tiff.cpp @@ -118,10 +118,13 @@ bool TiffDecoder::readHeader() { bool result = false; - close(); - // TIFFOpen() mode flags are different to fopen(). A 'b' in mode "rb" has no effect when reading. - // http://www.remotesensing.org/libtiff/man/TIFFOpen.3tiff.html - TIFF* tif = TIFFOpen( m_filename.c_str(), "r" ); + TIFF* tif = static_cast(m_tif); + if (!m_tif) + { + // TIFFOpen() mode flags are different to fopen(). A 'b' in mode "rb" has no effect when reading. + // http://www.remotesensing.org/libtiff/man/TIFFOpen.3tiff.html + tif = TIFFOpen(m_filename.c_str(), "r"); + } if( tif ) { @@ -182,6 +185,13 @@ bool TiffDecoder::readHeader() return result; } +bool TiffDecoder::nextPage() +{ + // Prepare the next page, if any. + return m_tif && + TIFFReadDirectory(static_cast(m_tif)) && + readHeader(); +} bool TiffDecoder::readData( Mat& img ) { @@ -413,7 +423,6 @@ bool TiffDecoder::readData( Mat& img ) } } - close(); return result; } diff --git a/modules/imgcodecs/src/grfmt_tiff.hpp b/modules/imgcodecs/src/grfmt_tiff.hpp index ec29fbc..f019082 100644 --- a/modules/imgcodecs/src/grfmt_tiff.hpp +++ b/modules/imgcodecs/src/grfmt_tiff.hpp @@ -100,6 +100,7 @@ public: bool readHeader(); bool readData( Mat& img ); void close(); + bool nextPage(); size_t signatureLength() const; bool checkSignature( const String& signature ) const; -- 2.7.4