blob: c61e4905f25b27e6f112676eea8a5dbc3e357380 [file] [log] [blame]
Cindy Liu43879e42023-10-18 11:18:03 -07001/*
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 Liue1ddfd52023-08-30 15:47:00 -070016
17#include "tests/cv/downsample.h"
18
19#include <cstdint>
Alex Van Dammec2239bd2023-09-21 15:16:48 -070020#include <cstdio>
Cindy Liue1ddfd52023-08-30 15:47:00 -070021
22#include "crt/kelvin.h"
23#include "tests/cv/test_helper.h"
24
25void 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
49int main() {
50 downsample_test();
51 return 0;
52}