mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Extract highest resolution from downloaded ICO files
This commit is contained in:
parent
b5554e05d8
commit
4de99cfe8e
BIN
share/demo.kdbx
BIN
share/demo.kdbx
Binary file not shown.
@ -20,6 +20,7 @@
|
||||
#include "core/NetworkManager.h"
|
||||
|
||||
#include <QHostInfo>
|
||||
#include <QImageReader>
|
||||
#include <QtNetwork>
|
||||
|
||||
#define MAX_REDIRECTS 5
|
||||
@ -188,7 +189,7 @@ void IconDownloader::fetchFinished()
|
||||
}
|
||||
} else {
|
||||
// No redirect, and we theoretically have some icon data now.
|
||||
image.loadFromData(m_bytesReceived);
|
||||
image = parseImage(m_bytesReceived);
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,3 +207,33 @@ void IconDownloader::fetchFinished()
|
||||
emit finished(url, image);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse fetched image bytes.
|
||||
*
|
||||
* Parses the given byte array into a QImage. Unlike QImage::loadFromData(), this method
|
||||
* tries to extract the highest resolution image from .ICO files.
|
||||
*
|
||||
* @param imageBytes raw image bytes
|
||||
* @return parsed image
|
||||
*/
|
||||
QImage IconDownloader::parseImage(QByteArray& imageBytes) const
|
||||
{
|
||||
QBuffer buff(&imageBytes);
|
||||
buff.open(QIODevice::ReadOnly);
|
||||
QImageReader reader(&buff);
|
||||
|
||||
if (reader.imageCount() <= 0) {
|
||||
return reader.read();
|
||||
}
|
||||
|
||||
QImage img;
|
||||
for (int i = 0; i < reader.imageCount(); ++i) {
|
||||
if (img.isNull() || reader.size().width() > img.size().width()) {
|
||||
img = reader.read();
|
||||
}
|
||||
reader.jumpToNextImage();
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ private slots:
|
||||
|
||||
private:
|
||||
void fetchFavicon(const QUrl& url);
|
||||
QImage parseImage(QByteArray& imageBytes) const;
|
||||
|
||||
QString m_url;
|
||||
QUrl m_fetchUrl;
|
||||
|
Loading…
Reference in New Issue
Block a user