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