Update image creation function
This commit is contained in:
parent
69c13b83ea
commit
8f20c7b30a
@ -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;
|
||||||
|
@ -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[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user