/*
 * 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.
 */

#ifndef RISP4ML_COMMON_TEST_UTILS_H_
#define RISP4ML_COMMON_TEST_UTILS_H_

#include <stdio.h>
#include <stdlib.h>

#include "risp4ml/common/image.h"

static inline pixel_type_t Pattern(uint16_t c, uint16_t y, uint16_t x) {
  return (pixel_type_t)(x + y * 100 + c * 10000);
}

inline void FillImage(Image* img) {
  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) {
        *image_pixel(img, c, y, x) = Pattern(c, y, x);
      }
    }
  }
}

// Initializes raw image to random value within min and max range
static inline void InitImageRandom(Image* image, pixel_type_t min_val,
                                   pixel_type_t max_val) {
  int range = max_val + 1 - min_val;
  for (uint16_t c = 0; c < image->num_channels; ++c) {
    for (uint16_t y = 0; y < image->height; ++y) {
      for (uint16_t x = 0; x < image->width; ++x) {
        *image_pixel(image, 0, y, x) =
            (pixel_type_t)(rand() % range +  // NOLINT(runtime/threadsafe_fn)
                           min_val);
      }
    }
  }
}

// Initializes raw image to raw pixel value
static inline void InitImage(Image* image, pixel_type_t val) {
  for (uint16_t c = 0; c < image->num_channels; ++c) {
    for (uint16_t y = 0; y < image->height; ++y) {
      for (uint16_t x = 0; x < image->width; ++x) {
        *image_pixel(image, 0, y, x) = val;
      }
    }
  }
}

#endif  // RISP4ML_COMMON_TEST_UTILS_H_
