-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageLoader.cpp
More file actions
executable file
·94 lines (75 loc) · 2.5 KB
/
Copy pathImageLoader.cpp
File metadata and controls
executable file
·94 lines (75 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Copyright (c) 2017-2019 by Ilya Barykin
Released under the MIT License.
See the provided LICENSE.TXT file for details.
*/
#include "ImageLoader.h"
ImageLoader::ImageLoader(ImageProvider *p) : prv(p) {
resize = new Resize();
}
void ImageLoader::loadImage(QString file) {
prv->setLoading(true);
QImage in(file), image, scaled;
QString title;
int wH = prv->getWnd()->height();
int wW = prv->getWnd()->width();
image = isBlurred ? process(in) : in;
scaled = image.height() > wH || image.width() > wW ?
image.scaled(prv->getWnd()->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) :
image;
float s1 = float(wH) / image.height(), s2 = float(wW) / image.width(), scale, original_scale;
scale = qMin(s1, s2);
scale = scale > 1.0f ? 1.0f : scale;
original_scale = scale;
QString rat, size = "%1 ";
if (in.width() / 16 * 9 == in.height()) {
rat = "16/9";
} else if (in.width() / 16 * 10 == in.height()) {
rat = "16/10";
} else {
rat = QString::number(float(in.width()) / in.height(), 'f', 3);
}
double s = QFile(file).size();
if (s > 1024 * 1024) {
s /= 1024 * 1024;
size += " Mb";
} else if (s > 1024) {
s /= 1024;
size += " Kb";
} else {
size += " b";
}
file = file.remove(0, file.lastIndexOf('/') + 1);
if (in.width() != 0) {
title = QString("File: %1 | Ratio: %2 (%3:%4) | Size: %5 | %6/%7 ");
title = title.arg(file.size() < 100 ? file : QStringRef(&file, 0, 100).toString())
.arg(rat)
.arg(in.width())
.arg(in.height())
.arg(size.arg(s, 4, 'f', 3, ' '))
.arg(prv->getCurrent() + 1)
.arg(prv->getSize());
} else {
title = QString("Error opening file: %1");
title = title.arg(file);
}
prv->setText(title);
prv->setOriginal(image);
prv->setScale(scale);
prv->setOriginalScale(original_scale);
prv->setScaled(scaled);
prv->setLoading(false);
}
QImage ImageLoader::process(QImage in) {
int wW = prv->getWnd()->width(), wH = prv->getWnd()->height();
float s1 = float(wH) / in.height(), s2 = float(wW) / in.width();
int mw, mh;
if (s1 < s2) {
mh = in.height() > wH ? in.height() : wH;
mw = int(float(wW) / wH * (mh));
} else {
mw = in.width() > wW ? in.width() : wW;
mh = int(float(wH) / wW * (mw));
}
return resize->process(in, mw, mh);
}