Chromium Code Reviews| 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/api/video/i420_buffer.h" | 10 #include "webrtc/api/video/i420_buffer.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, | 69 rtc::scoped_refptr<I420Buffer> I420Buffer::Create(int width, |
| 70 int height, | 70 int height, |
| 71 int stride_y, | 71 int stride_y, |
| 72 int stride_u, | 72 int stride_u, |
| 73 int stride_v) { | 73 int stride_v) { |
| 74 return new rtc::RefCountedObject<I420Buffer>( | 74 return new rtc::RefCountedObject<I420Buffer>( |
| 75 width, height, stride_y, stride_u, stride_v); | 75 width, height, stride_y, stride_u, stride_v); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // static | 78 // static |
| 79 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | 79 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(const PlanarYuvBuffer& source) { |
| 80 const VideoFrameBuffer& source) { | 80 RTC_CHECK(source.type() == Type::kI420); |
| 81 return Copy(source.width(), source.height(), | 81 return Copy(source.width(), source.height(), |
| 82 source.DataY(), source.StrideY(), | 82 source.DataY(), source.StrideY(), |
| 83 source.DataU(), source.StrideU(), | 83 source.DataU(), source.StrideU(), |
| 84 source.DataV(), source.StrideV()); | 84 source.DataV(), source.StrideV()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // static | 87 // static |
| 88 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( | 88 rtc::scoped_refptr<I420Buffer> I420Buffer::Copy( |
| 89 int width, int height, | 89 int width, int height, |
| 90 const uint8_t* data_y, int stride_y, | 90 const uint8_t* data_y, int stride_y, |
| 91 const uint8_t* data_u, int stride_u, | 91 const uint8_t* data_u, int stride_u, |
| 92 const uint8_t* data_v, int stride_v) { | 92 const uint8_t* data_v, int stride_v) { |
| 93 // Note: May use different strides than the input data. | 93 // Note: May use different strides than the input data. |
| 94 rtc::scoped_refptr<I420Buffer> buffer = Create(width, height); | 94 rtc::scoped_refptr<I420Buffer> buffer = Create(width, height); |
| 95 RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, | 95 RTC_CHECK_EQ(0, libyuv::I420Copy(data_y, stride_y, |
| 96 data_u, stride_u, | 96 data_u, stride_u, |
| 97 data_v, stride_v, | 97 data_v, stride_v, |
| 98 buffer->MutableDataY(), buffer->StrideY(), | 98 buffer->MutableDataY(), buffer->StrideY(), |
| 99 buffer->MutableDataU(), buffer->StrideU(), | 99 buffer->MutableDataU(), buffer->StrideU(), |
| 100 buffer->MutableDataV(), buffer->StrideV(), | 100 buffer->MutableDataV(), buffer->StrideV(), |
| 101 width, height)); | 101 width, height)); |
| 102 return buffer; | 102 return buffer; |
| 103 } | 103 } |
| 104 | 104 |
| 105 // static | 105 // static |
| 106 rtc::scoped_refptr<I420Buffer> I420Buffer::Rotate( | 106 rtc::scoped_refptr<I420Buffer> I420Buffer::Rotate(const PlanarYuvBuffer& src, |
| 107 const VideoFrameBuffer& src, VideoRotation rotation) { | 107 VideoRotation rotation) { |
| 108 RTC_CHECK(src.type() == Type::kI420); | |
|
nisse-webrtc
2017/05/29 08:22:22
Hmm. To get better compile time type-checking, cou
magjed_webrtc
2017/05/29 12:12:06
Yeah, this is something I thought about when I did
nisse-webrtc
2017/05/29 12:37:17
Maybe we have to prepare some experimental cl to f
magjed_webrtc
2017/05/29 13:57:02
It's feasible, I uploaded a CL here: https://coder
nisse-webrtc
2017/05/29 14:35:55
I420BufferInterface is good enough, I think. And I
| |
| 108 RTC_CHECK(src.DataY()); | 109 RTC_CHECK(src.DataY()); |
| 109 RTC_CHECK(src.DataU()); | 110 RTC_CHECK(src.DataU()); |
| 110 RTC_CHECK(src.DataV()); | 111 RTC_CHECK(src.DataV()); |
| 111 | 112 |
| 112 int rotated_width = src.width(); | 113 int rotated_width = src.width(); |
| 113 int rotated_height = src.height(); | 114 int rotated_height = src.height(); |
| 114 if (rotation == webrtc::kVideoRotation_90 || | 115 if (rotation == webrtc::kVideoRotation_90 || |
| 115 rotation == webrtc::kVideoRotation_270) { | 116 rotation == webrtc::kVideoRotation_270) { |
| 116 std::swap(rotated_width, rotated_height); | 117 std::swap(rotated_width, rotated_height); |
| 117 } | 118 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 | 181 |
| 181 // static | 182 // static |
| 182 void I420Buffer::SetBlack(I420Buffer* buffer) { | 183 void I420Buffer::SetBlack(I420Buffer* buffer) { |
| 183 RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), | 184 RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), |
| 184 buffer->MutableDataU(), buffer->StrideU(), | 185 buffer->MutableDataU(), buffer->StrideU(), |
| 185 buffer->MutableDataV(), buffer->StrideV(), | 186 buffer->MutableDataV(), buffer->StrideV(), |
| 186 0, 0, buffer->width(), buffer->height(), | 187 0, 0, buffer->width(), buffer->height(), |
| 187 0, 128, 128) == 0); | 188 0, 128, 128) == 0); |
| 188 } | 189 } |
| 189 | 190 |
| 190 void I420Buffer::CropAndScaleFrom( | 191 void I420Buffer::CropAndScaleFrom(const PlanarYuvBuffer& src, |
| 191 const VideoFrameBuffer& src, | 192 int offset_x, |
| 192 int offset_x, | 193 int offset_y, |
| 193 int offset_y, | 194 int crop_width, |
| 194 int crop_width, | 195 int crop_height) { |
| 195 int crop_height) { | 196 RTC_CHECK(src.type() == Type::kI420); |
| 196 RTC_CHECK_LE(crop_width, src.width()); | 197 RTC_CHECK_LE(crop_width, src.width()); |
| 197 RTC_CHECK_LE(crop_height, src.height()); | 198 RTC_CHECK_LE(crop_height, src.height()); |
| 198 RTC_CHECK_LE(crop_width + offset_x, src.width()); | 199 RTC_CHECK_LE(crop_width + offset_x, src.width()); |
| 199 RTC_CHECK_LE(crop_height + offset_y, src.height()); | 200 RTC_CHECK_LE(crop_height + offset_y, src.height()); |
| 200 RTC_CHECK_GE(offset_x, 0); | 201 RTC_CHECK_GE(offset_x, 0); |
| 201 RTC_CHECK_GE(offset_y, 0); | 202 RTC_CHECK_GE(offset_y, 0); |
| 202 | 203 |
| 203 // Make sure offset is even so that u/v plane becomes aligned. | 204 // Make sure offset is even so that u/v plane becomes aligned. |
| 204 const int uv_offset_x = offset_x / 2; | 205 const int uv_offset_x = offset_x / 2; |
| 205 const int uv_offset_y = offset_y / 2; | 206 const int uv_offset_y = offset_y / 2; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 217 v_plane, src.StrideV(), | 218 v_plane, src.StrideV(), |
| 218 crop_width, crop_height, | 219 crop_width, crop_height, |
| 219 MutableDataY(), StrideY(), | 220 MutableDataY(), StrideY(), |
| 220 MutableDataU(), StrideU(), | 221 MutableDataU(), StrideU(), |
| 221 MutableDataV(), StrideV(), | 222 MutableDataV(), StrideV(), |
| 222 width(), height(), libyuv::kFilterBox); | 223 width(), height(), libyuv::kFilterBox); |
| 223 | 224 |
| 224 RTC_DCHECK_EQ(res, 0); | 225 RTC_DCHECK_EQ(res, 0); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void I420Buffer::CropAndScaleFrom( | 228 void I420Buffer::CropAndScaleFrom(const PlanarYuvBuffer& src) { |
| 228 const VideoFrameBuffer& src) { | |
| 229 const int crop_width = | 229 const int crop_width = |
| 230 std::min(src.width(), width() * src.height() / height()); | 230 std::min(src.width(), width() * src.height() / height()); |
| 231 const int crop_height = | 231 const int crop_height = |
| 232 std::min(src.height(), height() * src.width() / width()); | 232 std::min(src.height(), height() * src.width() / width()); |
| 233 | 233 |
| 234 CropAndScaleFrom( | 234 CropAndScaleFrom( |
| 235 src, | 235 src, |
| 236 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, | 236 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, |
| 237 crop_width, crop_height); | 237 crop_width, crop_height); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { | 240 void I420Buffer::ScaleFrom(const PlanarYuvBuffer& src) { |
| 241 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); | 241 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace webrtc | 244 } // namespace webrtc |
| OLD | NEW |