-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.c
65 lines (55 loc) · 1.76 KB
/
color.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmikaeli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/16 16:08:45 by aelola #+# #+# */
/* Updated: 2014/03/17 14:06:43 by bmikaeli ### ########.fr */
/* */
/* ************************************************************************** */
#include "color.h"
t_color *new_color(int r, int g, int b)
{
t_color *c;
c = NEW(t_color);
c->r = r;
c->g = g;
c->b = b;
return (c);
}
void mult(t_color *c1, double f)
{
c1->r = MIN(c1->r * f, 255);
c1->g = MIN(c1->g * f, 255);
c1->b = MIN(c1->b * f, 255);
}
t_color *cpy_color(t_color *c)
{
return (new_color(c->r, c->g, c->b));
}
t_color *sub_colour(t_color *c1, const t_color *c2)
{
t_color *c3;
c3 = NEW(t_color);
c3->r = -MIN(c1->r - c2->r, 0);
c3->g = -MIN(c1->g - c2->g, 0);
c3->b = -MIN(c1->b - c2->b, 0);
return (c3);
}
void sub_color(t_color *c1, const t_color *c2)
{
c1->r = MIN(c1->r - c2->r, 0);
c1->g = MIN(c1->g - c2->g, 0);
c1->b = MIN(c1->b - c2->b, 0);
}
t_color *add_colour(t_color *c1, const t_color *c2)
{
t_color *c3;
c3 = NEW(t_color);
c3->r = MIN(c1->r + c2->r, 255);
c3->g = MIN(c1->g + c2->g, 255);
c3->b = MIN(c1->b + c2->b, 255);
return (c3);
}