kimgio: partial fix for blended webp animations

not sure what to do with the offsets

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-10 06:08:38 +03:00
parent c8056b579b
commit 08154cd8c1
2 changed files with 27 additions and 1 deletions

View file

@ -18,8 +18,9 @@
#include "webp.h" #include "webp.h"
#include "kdebug.h" #include "kdebug.h"
#include <QImage>
#include <QVariant> #include <QVariant>
#include <QPainter>
#include <webp/decode.h> #include <webp/decode.h>
#include <webp/encode.h> #include <webp/encode.h>
@ -119,10 +120,33 @@ bool WebPHandler::read(QImage *image)
return false; return false;
} }
switch (webpiter.blend_method) {
case WEBP_MUX_BLEND: {
if (Q_UNLIKELY(m_lastframe.isNull())) {
kWarning() << "Last frame is null";
} else {
QPainter p(image);
// TODO: offsets (webpiter.x_offset and webpiter.y_offset)
p.setCompositionMode(QPainter::CompositionMode_DestinationOver);
p.drawImage(0, 0, m_lastframe);
p.end();
}
break;
}
case WEBP_MUX_NO_BLEND: {
break;
}
default: {
kWarning() << "Unknown blend method" << webpiter.blend_method;
break;
}
}
m_currentimage++; m_currentimage++;
if (m_currentimage >= m_imagecount) { if (m_currentimage >= m_imagecount) {
m_currentimage = 0; m_currentimage = 0;
} }
m_lastframe = *image;
WebPDemuxReleaseIterator(&webpiter); WebPDemuxReleaseIterator(&webpiter);
WebPAnimDecoderDelete(webpanimdec); WebPAnimDecoderDelete(webpanimdec);

View file

@ -21,6 +21,7 @@
#include <QStringList> #include <QStringList>
#include <QImageIOHandler> #include <QImageIOHandler>
#include <QImage>
class WebPHandler : public QImageIOHandler class WebPHandler : public QImageIOHandler
{ {
@ -52,6 +53,7 @@ private:
int m_imagecount; int m_imagecount;
int m_imagedelay; int m_imagedelay;
int m_currentimage; int m_currentimage;
QImage m_lastframe;
}; };