Skip to content
Snippets Groups Projects
Unverified Commit 64767190 authored by Sébastien Blin's avatar Sébastien Blin
Browse files

storagehelper: rework jpeg compression for sendTrustRequest

Compress the image to a value under 48k to be able to send it
through the DHT.

Change-Id: I4eee67e0a667bb278d2099abaf5305ca0a767efc
parent d0389ff7
Branches
No related tags found
No related merge requests found
...@@ -163,7 +163,13 @@ compressedAvatar(const QString& image) ...@@ -163,7 +163,13 @@ compressedAvatar(const QString& image)
auto size = qMin(qimage.width(), qimage.height()); auto size = qMin(qimage.width(), qimage.height());
auto rect = QRect((qimage.width() - size) / 2, (qimage.height() - size) / 2, size, size); auto rect = QRect((qimage.width() - size) / 2, (qimage.height() - size) / 2, size, size);
qimage.copy(rect).scaled({size, size}, Qt::KeepAspectRatio).save(&buffer, "JPEG", 90); constexpr auto quality = 88; // Same as android, between 80 and 90 jpeg compression changes a lot
constexpr auto maxSize = 16000 * 8; // Because 16*3 (rgb) = 48k, which is a valid size for the
// DHT and * 8 because typical jpeg compression
// divides the size per 8
while (size * size > maxSize)
size /= 2;
qimage.copy(rect).scaled({size, size}, Qt::KeepAspectRatio).save(&buffer, "JPEG", quality);
auto b64Img = bArray.toBase64().trimmed(); auto b64Img = bArray.toBase64().trimmed();
return QString::fromLocal8Bit(b64Img.constData(), b64Img.length()); return QString::fromLocal8Bit(b64Img.constData(), b64Img.length());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment