From 7f6ffd0fea1cd9865b2050670f4e6a9b7bc64369 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Sat, 20 Apr 2024 18:41:41 +0100 Subject: [PATCH] Add destroy_image function --- src/image.c | 15 +++++++++++++++ src/image.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/image.c b/src/image.c index 38b8d6e..f6de50b 100644 --- a/src/image.c +++ b/src/image.c @@ -28,3 +28,18 @@ Image *create_image(u64 width, u64 height, Pixel *data, 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); +} diff --git a/src/image.h b/src/image.h index eb27493..433f47a 100644 --- a/src/image.h +++ b/src/image.h @@ -26,6 +26,7 @@ struct image { Image *create_image(u64 width, u64 height, Pixel *data, const Allocator *allocator); +void destroy_image(Image **img, const Allocator *allocator); #ifdef __cplusplus }