| #include <stdio.h> |
| #include <stdlib.h> |
| |
| #include "samples/risp4ml/common/image.h" |
| |
| 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 |
| inline void InitImageRandom(Image* image, pixel_type_t min_val, |
| pixel_type_t max_val) { |
| pixel_type_t 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 + min_val); |
| } |
| } |
| } |
| } |
| |
| // Initializes raw image to raw pixel value |
| 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; |
| } |
| } |
| } |
| } |