comparison scripts/image/colormap.m @ 14640:b9c02ee24de1

new colormap options * colormap.m: New options, list, register, and unregister. * NEWS: Note new colormap options. * 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. Include PKD_ADD and PKG_DEL commands to register and unregister colormap funtions.
author Carnë Draug <carandraug+dev@gmail.com>
date Wed, 16 May 2012 16:52:08 -0400
parents 1f911333ed3d
children 806ea52af230
comparison
equal deleted inserted replaced
14639:87a50e7cec7a 14640:b9c02ee24de1
1 ## Copyright (C) 1994-2012 John W. Eaton 1 ## Copyright (C) 1994-2012 John W. Eaton
2 ## Copyright (C) 2012 Carnë Draug
2 ## 3 ##
3 ## This file is part of Octave. 4 ## This file is part of Octave.
4 ## 5 ##
5 ## Octave is free software; you can redistribute it and/or modify it 6 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by 7 ## under the terms of the GNU General Public License as published by
18 19
19 ## -*- texinfo -*- 20 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{cmap} =} colormap () 21 ## @deftypefn {Function File} {@var{cmap} =} colormap ()
21 ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map}) 22 ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map})
22 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default") 23 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default")
24 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("list")
25 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("register", "name")
26 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("unregister", "name")
23 ## Query or set the current colormap. 27 ## Query or set the current colormap.
24 ## 28 ##
25 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The 29 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The
26 ## colormap should be an @var{n} row by 3 column matrix. The columns 30 ## colormap should be an @var{n} row by 3 column matrix. The columns
27 ## contain red, green, and blue intensities respectively. All entries 31 ## contain red, green, and blue intensities respectively. All entries
28 ## must be between 0 and 1 inclusive. The new colormap is returned. 32 ## must be between 0 and 1 inclusive. The new colormap is returned.
29 ## 33 ##
30 ## @code{colormap ("default")} restores the default colormap (the 34 ## @code{colormap ("default")} restores the default colormap (the
31 ## @code{jet} map with 64 entries). The default colormap is returned. 35 ## @code{jet} map with 64 entries). The default colormap is returned.
32 ## 36 ##
37 ## @code{colormap ("list")} returns a cell array with all the available
38 ## colormaps. The options `register' and `unregister' will add or remove the
39 ## colormap @var{name} to it.
40 ##
33 ## With no arguments, @code{colormap} returns the current color map. 41 ## With no arguments, @code{colormap} returns the current color map.
34 ## @seealso{jet} 42 ## @seealso{jet}
35 ## @end deftypefn 43 ## @end deftypefn
36 44
37 ## Author: Tony Richardson <arichard@stark.cc.oh.us> 45 ## Author: Tony Richardson <arichard@stark.cc.oh.us>
38 ## Created: July 1994 46 ## Created: July 1994
39 ## Adapted-By: jwe 47 ## Adapted-By: jwe
40 48
41 function cmap = colormap (map) 49 function cmap = colormap (map, name)
42 50
43 if (nargin > 1) 51 if (nargin > 2)
44 print_usage (); 52 print_usage ();
45 endif 53 endif
54
55 persistent map_list = cell ();
46 56
47 if (nargin == 1) 57 if (nargin == 1)
48 58
49 if (ischar (map)) 59 if (ischar (map))
50 if (strcmp (map, "default")) 60 if (strcmp (map, "default"))
51 map = jet (64); 61 map = jet (64);
62 elseif (strcmp (map, "list"))
63 cmap = map_list;
64 return;
52 else 65 else
53 map = feval (map); 66 map = feval (map);
54 endif 67 endif
55 endif 68 endif
56 69
63 endif 76 endif
64 ## Set the new color map 77 ## Set the new color map
65 set (gcf (), "colormap", map); 78 set (gcf (), "colormap", map);
66 endif 79 endif
67 80
81 elseif (nargin == 2)
82 if (! ischar (map) || all (! strcmp (map, {"register", "unregister"})))
83 print_usage ();
84 elseif (! ischar (name))
85 error ("colormap: to register/unregister a colormap, NAME must be a string");
86 elseif (strcmp (map, "register"))
87 map_list{end+1} = name;
88 elseif (strcmp (map, "unregister"))
89 map_list(strcmp (name, map_list)) = [];
90 endif
68 endif 91 endif
69 92
70 ## Return current color map. 93 ## Return current color map.
71 if (nargout > 0 || (nargout == 0 && nargin == 0)) 94 if (nargout > 0 || (nargout == 0 && nargin == 0))
72 cmap = get (gcf (), "colormap"); 95 cmap = get (gcf (), "colormap");