| 596 | } |
| 597 | |
| 598 | void writeBackground(const Data::WallPaper &paper, const QImage &image) { |
| 599 | Expects(_settingsWriteAllowed); |
| 600 | |
| 601 | if (!_backgroundCanWrite) { |
| 602 | return; |
| 603 | } |
| 604 | |
| 605 | _useGlobalBackgroundKeys = true; |
| 606 | auto &backgroundKey = Window::Theme::IsNightMode() |
| 607 | ? _backgroundKeyNight |
| 608 | : _backgroundKeyDay; |
| 609 | auto imageData = QByteArray(); |
| 610 | if (!image.isNull()) { |
| 611 | const auto width = qint32(image.width()); |
| 612 | const auto height = qint32(image.height()); |
| 613 | const auto perpixel = (image.depth() >> 3); |
| 614 | const auto srcperline = image.bytesPerLine(); |
| 615 | const auto srcsize = srcperline * height; |
| 616 | const auto dstperline = width * perpixel; |
| 617 | const auto dstsize = dstperline * height; |
| 618 | const auto copy = (image.format() != kSavedBackgroundFormat) |
| 619 | ? image.convertToFormat(kSavedBackgroundFormat) |
| 620 | : image; |
| 621 | imageData.resize(2 * sizeof(qint32) + dstsize); |
| 622 | |
| 623 | auto dst = bytes::make_detached_span(imageData); |
| 624 | bytes::copy(dst, bytes::object_as_span(&width)); |
| 625 | dst = dst.subspan(sizeof(qint32)); |
| 626 | bytes::copy(dst, bytes::object_as_span(&height)); |
| 627 | dst = dst.subspan(sizeof(qint32)); |
| 628 | const auto src = bytes::make_span(copy.constBits(), srcsize); |
| 629 | if (srcsize == dstsize) { |
| 630 | bytes::copy(dst, src); |
| 631 | } else { |
| 632 | for (auto y = 0; y != height; ++y) { |
| 633 | bytes::copy(dst, src.subspan(y * srcperline, dstperline)); |
| 634 | dst = dst.subspan(dstperline); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | if (!backgroundKey) { |
| 639 | backgroundKey = GenerateKey(_basePath); |
| 640 | writeSettings(); |
| 641 | } |
| 642 | const auto serialized = paper.serialize(); |
| 643 | quint32 size = sizeof(qint32) |
| 644 | + Serialize::bytearraySize(serialized) |
| 645 | + Serialize::bytearraySize(imageData); |
| 646 | EncryptedDescriptor data(size); |
| 647 | data.stream |
| 648 | << qint32(kWallPaperSerializeTagId) |
| 649 | << serialized |
| 650 | << imageData; |
| 651 | |
| 652 | FileWriteDescriptor file(backgroundKey, _basePath); |
| 653 | file.writeEncrypted(data, SettingsKey); |
| 654 | } |
| 655 |
no test coverage detected