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

Function writeBackground

Telegram/SourceFiles/storage/localstorage.cpp:598–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596}
597
598void 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

Callers 2

startMethod · 0.85

Calls 12

QByteArrayClass · 0.85
GenerateKeyFunction · 0.85
writeSettingsFunction · 0.85
bytearraySizeFunction · 0.85
resizeMethod · 0.80
writeEncryptedMethod · 0.80
IsNightModeFunction · 0.50
isNullMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
formatMethod · 0.45
serializeMethod · 0.45

Tested by

no test coverage detected