Fix line-end convention in new i444 source files.

Bug: chromium:1251096
Change-Id: Id094ac65d775bb38d8a5b8657a3263c97f4052e2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/246441
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35698}
This commit is contained in:
Niels Möller
2022-01-14 14:34:31 +01:00
committed by WebRTC LUCI CQ
parent 899d8c8db2
commit 02d359e7af
3 changed files with 427 additions and 427 deletions

View File

@ -1,211 +1,211 @@
/* /*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found * tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "api/video/i444_buffer.h" #include "api/video/i444_buffer.h"
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/ref_counted_object.h" #include "rtc_base/ref_counted_object.h"
#include "third_party/libyuv/include/libyuv/convert.h" #include "third_party/libyuv/include/libyuv/convert.h"
#include "third_party/libyuv/include/libyuv/planar_functions.h" #include "third_party/libyuv/include/libyuv/planar_functions.h"
#include "third_party/libyuv/include/libyuv/scale.h" #include "third_party/libyuv/include/libyuv/scale.h"
// Aligning pointer to 64 bytes for improved performance, e.g. use SIMD. // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
static const int kBufferAlignment = 64; static const int kBufferAlignment = 64;
namespace webrtc { namespace webrtc {
namespace { namespace {
int I444DataSize(int height, int stride_y, int stride_u, int stride_v) { int I444DataSize(int height, int stride_y, int stride_u, int stride_v) {
return stride_y * height + stride_u * height + stride_v * height; return stride_y * height + stride_u * height + stride_v * height;
} }
} // namespace } // namespace
I444Buffer::I444Buffer(int width, int height) I444Buffer::I444Buffer(int width, int height)
: I444Buffer(width, height, width, (width), (width)) {} : I444Buffer(width, height, width, (width), (width)) {}
I444Buffer::I444Buffer(int width, I444Buffer::I444Buffer(int width,
int height, int height,
int stride_y, int stride_y,
int stride_u, int stride_u,
int stride_v) int stride_v)
: width_(width), : width_(width),
height_(height), height_(height),
stride_y_(stride_y), stride_y_(stride_y),
stride_u_(stride_u), stride_u_(stride_u),
stride_v_(stride_v), stride_v_(stride_v),
data_(static_cast<uint8_t*>( data_(static_cast<uint8_t*>(
AlignedMalloc(I444DataSize(height, stride_y, stride_u, stride_v), AlignedMalloc(I444DataSize(height, stride_y, stride_u, stride_v),
kBufferAlignment))) { kBufferAlignment))) {
RTC_DCHECK_GT(width, 0); RTC_DCHECK_GT(width, 0);
RTC_DCHECK_GT(height, 0); RTC_DCHECK_GT(height, 0);
RTC_DCHECK_GE(stride_y, width); RTC_DCHECK_GE(stride_y, width);
RTC_DCHECK_GE(stride_u, (width)); RTC_DCHECK_GE(stride_u, (width));
RTC_DCHECK_GE(stride_v, (width)); RTC_DCHECK_GE(stride_v, (width));
} }
I444Buffer::~I444Buffer() {} I444Buffer::~I444Buffer() {}
// static // static
rtc::scoped_refptr<I444Buffer> I444Buffer::Create(int width, int height) { rtc::scoped_refptr<I444Buffer> I444Buffer::Create(int width, int height) {
return new rtc::RefCountedObject<I444Buffer>(width, height); return new rtc::RefCountedObject<I444Buffer>(width, height);
} }
// static // static
rtc::scoped_refptr<I444Buffer> I444Buffer::Create(int width, rtc::scoped_refptr<I444Buffer> I444Buffer::Create(int width,
int height, int height,
int stride_y, int stride_y,
int stride_u, int stride_u,
int stride_v) { int stride_v) {
return new rtc::RefCountedObject<I444Buffer>(width, height, stride_y, return new rtc::RefCountedObject<I444Buffer>(width, height, stride_y,
stride_u, stride_v); stride_u, stride_v);
} }
// static // static
rtc::scoped_refptr<I444Buffer> I444Buffer::Copy( rtc::scoped_refptr<I444Buffer> I444Buffer::Copy(
const I444BufferInterface& source) { const I444BufferInterface& source) {
return Copy(source.width(), source.height(), source.DataY(), source.StrideY(), return Copy(source.width(), source.height(), source.DataY(), source.StrideY(),
source.DataU(), source.StrideU(), source.DataV(), source.DataU(), source.StrideU(), source.DataV(),
source.StrideV()); source.StrideV());
} }
// static // static
rtc::scoped_refptr<I444Buffer> I444Buffer::Copy(int width, rtc::scoped_refptr<I444Buffer> I444Buffer::Copy(int width,
int height, int height,
const uint8_t* data_y, const uint8_t* data_y,
int stride_y, int stride_y,
const uint8_t* data_u, const uint8_t* data_u,
int stride_u, int stride_u,
const uint8_t* data_v, const uint8_t* data_v,
int stride_v) { int stride_v) {
// Note: May use different strides than the input data. // Note: May use different strides than the input data.
rtc::scoped_refptr<I444Buffer> buffer = Create(width, height); rtc::scoped_refptr<I444Buffer> buffer = Create(width, height);
RTC_CHECK_EQ(0, libyuv::I444Copy(data_y, stride_y, data_u, stride_u, data_v, RTC_CHECK_EQ(0, libyuv::I444Copy(data_y, stride_y, data_u, stride_u, data_v,
stride_v, buffer->MutableDataY(), stride_v, buffer->MutableDataY(),
buffer->StrideY(), buffer->MutableDataU(), buffer->StrideY(), buffer->MutableDataU(),
buffer->StrideU(), buffer->MutableDataV(), buffer->StrideU(), buffer->MutableDataV(),
buffer->StrideV(), width, height)); buffer->StrideV(), width, height));
return buffer; return buffer;
} }
// static // static
rtc::scoped_refptr<I444Buffer> I444Buffer::Rotate( rtc::scoped_refptr<I444Buffer> I444Buffer::Rotate(
const I444BufferInterface& src, const I444BufferInterface& src,
VideoRotation rotation) { VideoRotation rotation) {
RTC_CHECK(src.DataY()); RTC_CHECK(src.DataY());
RTC_CHECK(src.DataU()); RTC_CHECK(src.DataU());
RTC_CHECK(src.DataV()); RTC_CHECK(src.DataV());
int rotated_width = src.width(); int rotated_width = src.width();
int rotated_height = src.height(); int rotated_height = src.height();
if (rotation == webrtc::kVideoRotation_90 || if (rotation == webrtc::kVideoRotation_90 ||
rotation == webrtc::kVideoRotation_270) { rotation == webrtc::kVideoRotation_270) {
std::swap(rotated_width, rotated_height); std::swap(rotated_width, rotated_height);
} }
rtc::scoped_refptr<webrtc::I444Buffer> buffer = rtc::scoped_refptr<webrtc::I444Buffer> buffer =
I444Buffer::Create(rotated_width, rotated_height); I444Buffer::Create(rotated_width, rotated_height);
RTC_CHECK_EQ(0, RTC_CHECK_EQ(0,
libyuv::I444Rotate( libyuv::I444Rotate(
src.DataY(), src.StrideY(), src.DataU(), src.StrideU(), src.DataY(), src.StrideY(), src.DataU(), src.StrideU(),
src.DataV(), src.StrideV(), buffer->MutableDataY(), src.DataV(), src.StrideV(), buffer->MutableDataY(),
buffer->StrideY(), buffer->MutableDataU(), buffer->StrideU(), buffer->StrideY(), buffer->MutableDataU(), buffer->StrideU(),
buffer->MutableDataV(), buffer->StrideV(), src.width(), buffer->MutableDataV(), buffer->StrideV(), src.width(),
src.height(), static_cast<libyuv::RotationMode>(rotation))); src.height(), static_cast<libyuv::RotationMode>(rotation)));
return buffer; return buffer;
} }
rtc::scoped_refptr<I420BufferInterface> I444Buffer::ToI420() { rtc::scoped_refptr<I420BufferInterface> I444Buffer::ToI420() {
rtc::scoped_refptr<I420Buffer> i420_buffer = rtc::scoped_refptr<I420Buffer> i420_buffer =
I420Buffer::Create(width(), height()); I420Buffer::Create(width(), height());
libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(), libyuv::I444ToI420(DataY(), StrideY(), DataU(), StrideU(), DataV(), StrideV(),
i420_buffer->MutableDataY(), i420_buffer->StrideY(), i420_buffer->MutableDataY(), i420_buffer->StrideY(),
i420_buffer->MutableDataU(), i420_buffer->StrideU(), i420_buffer->MutableDataU(), i420_buffer->StrideU(),
i420_buffer->MutableDataV(), i420_buffer->StrideV(), i420_buffer->MutableDataV(), i420_buffer->StrideV(),
width(), height()); width(), height());
return i420_buffer; return i420_buffer;
} }
void I444Buffer::InitializeData() { void I444Buffer::InitializeData() {
memset(data_.get(), 0, memset(data_.get(), 0,
I444DataSize(height_, stride_y_, stride_u_, stride_v_)); I444DataSize(height_, stride_y_, stride_u_, stride_v_));
} }
int I444Buffer::width() const { int I444Buffer::width() const {
return width_; return width_;
} }
int I444Buffer::height() const { int I444Buffer::height() const {
return height_; return height_;
} }
const uint8_t* I444Buffer::DataY() const { const uint8_t* I444Buffer::DataY() const {
return data_.get(); return data_.get();
} }
const uint8_t* I444Buffer::DataU() const { const uint8_t* I444Buffer::DataU() const {
return data_.get() + stride_y_ * height_; return data_.get() + stride_y_ * height_;
} }
const uint8_t* I444Buffer::DataV() const { const uint8_t* I444Buffer::DataV() const {
return data_.get() + stride_y_ * height_ + stride_u_ * ((height_)); return data_.get() + stride_y_ * height_ + stride_u_ * ((height_));
} }
int I444Buffer::StrideY() const { int I444Buffer::StrideY() const {
return stride_y_; return stride_y_;
} }
int I444Buffer::StrideU() const { int I444Buffer::StrideU() const {
return stride_u_; return stride_u_;
} }
int I444Buffer::StrideV() const { int I444Buffer::StrideV() const {
return stride_v_; return stride_v_;
} }
uint8_t* I444Buffer::MutableDataY() { uint8_t* I444Buffer::MutableDataY() {
return const_cast<uint8_t*>(DataY()); return const_cast<uint8_t*>(DataY());
} }
uint8_t* I444Buffer::MutableDataU() { uint8_t* I444Buffer::MutableDataU() {
return const_cast<uint8_t*>(DataU()); return const_cast<uint8_t*>(DataU());
} }
uint8_t* I444Buffer::MutableDataV() { uint8_t* I444Buffer::MutableDataV() {
return const_cast<uint8_t*>(DataV()); return const_cast<uint8_t*>(DataV());
} }
void I444Buffer::CropAndScaleFrom(const I444BufferInterface& src, void I444Buffer::CropAndScaleFrom(const I444BufferInterface& src,
int offset_x, int offset_x,
int offset_y, int offset_y,
int crop_width, int crop_width,
int crop_height) { int crop_height) {
RTC_CHECK_LE(crop_width, src.width()); RTC_CHECK_LE(crop_width, src.width());
RTC_CHECK_LE(crop_height, src.height()); RTC_CHECK_LE(crop_height, src.height());
RTC_CHECK_LE(crop_width + offset_x, src.width()); RTC_CHECK_LE(crop_width + offset_x, src.width());
RTC_CHECK_LE(crop_height + offset_y, src.height()); RTC_CHECK_LE(crop_height + offset_y, src.height());
RTC_CHECK_GE(offset_x, 0); RTC_CHECK_GE(offset_x, 0);
RTC_CHECK_GE(offset_y, 0); RTC_CHECK_GE(offset_y, 0);
const uint8_t* y_plane = src.DataY() + src.StrideY() * offset_y + offset_x; const uint8_t* y_plane = src.DataY() + src.StrideY() * offset_y + offset_x;
const uint8_t* u_plane = src.DataU() + src.StrideU() * offset_y + offset_x; const uint8_t* u_plane = src.DataU() + src.StrideU() * offset_y + offset_x;
const uint8_t* v_plane = src.DataV() + src.StrideV() * offset_y + offset_x; const uint8_t* v_plane = src.DataV() + src.StrideV() * offset_y + offset_x;
int res = int res =
libyuv::I444Scale(y_plane, src.StrideY(), u_plane, src.StrideU(), v_plane, libyuv::I444Scale(y_plane, src.StrideY(), u_plane, src.StrideU(), v_plane,
src.StrideV(), crop_width, crop_height, MutableDataY(), src.StrideV(), crop_width, crop_height, MutableDataY(),
StrideY(), MutableDataU(), StrideU(), MutableDataV(), StrideY(), MutableDataU(), StrideU(), MutableDataV(),
StrideV(), width(), height(), libyuv::kFilterBox); StrideV(), width(), height(), libyuv::kFilterBox);
RTC_DCHECK_EQ(res, 0); RTC_DCHECK_EQ(res, 0);
} }
} // namespace webrtc } // namespace webrtc

View File

@ -1,104 +1,104 @@
/* /*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found * tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef API_VIDEO_I444_BUFFER_H_ #ifndef API_VIDEO_I444_BUFFER_H_
#define API_VIDEO_I444_BUFFER_H_ #define API_VIDEO_I444_BUFFER_H_
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
#include "api/video/video_frame_buffer.h" #include "api/video/video_frame_buffer.h"
#include "api/video/video_rotation.h" #include "api/video/video_rotation.h"
#include "rtc_base/memory/aligned_malloc.h" #include "rtc_base/memory/aligned_malloc.h"
#include "rtc_base/system/rtc_export.h" #include "rtc_base/system/rtc_export.h"
namespace webrtc { namespace webrtc {
// Plain I444 buffer in standard memory. // Plain I444 buffer in standard memory.
// I444 represents an image with in YUV format withouth any chroma subsampling. // I444 represents an image with in YUV format withouth any chroma subsampling.
// https://en.wikipedia.org/wiki/Chroma_subsampling#4:4:4 // https://en.wikipedia.org/wiki/Chroma_subsampling#4:4:4
class RTC_EXPORT I444Buffer : public I444BufferInterface { class RTC_EXPORT I444Buffer : public I444BufferInterface {
public: public:
static rtc::scoped_refptr<I444Buffer> Create(int width, int height); static rtc::scoped_refptr<I444Buffer> Create(int width, int height);
static rtc::scoped_refptr<I444Buffer> Create(int width, static rtc::scoped_refptr<I444Buffer> Create(int width,
int height, int height,
int stride_y, int stride_y,
int stride_u, int stride_u,
int stride_v); int stride_v);
// Create a new buffer and copy the pixel data. // Create a new buffer and copy the pixel data.
static rtc::scoped_refptr<I444Buffer> Copy(const I444BufferInterface& buffer); static rtc::scoped_refptr<I444Buffer> Copy(const I444BufferInterface& buffer);
static rtc::scoped_refptr<I444Buffer> Copy(int width, static rtc::scoped_refptr<I444Buffer> Copy(int width,
int height, int height,
const uint8_t* data_y, const uint8_t* data_y,
int stride_y, int stride_y,
const uint8_t* data_u, const uint8_t* data_u,
int stride_u, int stride_u,
const uint8_t* data_v, const uint8_t* data_v,
int stride_v); int stride_v);
// Returns a rotated copy of |src|. // Returns a rotated copy of |src|.
static rtc::scoped_refptr<I444Buffer> Rotate(const I444BufferInterface& src, static rtc::scoped_refptr<I444Buffer> Rotate(const I444BufferInterface& src,
VideoRotation rotation); VideoRotation rotation);
rtc::scoped_refptr<I420BufferInterface> ToI420() final; rtc::scoped_refptr<I420BufferInterface> ToI420() final;
const I420BufferInterface* GetI420() const final { return nullptr; } const I420BufferInterface* GetI420() const final { return nullptr; }
// Sets all three planes to all zeros. Used to work around for // Sets all three planes to all zeros. Used to work around for
// quirks in memory checkers // quirks in memory checkers
// (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and
// ffmpeg (http://crbug.com/390941). // ffmpeg (http://crbug.com/390941).
// TODO(nisse): Deprecated. Should be deleted if/when those issues // TODO(nisse): Deprecated. Should be deleted if/when those issues
// are resolved in a better way. Or in the mean time, use SetBlack. // are resolved in a better way. Or in the mean time, use SetBlack.
void InitializeData(); void InitializeData();
int width() const override; int width() const override;
int height() const override; int height() const override;
const uint8_t* DataY() const override; const uint8_t* DataY() const override;
const uint8_t* DataU() const override; const uint8_t* DataU() const override;
const uint8_t* DataV() const override; const uint8_t* DataV() const override;
int StrideY() const override; int StrideY() const override;
int StrideU() const override; int StrideU() const override;
int StrideV() const override; int StrideV() const override;
uint8_t* MutableDataY(); uint8_t* MutableDataY();
uint8_t* MutableDataU(); uint8_t* MutableDataU();
uint8_t* MutableDataV(); uint8_t* MutableDataV();
// Scale the cropped area of |src| to the size of |this| buffer, and // Scale the cropped area of |src| to the size of |this| buffer, and
// write the result into |this|. // write the result into |this|.
void CropAndScaleFrom(const I444BufferInterface& src, void CropAndScaleFrom(const I444BufferInterface& src,
int offset_x, int offset_x,
int offset_y, int offset_y,
int crop_width, int crop_width,
int crop_height); int crop_height);
protected: protected:
I444Buffer(int width, int height); I444Buffer(int width, int height);
I444Buffer(int width, int height, int stride_y, int stride_u, int stride_v); I444Buffer(int width, int height, int stride_y, int stride_u, int stride_v);
~I444Buffer() override; ~I444Buffer() override;
private: private:
const int width_; const int width_;
const int height_; const int height_;
const int stride_y_; const int stride_y_;
const int stride_u_; const int stride_u_;
const int stride_v_; const int stride_v_;
const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_;
}; };
} // namespace webrtc } // namespace webrtc
#endif // API_VIDEO_I444_BUFFER_H_ #endif // API_VIDEO_I444_BUFFER_H_

View File

@ -1,112 +1,112 @@
/* /*
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * 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 * that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found * tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may * in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include "api/video/i444_buffer.h" #include "api/video/i444_buffer.h"
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
#include "test/frame_utils.h" #include "test/frame_utils.h"
#include "test/gmock.h" #include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
namespace webrtc { namespace webrtc {
namespace { namespace {
int GetY(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) { int GetY(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataY()[row * buf->StrideY() + col]; return buf->DataY()[row * buf->StrideY() + col];
} }
int GetU(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) { int GetU(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataU()[row * buf->StrideU() + col]; return buf->DataU()[row * buf->StrideU() + col];
} }
int GetV(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) { int GetV(rtc::scoped_refptr<I444BufferInterface> buf, int col, int row) {
return buf->DataV()[row * buf->StrideV() + col]; return buf->DataV()[row * buf->StrideV() + col];
} }
void FillI444Buffer(rtc::scoped_refptr<I444Buffer> buf) { void FillI444Buffer(rtc::scoped_refptr<I444Buffer> buf) {
const uint8_t Y = 1; const uint8_t Y = 1;
const uint8_t U = 2; const uint8_t U = 2;
const uint8_t V = 3; const uint8_t V = 3;
for (int row = 0; row < buf->height(); ++row) { for (int row = 0; row < buf->height(); ++row) {
for (int col = 0; col < buf->width(); ++col) { for (int col = 0; col < buf->width(); ++col) {
buf->MutableDataY()[row * buf->StrideY() + col] = Y; buf->MutableDataY()[row * buf->StrideY() + col] = Y;
buf->MutableDataU()[row * buf->StrideU() + col] = U; buf->MutableDataU()[row * buf->StrideU() + col] = U;
buf->MutableDataV()[row * buf->StrideV() + col] = V; buf->MutableDataV()[row * buf->StrideV() + col] = V;
} }
} }
} }
} // namespace } // namespace
TEST(I444BufferTest, InitialData) { TEST(I444BufferTest, InitialData) {
constexpr int stride = 3; constexpr int stride = 3;
constexpr int width = 3; constexpr int width = 3;
constexpr int height = 3; constexpr int height = 3;
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height)); rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
EXPECT_EQ(width, i444_buffer->width()); EXPECT_EQ(width, i444_buffer->width());
EXPECT_EQ(height, i444_buffer->height()); EXPECT_EQ(height, i444_buffer->height());
EXPECT_EQ(stride, i444_buffer->StrideY()); EXPECT_EQ(stride, i444_buffer->StrideY());
EXPECT_EQ(stride, i444_buffer->StrideU()); EXPECT_EQ(stride, i444_buffer->StrideU());
EXPECT_EQ(stride, i444_buffer->StrideV()); EXPECT_EQ(stride, i444_buffer->StrideV());
EXPECT_EQ(3, i444_buffer->ChromaWidth()); EXPECT_EQ(3, i444_buffer->ChromaWidth());
EXPECT_EQ(3, i444_buffer->ChromaHeight()); EXPECT_EQ(3, i444_buffer->ChromaHeight());
} }
TEST(I444BufferTest, ReadPixels) { TEST(I444BufferTest, ReadPixels) {
constexpr int width = 3; constexpr int width = 3;
constexpr int height = 3; constexpr int height = 3;
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height)); rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
// Y = 1, U = 2, V = 3. // Y = 1, U = 2, V = 3.
FillI444Buffer(i444_buffer); FillI444Buffer(i444_buffer);
for (int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) { for (int col = 0; col < width; col++) {
EXPECT_EQ(1, GetY(i444_buffer, col, row)); EXPECT_EQ(1, GetY(i444_buffer, col, row));
EXPECT_EQ(2, GetU(i444_buffer, col, row)); EXPECT_EQ(2, GetU(i444_buffer, col, row));
EXPECT_EQ(3, GetV(i444_buffer, col, row)); EXPECT_EQ(3, GetV(i444_buffer, col, row));
} }
} }
} }
TEST(I444BufferTest, ToI420) { TEST(I444BufferTest, ToI420) {
constexpr int width = 3; constexpr int width = 3;
constexpr int height = 3; constexpr int height = 3;
constexpr int size_y = width * height; constexpr int size_y = width * height;
constexpr int size_u = (width + 1) / 2 * (height + 1) / 2; constexpr int size_u = (width + 1) / 2 * (height + 1) / 2;
constexpr int size_v = (width + 1) / 2 * (height + 1) / 2; constexpr int size_v = (width + 1) / 2 * (height + 1) / 2;
rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height)); rtc::scoped_refptr<I420Buffer> reference(I420Buffer::Create(width, height));
memset(reference->MutableDataY(), 8, size_y); memset(reference->MutableDataY(), 8, size_y);
memset(reference->MutableDataU(), 4, size_u); memset(reference->MutableDataU(), 4, size_u);
memset(reference->MutableDataV(), 2, size_v); memset(reference->MutableDataV(), 2, size_v);
rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height)); rtc::scoped_refptr<I444Buffer> i444_buffer(I444Buffer::Create(width, height));
// Convert the reference buffer to I444. // Convert the reference buffer to I444.
memset(i444_buffer->MutableDataY(), 8, size_y); memset(i444_buffer->MutableDataY(), 8, size_y);
memset(i444_buffer->MutableDataU(), 4, size_y); memset(i444_buffer->MutableDataU(), 4, size_y);
memset(i444_buffer->MutableDataV(), 2, size_y); memset(i444_buffer->MutableDataV(), 2, size_y);
// Confirm YUV values are as expected. // Confirm YUV values are as expected.
for (int row = 0; row < height; row++) { for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) { for (int col = 0; col < width; col++) {
EXPECT_EQ(8, GetY(i444_buffer, col, row)); EXPECT_EQ(8, GetY(i444_buffer, col, row));
EXPECT_EQ(4, GetU(i444_buffer, col, row)); EXPECT_EQ(4, GetU(i444_buffer, col, row));
EXPECT_EQ(2, GetV(i444_buffer, col, row)); EXPECT_EQ(2, GetV(i444_buffer, col, row));
} }
} }
rtc::scoped_refptr<I420BufferInterface> i420_buffer(i444_buffer->ToI420()); rtc::scoped_refptr<I420BufferInterface> i420_buffer(i444_buffer->ToI420());
EXPECT_EQ(height, i420_buffer->height()); EXPECT_EQ(height, i420_buffer->height());
EXPECT_EQ(width, i420_buffer->width()); EXPECT_EQ(width, i420_buffer->width());
EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer)); EXPECT_TRUE(test::FrameBufsEqual(reference, i420_buffer));
} }
} // namespace webrtc } // namespace webrtc