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

Method GenerateUserpicImage

Telegram/SourceFiles/data/data_peer.cpp:522–572  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

520}
521
522QImage PeerData::GenerateUserpicImage(
523 not_null<PeerData*> peer,
524 Ui::PeerUserpicView &view,
525 int size,
526 std::optional<int> radius) {
527 if (const auto userpic = peer->userpicCloudImage(view)) {
528 auto image = userpic->scaled(
529 { size, size },
530 Qt::IgnoreAspectRatio,
531 Qt::SmoothTransformation);
532 const auto round = [&](int radius) {
533 return Images::Round(
534 std::move(image),
535 Images::CornersMask(radius / style::DevicePixelRatio()));
536 };
537 if (radius == 0) {
538 return image;
539 } else if (radius) {
540 return round(*radius);
541 } else if (peer->isForum()) {
542 return round(size * Ui::ForumUserpicRadiusMultiplier());
543 } else {
544 return Images::Circle(std::move(image));
545 }
546 }
547 auto result = QImage(
548 QSize(size, size),
549 QImage::Format_ARGB32_Premultiplied);
550 result.fill(Qt::transparent);
551
552 Painter p(&result);
553 if (radius == 0) {
554 peer->ensureEmptyUserpic()->paintSquare(p, 0, 0, size, size);
555 } else if (radius) {
556 const auto r = *radius;
557 peer->ensureEmptyUserpic()->paintRounded(p, 0, 0, size, size, r);
558 } else if (peer->isForum()) {
559 peer->ensureEmptyUserpic()->paintRounded(
560 p,
561 0,
562 0,
563 size,
564 size,
565 size * Ui::ForumUserpicRadiusMultiplier());
566 } else {
567 peer->ensureEmptyUserpic()->paintCircle(p, 0, 0, size, size);
568 }
569 p.end();
570
571 return result;
572}
573
574ImageLocation PeerData::userpicLocation() const {
575 return _userpic.location();

Callers

nothing calls this directly

Calls 12

userpicCloudImageMethod · 0.80
scaledMethod · 0.80
paintSquareMethod · 0.80
ensureEmptyUserpicMethod · 0.80
paintRoundedMethod · 0.80
paintCircleMethod · 0.80
RoundFunction · 0.50
QImageClass · 0.50
isForumMethod · 0.45
fillMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected