mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-12 16:09:37 -05:00
Optimized image embedding algorithm
This commit is contained in:
parent
15ac7eecc8
commit
cb68cb73d0
@ -73,14 +73,12 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
|||||||
//nothing to do if it fits into the limits
|
//nothing to do if it fits into the limits
|
||||||
optimized = original;
|
optimized = original;
|
||||||
if ((maxPixels <= 0) || (optimized.width()*optimized.height() <= maxPixels)) {
|
if ((maxPixels <= 0) || (optimized.width()*optimized.height() <= maxPixels)) {
|
||||||
if(checkSize(html, optimized, maxBytes) <= maxBytes) {
|
int s = checkSize(html, optimized, maxBytes);
|
||||||
|
if((maxBytes <= 0) || (s <= maxBytes)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<QRgb> ct;
|
|
||||||
quantization(original, ct);
|
|
||||||
|
|
||||||
//Downscale the image to fit into maxPixels
|
//Downscale the image to fit into maxPixels
|
||||||
double whratio = (qreal)original.width() / (qreal)original.height();
|
double whratio = (qreal)original.width() / (qreal)original.height();
|
||||||
int maxwidth;
|
int maxwidth;
|
||||||
@ -98,6 +96,9 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<QRgb> ct;
|
||||||
|
quantization(original, ct);
|
||||||
|
|
||||||
//Use binary search to find a suitable image size + linear regression to guess the file size
|
//Use binary search to find a suitable image size + linear regression to guess the file size
|
||||||
double maxsize = (double)checkSize(html, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither), maxBytes);
|
double maxsize = (double)checkSize(html, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither), maxBytes);
|
||||||
if(maxsize <= maxBytes) return true; //success
|
if(maxsize <= maxBytes) return true; //success
|
||||||
|
Loading…
Reference in New Issue
Block a user