summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpacien2017-12-28 01:24:14 +0100
committerpacien2017-12-28 01:27:14 +0100
commita1aa852d6e443394f79e7d1198b0bc2e5e6d2d66 (patch)
tree15468db1c658e9f93adc95e6d5c087c8bea01a4c
parentc502b20bac91ebc9128c2e3a586391fcabd84b6b (diff)
parent330fd85db8c89c178621d978929d911bbe93fec7 (diff)
downloadmorpher-a1aa852d6e443394f79e7d1198b0bc2e5e6d2d66.tar.gz
Merge branch 'morpher'
Signed-off-by: pacien <pacien.trangirard@pacien.net>
-rw-r--r--include/blender/blender.h26
-rw-r--r--include/common/geom.h93
-rw-r--r--include/common/time.h4
-rw-r--r--include/painter/canvas.h76
-rw-r--r--include/painter/color.h61
-rw-r--r--include/painter/rasterizer.h41
-rw-r--r--src/blender/blender.c39
-rw-r--r--src/blender/canvas.c23
-rw-r--r--src/blender/color.c8
-rw-r--r--src/common/geom.c27
-rw-r--r--src/morpher/trianglemap.c2
-rw-r--r--src/painter/canvas.c27
-rw-r--r--src/painter/color.c20
-rw-r--r--src/painter/rasterizer.c86
-rw-r--r--test/blender/blender.c29
-rw-r--r--test/common/geom.c21
-rw-r--r--test/painter/color.c14
-rw-r--r--test/painter/rasterizer.c27
18 files changed, 489 insertions, 135 deletions
diff --git a/include/blender/blender.h b/include/blender/blender.h
deleted file mode 100644
index 26ff802..0000000
--- a/include/blender/blender.h
+++ /dev/null
@@ -1,26 +0,0 @@
1#ifndef UPEM_MORPHING_BLENDER
2#define UPEM_MORPHING_BLENDER
3
4/**
5 * File: blender.h
6 * Will it blend? That is the question.
7 */
8
9#include "common/time.h"
10#include "blender/canvas.h"
11#include "morpher/morphing.h"
12
13/**
14 * Function: blender_blend_canvas
15 * Blends two canvas by applying the given morphing at the requested time frame.
16 *
17 * Parameters:
18 * *canvas - pointer to the canvas to paint
19 * *source - source image
20 * *target - target image
21 * *morphing - morphing transform to apply
22 * frame - the interpolation distance from the origin canvas [0;1]
23 */
24void blender_blend_canvas(Canvas *canvas, Canvas *source, Canvas *target, Morphing *morphing, TimeVector frame);
25
26#endif
diff --git a/include/common/geom.h b/include/common/geom.h
index b3564a5..334e95c 100644
--- a/include/common/geom.h
+++ b/include/common/geom.h
@@ -15,6 +15,12 @@
15typedef int32_t IntVector; 15typedef int32_t IntVector;
16 16
17/** 17/**
18 * Type: RealVector
19 * An abstract 1-D real vector.
20 */
21typedef double RealVector;
22
23/**
18 * Struct: CartesianVector 24 * Struct: CartesianVector
19 * An abstract 2-D vector in cartesian coordinates. 25 * An abstract 2-D vector in cartesian coordinates.
20 * 26 *
@@ -27,6 +33,19 @@ typedef struct {
27} CartesianVector; 33} CartesianVector;
28 34
29/** 35/**
36 * Struct: BarycentricVector
37 * An abstract barycentric coordinate tuple relative to a triangle.
38 * The third barycentric coordinate is deduced from the first two ones.
39 *
40 * Fields:
41 * a - the first barycentric coordinate
42 * b - the second barycentric coordinate
43 */
44typedef struct {
45 RealVector a, b;
46} BarycentricVector;
47
48/**
30 * Struct: CartesianMapping 49 * Struct: CartesianMapping
31 * A tuple of cartesian vectors representing a mapping. 50 * A tuple of cartesian vectors representing a mapping.
32 * 51 *
@@ -38,6 +57,16 @@ typedef struct {
38 CartesianVector origin, target; 57 CartesianVector origin, target;
39} CartesianMapping; 58} CartesianMapping;
40 59
60/**
61 * Struct: Triangle
62 * Represents a simple triangle with three vertices.
63 *
64 * Fields:
65 * v[] - array of vertices
66 */
67typedef struct {
68 CartesianVector v[3];
69} Triangle;
41 70
42/** 71/**
43 * Function: m 72 * Function: m
@@ -66,6 +95,19 @@ CartesianMapping m(int x, int y);
66CartesianVector v(int x, int y); 95CartesianVector v(int x, int y);
67 96
68/** 97/**
98 * Function: b
99 * Shorthand for a barycentric vector.
100 *
101 * Parameters:
102 * a - the a-coordinate
103 * b - the b-coordinate
104 *
105 * Returns:
106 * A barycentric vector
107 */
108BarycentricVector b(double a, double b);
109
110/**
69 * Function: mappings_equals 111 * Function: mappings_equals
70 * Compares two cartesian mappings. 112 * Compares two cartesian mappings.
71 * 113 *
@@ -92,17 +134,54 @@ bool mappings_equals(CartesianMapping m1, CartesianMapping m2);
92bool vector_equals(CartesianVector v1, CartesianVector v2); 134bool vector_equals(CartesianVector v1, CartesianVector v2);
93 135
94/** 136/**
95 * Function: triangle_area 137 * Function: barycentric_vector_equals
96 * Computes the area of a triangle. 138 * Compares two barycentric vectors.
139 *
140 * Parameters:
141 * v1 - the first vector
142 * v2 - the second vector
143 *
144 * Returns:
145 * T(v1 is equal to v2)
146 */
147bool barycentric_vector_equals(BarycentricVector b1, BarycentricVector b2);
148
149/**
150 * Function: square_area
151 * Computes the area of a square spawned by three positively oriented vertices.
152 *
153 * Parameters:
154 * vi - vertices
155 *
156 * Returns:
157 * The area of the square
158 */
159IntVector square_area(CartesianVector v1, CartesianVector v2, CartesianVector v3);
160
161/**
162 * Function: cartesian_to_barycentric
163 * Computes and returns the barycentric coordinates of a given point in the given reference triangle.
164 *
165 * Parameters:
166 * t - reference triangle
167 * p - the vector to convert
168 *
169 * Returns:
170 * The barycentric coordinates vector
171 */
172BarycentricVector cartesian_to_barycentric(Triangle t, CartesianVector p);
173
174/**
175 * Function: barycentric_to_cartesian
176 * Computes and returns the cartesian coordinates of a given point in the given reference triangle.
97 * 177 *
98 * Parameters: 178 * Parameters:
99 * v1 - first vertex 179 * t - reference triangle
100 * v2 - second vertex 180 * p - the vector to convert
101 * v3 - third vertex
102 * 181 *
103 * Returns: 182 * Returns:
104 * The area of the triangle spawned by the three supplied vertices 183 * The cartesian coordinate vector
105 */ 184 */
106IntVector triangle_area(CartesianVector v1, CartesianVector v2, CartesianVector v3); 185CartesianVector barycentric_to_cartesian(Triangle t, BarycentricVector p);
107 186
108#endif 187#endif
diff --git a/include/common/time.h b/include/common/time.h
index 54a7bb2..e207ad7 100644
--- a/include/common/time.h
+++ b/include/common/time.h
@@ -5,6 +5,8 @@
5 * File: time.h 5 * File: time.h
6 */ 6 */
7 7
8#include "geom.h"
9
8/** 10/**
9 * Constants: Time vectors 11 * Constants: Time vectors
10 * 12 *
@@ -18,6 +20,6 @@
18 * Type: TimeVector 20 * Type: TimeVector
19 * An abstract time vector. 21 * An abstract time vector.
20 */ 22 */
21typedef float TimeVector; 23typedef RealVector TimeVector;
22 24
23#endif 25#endif
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 */