Mercurial > hg > octave-nkf
annotate scripts/image/brighten.m @ 10400:b14fd5116c29
Ensure that 'limits' is a 2 or 4 vector, and that 'fn' is a function
author | Soren Hauberg <hauberg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 14:29:47 -0800 |
parents | 1bf0ce0930be |
children | ec34c7acd057 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1999, 2000, 2007, 2009 Kai Habel |
6788 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6788 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6788 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {@var{map_out} =} brighten (@var{map}, @var{beta}) | |
6792 | 21 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{h}, @var{beta}) |
6788 | 22 ## @deftypefnx {Function File} {@var{map_out} =} brighten (@var{beta}) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## Darkens or brightens the given colormap. If the @var{map} argument |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## is omitted, the function is applied to the current colormap. The first |
6788 | 25 ## argument can also be a valid graphics handle @var{h}, in which case |
26 ## @code{brighten} is applied to the colormap associated with this handle. | |
27 ## | |
28 ## Should the resulting colormap @var{map_out} not be assigned, it will be | |
29 ## written to the current colormap. | |
30 ## | |
31 ## The argument @var{beta} should be a scalar between -1 and 1, | |
32 ## where a negative value darkens and a positive value brightens | |
33 ## the colormap. | |
34 ## @seealso{colormap} | |
35 ## @end deftypefn | |
36 | |
37 function Rmap = brighten (m, beta) | |
38 h = -1; | |
39 if (nargin == 1) | |
40 beta = m; | |
41 m = colormap; | |
42 h = gcf (); | |
43 elseif (nargin == 2) | |
44 if (ishandle (m)) | |
45 h = m; | |
46 m = get (h, "colormap"); | |
8507 | 47 elseif (! is_matrix (m) || size (m, 2) != 3) |
8664 | 48 error ("brighten: first argument must be an Nx3 matrix or a handle"); |
6788 | 49 endif |
50 else | |
51 print_usage (); | |
52 endif | |
53 | |
8507 | 54 if (! isscalar (beta) || beta <= -1 || beta >= 1) |
8664 | 55 error ("brighten: beta must be a scalar in the range (-1,1)"); |
6788 | 56 endif |
57 | |
58 if (beta > 0) | |
59 gamma = 1 - beta; | |
60 else | |
61 gamma = 1 / (1 + beta); | |
62 endif | |
63 | |
64 if (nargout == 0) | |
65 if (ishandle (h)) | |
66 set (h, "colormap", m .^ gamma); | |
67 else | |
68 colormap (m .^ gamma); | |
69 endif | |
70 else | |
71 Rmap = m .^ gamma; | |
72 endif | |
73 | |
74 endfunction |