7017
|
1 ## Copyright (C) 1999, 2000, 2007 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}) |
|
23 ## Darkens or brightens the given colormap. If the @var{map} argument |
|
24 ## is omitted, the function is applied to the current colormap. The first |
|
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"); |
|
47 elseif ((!is_matrix (m)) || (size (m, 2) != 3)) |
|
48 error ("First argument must be a matrix of size nx3 or a handle."); |
|
49 endif |
|
50 else |
|
51 print_usage (); |
|
52 endif |
|
53 |
6791
|
54 if ( (!isscalar (beta)) || (beta <= -1) || (beta >= 1) ) |
6788
|
55 error ("brighten(...,beta) beta must be a scalar in the range (-1,1)."); |
|
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 |