-
Notifications
You must be signed in to change notification settings - Fork 0
/
f_color.c
71 lines (60 loc) · 2.26 KB
/
f_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
66
67
68
69
70
71
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* f_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sboeuf <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/16 19:17:55 by sboeuf #+# #+# */
/* Updated: 2014/02/16 22:06:48 by sboeuf ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/rtv1.h"
t_color *color_scalar(double scalar, t_color *c1)
{
t_color *c2;
c2 = new_color(c1->red * scalar, c1->green * scalar,
c1->blue *scalar, c1->spec);
return (c2);
}
t_color *color_add(t_color *c1, t_color *c2)
{
t_color *rslt;
rslt = new_color(c1->red + c2->red, c1->green + c2->green,
c1->blue + c2->blue, c1->spec);
return (rslt);
}
t_color *color_multiply(t_color *c1, t_color *c2)
{
t_color *rslt;
rslt = new_color(c1->red * c2->red, c1->green * c2->green,
c1->blue * c2->blue, c1->spec);
return (rslt);
}
t_color *color_average(t_color *c1, t_color *c2)
{
t_color *r;
r = new_color((c1->red + c2->red) / 2, (c1->green + c2->green) / 2,
(c1->blue * c2->blue) / 2, c1->spec);
return (r);
}
t_color *clip(t_color *c1)
{
double all_light;
double excess_light;
all_light = c1->red + c1->green + c1->blue;
excess_light = all_light - 3;
if (excess_light > 0)
{
c1->red = c1->red + excess_light * (c1->red / all_light);
c1->green = c1->green + excess_light * (c1->green / all_light);
c1->blue = c1->blue + excess_light * (c1->blue / all_light);
}
c1->red = c1->red < 0 ? 0 : c1->red;
c1->red = c1->red > 1 ? 1 : c1->red;
c1->green = c1->green < 0 ? 0 : c1->green;
c1->green = c1->green > 1 ? 1 : c1->green;
c1->blue = c1->blue < 0 ? 0 : c1->blue;
c1->blue = c1->blue > 1 ? 1 : c1->blue;
return (new_color(c1->red, c1->green, c1->blue, c1->spec));
}