diff options
Diffstat (limited to 'src/painter/canvas.c')
-rw-r--r-- | src/painter/canvas.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/painter/canvas.c b/src/painter/canvas.c new file mode 100644 index 0000000..53deeb9 --- /dev/null +++ b/src/painter/canvas.c | |||
@@ -0,0 +1,27 @@ | |||
1 | #include "painter/canvas.h" | ||
2 | #include "common/mem.h" | ||
3 | |||
4 | Canvas *canvas_create(IntVector width, IntVector height) { | ||
5 | Canvas *c = malloc_or_die(sizeof(Canvas)); | ||
6 | c->mlv = MLV_create_image(width, height); | ||
7 | return c; | ||
8 | } | ||
9 | |||
10 | void canvas_destroy(Canvas *c) { | ||
11 | MLV_free_image(c->mlv); | ||
12 | free(c); | ||
13 | } | ||
14 | |||
15 | void canvas_set_pixel(Canvas *c, CartesianVector pos, Color color) { | ||
16 | MLV_set_pixel_on_image(pos.x, pos.y, color.mlv, c->mlv); | ||
17 | } | ||
18 | |||
19 | Color canvas_get_pixel(Canvas *c, CartesianVector pos) { | ||
20 | int r, g, b, a; | ||
21 | MLV_get_pixel_on_image(c->mlv, pos.x, pos.y, &r, &g, &b, &a); | ||
22 | return (Color) {{a, b, g, r}}; | ||
23 | } | ||
24 | |||
25 | CartesianVector canvas_get_dim(Canvas *c) { | ||
26 | return (CartesianVector) {MLV_get_image_width(c->mlv), MLV_get_image_height(c->mlv)}; | ||
27 | } | ||