Mercurial > hg > octave-lyh
annotate 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 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1 ## Copyright (C) 1994-2012 John W. Eaton |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
2 ## Copyright (C) 2012 Carnë Draug |
2313 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
1024 | 19 |
3381 | 20 ## -*- texinfo -*- |
14246
8b220af26cfb
doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
21 ## @deftypefn {Function File} {@var{cmap} =} colormap () |
8b220af26cfb
doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map}) |
8b220af26cfb
doc: Update docstring for colormap()
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default") |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
24 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("list") |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
25 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("register", "name") |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
26 ## @deftypefnx {Function File} {@var{cmap} =} colormap ("unregister", "name") |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14246
diff
changeset
|
27 ## Query or set the current colormap. |
3426 | 28 ## |
3373 | 29 ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14246
diff
changeset
|
30 ## colormap should be an @var{n} row by 3 column matrix. The columns |
3373 | 31 ## contain red, green, and blue intensities respectively. All entries |
14260
1f911333ed3d
doc: Update docstrings for functions in image/ directory
Rik <octave@nomad.inbox5.com>
parents:
14246
diff
changeset
|
32 ## must be between 0 and 1 inclusive. The new colormap is returned. |
3426 | 33 ## |
6895 | 34 ## @code{colormap ("default")} restores the default colormap (the |
35 ## @code{jet} map with 64 entries). The default colormap is returned. | |
3426 | 36 ## |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
37 ## @code{colormap ("list")} returns a cell array with all the available |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
38 ## colormaps. The options `register' and `unregister' will add or remove the |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
39 ## colormap @var{name} to it. |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
40 ## |
3373 | 41 ## With no arguments, @code{colormap} returns the current color map. |
6895 | 42 ## @seealso{jet} |
3373 | 43 ## @end deftypefn |
559 | 44 |
3202 | 45 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 46 ## Created: July 1994 |
47 ## Adapted-By: jwe | |
904 | 48 |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
49 function cmap = colormap (map, name) |
559 | 50 |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
51 if (nargin > 2) |
5923 | 52 print_usage (); |
1062 | 53 endif |
559 | 54 |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
55 persistent map_list = cell (); |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
56 |
1024 | 57 if (nargin == 1) |
3238 | 58 |
5443 | 59 if (ischar (map)) |
1024 | 60 if (strcmp (map, "default")) |
6895 | 61 map = jet (64); |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
62 elseif (strcmp (map, "list")) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
63 cmap = map_list; |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
64 return; |
559 | 65 else |
6257 | 66 map = feval (map); |
559 | 67 endif |
3238 | 68 endif |
69 | |
70 if (! isempty (map)) | |
71 if (columns (map) != 3) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
72 error ("colormap: MAP must have 3 columns: [R,G,B]"); |
3238 | 73 endif |
74 if (min (min (map)) < 0 || max (max (map)) > 1) | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
75 error ("colormap: MAP must have values in [0,1]"); |
3238 | 76 endif |
2303 | 77 ## Set the new color map |
6257 | 78 set (gcf (), "colormap", map); |
559 | 79 endif |
3238 | 80 |
14640
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
81 elseif (nargin == 2) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
82 if (! ischar (map) || all (! strcmp (map, {"register", "unregister"}))) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
83 print_usage (); |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
84 elseif (! ischar (name)) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
85 error ("colormap: to register/unregister a colormap, NAME must be a string"); |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
86 elseif (strcmp (map, "register")) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
87 map_list{end+1} = name; |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
88 elseif (strcmp (map, "unregister")) |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
89 map_list(strcmp (name, map_list)) = []; |
b9c02ee24de1
new colormap options
Carnë Draug <carandraug+dev@gmail.com>
parents:
14260
diff
changeset
|
90 endif |
559 | 91 endif |
92 | |
2303 | 93 ## Return current color map. |
7108 | 94 if (nargout > 0 || (nargout == 0 && nargin == 0)) |
6762 | 95 cmap = get (gcf (), "colormap"); |
96 endif | |
1024 | 97 |
559 | 98 endfunction |