Use uint8 pointer instead of std::vector in NV12Scale.
To prepare for landing 536773. Bug: webrtc:7785 Change-Id: I841218dca3fb9d83f362f7f2b9076f3f189e7c15 Reviewed-on: https://chromium-review.googlesource.com/539577 Commit-Queue: Anders Carlsson <andersc@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#18662}
This commit is contained in:
parent
652abc9a47
commit
bfe45c29c5
@ -117,7 +117,11 @@ double I420SSIM(const I420BufferInterface& ref_buffer,
|
||||
const I420BufferInterface& test_buffer);
|
||||
|
||||
// Helper function for scaling NV12 to NV12.
|
||||
void NV12Scale(std::vector<uint8_t>* tmp_buffer,
|
||||
// If the |src_width| and |src_height| matches the |dst_width| and |dst_height|,
|
||||
// then |tmp_buffer| is not used. In other cases, the minimum size of
|
||||
// |tmp_buffer| should be:
|
||||
// (src_width/2) * (src_height/2) * 2 + (dst_width/2) * (dst_height/2) * 2
|
||||
void NV12Scale(uint8_t* tmp_buffer,
|
||||
const uint8_t* src_y, int src_stride_y,
|
||||
const uint8_t* src_uv, int src_stride_uv,
|
||||
int src_width, int src_height,
|
||||
|
||||
@ -277,8 +277,9 @@ TEST_F(TestLibYuv, NV12Scale2x2to2x2) {
|
||||
std::vector<uint8_t> dst_y(4);
|
||||
std::vector<uint8_t> dst_uv(2);
|
||||
|
||||
std::vector<uint8_t> tmp_buffer;
|
||||
NV12Scale(&tmp_buffer,
|
||||
uint8_t* tmp_buffer = nullptr;
|
||||
|
||||
NV12Scale(tmp_buffer,
|
||||
src_y.data(), 2,
|
||||
src_uv.data(), 2,
|
||||
2, 2,
|
||||
@ -301,7 +302,15 @@ TEST_F(TestLibYuv, NV12Scale4x4to2x2) {
|
||||
std::vector<uint8_t> dst_uv(2);
|
||||
|
||||
std::vector<uint8_t> tmp_buffer;
|
||||
NV12Scale(&tmp_buffer,
|
||||
const int src_chroma_width = (4 + 1) / 2;
|
||||
const int src_chroma_height = (4 + 1) / 2;
|
||||
const int dst_chroma_width = (2 + 1) / 2;
|
||||
const int dst_chroma_height = (2 + 1) / 2;
|
||||
tmp_buffer.resize(src_chroma_width * src_chroma_height * 2 +
|
||||
dst_chroma_width * dst_chroma_height * 2);
|
||||
tmp_buffer.shrink_to_fit();
|
||||
|
||||
NV12Scale(tmp_buffer.data(),
|
||||
src_y, 4,
|
||||
src_uv, 4,
|
||||
4, 4,
|
||||
|
||||
@ -307,7 +307,7 @@ double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) {
|
||||
*test_frame->video_frame_buffer()->ToI420());
|
||||
}
|
||||
|
||||
void NV12Scale(std::vector<uint8_t>* tmp_buffer,
|
||||
void NV12Scale(uint8_t* tmp_buffer,
|
||||
const uint8_t* src_y, int src_stride_y,
|
||||
const uint8_t* src_uv, int src_stride_uv,
|
||||
int src_width, int src_height,
|
||||
@ -319,8 +319,6 @@ void NV12Scale(std::vector<uint8_t>* tmp_buffer,
|
||||
|
||||
if (src_width == dst_width && src_height == dst_height) {
|
||||
// No scaling.
|
||||
tmp_buffer->clear();
|
||||
tmp_buffer->shrink_to_fit();
|
||||
libyuv::CopyPlane(src_y, src_stride_y, dst_y, dst_stride_y, src_width,
|
||||
src_height);
|
||||
libyuv::CopyPlane(src_uv, src_stride_uv, dst_uv, dst_stride_uv,
|
||||
@ -332,11 +330,8 @@ void NV12Scale(std::vector<uint8_t>* tmp_buffer,
|
||||
// Allocate temporary memory for spitting UV planes and scaling them.
|
||||
const int dst_chroma_width = (dst_width + 1) / 2;
|
||||
const int dst_chroma_height = (dst_height + 1) / 2;
|
||||
tmp_buffer->resize(src_chroma_width * src_chroma_height * 2 +
|
||||
dst_chroma_width * dst_chroma_height * 2);
|
||||
tmp_buffer->shrink_to_fit();
|
||||
|
||||
uint8_t* const src_u = tmp_buffer->data();
|
||||
uint8_t* const src_u = tmp_buffer;
|
||||
uint8_t* const src_v = src_u + src_chroma_width * src_chroma_height;
|
||||
uint8_t* const dst_u = src_v + src_chroma_width * src_chroma_height;
|
||||
uint8_t* const dst_v = dst_u + dst_chroma_width * dst_chroma_height;
|
||||
|
||||
@ -148,7 +148,20 @@ bool CoreVideoFrameBuffer::CropAndScaleTo(
|
||||
src_y += src_y_stride * crop_y_ + crop_x_;
|
||||
src_uv += src_uv_stride * (crop_y_ / 2) + crop_x_;
|
||||
|
||||
NV12Scale(tmp_buffer,
|
||||
if (crop_width_ == dst_width && crop_height_ == dst_height) {
|
||||
tmp_buffer->clear();
|
||||
tmp_buffer->shrink_to_fit();
|
||||
} else {
|
||||
const int src_chroma_width = (crop_width_ + 1) / 2;
|
||||
const int src_chroma_height = (crop_height_ + 1) / 2;
|
||||
const int dst_chroma_width = (dst_width + 1) / 2;
|
||||
const int dst_chroma_height = (dst_height + 1) / 2;
|
||||
tmp_buffer->resize(src_chroma_width * src_chroma_height * 2 +
|
||||
dst_chroma_width * dst_chroma_height * 2);
|
||||
tmp_buffer->shrink_to_fit();
|
||||
}
|
||||
|
||||
NV12Scale(tmp_buffer->data(),
|
||||
src_y, src_y_stride,
|
||||
src_uv, src_uv_stride,
|
||||
crop_width_, crop_height_,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user