blob: ddd782b3921857bf85826fade385232850439aef [file] [log] [blame]
#include "pw_unit_test/framework.h"
#include "samples/risp4ml/common/constants.h"
#include "samples/risp4ml/common/test_utils.h"
#include "samples/risp4ml/isp_stages/blc.h"
static constexpr int kFrameSize = 16;
static constexpr int kNumPatterns = 4;
class BlcTest : public ::testing::Test {
protected:
void SetUp() override {
in_ = image_new(1, kFrameSize, kFrameSize);
InitImageRandom(in_, 0, kRawPipelineMaxVal);
// Force max/min values to be included.
*image_pixel(in_, 0, 0, 0) = 0;
*image_pixel(in_, 0, 0, 1) = kRawPipelineMaxVal;
out_ = image_new(1, kFrameSize, kFrameSize);
const uint32_t num_bytes =
in_->num_channels * in_->height * in_->width * sizeof(pixel_type_t);
memcpy(out_->data, in_->data, num_bytes);
}
void TearDown() override {
image_delete(in_);
image_delete(out_);
}
Image* in_;
Image* out_;
};
TEST_F(BlcTest, Bypass) {
BlcParams params = {.enable = false, .offsets = {20, 20, 20, 20}};
set_blc_params(&params);
blc_process(out_);
// Expect no change
for (uint16_t c = 0; c < in_->num_channels; ++c) {
for (uint16_t y = 0; y < in_->height; ++y) {
for (uint16_t x = 0; x < in_->width; ++x) {
ASSERT_EQ(image_pixel_val(in_, c, y, x),
image_pixel_val(out_, c, y, x));
}
}
}
}
TEST_F(BlcTest, NoChangeRandomPixel) {
// Set all 4 Bayer channel offsets to 0.
BlcParams params = {.enable = true, .offsets = {0, 0, 0, 0}};
set_blc_params(&params);
blc_process(out_);
// Expect no change
for (uint16_t c = 0; c < in_->num_channels; ++c) {
for (uint16_t y = 0; y < in_->height; ++y) {
for (uint16_t x = 0; x < in_->width; ++x) {
ASSERT_EQ(image_pixel_val(in_, c, y, x),
image_pixel_val(out_, c, y, x));
}
}
}
}
TEST_F(BlcTest, MaxOffsetClampToZero) {
// Set all 4 Bayer channel offsets to max allowed value.
BlcParams params = {.enable = true,
.offsets = {kRawPipelineMaxVal, kRawPipelineMaxVal,
kRawPipelineMaxVal, kRawPipelineMaxVal}};
set_blc_params(&params);
blc_process(out_);
// Expect correct subtraction
for (uint16_t c = 0; c < in_->num_channels; ++c) {
for (uint16_t y = 0; y < in_->height; ++y) {
for (uint16_t x = 0; x < in_->width; ++x) {
ASSERT_EQ(0, image_pixel_val(out_, c, y, x));
}
}
}
}