/* * Copyright 2023 The LibYuv Project Authors. All rights reserved. * * 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.
*/
#if !defined(DISABLE_SLOW_TESTS) || defined(__x86_64__) || defined(__i386__) // SLOW TESTS are those that are unoptimized C code. // FULL TESTS are optimized but test many variations of the same code. #define ENABLE_FULL_TESTS #endif
// Test one pixel less, should skip the last pixel.
memset(dst_pixels_c, 0, sizeof(dst_pixels_c));
ScaleRowDown2Box_Odd_C(orig_pixels, 128, dst_pixels_c, 63);
// Test scaling plane with 8 bit C vs 12 bit C and return maximum pixel // difference. // 0 = exact. staticint TestPlaneFilter_16(int src_width, int src_height, int dst_width, int dst_height,
FilterMode f, int benchmark_iterations, int disable_cpu_flags, int benchmark_cpu_info) { if (!SizeValid(src_width, src_height, dst_width, dst_height)) { return 0;
}
int i;
int64_t src_y_plane_size = (Abs(src_width)) * (Abs(src_height)); int src_stride_y = Abs(src_width); int dst_y_plane_size = dst_width * dst_height; int dst_stride_y = dst_width;
for (i = 0; i < src_y_plane_size; ++i) {
p_src_y_16[i] = src_y[i] & 255;
}
MaskCpuFlags(disable_cpu_flags); // Disable all CPU optimization.
ScalePlane(src_y, src_stride_y, src_width, src_height, dst_y_8, dst_stride_y,
dst_width, dst_height, f);
MaskCpuFlags(benchmark_cpu_info); // Enable all CPU optimization.
for (i = 0; i < benchmark_iterations; ++i) {
ScalePlane_16(p_src_y_16, src_stride_y, src_width, src_height, p_dst_y_16,
dst_stride_y, dst_width, dst_height, f);
}
// Expect an exact match. int max_diff = 0; for (i = 0; i < dst_y_plane_size; ++i) { int abs_diff = Abs(dst_y_8[i] - p_dst_y_16[i]); if (abs_diff > max_diff) {
max_diff = abs_diff;
}
}
// The following adjustments in dimensions ensure the scale factor will be // exactly achieved. // 2 is chroma subsample. #define DX(x, nom, denom) static_cast<int>(((Abs(x) / nom + 1) / 2) * nom * 2) #define SX(x, nom, denom) static_cast<int>(((x / nom + 1) / 2) * denom * 2)
// Test a scale factor with all 4 filters. Expect unfiltered to be exact, but // filtering is different fixed point implementations for SSSE3, Neon and C. #define TEST_FACTOR(name, nom, denom, boxdiff) \
TEST_FACTOR1(name, None, nom, denom, 0) \
TEST_FACTOR1(name, Linear, nom, denom, boxdiff) \
TEST_FACTOR1(name, Bilinear, nom, denom, boxdiff) \
TEST_FACTOR1(name, Box, nom, denom, boxdiff)
// Intent is to test 200x50 to 50x200 but width and height can be parameters.
TEST_F(LibYUVScaleTest, PlaneTestRotate_None) { constint kSize = benchmark_width_ * benchmark_height_;
align_buffer_page_end(orig_pixels, kSize); for (int i = 0; i < kSize; ++i) {
orig_pixels[i] = i;
}
align_buffer_page_end(dest_opt_pixels, kSize);
align_buffer_page_end(dest_c_pixels, kSize);
MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
dest_c_pixels, benchmark_height_, benchmark_height_,
benchmark_width_, kFilterNone);
MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
for (int i = 0; i < benchmark_iterations_; ++i) {
ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
benchmark_height_, dest_opt_pixels, benchmark_height_,
benchmark_height_, benchmark_width_, kFilterNone);
}
for (int i = 0; i < kSize; ++i) {
EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
}
// Intent is to test 200x50 to 50x200 but width and height can be parameters.
TEST_F(LibYUVScaleTest, PlaneTestRotate_Box) { constint kSize = benchmark_width_ * benchmark_height_;
align_buffer_page_end(orig_pixels, kSize); for (int i = 0; i < kSize; ++i) {
orig_pixels[i] = i;
}
align_buffer_page_end(dest_opt_pixels, kSize);
align_buffer_page_end(dest_c_pixels, kSize);
MaskCpuFlags(disable_cpu_flags_); // Disable all CPU optimization.
ScalePlane(orig_pixels, benchmark_width_, benchmark_width_, benchmark_height_,
dest_c_pixels, benchmark_height_, benchmark_height_,
benchmark_width_, kFilterBox);
MaskCpuFlags(benchmark_cpu_info_); // Enable all CPU optimization.
for (int i = 0; i < benchmark_iterations_; ++i) {
ScalePlane(orig_pixels, benchmark_width_, benchmark_width_,
benchmark_height_, dest_opt_pixels, benchmark_height_,
benchmark_height_, benchmark_width_, kFilterBox);
}
for (int i = 0; i < kSize; ++i) {
EXPECT_EQ(dest_c_pixels[i], dest_opt_pixels[i]);
}
// Pad the 1x1 byte image with invalid values before and after in case libyuv // reads outside the memory boundaries.
orig_pixels[0] = 0;
orig_pixels[1] = 1; // scale this pixel
orig_pixels[2] = 2;
dst_pixels[0] = 3;
dst_pixels[1] = 3;
dst_pixels[2] = 3;
// Pad the 1x1 byte image with invalid values before and after in case libyuv // reads outside the memory boundaries.
orig_pixels[0] = 0;
orig_pixels[1] = 1; // scale this pixel
orig_pixels[2] = 2;
dst_pixels[0] = 3;
dst_pixels[1] = 3;
dst_pixels[2] = 3;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.