Support selecting Webm stickers.

This commit is contained in:
John Preston 2022-01-21 18:00:13 +03:00
parent 044c7f3ce9
commit 2f9c39fe53
5 changed files with 26 additions and 5 deletions

View file

@ -391,7 +391,10 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
auto request = ::Media::Streaming::FrameRequest();
request.outer = QSize(usew, painth) * cIntRetinaFactor();
request.resize = QSize(_thumbw, _thumbh) * cIntRetinaFactor();
request.keepAlpha = !isRound && unwrapped;
request.keepAlpha = (sticker != nullptr);
if (sticker && context.selected()) {
request.colored = context.st->msgStickerOverlay()->c;
}
request.corners = roundCorners;
request.radius = roundRadius;
if (!activeRoundPlaying && activeOwnPlaying->instance.playerLocked()) {
@ -442,8 +445,13 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
ensureDataMediaCreated();
const auto size = QSize(_thumbw, _thumbh);
const auto args = Images::PrepareArgs{
.options = Images::RoundOptions(roundRadius, roundCorners),
.outer = QSize(usew, painth),
.colored = ((sticker && context.selected())
? &context.st->msgStickerOverlay()
: nullptr),
.options = (sticker
? Images::Option::TransparentBackground
: Images::RoundOptions(roundRadius, roundCorners)),
.outer = sticker ? QSize() : QSize(usew, painth),
};
if (const auto good = _dataMedia->goodThumbnail()) {
p.drawPixmap(rthumb.topLeft(), good->pixSingle(size, args));

View file

@ -59,6 +59,7 @@ struct VideoInformation {
QSize size;
QImage cover;
int rotation = 0;
bool alpha = false;
};
struct AudioInformation {
@ -120,6 +121,7 @@ struct FrameRequest {
QSize outer;
ImageRoundRadius radius = ImageRoundRadius();
RectParts corners = RectPart::AllCorners;
QColor colored = QColor(0, 0, 0, 0);
bool requireARGB32 = true;
bool keepAlpha = false;
bool strict = true;
@ -139,6 +141,7 @@ struct FrameRequest {
&& (outer == other.outer)
&& (radius == other.radius)
&& (corners == other.corners)
&& (colored == other.colored)
&& (keepAlpha == other.keepAlpha)
&& (requireARGB32 == other.requireARGB32);
}
@ -149,7 +152,8 @@ struct FrameRequest {
[[nodiscard]] bool goodFor(const FrameRequest &other) const {
return (requireARGB32 == other.requireARGB32)
&& (keepAlpha == other.keepAlpha)
&& ((*this == other) || (strict && !other.strict));
&& (colored == other.colored)
&& ((strict && !other.strict) || (*this == other));
}
};
@ -177,6 +181,7 @@ struct FrameWithInfo {
FrameYUV420 *yuv420 = nullptr;
FrameFormat format = FrameFormat::None;
int index = -1;
bool alpha = false;
};
} // namespace Streaming

View file

@ -63,6 +63,7 @@ void SaveValidVideoInformation(
to.size = from.size;
to.cover = std::move(from.cover);
to.rotation = from.rotation;
to.alpha = from.alpha;
}
void SaveValidStartInformation(Information &to, Information &&from) {

View file

@ -92,7 +92,9 @@ bool GoodForRequest(
bool hasAlpha,
int rotation,
const FrameRequest &request) {
if (image.isNull() || (hasAlpha && !request.keepAlpha)) {
if (image.isNull()
|| (hasAlpha && !request.keepAlpha)
|| request.colored.alpha() != 0) {
return false;
} else if (request.resize.isEmpty()) {
return true;
@ -321,6 +323,9 @@ QImage PrepareByRequest(
p.end();
ApplyFrameRounding(storage, request);
if (request.colored.alpha() != 0) {
storage = Images::Colored(std::move(storage), request.colored);
}
return storage;
}

View file

@ -661,6 +661,7 @@ void VideoTrackObject::callReady() {
}
data.cover = frame->original;
data.rotation = _stream.rotation;
data.alpha = frame->alpha;
data.state.duration = _stream.duration;
data.state.position = _syncTimePoint.trackTime;
data.state.receivedTill = _readTillEnd
@ -1166,6 +1167,7 @@ FrameWithInfo VideoTrack::frameWithInfo(const Instance *instance) {
.yuv420 = &data.frame->yuv420,
.format = data.frame->format,
.index = data.index,
.alpha = data.frame->alpha,
};
}