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
92
93
|
#include <stdlib.h>
#include <string.h>
#include "plotting.h"
/*
* Gets the corresponding color for a given number of iterations according to a gradient
*/
color get_color(const size_t iterations, const size_t max_iterations, const gradient map){
const size_t val = (max_iterations - iterations) / max_iterations;
color color;
//TODO: map the interval of [0,max_iterations] to a value given a gradient
return color;
}
/*
* Gets the associated "red" value for a given number of iterations according to a gradient
*/
char get_red(const size_t iterations, const size_t max_iterations, const gradient map){
char red;
return red;
}
/*
* Gets the associated "green" value for a given number of iterations according to a gradient
*/
char get_green(const size_t iterations, const size_t max_iterations, const gradient map){
char green;
return green;
}
/*
* Gets the associated "blue" value for a given number of iterations according to a gradient
*/
char get_blue(const size_t iterations, const size_t max_iterations, const gradient map){
char blue;
return blue;
}
colors_t* create_colors(const size_t x, const size_t y){
if(x <= 0 || y <= 0) return NULL;
char* red = malloc(x*y);
char* green = malloc(x*y);
char* blue = malloc(x*y);
if(!red || !green || !blue){
free(red); free(green); free(blue);
return NULL;
}
colors_t* colors = malloc(sizeof(colors_t));
if(!colors){
free(red); free(green); free(blue);
return NULL;
}
colors->x = x;
colors->y = y;
colors->size = x*y;
colors->red = red;
colors->green = green;
colors->blue = blue;
return colors;
}
colors_t* copy_colors(const colors_t* colors){
if(!colors || !colors->red || !colors->green || !colors->blue) return NULL;
colors_t* colors_copy = create_colors(colors->x, colors->y);
if(!colors_copy) return NULL;
const size_t size = colors->size;
memcpy(colors_copy->red, colors->red, size);
memcpy(colors_copy->green, colors->green, size);
memcpy(colors_copy->blue, colors->blue, size);
return colors_copy;
}
void free_colors(colors_t* colors){
if(!colors) return;
free(colors->red);
free(colors->green);
free(colors->blue);
free(colors);
}
|