Mercurial > octave-nkf
annotate scripts/image/image_viewer.m @ 10846:a4f482e66b65
Grammarcheck more of the documentation.
Use @noindent macro appropriately.
Limit line length to 80 characters.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 01 Aug 2010 20:22:17 -0700 |
parents | 693e22af08ae |
children |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2006, 2007, 2008, 2009 S�ren Hauberg |
6164 | 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 | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
25 ## launch an external program to display the image. The default behavior |
6164 | 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 | |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9051
diff
changeset
|
29 ## behavior. |
6164 | 30 ## |
31 ## When called with one input argument images will be displayed by saving | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
7017
diff
changeset
|
32 ## the image to a file and the system command @var{command} will be called |
6164 | 33 ## to view the image. The @var{command} must be a string containing |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
34 ## @code{%s} and possibly @code{%f}. The @code{%s} will be replaced by |
6164 | 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, | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
38 ## |
6164 | 39 ## @example |
40 ## image_viewer ("eog %s"); | |
41 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
42 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
43 ## @noindent |
6164 | 44 ## changes the image viewer to the @code{eog} program. |
45 ## | |
46 ## With two input arguments, images will be displayed by calling | |
47 ## the function @var{function_handle}. For example, | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
48 ## |
6164 | 49 ## @example |
50 ## image_viewer (data, @@my_image_viewer); | |
51 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
52 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
53 ## @noindent |
6164 | 54 ## sets the image viewer function to @code{my_image_viewer}. The image |
55 ## viewer function is called with | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
56 ## |
6164 | 57 ## @example |
58 ## my_image_viewer (@var{x}, @var{y}, @var{im}, @var{zoom}, @var{data}) | |
59 ## @end example | |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10635
diff
changeset
|
60 ## |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10821
diff
changeset
|
61 ## @noindent |
6164 | 62 ## where @var{x} and @var{y} are the axis of the image, @var{im} is the image |
63 ## variable, and @var{data} is extra user-supplied data to be passed to | |
64 ## the viewer function. | |
65 ## | |
66 ## With three input arguments it is possible to change the zooming. | |
67 ## Some programs (like @code{xloadimage}) require the zoom factor to be | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
68 ## between 0 and 100, and not 0 and 1 like Octave assumes. This is |
6164 | 69 ## solved by setting the third argument to 100. |
70 ## | |
6944 | 71 ## @seealso{image, imshow} |
6164 | 72 ## @end deftypefn |
73 | |
74 function [ocmd, ofcn, ozoom] = image_viewer (cmd, fcn, zoom) | |
75 | |
76 persistent view_cmd; | |
77 persistent view_fcn; | |
78 persistent view_zoom = 1; | |
79 | |
80 if (isempty (view_fcn)) | |
81 if (isempty (view_cmd) | |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
82 && compare_versions (__gnuplot_version__ (), "4.0", ">")) |
6257 | 83 view_fcn = "gnuplot_internal"; |
6164 | 84 else |
85 view_fcn = @__img_via_file__; | |
86 endif | |
87 endif | |
88 | |
89 if (nargin > 3) | |
90 print_usage (); | |
91 endif | |
92 | |
6165 | 93 if (nargout > 0) |
94 ocmd = view_cmd; | |
95 ofcn = view_fcn; | |
96 ozoom = view_zoom; | |
6164 | 97 endif |
98 | |
6165 | 99 if (nargin > 0) |
100 | |
101 if (nargin < 3) | |
102 zoom = 1; | |
103 if (nargin < 2) | |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
104 fcn = []; |
6165 | 105 endif |
6164 | 106 endif |
6165 | 107 |
108 view_cmd = cmd; | |
109 view_fcn = fcn; | |
110 view_zoom = zoom; | |
6164 | 111 |
6165 | 112 if (nargin > 1) |
113 if (isa (fcn, "function_handle")) | |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
114 view_fcn = fcn; |
6165 | 115 else |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
116 error ("image_viewer: expecting second argument to be a function handle"); |
6165 | 117 endif |
6164 | 118 endif |
6165 | 119 |
120 if (nargin > 2) | |
121 if (isnumeric (zoom) && isscalar (zoom) && isreal (zoom)) | |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
122 view_zoom = zoom; |
6165 | 123 else |
10433
2c01d24459fb
Detabify scripts in 'scripts/image/'
Soren Hauberg <hauberg@gmail.com>
parents:
9899
diff
changeset
|
124 error ("image_viewer: expecting third argument to be a real scalar"); |
6165 | 125 endif |
126 endif | |
127 | |
6164 | 128 endif |
129 | |
130 endfunction | |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
131 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
132 ## Display an image by saving it to a file in PPM format and launching |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
133 ## @var{command}. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
134 ## |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
135 ## The @var{command} must be a format string containing @code{%s} and |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
136 ## possibly @code{%f}. The @code{%s} will be replaced by the filename |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
137 ## of the image, and the @code{%f} will be replaced by @var{zoom}. The |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
138 ## @var{x} and @var{y} arguments are ignored. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
139 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
140 function __img_via_file__ (x, y, im, zoom, command) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
141 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
142 ppm_name = tmpnam (); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
143 saveimage (ppm_name, im, "ppm"); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
144 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
145 rm = sprintf ("rm -f \"%s\"", ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
146 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
147 if (isempty (command)) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
148 ## Different image viewer commands. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
149 xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
150 xloadimage = sprintf ("xloadimage -zoom %f \"%s\"", zoom*100, ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
151 im_display = sprintf ("display -resize %f%% \"%s\"", zoom*100, ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
152 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
153 ## Need to let the shell clean up the tmp file because we are putting |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
154 ## the viewer in the background. |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
155 status = system (sprintf ("( %s || %s || %s && %s ) > /dev/null 2>&1 &", |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
156 im_display, xv, xloadimage, rm)); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
157 else |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
158 ## Does the command support zooming? |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
159 if (findstr (command, "%f")) |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
160 command = sprintf (command, zoom, ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
161 else |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
162 command = sprintf (command, ppm_name); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
163 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
164 status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm)); |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
165 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
166 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
167 ## Did the system call fail? |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
168 if (status != 0) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10433
diff
changeset
|
169 error ("image_viewer: the image viewing command failed"); |
9899
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
170 endif |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
171 |
9f25290a35e8
more private function and subfunction changes
John W. Eaton <jwe@octave.org>
parents:
9245
diff
changeset
|
172 endfunction |