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 | 10 |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 CropAndScaleFrom( | 209 CropAndScaleFrom( |
210 src, | 210 src, |
211 (src->width() - crop_width) / 2, (src->height() - crop_height) / 2, | 211 (src->width() - crop_width) / 2, (src->height() - crop_height) / 2, |
212 crop_width, crop_height); | 212 crop_width, crop_height); |
213 } | 213 } |
214 | 214 |
215 void I420Buffer::ScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { | 215 void I420Buffer::ScaleFrom(const rtc::scoped_refptr<VideoFrameBuffer>& src) { |
216 CropAndScaleFrom(src, 0, 0, src->width(), src->height()); | 216 CropAndScaleFrom(src, 0, 0, src->width(), src->height()); |
217 } | 217 } |
218 | 218 |
| 219 // static |
219 rtc::scoped_refptr<I420Buffer> I420Buffer::CopyKeepStride( | 220 rtc::scoped_refptr<I420Buffer> I420Buffer::CopyKeepStride( |
220 const rtc::scoped_refptr<VideoFrameBuffer>& source) { | 221 const rtc::scoped_refptr<VideoFrameBuffer>& source) { |
221 int width = source->width(); | 222 int width = source->width(); |
222 int height = source->height(); | 223 int height = source->height(); |
223 int stride_y = source->StrideY(); | 224 int stride_y = source->StrideY(); |
224 int stride_u = source->StrideU(); | 225 int stride_u = source->StrideU(); |
225 int stride_v = source->StrideV(); | 226 int stride_v = source->StrideV(); |
226 rtc::scoped_refptr<I420Buffer> target = | 227 rtc::scoped_refptr<I420Buffer> target = |
227 I420Buffer::Create(width, height, stride_y, stride_u, stride_v); | 228 I420Buffer::Create(width, height, stride_y, stride_u, stride_v); |
228 RTC_CHECK(libyuv::I420Copy(source->DataY(), stride_y, | 229 RTC_CHECK(libyuv::I420Copy(source->DataY(), stride_y, |
229 source->DataU(), stride_u, | 230 source->DataU(), stride_u, |
230 source->DataV(), stride_v, | 231 source->DataV(), stride_v, |
231 target->MutableDataY(), stride_y, | 232 target->MutableDataY(), stride_y, |
232 target->MutableDataU(), stride_u, | 233 target->MutableDataU(), stride_u, |
233 target->MutableDataV(), stride_v, | 234 target->MutableDataV(), stride_v, |
234 width, height) == 0); | 235 width, height) == 0); |
235 | 236 |
236 return target; | 237 return target; |
237 } | 238 } |
238 | 239 |
| 240 // static |
| 241 rtc::scoped_refptr<VideoFrameBuffer> I420Buffer::Rotate( |
| 242 const rtc::scoped_refptr<VideoFrameBuffer>& src, |
| 243 VideoRotation rotation) { |
| 244 RTC_DCHECK(src->DataY()); |
| 245 RTC_DCHECK(src->DataU()); |
| 246 RTC_DCHECK(src->DataV()); |
| 247 |
| 248 if (rotation == webrtc::kVideoRotation_0) { |
| 249 return src; |
| 250 } |
| 251 |
| 252 int rotated_width = src->width(); |
| 253 int rotated_height = src->height(); |
| 254 if (rotation == webrtc::kVideoRotation_90 || |
| 255 rotation == webrtc::kVideoRotation_270) { |
| 256 std::swap(rotated_width, rotated_height); |
| 257 } |
| 258 |
| 259 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 260 I420Buffer::Create(rotated_width, rotated_height); |
| 261 |
| 262 int res = libyuv::I420Rotate( |
| 263 src->DataY(), src->StrideY(), |
| 264 src->DataU(), src->StrideU(), |
| 265 src->DataV(), src->StrideV(), |
| 266 buffer->MutableDataY(), buffer->StrideY(), buffer->MutableDataU(), |
| 267 buffer->StrideU(), buffer->MutableDataV(), buffer->StrideV(), |
| 268 src->width(), src->height(), |
| 269 static_cast<libyuv::RotationMode>(rotation)); |
| 270 RTC_DCHECK_EQ(res, 0); |
| 271 |
| 272 return buffer; |
| 273 } |
| 274 |
239 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 275 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
240 int width, | 276 int width, |
241 int height) | 277 int height) |
242 : native_handle_(native_handle), width_(width), height_(height) { | 278 : native_handle_(native_handle), width_(width), height_(height) { |
243 RTC_DCHECK(native_handle != nullptr); | 279 RTC_DCHECK(native_handle != nullptr); |
244 RTC_DCHECK_GT(width, 0); | 280 RTC_DCHECK_GT(width, 0); |
245 RTC_DCHECK_GT(height, 0); | 281 RTC_DCHECK_GT(height, 0); |
246 } | 282 } |
247 | 283 |
248 int NativeHandleBuffer::width() const { | 284 int NativeHandleBuffer::width() const { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 void* WrappedI420Buffer::native_handle() const { | 374 void* WrappedI420Buffer::native_handle() const { |
339 return nullptr; | 375 return nullptr; |
340 } | 376 } |
341 | 377 |
342 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { | 378 rtc::scoped_refptr<VideoFrameBuffer> WrappedI420Buffer::NativeToI420Buffer() { |
343 RTC_NOTREACHED(); | 379 RTC_NOTREACHED(); |
344 return nullptr; | 380 return nullptr; |
345 } | 381 } |
346 | 382 |
347 } // namespace webrtc | 383 } // namespace webrtc |
OLD | NEW |