Prevent upscaling when calculating sample values.
Bug: webrtc:358039777 Change-Id: I33edc12f312d0d37eac0c39a913313a1aa6f1de5 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/366942 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Emil Vardar (xWF) <vardar@google.com> Reviewed-by: Sergey Silkin <ssilkin@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43394}
This commit is contained in:
parent
ebb11c4c87
commit
4c171e84c3
@ -173,6 +173,13 @@ std::vector<FilteredSample> GetSampleValuesForFrame(
|
||||
<< std_dev_gaussian_blur << ".\n";
|
||||
return {};
|
||||
}
|
||||
if (scaled_width > i420_frame_buffer->width() ||
|
||||
scaled_height > i420_frame_buffer->height()) {
|
||||
RTC_LOG(LS_WARNING)
|
||||
<< "Upscaling causes corruption. Therefore, only down-scaling is "
|
||||
"permissible.";
|
||||
return {};
|
||||
}
|
||||
|
||||
// Scale the frame to the desired resolution:
|
||||
// 1. Create a new buffer with the desired resolution.
|
||||
|
||||
@ -157,6 +157,7 @@ TEST(HaltonFrameSamplerTest, FrameIsNotSampledWhenTimestampsAreEqual) {
|
||||
/*is_key_frame=*/false, /*rtp_timestamp=*/0, /*num_samples=*/1),
|
||||
_);
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
@ -236,6 +237,18 @@ TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
IsEmpty());
|
||||
}
|
||||
|
||||
TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
ShouldReturnEmptyListWhenUpscaling) {
|
||||
const scoped_refptr<I420Buffer> kDefaultI420Buffer =
|
||||
MakeDefaultI420FrameBuffer();
|
||||
|
||||
EXPECT_THAT(GetSampleValuesForFrame(kDefaultI420Buffer,
|
||||
MakeDefaultSampleCoordinates(),
|
||||
/*scaled_width=*/8, /*scaled_height=*/8,
|
||||
kDefaultStdDevGaussianBlur),
|
||||
IsEmpty());
|
||||
}
|
||||
|
||||
TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
ShouldReturnGivenValueWhenStdDevZero) {
|
||||
// 4x4 i420 frame data.
|
||||
@ -337,8 +350,8 @@ TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
{.row = 0.8, .column = 0.4}};
|
||||
|
||||
// With scaling.
|
||||
const int kScaledWidth = 10;
|
||||
const int kScaledHeight = 10;
|
||||
const int kScaledWidth = 2;
|
||||
const int kScaledHeight = 2;
|
||||
|
||||
// No filtering.
|
||||
const double kStdDevGaussianBlur = 0.02;
|
||||
@ -346,13 +359,13 @@ TEST(HaltonFrameSamplerGaussianFilteringTest,
|
||||
EXPECT_THAT(
|
||||
GetSampleValuesForFrame(kI420Buffer, kSampleCoordinates, kScaledWidth,
|
||||
kScaledHeight, kStdDevGaussianBlur),
|
||||
ElementsAre(AllOf(Field(&FilteredSample::value, DoubleEq(96.0)),
|
||||
ElementsAre(AllOf(Field(&FilteredSample::value, DoubleEq(131.0)),
|
||||
Field(&FilteredSample::plane, ImagePlane::kChroma)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleEq(30.0)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleEq(35.0)),
|
||||
Field(&FilteredSample::plane, ImagePlane::kChroma)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleEq(66.0)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleEq(131.0)),
|
||||
Field(&FilteredSample::plane, ImagePlane::kChroma)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleNear(127.0, 1.0)),
|
||||
AllOf(Field(&FilteredSample::value, DoubleEq(98.0)),
|
||||
Field(&FilteredSample::plane, ImagePlane::kLuma))));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user