-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_color_conversions.m
52 lines (40 loc) · 1.31 KB
/
test_color_conversions.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
color_conversions()
function color_conversions()
disp('TESTING all color conversions [str2rgb;rgb2hex;hex2rgb]')
colorlab.enter
close all
clear
A = rgb.X11('list');
B = rgb.xkcd('list');
C = build_cnames('pyplot',10);
D = build_cnames('matlab',7);
disp('str2rgb pass')
evalc('rgbA = str2rgb(A);'); % Nasty trick
evalc('rgbB = str2rgb(B);'); % to suppress
evalc('rgbC = str2rgb(C);'); % stdout from
evalc('rgbD = str2rgb(D);'); % str2rgb...
disp('rgb2hex pass')
hexA = rgb2hex(rgbA);
hexB = rgb2hex(rgbB);
hexC = rgb2hex(rgbC);
hexD = rgb2hex(rgbD);
disp('hex2rgb pass')
Argb = hex2rgb(hexA);
Brgb = hex2rgb(hexB);
Crgb = hex2rgb(hexC);
Drgb = hex2rgb(hexD); % For some reason this has serious precision issues!
Drgb = lines(7); % Alternative cross-check while we understand the issue.
disp('cross checks')
assert(isequal(Argb,rgbA),'problems with X11 colors')
assert(isequal(Brgb,rgbB),'problems with xkcd colors')
assert(isequal(Crgb,rgbC),'problems with pyplot colors')
assert(isequal(Drgb,rgbD),'problems with matlab colors')
disp('>> All good!')
disp('------------')
end
function list = build_cnames(prefix,n)
list = cell(n,1);
for i = 1:n
list{i} = [prefix,sprintf('%d',i)];
end
end