6164
|
1 ## Copyright (C) 2006 S�ren Hauberg |
|
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. |
6164
|
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/>. |
6164
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{fcn}, @var{default_zoom}] =} image_viewer (@var{fcn}, @var{default_zoom}) |
|
21 ## Change the program or function used for viewing images and return the |
|
22 ## previous values. |
|
23 ## |
|
24 ## When the @code{image} or @code{imshow} function is called it will |
|
25 ## launch an external program to display the image. The default behaviour |
|
26 ## is to use gnuplot if the installed version supports image viewing, |
|
27 ## and otherwise try the programs @code{display}, @code{xv}, and |
|
28 ## @code{xloadimage}. Using this function it is possible to change that |
|
29 ## behaviour. |
|
30 ## |
|
31 ## When called with one input argument images will be displayed by saving |
|
32 ## the image to a file and the system command @var{command} will called |
|
33 ## to view the image. The @var{command} must be a string containing |
|
34 ## @code{%s} and possibly @code{%f}. The @code{%s} will be replaced by |
|
35 ## the filename of the image, and the @code{%f} will (if present) be |
|
36 ## replaced by the zoom factor given to the @code{image} function. |
|
37 ## For example, |
|
38 ## @example |
|
39 ## image_viewer ("eog %s"); |
|
40 ## @end example |
|
41 ## changes the image viewer to the @code{eog} program. |
|
42 ## |
|
43 ## With two input arguments, images will be displayed by calling |
|
44 ## the function @var{function_handle}. For example, |
|
45 ## @example |
|
46 ## image_viewer (data, @@my_image_viewer); |
|
47 ## @end example |
|
48 ## sets the image viewer function to @code{my_image_viewer}. The image |
|
49 ## viewer function is called with |
|
50 ## @example |
|
51 ## my_image_viewer (@var{x}, @var{y}, @var{im}, @var{zoom}, @var{data}) |
|
52 ## @end example |
|
53 ## where @var{x} and @var{y} are the axis of the image, @var{im} is the image |
|
54 ## variable, and @var{data} is extra user-supplied data to be passed to |
|
55 ## the viewer function. |
|
56 ## |
|
57 ## With three input arguments it is possible to change the zooming. |
|
58 ## Some programs (like @code{xloadimage}) require the zoom factor to be |
|
59 ## between 0 and 100, and not 0 and 1 like Octave assumes. This is |
|
60 ## solved by setting the third argument to 100. |
|
61 ## |
6944
|
62 ## @seealso{image, imshow} |
6164
|
63 ## @end deftypefn |
|
64 |
|
65 function [ocmd, ofcn, ozoom] = image_viewer (cmd, fcn, zoom) |
|
66 |
|
67 persistent view_cmd; |
|
68 persistent view_fcn; |
|
69 persistent view_zoom = 1; |
|
70 |
|
71 if (isempty (view_fcn)) |
|
72 if (isempty (view_cmd) |
|
73 && compare_versions (__gnuplot_version__ (), "4.0", ">")) |
6257
|
74 view_fcn = "gnuplot_internal"; |
6164
|
75 else |
|
76 view_fcn = @__img_via_file__; |
|
77 endif |
|
78 endif |
|
79 |
|
80 if (nargin > 3) |
|
81 print_usage (); |
|
82 endif |
|
83 |
6165
|
84 if (nargout > 0) |
|
85 ocmd = view_cmd; |
|
86 ofcn = view_fcn; |
|
87 ozoom = view_zoom; |
6164
|
88 endif |
|
89 |
6165
|
90 if (nargin > 0) |
|
91 |
|
92 if (nargin < 3) |
|
93 zoom = 1; |
|
94 if (nargin < 2) |
|
95 fcn = []; |
|
96 endif |
6164
|
97 endif |
6165
|
98 |
|
99 view_cmd = cmd; |
|
100 view_fcn = fcn; |
|
101 view_zoom = zoom; |
6164
|
102 |
6165
|
103 if (nargin > 1) |
|
104 if (isa (fcn, "function_handle")) |
|
105 view_fcn = fcn; |
|
106 else |
|
107 error ("image_viewer: expecting second argument to be a function handle"); |
|
108 endif |
6164
|
109 endif |
6165
|
110 |
|
111 if (nargin > 2) |
|
112 if (isnumeric (zoom) && isscalar (zoom) && isreal (zoom)) |
|
113 view_zoom = zoom; |
|
114 else |
|
115 error ("image_viewer: expecting third argument to be a real scalar"); |
|
116 endif |
|
117 endif |
|
118 |
6164
|
119 endif |
|
120 |
|
121 endfunction |