# HG changeset patch # User Carnë Draug # Date 1354465787 -3600 # Node ID 168e380c8f1875b572404fe9eeb77261652209a7 # Parent 74ff287f41cbb1dfe46d356ee27a37ad4cb4bdfe rgbplot.m: create style option and add new composite style diff --git a/scripts/image/rgbplot.m b/scripts/image/rgbplot.m --- a/scripts/image/rgbplot.m +++ b/scripts/image/rgbplot.m @@ -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 ()