2011-11-28 18:09:41 +00:00
|
|
|
/*
|
2012-03-13 17:22:44 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-11-28 18:09:41 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-04 09:02:37 +00:00
|
|
|
#include "webrtc/common_video/libyuv/include/scaler.h"
|
2011-11-28 18:09:41 +00:00
|
|
|
|
2013-06-04 23:53:48 +00:00
|
|
|
// NOTE(ajm): Path provided by gyp.
|
|
|
|
|
#include "libyuv.h" // NOLINT
|
2011-11-28 18:09:41 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
Scaler::Scaler()
|
|
|
|
|
: method_(kScaleBox),
|
|
|
|
|
src_width_(0),
|
|
|
|
|
src_height_(0),
|
|
|
|
|
dst_width_(0),
|
|
|
|
|
dst_height_(0),
|
|
|
|
|
set_(false) {}
|
|
|
|
|
|
|
|
|
|
Scaler::~Scaler() {}
|
|
|
|
|
|
|
|
|
|
int Scaler::Set(int src_width, int src_height,
|
|
|
|
|
int dst_width, int dst_height,
|
|
|
|
|
VideoType src_video_type, VideoType dst_video_type,
|
|
|
|
|
ScaleMethod method) {
|
|
|
|
|
set_ = false;
|
|
|
|
|
if (src_width < 1 || src_height < 1 || dst_width < 1 || dst_height < 1)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (!SupportedVideoType(src_video_type, dst_video_type))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
src_width_ = src_width;
|
|
|
|
|
src_height_ = src_height;
|
|
|
|
|
dst_width_ = dst_width;
|
|
|
|
|
dst_height_ = dst_height;
|
|
|
|
|
method_ = method;
|
|
|
|
|
set_ = true;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 18:33:04 +00:00
|
|
|
int Scaler::Scale(const I420VideoFrame& src_frame,
|
|
|
|
|
I420VideoFrame* dst_frame) {
|
2012-09-28 19:47:23 +00:00
|
|
|
assert(dst_frame);
|
2012-10-24 18:33:04 +00:00
|
|
|
if (src_frame.IsZeroSize())
|
2011-11-28 18:09:41 +00:00
|
|
|
return -1;
|
|
|
|
|
if (!set_)
|
|
|
|
|
return -2;
|
|
|
|
|
|
2012-09-28 19:47:23 +00:00
|
|
|
// Making sure that destination frame is of sufficient size.
|
2012-10-24 18:33:04 +00:00
|
|
|
// Aligning stride values based on width.
|
|
|
|
|
dst_frame->CreateEmptyFrame(dst_width_, dst_height_,
|
|
|
|
|
dst_width_, (dst_width_ + 1) / 2,
|
|
|
|
|
(dst_width_ + 1) / 2);
|
|
|
|
|
|
|
|
|
|
return libyuv::I420Scale(src_frame.buffer(kYPlane),
|
|
|
|
|
src_frame.stride(kYPlane),
|
|
|
|
|
src_frame.buffer(kUPlane),
|
|
|
|
|
src_frame.stride(kUPlane),
|
|
|
|
|
src_frame.buffer(kVPlane),
|
|
|
|
|
src_frame.stride(kVPlane),
|
2011-11-28 18:09:41 +00:00
|
|
|
src_width_, src_height_,
|
2012-10-24 18:33:04 +00:00
|
|
|
dst_frame->buffer(kYPlane),
|
|
|
|
|
dst_frame->stride(kYPlane),
|
|
|
|
|
dst_frame->buffer(kUPlane),
|
|
|
|
|
dst_frame->stride(kUPlane),
|
|
|
|
|
dst_frame->buffer(kVPlane),
|
|
|
|
|
dst_frame->stride(kVPlane),
|
2011-11-28 18:09:41 +00:00
|
|
|
dst_width_, dst_height_,
|
|
|
|
|
libyuv::FilterMode(method_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Scaler::SupportedVideoType(VideoType src_video_type,
|
|
|
|
|
VideoType dst_video_type) {
|
|
|
|
|
if (src_video_type != dst_video_type)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if ((src_video_type == kI420) || (src_video_type == kIYUV) ||
|
|
|
|
|
(src_video_type == kYV12))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|