diff --git a/intrinsiccv/include/intrinsiccv.h b/intrinsiccv/include/intrinsiccv.h index bc4a24a8e5b2243b657e1b99ce8c7443b4611f88..2016dde0fba26fc47b82ca17d281980135fc5503 100644 --- a/intrinsiccv/include/intrinsiccv.h +++ b/intrinsiccv/include/intrinsiccv.h @@ -543,6 +543,24 @@ void INTRINSICCV_C_API(yuv_sp_to_bgra_u8)(const uint8_t *src_y, size_t dst_stride, size_t width, size_t height, bool is_nv21); +/// Performs a comparison of each element's value in `src` with respect to a +/// caller defined threshold. The strictly larger elements are set to +/// `value` and the rest to 0. +/// +/// @param src Pointer to the source data. Must be non-null. +/// @param src_stride Distance in bytes from the start of one row to the +/// start of the next row for the source data. Must +/// not be less than width * sizeof(type). +/// @param dst Pointer to the first destination data. Must be non-null. +/// @param dst_stride Distance in bytes from the start of one row to the +/// start of the next row for the destination data. Must +/// not be less than width * sizeof(type). +/// @param width How many elements are in a row for the output. +/// @param height How many rows are in the output. +/// @param threshold The value that the elements of the source data are +/// compared to. +/// @param value The value that the larger elements are set to. +/// void INTRINSICCV_C_API(threshold_binary_u8)(const uint8_t *src, size_t src_stride, uint8_t *dst, size_t dst_stride, size_t width, diff --git a/test/api/test_threshold_binary.cpp b/test/api/test_threshold_binary.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69c016791a29efc6dc7823030f8edd913c669a25 --- /dev/null +++ b/test/api/test_threshold_binary.cpp @@ -0,0 +1,121 @@ +// SPDX-FileCopyrightText: 2024 Arm Limited and/or its affiliates +// +// SPDX-License-Identifier: Apache-2.0 + +#include +#include + +#include "framework/operation.h" + +template +class ThresholdBinaryTestBase : public UnaryOperationTest { + // Needed to initialize value() + using UnaryOperationTest::max; + + protected: + /// Calls the API-under-test in the appropriate way. + void call_api() override { + intrinsiccv_threshold_binary_u8( + this->inputs_[0].data(), this->inputs_[0].stride(), + this->actual_[0].data(), this->actual_[0].stride(), this->width(), + this->height(), this->threshold(), this->value()); + } + + virtual ElementType threshold() = 0; + static constexpr ElementType value() { return max(); } +}; // end of class ThresholdBinaryTestBase + +template +class ThresholdBinaryTest final : public ThresholdBinaryTestBase { + using Elements = typename UnaryOperationTest::Elements; + + ElementType threshold() override { return 13; } + + const std::vector& test_elements() override { + static const std::vector kTestElements = { + // clang-format off + { 12, 0}, + { 13, 0}, + { 14, this->value()}, + // clang-format on + }; + return kTestElements; + } +}; + +template +class ThresholdBinaryTestMin final + : public ThresholdBinaryTestBase { + using Elements = typename UnaryOperationTest::Elements; + using UnaryOperationTest::min; + + ElementType threshold() override { return min(); } + + const std::vector& test_elements() override { + static const std::vector kTestElements = { + // clang-format off + { min(), 0}, + {min() + 1, this->value()}, + // clang-format on + }; + return kTestElements; + } +}; + +template +class ThresholdBinaryTestZero final + : public ThresholdBinaryTestBase { + using Elements = typename UnaryOperationTest::Elements; + + ElementType threshold() override { return 0; } + + const std::vector& test_elements() override { + static const std::vector kTestElements = { + // clang-format off + { 0, 0}, + { 1, this->value()}, + // clang-format on + }; + return kTestElements; + } +}; + +template +class ThresholdBinaryTestMax final + : public ThresholdBinaryTestBase { + using Elements = typename UnaryOperationTest::Elements; + using UnaryOperationTest::max; + + ElementType threshold() override { return max() - 1; } + + const std::vector& test_elements() override { + static const std::vector kTestElements = { + // clang-format off + {max() - 1, 0}, + { max(), this->value()}, + // clang-format on + }; + return kTestElements; + } +}; + +template +class ThresholdBinary : public testing::Test {}; + +using ElementTypes = ::testing::Types; + +TYPED_TEST_SUITE(ThresholdBinary, ElementTypes); + +TYPED_TEST(ThresholdBinary, Test) { ThresholdBinaryTest{}.test(); } + +TYPED_TEST(ThresholdBinary, TestMin) { + ThresholdBinaryTestMin{}.test(); +} + +TYPED_TEST(ThresholdBinary, TestZero) { + ThresholdBinaryTestZero{}.test(); +} + +TYPED_TEST(ThresholdBinary, TestMax) { + ThresholdBinaryTestMax{}.test(); +} diff --git a/test/framework/operation.h b/test/framework/operation.h index a69b47aa2116a3852efa13c607dd7cbd63007842..d372f8dc2d05d58fe44be1f2b60318776660b5a0 100644 --- a/test/framework/operation.h +++ b/test/framework/operation.h @@ -130,4 +130,8 @@ template class BinaryOperationTest : public OperationTest { }; // end of class BinaryOperationTest +template +class UnaryOperationTest : public OperationTest { +}; // end of class UnaryOperationTest + #endif // INTRINSICCV_TEST_FRAMEWORK_OPERATION_H_