changeset 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 87a50e7cec7a
children 5f1d4def40e1
files NEWS scripts/image/autumn.m scripts/image/bone.m scripts/image/colormap.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/white.m scripts/image/winter.m
diffstat 21 files changed, 87 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed May 16 16:38:39 2012 -0400
+++ b/NEWS	Wed May 16 16:52:08 2012 -0400
@@ -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:
 ---------------------------------------------------------
--- a/scripts/image/autumn.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/autumn.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "autumn");
+## PKG_DEL: colormap ("unregister", "autumn");
+
 function map = autumn (n)
 
   if (nargin == 0)
--- a/scripts/image/bone.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/bone.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "bone");
+## PKG_DEL: colormap ("unregister", "bone");
+
 function map = bone (n)
 
   if (nargin == 0)
--- a/scripts/image/colormap.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/colormap.m	Wed May 16 16:52:08 2012 -0400
@@ -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.
--- a/scripts/image/cool.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/cool.m	Wed May 16 16:52:08 2012 -0400
@@ -27,6 +27,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "cool");
+## PKG_DEL: colormap ("unregister", "cool");
+
 function map = cool (n)
 
   if (nargin == 0)
--- a/scripts/image/copper.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/copper.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "copper");
+## PKG_DEL: colormap ("unregister", "copper");
+
 function map = copper (n)
 
   if (nargin == 0)
--- a/scripts/image/flag.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/flag.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "flag");
+## PKG_DEL: colormap ("unregister", "flag");
+
 function map = flag (n)
 
   if (nargin == 0)
--- a/scripts/image/gmap40.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/gmap40.m	Wed May 16 16:52:08 2012 -0400
@@ -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)
--- a/scripts/image/gray.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/gray.m	Wed May 16 16:52:08 2012 -0400
@@ -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)
--- a/scripts/image/hot.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/hot.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "hot");
+## PKG_DEL: colormap ("unregister", "hot");
+
 function map = hot (n)
 
   if (nargin == 0)
--- a/scripts/image/hsv.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/hsv.m	Wed May 16 16:52:08 2012 -0400
@@ -32,6 +32,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "hsv");
+## PKG_DEL: colormap ("unregister", "hsv");
+
 function map = hsv (n)
 
   if (nargin == 0)
--- a/scripts/image/jet.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/jet.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "jet");
+## PKG_DEL: colormap ("unregister", "jet");
+
 function map = jet (n)
 
   if (nargin == 0)
--- a/scripts/image/lines.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/lines.m	Wed May 16 16:52:08 2012 -0400
@@ -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)
--- a/scripts/image/ocean.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/ocean.m	Wed May 16 16:52:08 2012 -0400
@@ -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)
--- a/scripts/image/pink.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/pink.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "pink");
+## PKG_DEL: colormap ("unregister", "pink");
+
 function map = pink (n)
 
   if (nargin == 0)
--- a/scripts/image/prism.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/prism.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "prism");
+## PKG_DEL: colormap ("unregister", "prism");
+
 function map = prism (n)
 
   if (nargin == 0)
--- a/scripts/image/rainbow.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/rainbow.m	Wed May 16 16:52:08 2012 -0400
@@ -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)
--- a/scripts/image/spring.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/spring.m	Wed May 16 16:52:08 2012 -0400
@@ -27,6 +27,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "spring");
+## PKG_DEL: colormap ("unregister", "spring");
+
 function map = spring (n)
 
   if (nargin == 0)
--- a/scripts/image/summer.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/summer.m	Wed May 16 16:52:08 2012 -0400
@@ -28,6 +28,9 @@
 ## Author:  Kai Habel <kai.habel@gmx.de>
 ## Date:  06/03/2000
 
+## PKG_ADD: colormap ("register", "summer");
+## PKG_DEL: colormap ("unregister", "summer");
+
 function map = summer (n)
 
   if (nargin == 0)
--- a/scripts/image/white.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/white.m	Wed May 16 16:52:08 2012 -0400
@@ -27,6 +27,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "white");
+## PKG_DEL: colormap ("unregister", "white");
+
 function map = white (n)
 
   if (nargin == 0)
--- a/scripts/image/winter.m	Wed May 16 16:38:39 2012 -0400
+++ b/scripts/image/winter.m	Wed May 16 16:52:08 2012 -0400
@@ -27,6 +27,9 @@
 
 ## Author:  Kai Habel <kai.habel@gmx.de>
 
+## PKG_ADD: colormap ("register", "winter");
+## PKG_DEL: colormap ("unregister", "winter");
+
 function map = winter (n)
 
   if (nargin == 0)