-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.h
78 lines (61 loc) · 1.89 KB
/
utilities.h
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
#ifndef UTILITIES_H
#define UTILITIES_H
#include <algorithm>
#include <array>
#include <vector>
#include <QSizeF>
#include <QString>
#include <QWidget>
#include <QtMath>
namespace Utilities
{
QSizeF GetDPIScale(const QWidget *widget);
template <typename T>
inline T DivideCeiling(const T a, const T b)
{
return (a + (b - 1)) / b;
}
template <typename T>
QString IntegerToZeroPaddedHexQString(const T integer)
{
return QStringLiteral("%1").arg(integer, sizeof(integer) * 2, 0x10, QLatin1Char('0')).toUpper();
}
std::array<qreal, 3> QColorTosRGB(const QColor &colour);
std::array<qreal, 3> sRGBToLinearRGB(const std::array<qreal, 3> &srgb);
std::array<qreal, 3> LinearRGBToXYZ(const std::array<qreal, 3> &linear_rgb);
std::array<qreal, 3> XYZToLAB(const std::array<qreal, 3> &xyz);
inline std::array<qreal, 3> QColorToLinearRGB(const QColor &colour)
{
return sRGBToLinearRGB(QColorTosRGB(colour));
}
inline std::array<qreal, 3> QColorToXYZ(const QColor &colour)
{
return LinearRGBToXYZ(QColorToLinearRGB(colour));
}
inline std::array<qreal, 3> QColorToLAB(const QColor &colour)
{
return XYZToLAB(QColorToXYZ(colour));
}
inline std::array<qreal, 3> sRGBToXYZ(const std::array<qreal, 3> &colour)
{
return LinearRGBToXYZ(sRGBToLinearRGB(colour));
}
inline std::array<qreal, 3> sRGBToLAB(const std::array<qreal, 3> &colour)
{
return XYZToLAB(sRGBToXYZ(colour));
}
inline std::array<qreal, 3> LinearRGBToLAB(const std::array<qreal, 3> &colour)
{
return XYZToLAB(LinearRGBToXYZ(colour));
}
template <typename T>
inline void Move(std::vector<T> &vector, const uint source, const uint destination)
{
auto it = vector.begin();
if (source < destination)
std::rotate(it + source, it + source + 1, it + destination + 1);
else if (source > destination)
std::rotate(it + destination, it + source, it + source + 1);
}
}
#endif // UTILITIES_H