Mercurial > hg > octave-nkf
changeset 14641:5f1d4def40e1
improve compatibility of colormap functions
* autumn.m, bone.m, cool.m, copper.m, flag.m, gmap40.m, gray.m, hot.m,
hsv.m, jet.m, lines.m, ocean.m, pink.m, prism.m, rainbow.m,
spring.m, summer.m, winter: Always size and return 0x3 when size < 1.
Return same values as Matlab when size == 1.
author | Carnë Draug <carandraug+dev@gmail.com> |
---|---|
date | Wed, 16 May 2012 16:52:44 -0400 |
parents | b9c02ee24de1 |
children | 6edd02858516 |
files | scripts/image/autumn.m scripts/image/bone.m scripts/image/cool.m scripts/image/copper.m scripts/image/flag.m scripts/image/gmap40.m scripts/image/gray.m scripts/image/hot.m scripts/image/hsv.m scripts/image/jet.m scripts/image/lines.m scripts/image/ocean.m scripts/image/pink.m scripts/image/prism.m scripts/image/rainbow.m scripts/image/spring.m scripts/image/summer.m scripts/image/winter.m |
diffstat | 18 files changed, 69 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/image/autumn.m +++ b/scripts/image/autumn.m @@ -51,7 +51,7 @@ b = zeros (n, 1); map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/bone.m +++ b/scripts/image/bone.m @@ -44,7 +44,7 @@ endif if (n == 1) - map = [0, 0, 0]; + map = [0.125, 0.125, 0.125]; elseif (n > 1) x = linspace (0, 1, n)'; r = (x < 3/4) .* (7/8 * x) ... @@ -56,7 +56,7 @@ + (x >= 3/8) .* (7/8 * x + 1/8); map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/cool.m +++ b/scripts/image/cool.m @@ -50,7 +50,7 @@ b = ones (n, 1); map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/copper.m +++ b/scripts/image/copper.m @@ -53,7 +53,7 @@ b = 1/2 * x; map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/flag.m +++ b/scripts/image/flag.m @@ -43,8 +43,14 @@ print_usage (); endif - C = [1, 0, 0; 1, 1, 1; 0, 0, 1; 0, 0, 0]; - map = C(rem (0:(n-1), 4) + 1, :); + if (n == 1) + map = [1, 0, 0]; + elseif (n > 1) + C = [1, 0, 0; 1, 1, 1; 0, 0, 1; 0, 0, 0]; + map = C(rem (0:(n-1), 4) + 1, :); + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/gmap40.m +++ b/scripts/image/gmap40.m @@ -43,8 +43,12 @@ print_usage (); endif - C = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; - map = C(rem (0:(n-1), 6) + 1, :); + if (n > 1) + C = [1, 0, 0; 0, 1, 0; 0, 0, 1; 1, 1, 0; 1, 0, 1; 0, 1, 1]; + map = C(rem (0:(n-1), 6) + 1, :); + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/gray.m +++ b/scripts/image/gray.m @@ -45,9 +45,14 @@ print_usage (); endif - gr = [0:(n-1)]' / (n - 1); - - map = [gr, gr, gr]; + if (n == 1) + map = [0, 0, 0]; + elseif (n > 1) + gr = [0:(n-1)]' / (n - 1); + map = [gr, gr, gr]; + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/hot.m +++ b/scripts/image/hot.m @@ -44,7 +44,7 @@ endif if (n == 1) - map = [0, 0, 0]; + map = [1, 1, 1]; elseif (n > 1) x = linspace (0, 1, n)'; r = (x < 2/5) .* (5/2 * x) ... @@ -54,7 +54,7 @@ b = (x >= 4/5) .* (5 * x - 4); map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/hsv.m +++ b/scripts/image/hsv.m @@ -53,7 +53,7 @@ hue = linspace (0, 1, n)'; map = hsv2rgb ([hue, ones(n,1), ones(n,1)]); else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/jet.m +++ b/scripts/image/jet.m @@ -44,7 +44,7 @@ endif if (n == 1) - map = [0, 0, 0.5]; + map = [0, 1, 1]; elseif (n > 1) x = linspace (0, 1, n)'; r = (x >= 3/8 & x < 5/8) .* (4 * x - 3/2) ... @@ -58,7 +58,7 @@ + (x >= 3/8 & x < 5/8) .* (-4 * x + 5/2); map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/lines.m +++ b/scripts/image/lines.m @@ -42,9 +42,15 @@ print_usage (); endif - C = get (gca, "colororder"); - nr = rows (C); - map = C(rem (0:(n-1), nr) + 1, :); + if (n == 1) + map = [0, 0, 1]; + elseif (n > 1) + C = get (gca, "colororder"); + nr = rows (C); + map = C(rem (0:(n-1), nr) + 1, :); + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/ocean.m +++ b/scripts/image/ocean.m @@ -45,17 +45,23 @@ print_usage (); endif - cutin = fix (n/3); + if (n == 1) + map = [0, 0, 0]; + elseif (n > 1) + cutin = fix (n/3); - dr = (n - 1) / cutin; - r = prepad ([0:dr:(n-1)], n)'; + dr = (n - 1) / cutin; + r = prepad ([0:dr:(n-1)], n)'; - dg = (n - 1) / (2 * cutin); - g = prepad ([0:dg:(n-1)], n)'; + dg = (n - 1) / (2 * cutin); + g = prepad ([0:dg:(n-1)], n)'; + + b = [0:(n-1)]'; - b = [0:(n-1)]'; - - map = [r, g, b] / (n - 1); + map = [r, g, b] / (n - 1); + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/pink.m +++ b/scripts/image/pink.m @@ -44,7 +44,7 @@ endif if (n == 1) - map = [0, 0, 0]; + map = sqrt([1/3, 1/3, 1/3]); elseif (n > 1) x = linspace (0, 1, n)'; r = (x < 3/8) .* (14/9 * x) ... @@ -56,7 +56,7 @@ + (x >= 3/4) .* (2 * x - 1); map = sqrt ([r, g, b]); else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/prism.m +++ b/scripts/image/prism.m @@ -43,8 +43,14 @@ print_usage (); endif - C = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; - map = C(rem (0:(n-1), 6) + 1, :); + if (n == 1) + map = [1 0 0]; + elseif (n > 1) + C = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; + map = C(rem (0:(n-1), 6) + 1, :); + else + map = zeros (0, 3); + endif endfunction
--- a/scripts/image/rainbow.m +++ b/scripts/image/rainbow.m @@ -63,7 +63,7 @@ map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction
--- a/scripts/image/spring.m +++ b/scripts/image/spring.m @@ -50,7 +50,7 @@ b = 1 - g; map = [r, g, b]; else - map = []; + map = zeros (0, 3); endif endfunction