changeset 15713:168e380c8f18

rgbplot.m: create style option and add new composite style
author Carnë Draug <carandraug+dev@gmail.com>
date Sun, 02 Dec 2012 17:29:47 +0100
parents 74ff287f41cb
children b1cd65881592
files scripts/image/rgbplot.m
diffstat 1 files changed, 36 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/image/rgbplot.m	Sun Dec 02 13:12:53 2012 +0100
+++ b/scripts/image/rgbplot.m	Sun Dec 02 17:29:47 2012 +0100
@@ -1,4 +1,5 @@
 ## Copyright (C) 2012 Rik Wehbring
+## Copyright (C) 2012 Carnë Draug
 ##
 ## This file is part of Octave.
 ##
@@ -18,30 +19,53 @@
 
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} rgbplot (@var{cmap})
-## @deftypefnx {Function File} {@var{h} =} rgbplot (@var{cmap})
+## @deftypefnx {Function File} {} rgbplot (@var{cmap}, @var{style})
+## @deftypefnx {Function File} {@var{h} =} rgbplot (@dots{})
 ## Plot the components of a colormap.
 ##
-## The first column is plotted in red, the second column in green, and
-## the third column in blue.  The values are between 0 and 1 and represent
-## the intensity of the RGB components in the given indexed color.
+## Two different @var{style}s are available for displaying the @var{cmap}:
+## @table @asis
+## @item profile (default)
+## Plots the RGB line profile of the colormap for each of the channels (red,
+## green and blue) with the plot lines colored appropriately.  Each line
+## represents the intensity of each RGB components across the colormap.
+##
+## @item composite
+## Draws the colormap across the X axis so that the actual colors are visible
+## rather than the individual color components.
+##
+## @end table
+##
+## Run @code{demo rgbplot} for a comparison display.
 ##
 ## The optional return value @var{h} is a graphics handle to the created plot.
 ##
 ## @seealso{colormap}
 ## @end deftypefn
 
-function retval = rgbplot (cmap)
+function retval = rgbplot (cmap, style)
 
-  if (nargin != 1)
+  if (nargin < 1 || nargin > 2)
     print_usage ();
   endif
 
   if (! iscolormap (cmap))
     error ("rgbplot: CMAP must be a colormap");
+  elseif (! ischar (style))
+    error ("rgbplot: STYLE must be a string");
   endif
 
-  h = plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b");
-  set (gca, 'ytick', 0:0.1:1);
+  switch tolower (style)
+    case "profile"
+      h = plot (cmap(:,1),"r", cmap(:,2),"g", cmap(:,3),"b");
+      set (gca, 'ytick', 0:0.1:1);
+    case "composite"
+      h = image (1:rows(cmap));
+      set (gca, 'ytick', []);
+      colormap (cmap);
+    otherwise
+      error ("rgbplot: unknown style `%s'", style);
+  endswitch
   xlabel ("color index");
 
   if (nargout > 0)
@@ -50,10 +74,12 @@
 
 endfunction
 
-
 %!demo
 %! clf;
-%! rgbplot (ocean);
+%! subplot (1, 2, 1);
+%! rgbplot (ocean, "profile");
+%! subplot (1, 2, 2)
+%! rgbplot (ocean, "composite");
 
 %%test input validation
 %!error rgbplot ()