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

Side by Side Diff: webrtc/common_video/libyuv/scaler.cc

Issue 1935443002: Revert of Delete webrtc::VideoFrame methods buffer and stride. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 29 matching lines...) Expand all
40 40
41 src_width_ = src_width; 41 src_width_ = src_width;
42 src_height_ = src_height; 42 src_height_ = src_height;
43 dst_width_ = dst_width; 43 dst_width_ = dst_width;
44 dst_height_ = dst_height; 44 dst_height_ = dst_height;
45 method_ = method; 45 method_ = method;
46 set_ = true; 46 set_ = true;
47 return 0; 47 return 0;
48 } 48 }
49 49
50 // TODO(nisse): Should work with VideoFrameBuffer instead.
51 int Scaler::Scale(const VideoFrame& src_frame, VideoFrame* dst_frame) { 50 int Scaler::Scale(const VideoFrame& src_frame, VideoFrame* dst_frame) {
52 assert(dst_frame); 51 assert(dst_frame);
53 if (src_frame.IsZeroSize()) 52 if (src_frame.IsZeroSize())
54 return -1; 53 return -1;
55 if (!set_) 54 if (!set_)
56 return -2; 55 return -2;
57 56
58 // Making sure that destination frame is of sufficient size. 57 // Making sure that destination frame is of sufficient size.
59 dst_frame->set_video_frame_buffer( 58 dst_frame->set_video_frame_buffer(
60 buffer_pool_.CreateBuffer(dst_width_, dst_height_)); 59 buffer_pool_.CreateBuffer(dst_width_, dst_height_));
61 60
62 // We want to preserve aspect ratio instead of stretching the frame. 61 // We want to preserve aspect ratio instead of stretching the frame.
63 // Therefore, we need to crop the source frame. Calculate the largest center 62 // Therefore, we need to crop the source frame. Calculate the largest center
64 // aligned region of the source frame that can be used. 63 // aligned region of the source frame that can be used.
65 const int cropped_src_width = 64 const int cropped_src_width =
66 std::min(src_width_, dst_width_ * src_height_ / dst_height_); 65 std::min(src_width_, dst_width_ * src_height_ / dst_height_);
67 const int cropped_src_height = 66 const int cropped_src_height =
68 std::min(src_height_, dst_height_ * src_width_ / dst_width_); 67 std::min(src_height_, dst_height_ * src_width_ / dst_width_);
69 // Make sure the offsets are even to avoid rounding errors for the U/V planes. 68 // Make sure the offsets are even to avoid rounding errors for the U/V planes.
70 const int src_offset_x = ((src_width_ - cropped_src_width) / 2) & ~1; 69 const int src_offset_x = ((src_width_ - cropped_src_width) / 2) & ~1;
71 const int src_offset_y = ((src_height_ - cropped_src_height) / 2) & ~1; 70 const int src_offset_y = ((src_height_ - cropped_src_height) / 2) & ~1;
72 71
73 const uint8_t* y_ptr = 72 const uint8_t* y_ptr = src_frame.buffer(kYPlane) +
74 src_frame.video_frame_buffer()->DataY() + 73 src_offset_y * src_frame.stride(kYPlane) +
75 src_offset_y * src_frame.video_frame_buffer()->StrideY() + 74 src_offset_x;
76 src_offset_x; 75 const uint8_t* u_ptr = src_frame.buffer(kUPlane) +
77 const uint8_t* u_ptr = 76 src_offset_y / 2 * src_frame.stride(kUPlane) +
78 src_frame.video_frame_buffer()->DataU() + 77 src_offset_x / 2;
79 src_offset_y / 2 * src_frame.video_frame_buffer()->StrideU() + 78 const uint8_t* v_ptr = src_frame.buffer(kVPlane) +
80 src_offset_x / 2; 79 src_offset_y / 2 * src_frame.stride(kVPlane) +
81 const uint8_t* v_ptr = 80 src_offset_x / 2;
82 src_frame.video_frame_buffer()->DataV() +
83 src_offset_y / 2 * src_frame.video_frame_buffer()->StrideV() +
84 src_offset_x / 2;
85 81
86 return libyuv::I420Scale( 82 return libyuv::I420Scale(y_ptr,
87 y_ptr, 83 src_frame.stride(kYPlane),
88 src_frame.video_frame_buffer()->StrideY(), 84 u_ptr,
89 u_ptr, 85 src_frame.stride(kUPlane),
90 src_frame.video_frame_buffer()->StrideU(), 86 v_ptr,
91 v_ptr, 87 src_frame.stride(kVPlane),
92 src_frame.video_frame_buffer()->StrideV(), 88 cropped_src_width, cropped_src_height,
93 cropped_src_width, cropped_src_height, 89 dst_frame->buffer(kYPlane),
94 dst_frame->video_frame_buffer()->MutableDataY(), 90 dst_frame->stride(kYPlane),
95 dst_frame->video_frame_buffer()->StrideY(), 91 dst_frame->buffer(kUPlane),
96 dst_frame->video_frame_buffer()->MutableDataU(), 92 dst_frame->stride(kUPlane),
97 dst_frame->video_frame_buffer()->StrideU(), 93 dst_frame->buffer(kVPlane),
98 dst_frame->video_frame_buffer()->MutableDataV(), 94 dst_frame->stride(kVPlane),
99 dst_frame->video_frame_buffer()->StrideV(), 95 dst_width_, dst_height_,
100 dst_width_, dst_height_, 96 libyuv::FilterMode(method_));
101 libyuv::FilterMode(method_));
102 } 97 }
103 98
104 bool Scaler::SupportedVideoType(VideoType src_video_type, 99 bool Scaler::SupportedVideoType(VideoType src_video_type,
105 VideoType dst_video_type) { 100 VideoType dst_video_type) {
106 if (src_video_type != dst_video_type) 101 if (src_video_type != dst_video_type)
107 return false; 102 return false;
108 103
109 if ((src_video_type == kI420) || (src_video_type == kIYUV) || 104 if ((src_video_type == kI420) || (src_video_type == kIYUV) ||
110 (src_video_type == kYV12)) 105 (src_video_type == kYV12))
111 return true; 106 return true;
112 107
113 return false; 108 return false;
114 } 109 }
115 110
116 } // namespace webrtc 111 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/libyuv/libyuv_unittest.cc ('k') | webrtc/common_video/libyuv/webrtc_libyuv.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698