mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-24 23:19:29 -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
|
||||
optimized = original;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRgb> ct;
|
||||
quantization(original, ct);
|
||||
|
||||
//Downscale the image to fit into maxPixels
|
||||
double whratio = (qreal)original.width() / (qreal)original.height();
|
||||
int maxwidth;
|
||||
@ -98,6 +96,9 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
||||
return true;
|
||||
}
|
||||
|
||||
QVector<QRgb> ct;
|
||||
quantization(original, ct);
|
||||
|
||||
//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);
|
||||
if(maxsize <= maxBytes) return true; //success
|
||||
|
Loading…
Reference in New Issue
Block a user