mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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()
|
maxWidth = qMax(maxWidth, st::msgPadding.left()
|
||||||
+ _caption.maxWidth()
|
+ _caption.maxWidth()
|
||||||
+ st::msgPadding.right());
|
+ st::msgPadding.right());
|
||||||
|
minHeight = adjustHeightForLessCrop(
|
||||||
|
scaled,
|
||||||
|
{ maxWidth, minHeight });
|
||||||
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
||||||
if (isBubbleBottom()) {
|
if (isBubbleBottom()) {
|
||||||
minHeight += st::msgPadding.bottom();
|
minHeight += st::msgPadding.bottom();
|
||||||
|
@ -209,6 +212,9 @@ QSize Gif::countCurrentSize(int newWidth) {
|
||||||
+ _caption.maxWidth()
|
+ _caption.maxWidth()
|
||||||
+ st::msgPadding.right()));
|
+ st::msgPadding.right()));
|
||||||
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
||||||
|
newHeight = adjustHeightForLessCrop(
|
||||||
|
scaled,
|
||||||
|
{ newWidth, newHeight });
|
||||||
const auto captionw = newWidth
|
const auto captionw = newWidth
|
||||||
- st::msgPadding.left()
|
- st::msgPadding.left()
|
||||||
- st::msgPadding.right();
|
- st::msgPadding.right();
|
||||||
|
@ -242,6 +248,19 @@ QSize Gif::countCurrentSize(int newWidth) {
|
||||||
return { newWidth, newHeight };
|
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 {
|
QSize Gif::videoSize() const {
|
||||||
if (const auto streamed = activeCurrentStreamed()) {
|
if (const auto streamed = activeCurrentStreamed()) {
|
||||||
return streamed->player().videoSize();
|
return streamed->player().videoSize();
|
||||||
|
|
|
@ -120,6 +120,9 @@ private:
|
||||||
|
|
||||||
void validateVideoThumbnail() const;
|
void validateVideoThumbnail() const;
|
||||||
[[nodiscard]] QSize countThumbSize(int &inOutWidthMax) const;
|
[[nodiscard]] QSize countThumbSize(int &inOutWidthMax) const;
|
||||||
|
[[nodiscard]] int adjustHeightForLessCrop(
|
||||||
|
QSize dimensions,
|
||||||
|
QSize current) const;
|
||||||
|
|
||||||
float64 dataProgress() const override;
|
float64 dataProgress() const override;
|
||||||
bool dataFinished() const override;
|
bool dataFinished() const override;
|
||||||
|
|
|
@ -169,14 +169,9 @@ QSize Photo::countOptimalSize() {
|
||||||
(st::msgPadding.left()
|
(st::msgPadding.left()
|
||||||
+ _caption.maxWidth()
|
+ _caption.maxWidth()
|
||||||
+ st::msgPadding.right()));
|
+ st::msgPadding.right()));
|
||||||
if (!dimensions.isEmpty()
|
minHeight = adjustHeightForLessCrop(
|
||||||
&& ::Media::Streaming::FrameResizeMayExpand(
|
dimensions,
|
||||||
{ maxWidth, minHeight },
|
{ maxWidth, minHeight });
|
||||||
dimensions)) {
|
|
||||||
minHeight = qMax(
|
|
||||||
minHeight,
|
|
||||||
maxWidth * dimensions.height() / dimensions.width());
|
|
||||||
}
|
|
||||||
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
minHeight += st::mediaCaptionSkip + _caption.minHeight();
|
||||||
if (isBubbleBottom()) {
|
if (isBubbleBottom()) {
|
||||||
minHeight += st::msgPadding.bottom();
|
minHeight += st::msgPadding.bottom();
|
||||||
|
@ -210,14 +205,9 @@ QSize Photo::countCurrentSize(int newWidth) {
|
||||||
+ _caption.maxWidth()
|
+ _caption.maxWidth()
|
||||||
+ st::msgPadding.right()));
|
+ st::msgPadding.right()));
|
||||||
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
newWidth = qMin(qMax(newWidth, maxWithCaption), thumbMaxWidth);
|
||||||
if (!dimensions.isEmpty()
|
newHeight = adjustHeightForLessCrop(
|
||||||
&& ::Media::Streaming::FrameResizeMayExpand(
|
dimensions,
|
||||||
{ newWidth, newHeight },
|
{ newWidth, newHeight });
|
||||||
dimensions)) {
|
|
||||||
newHeight = qMax(
|
|
||||||
newHeight,
|
|
||||||
newWidth * dimensions.height() / dimensions.width());
|
|
||||||
}
|
|
||||||
const auto captionw = newWidth
|
const auto captionw = newWidth
|
||||||
- st::msgPadding.left()
|
- st::msgPadding.left()
|
||||||
- st::msgPadding.right();
|
- st::msgPadding.right();
|
||||||
|
@ -229,6 +219,16 @@ QSize Photo::countCurrentSize(int newWidth) {
|
||||||
return { newWidth, newHeight };
|
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 {
|
void Photo::draw(Painter &p, const PaintContext &context) const {
|
||||||
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
|
||||||
|
|
||||||
|
|
|
@ -116,6 +116,9 @@ private:
|
||||||
|
|
||||||
QSize countOptimalSize() override;
|
QSize countOptimalSize() override;
|
||||||
QSize countCurrentSize(int newWidth) override;
|
QSize countCurrentSize(int newWidth) override;
|
||||||
|
[[nodiscard]] int adjustHeightForLessCrop(
|
||||||
|
QSize dimensions,
|
||||||
|
QSize current) const;
|
||||||
|
|
||||||
bool needInfoDisplay() const;
|
bool needInfoDisplay() const;
|
||||||
void validateGroupedCache(
|
void validateGroupedCache(
|
||||||
|
|
Loading…
Add table
Reference in a new issue