/*
 * Copyright 2023 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 "tests/cv/downsample.h"

#include <cstdint>
#include <cstdio>

#include "crt/kelvin.h"
#include "tests/cv/test_helper.h"

void downsample_test() {
  constexpr int kNumInputCols = 640;
  constexpr int kNumOutputCols = kNumInputCols / 2;
  uint16_t input0_row[kNumInputCols] __attribute__((aligned(64)));
  uint16_t input1_row[kNumInputCols] __attribute__((aligned(64)));
  uint16_t output_row[kNumOutputCols] __attribute__((aligned(64)));
  krand(kNumInputCols, input0_row);
  krand(kNumInputCols, input1_row);

  kelvin::cv::downsample(kNumOutputCols, input0_row, input1_row, output_row);

  for (int i = 0; i < kNumOutputCols; ++i) {
    const uint32_t s0 = input0_row[2 * i] + input0_row[2 * i + 1];
    const uint32_t s1 = input1_row[2 * i] + input1_row[2 * i + 1];
    const uint32_t s012 = s0 + s1 + 2;
    const uint16_t ref_value = s012 >> 2;
    if (ref_value != output_row[i]) {
      printf("**error::downsample_test[%d] %x %x\n", i, ref_value,
             output_row[i]);
      exit(-1);
    }
  }
}

int main() {
  downsample_test();
  return 0;
}
