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 | 10 |
| 11 #include <algorithm> | |
| 12 | |
| 11 #include "webrtc/common_video/include/video_frame_buffer.h" | 13 #include "webrtc/common_video/include/video_frame_buffer.h" |
| 12 | 14 |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/keep_ref_until_done.h" | 16 #include "webrtc/base/keep_ref_until_done.h" |
| 15 #include "libyuv/convert.h" | 17 #include "libyuv/convert.h" |
| 18 #include "libyuv/scale.h" | |
| 16 | 19 |
| 17 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. | 20 // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. |
| 18 static const int kBufferAlignment = 64; | 21 static const int kBufferAlignment = 64; |
| 19 | 22 |
| 20 namespace webrtc { | 23 namespace webrtc { |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { | 27 int I420DataSize(int height, int stride_y, int stride_u, int stride_v) { |
| 25 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); | 28 return stride_y * height + (stride_u + stride_v) * ((height + 1) / 2); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 buffer->DataU(), buffer->StrideU(), | 196 buffer->DataU(), buffer->StrideU(), |
| 194 buffer->DataV(), buffer->StrideV(), | 197 buffer->DataV(), buffer->StrideV(), |
| 195 copy->MutableDataY(), copy->StrideY(), | 198 copy->MutableDataY(), copy->StrideY(), |
| 196 copy->MutableDataU(), copy->StrideU(), | 199 copy->MutableDataU(), copy->StrideU(), |
| 197 copy->MutableDataV(), copy->StrideV(), | 200 copy->MutableDataV(), copy->StrideV(), |
| 198 width, height) == 0); | 201 width, height) == 0); |
| 199 | 202 |
| 200 return copy; | 203 return copy; |
| 201 } | 204 } |
| 202 | 205 |
| 206 void I420Buffer::CropAndScale( | |
| 207 const rtc::scoped_refptr<VideoFrameBuffer>& buffer, | |
| 208 int offset_x, | |
| 209 int offset_y, | |
| 210 int crop_width, | |
| 211 int crop_height) { | |
| 212 RTC_CHECK_LE(crop_width, buffer->width()); | |
| 213 RTC_CHECK_LE(crop_height, buffer->height()); | |
| 214 RTC_CHECK_LE(crop_width + offset_x, buffer->width()); | |
| 215 RTC_CHECK_LE(crop_height + offset_y, buffer->height()); | |
| 216 RTC_CHECK_GE(offset_x, 0); | |
| 217 RTC_CHECK_GE(offset_y, 0); | |
| 218 | |
| 219 // Make sure offset is even so that u/v plane becomes aligned. | |
| 220 const int uv_offset_x = offset_x / 2; | |
| 221 const int uv_offset_y = offset_y / 2; | |
| 222 offset_x = uv_offset_x * 2; | |
| 223 offset_y = uv_offset_y * 2; | |
| 224 | |
| 225 const uint8_t* y_plane = | |
| 226 buffer->DataY() + buffer->StrideY() * offset_y + offset_x; | |
| 227 const uint8_t* u_plane = | |
| 228 buffer->DataU() + buffer->StrideU() * uv_offset_y + uv_offset_x; | |
| 229 const uint8_t* v_plane = | |
| 230 buffer->DataV() + buffer->StrideV() * uv_offset_y + uv_offset_x; | |
| 231 int res = libyuv::I420Scale(y_plane, buffer->StrideY(), | |
| 232 u_plane, buffer->StrideU(), | |
| 233 v_plane, buffer->StrideV(), | |
| 234 crop_width, crop_height, | |
| 235 MutableDataY(), StrideY(), | |
| 236 MutableDataU(), StrideU(), | |
| 237 MutableDataV(), StrideV(), | |
| 238 width(), height(), libyuv::kFilterBox); | |
| 239 | |
| 240 RTC_DCHECK(res == 0); | |
|
magjed_webrtc
2016/05/30 11:58:26
Use RTC_DCHECK_EQ instead
nisse-webrtc
2016/05/30 12:58:22
Done.
| |
| 241 } | |
| 242 | |
| 243 void I420Buffer::CenterCropAndScale( | |
| 244 const rtc::scoped_refptr<I420Buffer>& dst, | |
| 245 const rtc::scoped_refptr<VideoFrameBuffer>& src) { | |
| 246 const int crop_width = | |
| 247 std::min(src->width(), dst->width() * src->height() / dst->height()); | |
| 248 const int crop_height = | |
| 249 std::min(src->height(), dst->height() * src->width() / dst->width()); | |
| 250 | |
| 251 dst->CropAndScale( | |
| 252 src, | |
| 253 (src->width() - crop_width) / 2, (src->height() - crop_height) / 2, | |
| 254 crop_width, crop_height); | |
| 255 } | |
| 256 | |
| 203 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, | 257 NativeHandleBuffer::NativeHandleBuffer(void* native_handle, |
| 204 int width, | 258 int width, |
| 205 int height) | 259 int height) |
| 206 : native_handle_(native_handle), width_(width), height_(height) { | 260 : native_handle_(native_handle), width_(width), height_(height) { |
| 207 RTC_DCHECK(native_handle != nullptr); | 261 RTC_DCHECK(native_handle != nullptr); |
| 208 RTC_DCHECK_GT(width, 0); | 262 RTC_DCHECK_GT(width, 0); |
| 209 RTC_DCHECK_GT(height, 0); | 263 RTC_DCHECK_GT(height, 0); |
| 210 } | 264 } |
| 211 | 265 |
| 212 int NativeHandleBuffer::width() const { | 266 int NativeHandleBuffer::width() const { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 buffer->StrideV() * uv_offset_y + uv_offset_x; | 387 buffer->StrideV() * uv_offset_y + uv_offset_x; |
| 334 return new rtc::RefCountedObject<WrappedI420Buffer>( | 388 return new rtc::RefCountedObject<WrappedI420Buffer>( |
| 335 cropped_width, cropped_height, | 389 cropped_width, cropped_height, |
| 336 y_plane, buffer->StrideY(), | 390 y_plane, buffer->StrideY(), |
| 337 u_plane, buffer->StrideU(), | 391 u_plane, buffer->StrideU(), |
| 338 v_plane, buffer->StrideV(), | 392 v_plane, buffer->StrideV(), |
| 339 rtc::KeepRefUntilDone(buffer)); | 393 rtc::KeepRefUntilDone(buffer)); |
| 340 } | 394 } |
| 341 | 395 |
| 342 } // namespace webrtc | 396 } // namespace webrtc |
| OLD | NEW |