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 |
6945
|
19 ## Undocumented internal function. |
|
20 |
6164
|
21 ## -*- texinfo -*- |
|
22 ## @deftypefn {Function File} {} __img_via_file__(@var{x}, @var{y}, @var{im}, @var{zoom}, @var{command}) |
|
23 ## Display an image by saving it to a file in PPM format and launching |
|
24 ## @var{command}. |
|
25 ## |
|
26 ## The @var{command} must be a format string containing @code{%s} and |
|
27 ## possibly @code{%f}. The @code{%s} will be replaced by the filename |
|
28 ## of the image, and the @code{%f} will be replaced by @var{zoom}. The |
|
29 ## @var{x} and @var{y} arguments are ignored. |
|
30 ## @seealso{image, imshow, __img__, __img_via_file__, image_viewer} |
|
31 ## @end deftypefn |
|
32 |
|
33 function __img_via_file__ (x, y, im, zoom, command) |
|
34 |
|
35 ppm_name = tmpnam (); |
|
36 saveimage (ppm_name, im, "ppm"); |
|
37 |
|
38 rm = sprintf ("rm -f \"%s\"", ppm_name); |
|
39 |
|
40 if (isempty (command)) |
|
41 ## Different image viewer commands. |
|
42 xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name); |
|
43 xloadimage = sprintf ("xloadimage -zoom %f \"%s\"", zoom*100, ppm_name); |
6257
|
44 im_display = sprintf ("display -resize %f%% \"%s\"", zoom*100, ppm_name); |
6164
|
45 |
|
46 ## Need to let the shell clean up the tmp file because we are putting |
|
47 ## the viewer in the background. |
|
48 status = system (sprintf ("( %s || %s || %s && %s ) > /dev/null 2>&1 &", |
|
49 im_display, xv, xloadimage, rm)); |
|
50 else |
|
51 ## Does the command support zooming? |
|
52 if (findstr (command, "%f")) |
|
53 command = sprintf (command, zoom, ppm_name); |
|
54 else |
|
55 command = sprintf (command, ppm_name); |
|
56 endif |
6967
|
57 status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm)); |
6164
|
58 endif |
|
59 |
|
60 ## Did the system call fail? |
|
61 if (status != 0) |
|
62 error ("the image viewing command failed"); |
|
63 endif |
|
64 |
|
65 endfunction |