diff options
author | Adam NAILI | 2017-12-28 16:23:17 +0100 |
---|---|---|
committer | Adam NAILI | 2017-12-28 16:23:17 +0100 |
commit | 9e4eb30f33867bcb37d5accfb5588cfb3b450f90 (patch) | |
tree | 57cc389a1c302d8278246fb8334ada216be82a01 /include/painter | |
parent | aaf57e5ee1e0cf74afdbdf56293f1afd7e79e6b0 (diff) | |
parent | 426ddbdd27d21383a3870980f9b787a8c58237aa (diff) | |
download | morpher-9e4eb30f33867bcb37d5accfb5588cfb3b450f90.tar.gz |
Merge remote-tracking branch 'origin/master' into gui
Diffstat (limited to 'include/painter')
-rw-r--r-- | include/painter/canvas.h | 92 | ||||
-rw-r--r-- | include/painter/color.h | 61 | ||||
-rw-r--r-- | include/painter/rasterizer.h | 41 |
3 files changed, 194 insertions, 0 deletions
diff --git a/include/painter/canvas.h b/include/painter/canvas.h new file mode 100644 index 0000000..928121a --- /dev/null +++ b/include/painter/canvas.h | |||
@@ -0,0 +1,92 @@ | |||
1 | #ifndef UPEM_MORPHING_CANVAS | ||
2 | #define UPEM_MORPHING_CANVAS | ||
3 | |||
4 | /** | ||
5 | * File: canvas.h | ||
6 | * > Everyday is a good day when you paint. | ||
7 | * -- Bob Ross | ||
8 | */ | ||
9 | |||
10 | #include <MLV/MLV_image.h> | ||
11 | #include "common/geom.h" | ||
12 | #include "painter/color.h" | ||
13 | |||
14 | /** | ||
15 | * Type: Canvas | ||
16 | * Represents a fixed size RGBa pixel matrix. | ||
17 | */ | ||
18 | typedef struct { | ||
19 | MLV_Image *mlv; | ||
20 | } Canvas; | ||
21 | |||
22 | /** | ||
23 | * Function: canvas_create | ||
24 | * Initialises a canvas of the given size | ||
25 | * | ||
26 | * Parameters: | ||
27 | * width - the width in pixels | ||
28 | * height - the height in pixels | ||
29 | * | ||
30 | * Returns: | ||
31 | * The initialised canvas | ||
32 | */ | ||
33 | Canvas *canvas_create(IntVector width, IntVector height); | ||
34 | |||
35 | /** | ||
36 | * Function: canvas_create_from_image | ||
37 | * Initialises a canvas with an image loaded from the given path. | ||
38 | * | ||
39 | * Parameters: | ||
40 | * *fpath - path to the base image file | ||
41 | * | ||
42 | * Returns: | ||
43 | * The initialised canvas | ||
44 | */ | ||
45 | Canvas *canvas_create_from_image(const char *fpath); | ||
46 | |||
47 | /** | ||
48 | * Function: canvas_destroy | ||
49 | * Frees all memory allocated to a canvas. | ||
50 | * | ||
51 | * Parameters: | ||
52 | * *c - the canvas to destroy | ||
53 | */ | ||
54 | void canvas_destroy(Canvas *c); | ||
55 | |||
56 | /** | ||
57 | * Function: canvas_set_pixel | ||
58 | * Sets the pixel colour at the given coordinates. | ||
59 | * | ||
60 | * Parameters: | ||
61 | * *c - the canvas to alter | ||
62 | * pos - the coordinate of the pixel to set | ||
63 | * color - the new colour to set | ||
64 | */ | ||
65 | void canvas_set_pixel(Canvas *c, CartesianVector pos, Color color); | ||
66 | |||
67 | /** | ||
68 | * Function: canvas_get_pixel | ||
69 | * Returns the colour of the pixel at the given position. | ||
70 | * | ||
71 | * Parameters: | ||
72 | * *c - the base canvas | ||
73 | * pos - the coordinate of the pixel to get | ||
74 | * | ||
75 | * Returns: | ||
76 | * The colour of the requested pixel | ||
77 | */ | ||
78 | Color canvas_get_pixel(Canvas *c, CartesianVector pos); | ||
79 | |||
80 | /** | ||
81 | * Function: canvas_get_dim | ||
82 | * Returns the size (in pixels) of the given canvas. | ||
83 | * | ||
84 | * Parameters: | ||
85 | * *c - the canvas | ||
86 | * | ||
87 | * Returns: | ||
88 | * The size of the canvas | ||
89 | */ | ||
90 | CartesianVector canvas_get_dim(Canvas *c); | ||
91 | |||
92 | #endif | ||
diff --git a/include/painter/color.h b/include/painter/color.h new file mode 100644 index 0000000..2aeee3e --- /dev/null +++ b/include/painter/color.h | |||
@@ -0,0 +1,61 @@ | |||
1 | #ifndef UPEM_MORPHING_COLOR | ||
2 | #define UPEM_MORPHING_COLOR | ||
3 | |||
4 | /** | ||
5 | * File: color.h | ||
6 | * | ||
7 | * See also: | ||
8 | * A rainbow | ||
9 | */ | ||
10 | |||
11 | #include <MLV/MLV_color.h> | ||
12 | #include <stdbool.h> | ||
13 | #include "common/time.h" | ||
14 | |||
15 | /** | ||
16 | * Type: ColorComponent | ||
17 | * Represents a single colour component of 32-bits RGBa tuple. | ||
18 | */ | ||
19 | typedef uint8_t ColorComponent; | ||
20 | |||
21 | /** | ||
22 | * Type: ColorPixel | ||
23 | * Represents a single RGBa coloured pixel. | ||
24 | * Compatible with the libMLV representation. | ||
25 | */ | ||
26 | typedef union { | ||
27 | struct { | ||
28 | ColorComponent a, b, g, r; | ||
29 | } rgba; | ||
30 | |||
31 | MLV_Color mlv; | ||
32 | } Color; | ||
33 | |||
34 | /** | ||
35 | * Function: color_equals | ||
36 | * Compares the supplied colors. | ||
37 | * | ||
38 | * Parameters: | ||
39 | * c1 - the first color | ||
40 | * c2 - the second color | ||
41 | * | ||
42 | * Returns: | ||
43 | * T(c1 is the same color as c2) | ||
44 | */ | ||
45 | bool color_equals(Color c1, Color c2); | ||
46 | |||
47 | /** | ||
48 | * Function: color_blend | ||
49 | * Blends two colors. | ||
50 | * | ||
51 | * Parameters: | ||
52 | * origin - the first color | ||
53 | * target - the second color | ||
54 | * distance - the distance from the first color | ||
55 | * | ||
56 | * Returns: | ||
57 | * The blended color | ||
58 | */ | ||
59 | Color color_blend(Color origin, Color target, TimeVector distance); | ||
60 | |||
61 | #endif | ||
diff --git a/include/painter/rasterizer.h b/include/painter/rasterizer.h new file mode 100644 index 0000000..204d616 --- /dev/null +++ b/include/painter/rasterizer.h | |||
@@ -0,0 +1,41 @@ | |||
1 | #ifndef UPEM_MORPHING_RASTERIZER | ||
2 | #define UPEM_MORPHING_RASTERIZER | ||
3 | |||
4 | /** | ||
5 | * File: rasterizer.h | ||
6 | */ | ||
7 | |||
8 | #include "painter/canvas.h" | ||
9 | #include "morpher/morphing.h" | ||
10 | |||
11 | /** | ||
12 | * Struct: RasterizationContext | ||
13 | */ | ||
14 | typedef struct { | ||
15 | Canvas *result, *source, *target; | ||
16 | TimeVector frame; | ||
17 | } RasterizationContext; | ||
18 | |||
19 | /** | ||
20 | * Struct: TriangleContext | ||
21 | */ | ||
22 | typedef struct { | ||
23 | Triangle current, source, target; | ||
24 | } TriangleContext; | ||
25 | |||
26 | /** | ||
27 | * Function: rasterize | ||
28 | * Rasterises a morphing from a source and a target image at the given time frame. | ||
29 | * | ||
30 | * Parameters: | ||
31 | * *source - source image canvas | ||
32 | * *target - target image canvas | ||
33 | * *m - reference morphing | ||
34 | * frame - time frame | ||
35 | * | ||
36 | * Returns: | ||
37 | * The drawn canvas, dynamically allocated | ||
38 | */ | ||
39 | Canvas *rasterize(Canvas *source, Canvas *target, Morphing *m, TimeVector frame); | ||
40 | |||
41 | #endif | ||