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

Side by Side 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: Addressed Dale's comments. 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/video_util.h" 5 #include "media/base/video_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/base/video_frame.h" 10 #include "media/base/video_frame.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 uint8* dest_ptr = dest; 263 uint8* dest_ptr = dest;
264 for (int col = 0; col < num_cols; ++col) { 264 for (int col = 0; col < num_cols; ++col) {
265 *dest_ptr = *src_ptr++; 265 *dest_ptr = *src_ptr++;
266 dest_ptr += dest_col_step; 266 dest_ptr += dest_col_step;
267 } 267 }
268 src += src_stride; 268 src += src_stride;
269 dest += dest_row_step; 269 dest += dest_row_step;
270 } 270 }
271 } 271 }
272 272
273 // Common logic for the letterboxing and scale-within/scale-encompassing
274 // functions. Scales |size| to either fit within or encompass |target|,
275 // depending on whether |fit_within_target| is true.
276 static gfx::Size ScaleSizeToTarget(const gfx::Size& size,
277 const gfx::Size& target,
278 bool fit_within_target) {
279 if (size.IsEmpty())
280 return gfx::Size(); // Corner case: Aspect ratio is undefined.
281
282 // Scale |size|, preserving aspect ratio.
Wez 2015/05/13 19:05:09 nit: This comment adds nothing, since that's the p
miu 2015/05/14 01:21:33 Done.
283 const int64 x = static_cast<int64>(size.width()) * target.height();
284 const int64 y = static_cast<int64>(size.height()) * target.width();
285 const bool use_target_width = fit_within_target ? (y < x) : (x < y);
286 return use_target_width ?
287 gfx::Size(target.width(), static_cast<int>(y / size.width())) :
288 gfx::Size(static_cast<int>(x / size.height()), target.height());
289 }
290
273 gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds, 291 gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds,
274 const gfx::Size& content) { 292 const gfx::Size& content) {
275 // If |content| has an undefined aspect ratio, let's not try to divide by 293 // If |content| has an undefined aspect ratio, let's not try to divide by
276 // zero. 294 // zero.
277 if (content.IsEmpty()) 295 if (content.IsEmpty())
278 return gfx::Rect(); 296 return gfx::Rect();
279 297
280 int64 x = static_cast<int64>(content.width()) * bounds.height(); 298 gfx::Rect result = bounds;
281 int64 y = static_cast<int64>(content.height()) * bounds.width(); 299 result.ClampToCenteredSize(ScaleSizeToTarget(content, bounds.size(), true));
300 return result;
301 }
282 302
283 gfx::Size letterbox(bounds.width(), bounds.height()); 303 gfx::Size ScaleSizeToFitWithinTarget(const gfx::Size& size,
284 if (y < x) 304 const gfx::Size& target) {
285 letterbox.set_height(static_cast<int>(y / content.width())); 305 return ScaleSizeToTarget(size, target, true);
286 else 306 }
287 letterbox.set_width(static_cast<int>(x / content.height())); 307
288 gfx::Rect result = bounds; 308 gfx::Size ScaleSizeToEncompassTarget(const gfx::Size& size,
289 result.ClampToCenteredSize(letterbox); 309 const gfx::Size& target) {
290 return result; 310 return ScaleSizeToTarget(size, target, false);
311 }
312
313 gfx::Size PadToMatchAspectRatio(const gfx::Size& size,
314 const gfx::Size& target) {
315 if (target.IsEmpty())
316 return gfx::Size(); // Aspect ratio is undefined.
317
318 const int64 x = static_cast<int64>(size.width()) * target.height();
319 const int64 y = static_cast<int64>(size.height()) * target.width();
320 if (x < y)
321 return gfx::Size(static_cast<int>(y / target.height()), size.height());
322 return gfx::Size(size.width(), static_cast<int>(x / target.width()));
291 } 323 }
292 324
293 void CopyRGBToVideoFrame(const uint8* source, 325 void CopyRGBToVideoFrame(const uint8* source,
294 int stride, 326 int stride,
295 const gfx::Rect& region_in_frame, 327 const gfx::Rect& region_in_frame,
296 VideoFrame* frame) { 328 VideoFrame* frame) {
297 const int kY = VideoFrame::kYPlane; 329 const int kY = VideoFrame::kYPlane;
298 const int kU = VideoFrame::kUPlane; 330 const int kU = VideoFrame::kUPlane;
299 const int kV = VideoFrame::kVPlane; 331 const int kV = VideoFrame::kVPlane;
300 CHECK_EQ(frame->stride(kU), frame->stride(kV)); 332 CHECK_EQ(frame->stride(kU), frame->stride(kV));
(...skipping 13 matching lines...) Expand all
314 frame->data(kU) + uv_offset, 346 frame->data(kU) + uv_offset,
315 frame->data(kV) + uv_offset, 347 frame->data(kV) + uv_offset,
316 region_in_frame.width(), 348 region_in_frame.width(),
317 region_in_frame.height(), 349 region_in_frame.height(),
318 stride, 350 stride,
319 frame->stride(kY), 351 frame->stride(kY),
320 uv_stride); 352 uv_stride);
321 } 353 }
322 354
323 } // namespace media 355 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698