mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2025-05-28 00:30:23 -04:00
raw: fix multi image load
Fixes not loading a second image in the file. This patch allow code like the following. QImageReader r(file); do { auto qi = r.read(); if (!qi.isNull()) { qi.save(QString("/tmp/%1_%2.tif") .arg(QFileInfo(file).baseName()) .arg(r.currentImageNumber())); } } while (r.jumpToNextImage()); m_startPos is used to reposition the device if you decide to do a subsequent read: libraw wants it to be at the beginning of the RAW stream
This commit is contained in:
parent
7899c27a80
commit
18ea0492bc
@ -444,7 +444,9 @@ void setParams(QImageIOHandler *handler, LibRaw *rawProcessor)
|
||||
auto &&rawparams = rawProcessor->imgdata.rawparams;
|
||||
#endif
|
||||
// Select one raw image from input file (0 - first, ...)
|
||||
rawparams.shot_select = handler->currentImageNumber();
|
||||
if (handler->currentImageNumber() > -1) {
|
||||
rawparams.shot_select = handler->currentImageNumber();
|
||||
}
|
||||
|
||||
// *** Set processing parameters
|
||||
|
||||
@ -722,6 +724,7 @@ RAWHandler::RAWHandler()
|
||||
: m_imageNumber(0)
|
||||
, m_imageCount(0)
|
||||
, m_quality(-1)
|
||||
, m_startPos(-1)
|
||||
{
|
||||
}
|
||||
|
||||
@ -738,6 +741,15 @@ bool RAWHandler::read(QImage *image)
|
||||
{
|
||||
auto dev = device();
|
||||
|
||||
// set the image position after the first run.
|
||||
if (!dev->isSequential()) {
|
||||
if (m_startPos < 0) {
|
||||
m_startPos = dev->pos();
|
||||
} else {
|
||||
dev->seek(m_startPos);
|
||||
}
|
||||
}
|
||||
|
||||
// Check image file format.
|
||||
if (dev->atEnd()) {
|
||||
return false;
|
||||
@ -819,7 +831,7 @@ bool RAWHandler::jumpToNextImage()
|
||||
|
||||
bool RAWHandler::jumpToImage(int imageNumber)
|
||||
{
|
||||
if (imageNumber >= imageCount()) {
|
||||
if (imageNumber < 0 || imageNumber >= imageCount()) {
|
||||
return false;
|
||||
}
|
||||
m_imageNumber = imageNumber;
|
||||
|
@ -74,6 +74,12 @@ private:
|
||||
* When the quality is -1, default quality is used.
|
||||
*/
|
||||
qint32 m_quality;
|
||||
|
||||
/*!
|
||||
* \brief m_startPos
|
||||
* The initial device position to allow multi image load (cache value).
|
||||
*/
|
||||
qint64 m_startPos;
|
||||
};
|
||||
|
||||
class RAWPlugin : public QImageIOPlugin
|
||||
|
Loading…
Reference in New Issue
Block a user