summaryrefslogtreecommitdiff
path: root/include/painter
diff options
context:
space:
mode:
Diffstat (limited to 'include/painter')
-rw-r--r--include/painter/canvas.h76
-rw-r--r--include/painter/color.h61
-rw-r--r--include/painter/rasterizer.h41
3 files changed, 178 insertions, 0 deletions
diff --git a/include/painter/canvas.h b/include/painter/canvas.h
new file mode 100644
index 0000000..e354938
--- /dev/null
+++ b/include/painter/canvas.h
@@ -0,0 +1,76 @@
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" – Bob Ross
7 */
8
9#include <MLV/MLV_image.h>
10#include "common/geom.h"
11#include "painter/color.h"
12
13/**
14 * Type: Canvas
15 * Represents a fixed size RGBa pixel matrix.
16 */
17typedef struct {
18 MLV_Image *mlv;
19} Canvas;
20
21/**
22 * Function: canvas_create
23 * Initialises a canvas of the given size
24 *
25 * Parameters:
26 * width - the width in pixels
27 * height - the height in pixels
28 */
29Canvas *canvas_create(IntVector width, IntVector height);
30
31/**
32 * Function: canvas_destroy
33 * Frees all memory allocated to a canvas.
34 *
35 * Parameters:
36 * *c - the canvas to destroy
37 */
38void canvas_destroy(Canvas *c);
39
40/**
41 * Function: canvas_set_pixel
42 * Sets the pixel colour at the given coordinates.
43 *
44 * Parameters:
45 * *c - the canvas to alter
46 * pos - the coordinate of the pixel to set
47 * color - the new colour to set
48 */
49void canvas_set_pixel(Canvas *c, CartesianVector pos, Color color);
50
51/**
52 * Function: canvas_get_pixel
53 * Returns the colour of the pixel at the given position.
54 *
55 * Parameters:
56 * *c - the base canvas
57 * pos - the coordinate of the pixel to get
58 *
59 * Returns:
60 * The colour of the requested pixel
61 */
62Color canvas_get_pixel(Canvas *c, CartesianVector pos);
63
64/**
65 * Function: canvas_get_dim
66 * Returns the size (in pixels) of the given canvas.
67 *
68 * Parameters:
69 * *c - the canvas
70 *
71 * Returns:
72 * The size of the canvas
73 */
74CartesianVector canvas_get_dim(Canvas *c);
75
76#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 */
19typedef uint8_t ColorComponent;
20
21/**
22 * Type: ColorPixel
23 * Represents a single RGBa coloured pixel.
24 * Compatible with the libMLV representation.
25 */
26typedef 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 */
45bool 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 */
59Color 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 */
14typedef struct {
15 Canvas *result, *source, *target;
16 TimeVector frame;
17} RasterizationContext;
18
19/**
20 * Struct: TriangleContext
21 */
22typedef 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 */
39Canvas *rasterize(Canvas *source, Canvas *target, Morphing *m, TimeVector frame);
40
41#endif