# HG changeset patch # User Carnë Draug # Date 1337201528 14400 # Node ID b9c02ee24de101692256e89d74c1841c2ee38de0 # Parent 87a50e7cec7acfe9d2f936e1fe51744904669ea0 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. diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -89,6 +89,11 @@ static + ** The colormap function now provides new options "list", "register", + and "unregister" to list all available colormap functions, and to + add or remove a function name from teh list of known colormap + functions. Packages that implement extra colormaps should use these + commands with PKG_ADD and PKG_DEL statements. Summary of important user-visible changes for version 3.6: --------------------------------------------------------- diff --git a/scripts/image/autumn.m b/scripts/image/autumn.m --- a/scripts/image/autumn.m +++ b/scripts/image/autumn.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "autumn"); +## PKG_DEL: colormap ("unregister", "autumn"); + function map = autumn (n) if (nargin == 0) diff --git a/scripts/image/bone.m b/scripts/image/bone.m --- a/scripts/image/bone.m +++ b/scripts/image/bone.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "bone"); +## PKG_DEL: colormap ("unregister", "bone"); + function map = bone (n) if (nargin == 0) diff --git a/scripts/image/colormap.m b/scripts/image/colormap.m --- a/scripts/image/colormap.m +++ b/scripts/image/colormap.m @@ -1,4 +1,5 @@ ## Copyright (C) 1994-2012 John W. Eaton +## Copyright (C) 2012 Carnë Draug ## ## This file is part of Octave. ## @@ -20,6 +21,9 @@ ## @deftypefn {Function File} {@var{cmap} =} colormap () ## @deftypefnx {Function File} {@var{cmap} =} colormap (@var{map}) ## @deftypefnx {Function File} {@var{cmap} =} colormap ("default") +## @deftypefnx {Function File} {@var{cmap} =} colormap ("list") +## @deftypefnx {Function File} {@var{cmap} =} colormap ("register", "name") +## @deftypefnx {Function File} {@var{cmap} =} colormap ("unregister", "name") ## Query or set the current colormap. ## ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The @@ -30,6 +34,10 @@ ## @code{colormap ("default")} restores the default colormap (the ## @code{jet} map with 64 entries). The default colormap is returned. ## +## @code{colormap ("list")} returns a cell array with all the available +## colormaps. The options `register' and `unregister' will add or remove the +## colormap @var{name} to it. +## ## With no arguments, @code{colormap} returns the current color map. ## @seealso{jet} ## @end deftypefn @@ -38,17 +46,22 @@ ## Created: July 1994 ## Adapted-By: jwe -function cmap = colormap (map) +function cmap = colormap (map, name) - if (nargin > 1) + if (nargin > 2) print_usage (); endif + persistent map_list = cell (); + if (nargin == 1) if (ischar (map)) if (strcmp (map, "default")) map = jet (64); + elseif (strcmp (map, "list")) + cmap = map_list; + return; else map = feval (map); endif @@ -65,6 +78,16 @@ set (gcf (), "colormap", map); endif + elseif (nargin == 2) + if (! ischar (map) || all (! strcmp (map, {"register", "unregister"}))) + print_usage (); + elseif (! ischar (name)) + error ("colormap: to register/unregister a colormap, NAME must be a string"); + elseif (strcmp (map, "register")) + map_list{end+1} = name; + elseif (strcmp (map, "unregister")) + map_list(strcmp (name, map_list)) = []; + endif endif ## Return current color map. diff --git a/scripts/image/cool.m b/scripts/image/cool.m --- a/scripts/image/cool.m +++ b/scripts/image/cool.m @@ -27,6 +27,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "cool"); +## PKG_DEL: colormap ("unregister", "cool"); + function map = cool (n) if (nargin == 0) diff --git a/scripts/image/copper.m b/scripts/image/copper.m --- a/scripts/image/copper.m +++ b/scripts/image/copper.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "copper"); +## PKG_DEL: colormap ("unregister", "copper"); + function map = copper (n) if (nargin == 0) diff --git a/scripts/image/flag.m b/scripts/image/flag.m --- a/scripts/image/flag.m +++ b/scripts/image/flag.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "flag"); +## PKG_DEL: colormap ("unregister", "flag"); + function map = flag (n) if (nargin == 0) diff --git a/scripts/image/gmap40.m b/scripts/image/gmap40.m --- a/scripts/image/gmap40.m +++ b/scripts/image/gmap40.m @@ -28,6 +28,9 @@ ## @seealso{colormap} ## @end deftypefn +## PKG_ADD: colormap ("register", "gmap40"); +## PKG_DEL: colormap ("unregister", "gmap40"); + function map = gmap40 (n) if (nargin == 0) diff --git a/scripts/image/gray.m b/scripts/image/gray.m --- a/scripts/image/gray.m +++ b/scripts/image/gray.m @@ -30,6 +30,9 @@ ## Created: July 1994 ## Adapted-By: jwe +## PKG_ADD: colormap ("register", "gray"); +## PKG_DEL: colormap ("unregister", "gray"); + function map = gray (n) if (nargin == 0) diff --git a/scripts/image/hot.m b/scripts/image/hot.m --- a/scripts/image/hot.m +++ b/scripts/image/hot.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "hot"); +## PKG_DEL: colormap ("unregister", "hot"); + function map = hot (n) if (nargin == 0) diff --git a/scripts/image/hsv.m b/scripts/image/hsv.m --- a/scripts/image/hsv.m +++ b/scripts/image/hsv.m @@ -32,6 +32,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "hsv"); +## PKG_DEL: colormap ("unregister", "hsv"); + function map = hsv (n) if (nargin == 0) diff --git a/scripts/image/jet.m b/scripts/image/jet.m --- a/scripts/image/jet.m +++ b/scripts/image/jet.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "jet"); +## PKG_DEL: colormap ("unregister", "jet"); + function map = jet (n) if (nargin == 0) diff --git a/scripts/image/lines.m b/scripts/image/lines.m --- a/scripts/image/lines.m +++ b/scripts/image/lines.m @@ -27,6 +27,9 @@ ## @seealso{colormap} ## @end deftypefn +## PKG_ADD: colormap ("register", "lines"); +## PKG_DEL: colormap ("unregister", "lines"); + function map = lines (n) if (nargin == 0) diff --git a/scripts/image/ocean.m b/scripts/image/ocean.m --- a/scripts/image/ocean.m +++ b/scripts/image/ocean.m @@ -30,6 +30,9 @@ ## Created: July 1994 ## Adapted-By: jwe +## PKG_ADD: colormap ("register", "ocean"); +## PKG_DEL: colormap ("unregister", "ocean"); + function map = ocean (n) if (nargin == 0) diff --git a/scripts/image/pink.m b/scripts/image/pink.m --- a/scripts/image/pink.m +++ b/scripts/image/pink.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "pink"); +## PKG_DEL: colormap ("unregister", "pink"); + function map = pink (n) if (nargin == 0) diff --git a/scripts/image/prism.m b/scripts/image/prism.m --- a/scripts/image/prism.m +++ b/scripts/image/prism.m @@ -28,6 +28,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "prism"); +## PKG_DEL: colormap ("unregister", "prism"); + function map = prism (n) if (nargin == 0) diff --git a/scripts/image/rainbow.m b/scripts/image/rainbow.m --- a/scripts/image/rainbow.m +++ b/scripts/image/rainbow.m @@ -31,6 +31,9 @@ ## this colormap is not part of matlab, it is like the prism ## colormap map but with a continuous map +## PKG_ADD: colormap ("register", "rainbow"); +## PKG_DEL: colormap ("unregister", "rainbow"); + function map = rainbow (n) if (nargin == 0) diff --git a/scripts/image/spring.m b/scripts/image/spring.m --- a/scripts/image/spring.m +++ b/scripts/image/spring.m @@ -27,6 +27,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "spring"); +## PKG_DEL: colormap ("unregister", "spring"); + function map = spring (n) if (nargin == 0) diff --git a/scripts/image/summer.m b/scripts/image/summer.m --- a/scripts/image/summer.m +++ b/scripts/image/summer.m @@ -28,6 +28,9 @@ ## Author: Kai Habel ## Date: 06/03/2000 +## PKG_ADD: colormap ("register", "summer"); +## PKG_DEL: colormap ("unregister", "summer"); + function map = summer (n) if (nargin == 0) diff --git a/scripts/image/white.m b/scripts/image/white.m --- a/scripts/image/white.m +++ b/scripts/image/white.m @@ -27,6 +27,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "white"); +## PKG_DEL: colormap ("unregister", "white"); + function map = white (n) if (nargin == 0) diff --git a/scripts/image/winter.m b/scripts/image/winter.m --- a/scripts/image/winter.m +++ b/scripts/image/winter.m @@ -27,6 +27,9 @@ ## Author: Kai Habel +## PKG_ADD: colormap ("register", "winter"); +## PKG_DEL: colormap ("unregister", "winter"); + function map = winter (n) if (nargin == 0)