Skip to content

Commit

Permalink
Indicate when all frames have been read
Browse files Browse the repository at this point in the history
  • Loading branch information
novomesk committed Oct 18, 2022
1 parent 909e1f8 commit d7f9b45
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/qjpegxlhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ bool QJpegXLHandler::canRead() const

if (m_parseState != ParseJpegXLError) {
setFormat("jxl");

if (m_parseState == ParseJpegXLFinished) {
return false;
}

return true;
}
return false;
Expand All @@ -69,7 +74,7 @@ bool QJpegXLHandler::canRead(QIODevice *device)

bool QJpegXLHandler::ensureParsed() const
{
if (m_parseState == ParseJpegXLSuccess || m_parseState == ParseJpegXLBasicInfoParsed) {
if (m_parseState == ParseJpegXLSuccess || m_parseState == ParseJpegXLBasicInfoParsed || m_parseState == ParseJpegXLFinished) {
return true;
}
if (m_parseState == ParseJpegXLError) {
Expand All @@ -87,7 +92,7 @@ bool QJpegXLHandler::ensureALLCounted() const
return false;
}

if (m_parseState == ParseJpegXLSuccess) {
if (m_parseState == ParseJpegXLSuccess || m_parseState == ParseJpegXLFinished) {
return true;
}

Expand Down Expand Up @@ -396,7 +401,15 @@ bool QJpegXLHandler::decode_one_frame()
if (!rewind()) {
return false;
}

// all frames in animation have been read
m_parseState = ParseJpegXLFinished;
} else {
m_parseState = ParseJpegXLSuccess;
}
} else {
// the static image has been read
m_parseState = ParseJpegXLFinished;
}

return true;
Expand Down Expand Up @@ -845,6 +858,7 @@ bool QJpegXLHandler::jumpToNextImage()
}
}

m_parseState = ParseJpegXLSuccess;
return true;
}

Expand All @@ -859,12 +873,14 @@ bool QJpegXLHandler::jumpToImage(int imageNumber)
}

if (imageNumber == m_currentimage_index) {
m_parseState = ParseJpegXLSuccess;
return true;
}

if (imageNumber > m_currentimage_index) {
JxlDecoderSkipFrames(m_decoder, imageNumber - m_currentimage_index);
m_currentimage_index = imageNumber;
m_parseState = ParseJpegXLSuccess;
return true;
}

Expand All @@ -876,6 +892,7 @@ bool QJpegXLHandler::jumpToImage(int imageNumber)
JxlDecoderSkipFrames(m_decoder, imageNumber);
}
m_currentimage_index = imageNumber;
m_parseState = ParseJpegXLSuccess;
return true;
}

Expand All @@ -899,7 +916,7 @@ int QJpegXLHandler::loopCount() const
}

if (m_basicinfo.have_animation) {
return 1;
return (m_basicinfo.animation.num_loops > 0) ? m_basicinfo.animation.num_loops - 1 : -1;
} else {
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/qjpegxlhandler_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class QJpegXLHandler : public QImageIOHandler
ParseJpegXLNotParsed = 0,
ParseJpegXLSuccess = 1,
ParseJpegXLBasicInfoParsed = 2,
ParseJpegXLFinished = 3,
};

ParseJpegXLState m_parseState;
Expand Down

0 comments on commit d7f9b45

Please sign in to comment.