mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Limit max cover height
Otherwise we can end with huge cover files if the source content has abnormally tall covers. This large files could end exhausting RAM in the iOS client.
This commit is contained in:
parent
1cf81ebac0
commit
a0dfa4e447
@ -72,14 +72,7 @@ void InitialComicInfoExtractor::extract()
|
|||||||
_cover = p;
|
_cover = p;
|
||||||
_coverSize = QPair<int, int>(p.width(), p.height());
|
_coverSize = QPair<int, int>(p.width(), p.height());
|
||||||
if (_target != "") {
|
if (_target != "") {
|
||||||
QImage scaled;
|
saveCover(_target, p);
|
||||||
if (p.width() > p.height()) // landscape??
|
|
||||||
{
|
|
||||||
scaled = p.scaledToWidth(640, Qt::SmoothTransformation);
|
|
||||||
} else {
|
|
||||||
scaled = p.scaledToWidth(480, Qt::SmoothTransformation);
|
|
||||||
}
|
|
||||||
scaled.save(_target, 0, 75);
|
|
||||||
} else if (_target != "") {
|
} else if (_target != "") {
|
||||||
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
QLOG_WARN() << "Extracting cover: requested cover index greater than numPages " << _fileSource;
|
||||||
// QImage p;
|
// QImage p;
|
||||||
@ -151,14 +144,7 @@ void InitialComicInfoExtractor::extract()
|
|||||||
QImage p;
|
QImage p;
|
||||||
if (p.loadFromData(archive.getRawDataAtIndex(index))) {
|
if (p.loadFromData(archive.getRawDataAtIndex(index))) {
|
||||||
_coverSize = QPair<int, int>(p.width(), p.height());
|
_coverSize = QPair<int, int>(p.width(), p.height());
|
||||||
QImage scaled;
|
saveCover(_target, p);
|
||||||
if (p.width() > p.height()) // landscape??
|
|
||||||
{
|
|
||||||
scaled = p.scaledToWidth(640, Qt::SmoothTransformation);
|
|
||||||
} else {
|
|
||||||
scaled = p.scaledToWidth(480, Qt::SmoothTransformation);
|
|
||||||
}
|
|
||||||
scaled.save(_target, 0, 75);
|
|
||||||
} else {
|
} else {
|
||||||
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
QLOG_WARN() << "Extracting cover: unable to load image from extracted cover " << _fileSource;
|
||||||
// p.load(":/images/notCover.png");
|
// p.load(":/images/notCover.png");
|
||||||
@ -172,3 +158,20 @@ QByteArray InitialComicInfoExtractor::getXMLInfoRawData()
|
|||||||
{
|
{
|
||||||
return _xmlInfoData;
|
return _xmlInfoData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitialComicInfoExtractor::saveCover(const QString &path, const QImage &cover)
|
||||||
|
{
|
||||||
|
QImage scaled;
|
||||||
|
if (cover.width() > cover.height()) {
|
||||||
|
scaled = cover.scaledToWidth(640, Qt::SmoothTransformation);
|
||||||
|
} else {
|
||||||
|
auto aspectRatio = static_cast<double>(cover.width()) / static_cast<double>(cover.height());
|
||||||
|
auto maxAllowedAspectRatio = 0.5;
|
||||||
|
if (aspectRatio < maxAllowedAspectRatio) { // cover is too tall, e.g. webtoon
|
||||||
|
scaled = cover.scaledToHeight(960, Qt::SmoothTransformation);
|
||||||
|
} else {
|
||||||
|
scaled = cover.scaledToWidth(480, Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scaled.save(_target, 0, 75);
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@ private:
|
|||||||
int _coverPage;
|
int _coverPage;
|
||||||
static bool crash;
|
static bool crash;
|
||||||
QByteArray _xmlInfoData;
|
QByteArray _xmlInfoData;
|
||||||
|
void saveCover(const QString &path, const QImage &cover);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void extract();
|
void extract();
|
||||||
|
Loading…
Reference in New Issue
Block a user