OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include "webrtc/common_video/include/video_frame_buffer.h" | 10 #include "webrtc/common_video/include/video_frame_buffer.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 void* I420Buffer::native_handle() const { | 120 void* I420Buffer::native_handle() const { |
121 return nullptr; | 121 return nullptr; |
122 } | 122 } |
123 | 123 |
124 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { | 124 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::NativeToI420Buffer() { |
125 RTC_NOTREACHED(); | 125 RTC_NOTREACHED(); |
126 return nullptr; | 126 return nullptr; |
127 } | 127 } |
128 | 128 |
| 129 // static |
129 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | 130 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( |
130 const rtc::scoped_refptr<VideoFrameBuffer>& source) { | 131 const VideoFrameBuffer& source) { |
131 int width = source->width(); | 132 int width = source.width(); |
132 int height = source->height(); | 133 int height = source.height(); |
133 rtc::scoped_refptr<I420Buffer> target = I420Buffer::Create(width, height); | 134 rtc::scoped_refptr<I420Buffer> target = I420Buffer::Create(width, height); |
134 RTC_CHECK(libyuv::I420Copy(source->DataY(), source->StrideY(), | 135 RTC_CHECK(libyuv::I420Copy(source.DataY(), source.StrideY(), |
135 source->DataU(), source->StrideU(), | 136 source.DataU(), source.StrideU(), |
136 source->DataV(), source->StrideV(), | 137 source.DataV(), source.StrideV(), |
137 target->MutableDataY(), target->StrideY(), | 138 target->MutableDataY(), target->StrideY(), |
138 target->MutableDataU(), target->StrideU(), | 139 target->MutableDataU(), target->StrideU(), |
139 target->MutableDataV(), target->StrideV(), | 140 target->MutableDataV(), target->StrideV(), |
140 width, height) == 0); | 141 width, height) == 0); |
141 | 142 |
142 return target; | 143 return target; |
143 } | 144 } |
144 | 145 |
145 void I420Buffer::SetToBlack() { | 146 void I420Buffer::SetToBlack() { |
146 RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(), | 147 RTC_CHECK(libyuv::I420Rect(MutableDataY(), StrideY(), |
147 MutableDataU(), StrideU(), | 148 MutableDataU(), StrideU(), |
148 MutableDataV(), StrideV(), | 149 MutableDataV(), StrideV(), |
149 0, 0, width(), height(), | 150 0, 0, width(), height(), |
150 0, 128, 128) == 0); | 151 0, 128, 128) == 0); |
151 } | 152 } |
152 | 153 |
153 void I420Buffer::CropAndScaleFrom( | 154 void I420Buffer::CropAndScaleFrom( |
154 const rtc::scoped_refptr<VideoFrameBuffer>& src, | 155 const VideoFrameBuffer& src, |
155 int offset_x, | 156 int offset_x, |
156 int offset_y, | 157 int offset_y, |
157 int crop_width, | 158 int crop_width, |
158 int crop_height) { | 159 int crop_height) { |
159 RTC_CHECK_LE(crop_width, src->width()); | 160 RTC_CHECK_LE(crop_width, src.width()); |
160 RTC_CHECK_LE(crop_height, src->height()); | 161 RTC_CHECK_LE(crop_height, src.height()); |
161 RTC_CHECK_LE(crop_width + offset_x, src->width()); | 162 RTC_CHECK_LE(crop_width + offset_x, src.width()); |
162 RTC_CHECK_LE(crop_height + offset_y, src->height()); | 163 RTC_CHECK_LE(crop_height + offset_y, src.height()); |
163 RTC_CHECK_GE(offset_x, 0); | 164 RTC_CHECK_GE(offset_x, 0); |
164 RTC_CHECK_GE(offset_y, 0); | 165 RTC_CHECK_GE(offset_y, 0); |
165 | 166 |
166 // Make sure offset is even so that u/v plane becomes aligned. | 167 // Make sure offset is even so that u/v plane becomes aligned. |
167 const int uv_offset_x = offset_x / 2; | 168 const int uv_offset_x = offset_x / 2; |
168 const int uv_offset_y = offset_y / 2; | 169 const int uv_offset_y = offset_y / 2; |
169 offset_x = uv_offset_x * 2; | 170 offset_x = uv_offset_x * 2; |
170 offset_y = uv_offset_y * 2; | 171 offset_y = uv_offset_y * 2; |
171 | 172 |
172 const uint8_t* y_plane = | 173 const uint8_t* y_plane = |
173 src->DataY() + src->StrideY() * offset_y + offset_x; | 174 src.DataY() + src.StrideY() * offset_y + offset_x; |
174 const uint8_t* u_plane = | 175 const uint8_t* u_plane = |
175 src->DataU() + src->StrideU() * uv_offset_y + uv_offset_x; | 176 src.DataU() + src.StrideU() * uv_offset_y + uv_offset_x; |
176 const uint8_t* v_plane = | 177 const uint8_t* v_plane = |
177 src->DataV() + src->StrideV() * uv_offset_y + uv_offset_x; | 178 src.DataV() + src.StrideV() * uv_offset_y + uv_offset_x; |
178 int res = libyuv::I420Scale(y_plane, src->StrideY(), | 179 int res = libyuv::I420Scale(y_plane, src.StrideY(), |
179 u_plane, src->StrideU(), | 180 u_plane, src.StrideU(), |
180 v_plane, src->StrideV(), | 181 v_plane, src.StrideV(), |
181 crop_width, crop_height, | 182 crop_width, crop_height, |
182 MutableDataY(), StrideY(), | 183 MutableDataY(), StrideY(), |
183 MutableDataU(), StrideU(), | 184 MutableDataU(), StrideU(), |
184 MutableDataV(), StrideV(), | 185 MutableDataV(), StrideV(), |
185 width(), height(), libyuv::kFilterBox); | 186 width(), height(), libyuv::kFilterBox); |
186 | 187 |
187 RTC_DCHECK_EQ(res, 0); | 188 RTC_DCHECK_EQ(res, 0); |
188 } | 189 } |
189 | 190 |
190 void I420Buffer::CropAndScaleFrom( | 191 void I420Buffer::CropAndScaleFrom( |
191 const rtc::scoped_refptr<VideoFrameBuffer>& src) { | 192 const VideoFrameBuffer& src) { |
192 const int crop_width = | 193 const int crop_width = |
193 std::min(src->width(), width() * src->height() / height()); | 194 std::min(src.width(), width() * src.height() / height()); |
194 const int crop_height = | 195 const int crop_height = |
195 std::min(src->height(), height() * src->width() / width()); | 196 std::min(src.height(), height() * src.width() / width()); |
196 | 197 |
197 CropAndScaleFrom( | 198 CropAndScaleFrom( |
198 src, | 199 src, |
199 (src->width() - crop_width) / 2, (src->height() - crop_height) / 2, | 200 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, |
200 crop_width, crop_height); | 201 crop_width, crop_height); |
201 } | 202 } |
202 | 203 |
203 void I420Buffer::ScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { | 204 void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { |
204 CropAndScaleFrom(src, 0, 0, src->width(), src->height()); | 205 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); |
205 } | 206 } |
206 | 207 |
207 // static | 208 // static |
208 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate( | 209 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate( |
209 const rtc::scoped_refptr<VideoFrameBuffer>& src, | 210 rtc::scoped_refptr<VideoFrameBuffer> src, |
210 VideoRotation rotation) { | 211 VideoRotation rotation) { |
211 RTC_DCHECK(src->DataY()); | 212 RTC_DCHECK(src->DataY()); |
212 RTC_DCHECK(src->DataU()); | 213 RTC_DCHECK(src->DataU()); |
213 RTC_DCHECK(src->DataV()); | 214 RTC_DCHECK(src->DataV()); |
214 | 215 |
215 if (rotation == webrtc::kVideoRotation_0) { | 216 if (rotation == webrtc::kVideoRotation_0) { |
216 return src; | 217 return src; |
217 } | 218 } |
218 | 219 |
219 int rotated_width = src->width(); | 220 int rotated_width = src->width(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 void* WrappedI420Buffer::native_handle() const { | 342 void* WrappedI420Buffer::native_handle() const { |
342 return nullptr; | 343 return nullptr; |
343 } | 344 } |
344 | 345 |
345 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { | 346 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { |
346 RTC_NOTREACHED(); | 347 RTC_NOTREACHED(); |
347 return nullptr; | 348 return nullptr; |
348 } | 349 } |
349 | 350 |
350 } // namespace webrtc | 351 } // namespace webrtc |
OLD | NEW |