mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
[Avatar] Respect EXIF orientation and decode at target size (#7634)
Read the avatar with setAutoTransform(true) so camera orientation is applied, and ask QImageReader for a scaled decode at MAX_AVATAR_DIMENSION instead of decoding a full-resolution photo and scaling it afterwards. Verification: cockatrice built. Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
66b9338c90
commit
3b07b10b19
1 changed files with 14 additions and 0 deletions
|
|
@ -71,7 +71,21 @@ void DlgEditAvatar::actBrowse()
|
||||||
|
|
||||||
QImageReader imgReader;
|
QImageReader imgReader;
|
||||||
imgReader.setDecideFormatFromContent(true);
|
imgReader.setDecideFormatFromContent(true);
|
||||||
|
// Honour the EXIF orientation phone cameras write; otherwise portrait
|
||||||
|
// photos are shown and stored sideways.
|
||||||
|
imgReader.setAutoTransform(true);
|
||||||
imgReader.setFileName(fileName);
|
imgReader.setFileName(fileName);
|
||||||
|
|
||||||
|
// Decode straight to the maximum avatar size. Scaling afterwards decodes
|
||||||
|
// the full-resolution image first, which can be tens of megabytes for a
|
||||||
|
// modern camera photo.
|
||||||
|
const QSize sourceSize = imgReader.size();
|
||||||
|
if (sourceSize.isValid() &&
|
||||||
|
(sourceSize.width() > MAX_AVATAR_DIMENSION || sourceSize.height() > MAX_AVATAR_DIMENSION)) {
|
||||||
|
const QSize targetSize = sourceSize.scaled(MAX_AVATAR_DIMENSION, MAX_AVATAR_DIMENSION, Qt::KeepAspectRatio);
|
||||||
|
imgReader.setScaledSize(targetSize);
|
||||||
|
}
|
||||||
|
|
||||||
if (!imgReader.read(&image)) {
|
if (!imgReader.read(&image)) {
|
||||||
qCWarning(DlgEditAvatarLog) << "Avatar image loading failed for file:" << fileName;
|
qCWarning(DlgEditAvatarLog) << "Avatar image loading failed for file:" << fileName;
|
||||||
imageLabel->setText(tr("Invalid image chosen."));
|
imageLabel->setText(tr("Invalid image chosen."));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue