Update image creation function
This commit is contained in:
		| @@ -8,17 +8,18 @@ Image *create_image(u64 width, u64 height, Pixel *data, Arena *arena) { | ||||
|     return NULL; | ||||
|   } | ||||
|  | ||||
|   u64 buf_length = width * height; | ||||
|   u64 total_size = sizeof(Image) + sizeof(Pixel) * buf_length; | ||||
|   u64 pixel_count = width * height; | ||||
|   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) { | ||||
|     return NULL; | ||||
|   } | ||||
|  | ||||
|   img->width = width; | ||||
|   img->height = height; | ||||
|   img->buf_length = buf_length; | ||||
|   img->pixel_count = pixel_count; | ||||
|   memcpy(img->data, data, buf_length); | ||||
|  | ||||
|   return img; | ||||
|   | ||||
| @@ -20,7 +20,7 @@ typedef struct image Image; | ||||
| struct image { | ||||
|   u64 width; | ||||
|   u64 height; | ||||
|   u64 buf_length; | ||||
|   u64 pixel_count; | ||||
|   Pixel data[]; | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user