Cindy Liu | 43879e4 | 2023-10-18 11:18:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 Google LLC |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Cindy Liu | e1ddfd5 | 2023-08-30 15:47:00 -0700 | [diff] [blame] | 16 | |
| 17 | #include "tests/cv/downsample.h" |
| 18 | |
| 19 | #include <cstdint> |
Alex Van Damme | c2239bd | 2023-09-21 15:16:48 -0700 | [diff] [blame] | 20 | #include <cstdio> |
Cindy Liu | e1ddfd5 | 2023-08-30 15:47:00 -0700 | [diff] [blame] | 21 | |
| 22 | #include "crt/kelvin.h" |
| 23 | #include "tests/cv/test_helper.h" |
| 24 | |
| 25 | void downsample_test() { |
| 26 | constexpr int kNumInputCols = 640; |
| 27 | constexpr int kNumOutputCols = kNumInputCols / 2; |
| 28 | uint16_t input0_row[kNumInputCols] __attribute__((aligned(64))); |
| 29 | uint16_t input1_row[kNumInputCols] __attribute__((aligned(64))); |
| 30 | uint16_t output_row[kNumOutputCols] __attribute__((aligned(64))); |
| 31 | krand(kNumInputCols, input0_row); |
| 32 | krand(kNumInputCols, input1_row); |
| 33 | |
| 34 | kelvin::cv::downsample(kNumOutputCols, input0_row, input1_row, output_row); |
| 35 | |
| 36 | for (int i = 0; i < kNumOutputCols; ++i) { |
| 37 | const uint32_t s0 = input0_row[2 * i] + input0_row[2 * i + 1]; |
| 38 | const uint32_t s1 = input1_row[2 * i] + input1_row[2 * i + 1]; |
| 39 | const uint32_t s012 = s0 + s1 + 2; |
| 40 | const uint16_t ref_value = s012 >> 2; |
| 41 | if (ref_value != output_row[i]) { |
| 42 | printf("**error::downsample_test[%d] %x %x\n", i, ref_value, |
| 43 | output_row[i]); |
| 44 | exit(-1); |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | int main() { |
| 50 | downsample_test(); |
| 51 | return 0; |
| 52 | } |