carandraug avatar carandraug committed 168e380

rgbplot.m: create style option and add new composite style

Comments (0)

Files changed (1)

scripts/image/rgbplot.m

 ## Copyright (C) 2012 Rik Wehbring
+## Copyright (C) 2012 Carnë Draug
 ##
 ## This file is part of Octave.
 ##
 
 ## -*- 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)
 
 endfunction
 
-
 %!demo
 %! clf;
-%! rgbplot (ocean);
+%! subplot (1, 2, 1);
+%! rgbplot (ocean, "profile");
+%! subplot (1, 2, 2)
+%! rgbplot (ocean, "composite");
 
 %%test input validation
 %!error rgbplot ()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.