| 40 | constexpr auto kBackgroundsInRow = 3; |
| 41 | |
| 42 | QImage 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 | |