blob: 5c774450edd7e8de2c1d222f377caefcce64c8bd [file] [log] [blame]
#include <stdlib.h>
#include "samples/risp4ml/common/image.h"
Image* image_new(uint16_t num_channels, uint16_t height, uint16_t width) {
Image* image = (Image*)malloc(sizeof(Image));
if (image) {
image->num_channels = num_channels;
image->height = height;
image->width = width;
uint32_t num_pixels = width * height * num_channels;
image->data = (pixel_type_t*)malloc(num_pixels * sizeof(pixel_type_t));
}
return image;
}
void image_delete(Image* image) {
if (image) {
if (image->data) free(image->data);
free(image);
}
}
pixel_type_t* image_pixel(Image* image, uint16_t c, uint16_t y, uint16_t x) {
const uint32_t stride_c = image->width * image->height;
const uint16_t stride_y = image->width;
const uint16_t stride_x = 1;
return (image->data + c * stride_c + y * stride_y + x * stride_x);
}
pixel_type_t* image_row(Image* image, uint16_t c, uint16_t y) {
const uint32_t stride_c = image->width * image->height;
const uint16_t stride_y = image->width;
return (image->data + c * stride_c + y * stride_y);
}