Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Unified Diff: media/base/video_util.cc

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: REBASE Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/video_util.h ('k') | media/base/video_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/video_util.cc
diff --git a/media/base/video_util.cc b/media/base/video_util.cc
index d7946743eae091cef3f9952c4a0d6cb5acd4ab40..e04a5a3c5439538f2f9f7d91578b8fea63aa86bd 100644
--- a/media/base/video_util.cc
+++ b/media/base/video_util.cc
@@ -270,6 +270,23 @@ void RotatePlaneByPixels(
}
}
+// Common logic for the letterboxing and scale-within/scale-encompassing
+// functions. Scales |size| to either fit within or encompass |target|,
+// depending on whether |fit_within_target| is true.
+static gfx::Size ScaleSizeToTarget(const gfx::Size& size,
+ const gfx::Size& target,
+ bool fit_within_target) {
+ if (size.IsEmpty())
+ return gfx::Size(); // Corner case: Aspect ratio is undefined.
+
+ const int64 x = static_cast<int64>(size.width()) * target.height();
+ const int64 y = static_cast<int64>(size.height()) * target.width();
+ const bool use_target_width = fit_within_target ? (y < x) : (x < y);
+ return use_target_width ?
+ gfx::Size(target.width(), static_cast<int>(y / size.width())) :
+ gfx::Size(static_cast<int>(x / size.height()), target.height());
+}
+
gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds,
const gfx::Size& content) {
// If |content| has an undefined aspect ratio, let's not try to divide by
@@ -277,19 +294,33 @@ gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds,
if (content.IsEmpty())
return gfx::Rect();
- int64 x = static_cast<int64>(content.width()) * bounds.height();
- int64 y = static_cast<int64>(content.height()) * bounds.width();
-
- gfx::Size letterbox(bounds.width(), bounds.height());
- if (y < x)
- letterbox.set_height(static_cast<int>(y / content.width()));
- else
- letterbox.set_width(static_cast<int>(x / content.height()));
gfx::Rect result = bounds;
- result.ClampToCenteredSize(letterbox);
+ result.ClampToCenteredSize(ScaleSizeToTarget(content, bounds.size(), true));
return result;
}
+gfx::Size ScaleSizeToFitWithinTarget(const gfx::Size& size,
+ const gfx::Size& target) {
+ return ScaleSizeToTarget(size, target, true);
+}
+
+gfx::Size ScaleSizeToEncompassTarget(const gfx::Size& size,
+ const gfx::Size& target) {
+ return ScaleSizeToTarget(size, target, false);
+}
+
+gfx::Size PadToMatchAspectRatio(const gfx::Size& size,
+ const gfx::Size& target) {
+ if (target.IsEmpty())
+ return gfx::Size(); // Aspect ratio is undefined.
+
+ const int64 x = static_cast<int64>(size.width()) * target.height();
+ const int64 y = static_cast<int64>(size.height()) * target.width();
+ if (x < y)
+ return gfx::Size(static_cast<int>(y / target.height()), size.height());
+ return gfx::Size(size.width(), static_cast<int>(x / target.width()));
+}
+
void CopyRGBToVideoFrame(const uint8* source,
int stride,
const gfx::Rect& region_in_frame,
« no previous file with comments | « media/base/video_util.h ('k') | media/base/video_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698