diff options
author | pacien | 2017-12-28 01:22:03 +0100 |
---|---|---|
committer | pacien | 2017-12-28 01:22:03 +0100 |
commit | c970da3f5830fae5b4d98dcdcc8d34d678ec0434 (patch) | |
tree | 3d1205342e104e89c802fa48c2d6df1f9fed32cc /src/painter | |
parent | c29e4ecb7de4cb10f48b2526bc1abae847c718e2 (diff) | |
download | morpher-c970da3f5830fae5b4d98dcdcc8d34d678ec0434.tar.gz |
Refactor canvas
Signed-off-by: pacien <pacien.trangirard@pacien.net>
Diffstat (limited to 'src/painter')
-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 | } | ||