Update image creation function

This commit is contained in:
Abdelrahman Said 2024-05-01 23:52:32 +01:00
parent 69c13b83ea
commit 8f20c7b30a
2 changed files with 6 additions and 5 deletions

View File

@ -8,17 +8,18 @@ Image *create_image(u64 width, u64 height, Pixel *data, Arena *arena) {
return NULL; return NULL;
} }
u64 buf_length = width * height; u64 pixel_count = width * height;
u64 total_size = sizeof(Image) + sizeof(Pixel) * buf_length; u64 buf_length = sizeof(Pixel) * pixel_count;
u64 alloc_size = sizeof(Image) + buf_length;
Image *img = wapp_mem_arena_alloc(arena, total_size); Image *img = wapp_mem_arena_alloc(arena, alloc_size);
if (!img) { if (!img) {
return NULL; return NULL;
} }
img->width = width; img->width = width;
img->height = height; img->height = height;
img->buf_length = buf_length; img->pixel_count = pixel_count;
memcpy(img->data, data, buf_length); memcpy(img->data, data, buf_length);
return img; return img;

View File

@ -20,7 +20,7 @@ typedef struct image Image;
struct image { struct image {
u64 width; u64 width;
u64 height; u64 height;
u64 buf_length; u64 pixel_count;
Pixel data[]; Pixel data[];
}; };