-
Notifications
You must be signed in to change notification settings - Fork 1
/
color.c
89 lines (80 loc) · 2.31 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mghalmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/27 13:17:41 by mghalmi #+# #+# */
/* Updated: 2024/01/27 13:19:06 by mghalmi ### ########.fr */
/* */
/* ************************************************************************** */
#include "main.h"
int cproduct(int color, double coef)
{
int mask;
int r;
int g;
int b;
mask = 255;
r = coef * ((color & (mask << 16)) >> 16);
g = coef * ((color & (mask << 8)) >> 8);
b = coef * (color & mask);
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
return ((r << 16) | (g << 8) | b);
}
int cadd(int color_a, int color_b)
{
int mask;
int r;
int g;
int b;
mask = 255;
r = ((color_a & (mask << 16)) + (color_b & (mask << 16))) & (mask << 16);
g = ((color_a & (mask << 8)) + (color_b & (mask << 8))) & (mask << 8);
b = ((color_a & mask) + (color_b & mask)) & mask;
return (r | g | b);
}
int color_x_light(int color, double rgb[3])
{
unsigned int mask;
unsigned int r;
unsigned int g;
unsigned int b;
mask = 255 << 16;
r = rgb[0] * ((color & mask) >> 16);
mask >>= 8;
g = rgb[1] * ((color & mask) >> 8);
mask >>= 8;
b = rgb[2] * (color & mask);
if (r > 255)
r = 255;
if (g > 255)
g = 255;
if (b > 255)
b = 255;
return ((r << 16) | (g << 8) | b);
}
int color_difference(int color1, int color2)
{
int mask;
int r[2];
int g[2];
int b[2];
int distance_exp2;
mask = 255;
r[0] = (color1 & (mask << 16)) >> 16;
g[0] = (color1 & (mask << 8)) >> 8;
b[0] = color1 & mask;
r[1] = (color2 & (mask << 16)) >> 16;
g[1] = (color2 & (mask << 8)) >> 8;
b[1] = color2 & mask;
distance_exp2 = pow((r[1] - r[0]), 2) + pow((g[1] - g[0]), 2) \
+ pow((b[1] - b[0]), 2);
return (distance_exp2 > 1000);
}