summaryrefslogtreecommitdiff
path: root/include/painter/canvas.h
blob: ba6d4daba8e451bbfd65e2bcfc69d57539f6e092 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef UPEM_MORPHING_CANVAS
#define UPEM_MORPHING_CANVAS

/**
 * File: canvas.h
 * "Everyday is a good day when you paint" – Bob Ross
 */

#include <MLV/MLV_image.h>
#include "common/geom.h"
#include "painter/color.h"

/**
 * Type: Canvas
 * Represents a fixed size RGBa pixel matrix.
 */
typedef struct {
  MLV_Image *mlv;
} Canvas;

/**
 * Function: canvas_create
 * Initialises a canvas of the given size
 *
 * Parameters:
 *   width  - the width in pixels
 *   height - the height in pixels
 *
 * Returns:
 *   The initialised canvas
 */
Canvas *canvas_create(IntVector width, IntVector height);

/**
 * Function: canvas_create_from_image
 * Initialises a canvas with an image loaded from the given path.
 *
 * Parameters:
 *   *fpath - path to the base image file
 *
 * Returns:
 *   The initialised canvas
 */
Canvas *canvas_create_from_image(const char *fpath);

/**
 * Function: canvas_destroy
 * Frees all memory allocated to a canvas.
 *
 * Parameters:
 *   *c - the canvas to destroy
 */
void canvas_destroy(Canvas *c);

/**
 * Function: canvas_set_pixel
 * Sets the pixel colour at the given coordinates.
 *
 * Parameters:
 *   *c    - the canvas to alter
 *   pos   - the coordinate of the pixel to set
 *   color - the new colour to set
 */
void canvas_set_pixel(Canvas *c, CartesianVector pos, Color color);

/**
 * Function: canvas_get_pixel
 * Returns the colour of the pixel at the given position.
 *
 * Parameters:
 *   *c  - the base canvas
 *   pos - the coordinate of the pixel to get
 *
 * Returns:
 *   The colour of the requested pixel
 */
Color canvas_get_pixel(Canvas *c, CartesianVector pos);

/**
 * Function: canvas_get_dim
 * Returns the size (in pixels) of the given canvas.
 *
 * Parameters:
 *   *c - the canvas
 *
 * Returns:
 *   The size of the canvas
 */
CartesianVector canvas_get_dim(Canvas *c);

#endif