| // Copyright 2022 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "risp4ml/common/image.h" |
| |
| #include "pw_unit_test/framework.h" |
| #include "risp4ml/common/test_utils.h" |
| |
| class ImageTest : public ::testing::Test { |
| protected: |
| void SetUp() override { |
| img_ = image_new(3, 32, 64); |
| FillImage(img_); |
| } |
| void TearDown() override { image_delete(img_); } |
| |
| Image* img_; |
| }; |
| |
| TEST_F(ImageTest, PixelAccess) { |
| for (uint16_t c = 0; c < img_->num_channels; ++c) { |
| for (uint16_t y = 0; y < img_->height; ++y) { |
| for (uint16_t x = 0; x < img_->width; ++x) { |
| ASSERT_EQ(image_pixel_val(img_, c, y, x), Pattern(c, y, x)); |
| } |
| } |
| } |
| } |
| |
| TEST_F(ImageTest, RowAccess) { |
| pixel_type_t* row_4 = image_row(img_, 1, 4); |
| for (uint16_t i = 0; i < 16; ++i) { |
| ASSERT_EQ(row_4[i], Pattern(1, 4, i)); |
| } |
| } |