mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Improve cropping for videos a bit.
Partially fixes #25061 for videos as well.
This commit is contained in:
parent
fc3810fd7f
commit
476a864be2
4 changed files with 41 additions and 16 deletions
|
@ -166,6 +166,9 @@ QSize Gif::countOptimalSize() {
|
|||
maxWidth = qMax(maxWidth, st::msgPadding.left()
|
||||
+ _caption.maxWidth()
|
||||
+ st::msgPadding.right());
|
||||
minHeight = adjustHeightForLessCrop(
|
||||
scaled,
|
||||
{ maxWidth, minHeight });
|
||||
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
||||
if (isBubbleBottom()) {
|
||||
minHeight += st::msgPadding.bottom();
|
||||
|
@ -209,6 +212,9 @@ QSize Gif::countCurrentSize(int newWidth) {
|
|||
+ _caption.maxWidth()
|
||||
+ st::msgPadding.right()));
|
||||
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
||||
newHeight = adjustHeightForLessCrop(
|
||||
scaled,
|
||||
{ newWidth, newHeight });
|
||||
const auto captionw = newWidth
|
||||
- st::msgPadding.left()
|
||||
- st::msgPadding.right();
|
||||
|
@ -242,6 +248,19 @@ QSize Gif::countCurrentSize(int newWidth) {
|
|||
return { newWidth, newHeight };
|
||||
}
|
||||
|
||||
int Gif::adjustHeightForLessCrop(QSize dimensions, QSize current) const {
|
||||
if (dimensions.isEmpty()) {
|
||||
return current.height();
|
||||
}
|
||||
// Allow some more vertical space for less cropping,
|
||||
// but not more than 1.33 * existing height.
|
||||
return qMax(
|
||||
current.height(),
|
||||
qMin(
|
||||
current.width() * dimensions.height() / dimensions.width(),
|
||||
current.height() * 4 / 3));
|
||||
}
|
||||
|
||||
QSize Gif::videoSize() const {
|
||||
if (const auto streamed = activeCurrentStreamed()) {
|
||||
return streamed->player().videoSize();
|
||||
|
|
|
@ -120,6 +120,9 @@ private:
|
|||
|
||||
void validateVideoThumbnail() const;
|
||||
[[nodiscard]] QSize countThumbSize(int &inOutWidthMax) const;
|
||||
[[nodiscard]] int adjustHeightForLessCrop(
|
||||
QSize dimensions,
|
||||
QSize current) const;
|
||||
|
||||
float64 dataProgress() const override;
|
||||
bool dataFinished() const override;
|
||||
|
|
|
@ -169,14 +169,9 @@ QSize Photo::countOptimalSize() {
|
|||
(st::msgPadding.left()
|
||||
+ _caption.maxWidth()
|
||||
+ st::msgPadding.right()));
|
||||
if (!dimensions.isEmpty()
|
||||
&& ::Media::Streaming::FrameResizeMayExpand(
|
||||
{ maxWidth, minHeight },
|
||||
dimensions)) {
|
||||
minHeight = qMax(
|
||||
minHeight,
|
||||
maxWidth * dimensions.height() / dimensions.width());
|
||||
}
|
||||
minHeight = adjustHeightForLessCrop(
|
||||
dimensions,
|
||||
{ maxWidth, minHeight });
|
||||
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
||||
if (isBubbleBottom()) {
|
||||
minHeight += st::msgPadding.bottom();
|
||||
|
@ -210,14 +205,9 @@ QSize Photo::countCurrentSize(int newWidth) {
|
|||
+ _caption.maxWidth()
|
||||
+ st::msgPadding.right()));
|
||||
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
||||
if (!dimensions.isEmpty()
|
||||
&& ::Media::Streaming::FrameResizeMayExpand(
|
||||
{ newWidth, newHeight },
|
||||
dimensions)) {
|
||||
newHeight = qMax(
|
||||
newHeight,
|
||||
newWidth * dimensions.height() / dimensions.width());
|
||||
}
|
||||
newHeight = adjustHeightForLessCrop(
|
||||
dimensions,
|
||||
{ newWidth, newHeight });
|
||||
const auto captionw = newWidth
|
||||
- st::msgPadding.left()
|
||||
- st::msgPadding.right();
|
||||
|
@ -229,6 +219,16 @@ QSize Photo::countCurrentSize(int newWidth) {
|
|||
return { newWidth, newHeight };
|
||||
}
|
||||
|
||||
int Photo::adjustHeightForLessCrop(QSize dimensions, QSize current) const {
|
||||
if (dimensions.isEmpty()
|
||||
|| !::Media::Streaming::FrameResizeMayExpand(current, dimensions)) {
|
||||
return current.height();
|
||||
}
|
||||
return qMax(
|
||||
current.height(),
|
||||
current.width() * dimensions.height() / dimensions.width());
|
||||
}
|
||||
|
||||
void Photo::draw(Painter &p, const PaintContext &context) const {
|
||||
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||
|
||||
|
|
|
@ -116,6 +116,9 @@ private:
|
|||
|
||||
QSize countOptimalSize() override;
|
||||
QSize countCurrentSize(int newWidth) override;
|
||||
[[nodiscard]] int adjustHeightForLessCrop(
|
||||
QSize dimensions,
|
||||
QSize current) const;
|
||||
|
||||
bool needInfoDisplay() const;
|
||||
void validateGroupedCache(
|
||||
|
|
Loading…
Add table
Reference in a new issue