MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / TakeMiddleSample

Function TakeMiddleSample

Telegram/SourceFiles/boxes/background_box.cpp:42–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40constexpr auto kBackgroundsInRow = 3;
41
42QImage TakeMiddleSample(QImage original, QSize size) {
43 size *= style::DevicePixelRatio();
44 const auto from = original.size();
45 if (from.isEmpty()) {
46 auto result = original.scaled(size);
47 result.setDevicePixelRatio(style::DevicePixelRatio());
48 return result;
49 }
50
51 const auto take = (from.width() * size.height()
52 > from.height() * size.width())
53 ? QSize(size.width() * from.height() / size.height(), from.height())
54 : QSize(from.width(), size.height() * from.width() / size.width());
55 auto result = original.copy(
56 (from.width() - take.width()) / 2,
57 (from.height() - take.height()) / 2,
58 take.width(),
59 take.height()
60 ).scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
61 result.setDevicePixelRatio(style::DevicePixelRatio());
62 return result;
63}
64
65} // namespace
66

Callers 1

Calls 5

scaledMethod · 0.80
sizeMethod · 0.45
isEmptyMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected