#include "image.h" #include "mem_allocator.h" #include "mem_libc.h" #include #include Image *create_image(u64 width, u64 height, Pixel *data, const Allocator *allocator) { Allocator alloc; if (!allocator) { alloc = wapp_mem_libc_allocator(); } else { alloc = *allocator; } u64 buf_length = width * height; u64 total_size = sizeof(Image) + sizeof(Pixel) * buf_length; Image *img = wapp_mem_allocator_alloc(&alloc, total_size); if (!img) { return NULL; } img->width = width; img->height = height; img->buf_length = buf_length; memcpy(img->data, data, buf_length); return img; } void destroy_image(Image **img, const Allocator *allocator) { if (!img || !(*img)) { return; } Allocator alloc; if (!allocator) { alloc = wapp_mem_libc_allocator(); } else { alloc = *allocator; } wapp_mem_allocator_free(&alloc, (void **)img); }