-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolor2rgb.m
52 lines (42 loc) · 1.08 KB
/
color2rgb.m
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
function color = color2rgb(color)
switch class(color)
case 'char'
RGB = COLOR2RGB(color);
color = RGB2ABGR(255, RGB);
case 'double'
color = RGB2ABGR(255, color);
otherwise
error('Unknown color')
end
end
function ARGB = RGB2ABGR(alpha, RGB)
if max(alpha) <= 1
alpha = alpha * 255;
end
if max(RGB(:)) <= 1
RGB = RGB * 255;
end
ARGB = [dec2hex(alpha,2) dec2hex(RGB(3),2) dec2hex(RGB(2),2) dec2hex(RGB(1),2)];
end
function RGB = COLOR2RGB(COLOR)
switch COLOR
case {'red', 'r'}
RGB = [255 0 0];
case {'green', 'g'}
RGB = [0 255 0];
case {'blue', 'b'}
RGB = [0 0 255];
case {'cyan', 'c'}
RGB = [0 255 255];
case {'magenta', 'm'}
RGB = [255 0 255];
case {'yellow', 'y'}
RGB = [255 255 0];
case {'black', 'k'}
RGB = [0 0 0];
case {'white', 'w'}
RGB = [255 255 255];
otherwise
error(['Unknown color code: ' COLOR])
end
end