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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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( |
80 const VideoFrameBuffer& source) { | 80 const I420BufferInterface& source) { |
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( |
107 const VideoFrameBuffer& src, VideoRotation rotation) { | 107 const I420BufferInterface& src, |
| 108 VideoRotation rotation) { |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 | 177 |
177 // static | 178 // static |
178 void I420Buffer::SetBlack(I420Buffer* buffer) { | 179 void I420Buffer::SetBlack(I420Buffer* buffer) { |
179 RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), | 180 RTC_CHECK(libyuv::I420Rect(buffer->MutableDataY(), buffer->StrideY(), |
180 buffer->MutableDataU(), buffer->StrideU(), | 181 buffer->MutableDataU(), buffer->StrideU(), |
181 buffer->MutableDataV(), buffer->StrideV(), | 182 buffer->MutableDataV(), buffer->StrideV(), |
182 0, 0, buffer->width(), buffer->height(), | 183 0, 0, buffer->width(), buffer->height(), |
183 0, 128, 128) == 0); | 184 0, 128, 128) == 0); |
184 } | 185 } |
185 | 186 |
186 void I420Buffer::CropAndScaleFrom( | 187 void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src, |
187 const VideoFrameBuffer& src, | 188 int offset_x, |
188 int offset_x, | 189 int offset_y, |
189 int offset_y, | 190 int crop_width, |
190 int crop_width, | 191 int crop_height) { |
191 int crop_height) { | |
192 RTC_CHECK_LE(crop_width, src.width()); | 192 RTC_CHECK_LE(crop_width, src.width()); |
193 RTC_CHECK_LE(crop_height, src.height()); | 193 RTC_CHECK_LE(crop_height, src.height()); |
194 RTC_CHECK_LE(crop_width + offset_x, src.width()); | 194 RTC_CHECK_LE(crop_width + offset_x, src.width()); |
195 RTC_CHECK_LE(crop_height + offset_y, src.height()); | 195 RTC_CHECK_LE(crop_height + offset_y, src.height()); |
196 RTC_CHECK_GE(offset_x, 0); | 196 RTC_CHECK_GE(offset_x, 0); |
197 RTC_CHECK_GE(offset_y, 0); | 197 RTC_CHECK_GE(offset_y, 0); |
198 | 198 |
199 // Make sure offset is even so that u/v plane becomes aligned. | 199 // Make sure offset is even so that u/v plane becomes aligned. |
200 const int uv_offset_x = offset_x / 2; | 200 const int uv_offset_x = offset_x / 2; |
201 const int uv_offset_y = offset_y / 2; | 201 const int uv_offset_y = offset_y / 2; |
(...skipping 11 matching lines...) Expand all Loading... |
213 v_plane, src.StrideV(), | 213 v_plane, src.StrideV(), |
214 crop_width, crop_height, | 214 crop_width, crop_height, |
215 MutableDataY(), StrideY(), | 215 MutableDataY(), StrideY(), |
216 MutableDataU(), StrideU(), | 216 MutableDataU(), StrideU(), |
217 MutableDataV(), StrideV(), | 217 MutableDataV(), StrideV(), |
218 width(), height(), libyuv::kFilterBox); | 218 width(), height(), libyuv::kFilterBox); |
219 | 219 |
220 RTC_DCHECK_EQ(res, 0); | 220 RTC_DCHECK_EQ(res, 0); |
221 } | 221 } |
222 | 222 |
223 void I420Buffer::CropAndScaleFrom( | 223 void I420Buffer::CropAndScaleFrom(const I420BufferInterface& src) { |
224 const VideoFrameBuffer& src) { | |
225 const int crop_width = | 224 const int crop_width = |
226 std::min(src.width(), width() * src.height() / height()); | 225 std::min(src.width(), width() * src.height() / height()); |
227 const int crop_height = | 226 const int crop_height = |
228 std::min(src.height(), height() * src.width() / width()); | 227 std::min(src.height(), height() * src.width() / width()); |
229 | 228 |
230 CropAndScaleFrom( | 229 CropAndScaleFrom( |
231 src, | 230 src, |
232 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, | 231 (src.width() - crop_width) / 2, (src.height() - crop_height) / 2, |
233 crop_width, crop_height); | 232 crop_width, crop_height); |
234 } | 233 } |
235 | 234 |
236 void I420Buffer::ScaleFrom(const VideoFrameBuffer& src) { | 235 void I420Buffer::ScaleFrom(const I420BufferInterface& src) { |
237 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); | 236 CropAndScaleFrom(src, 0, 0, src.width(), src.height()); |
238 } | 237 } |
239 | 238 |
240 } // namespace webrtc | 239 } // namespace webrtc |
OLD | NEW |