Mercurial > octave-antonio
annotate scripts/image/__img_via_file__.m @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 7d48766c21a5 |
children |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2006, 2007, 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 |
6945 | 19 ## Undocumented internal function. |
20 | |
6164 | 21 ## -*- texinfo -*- |
8812
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
22 ## @deftypefn {Function File} {} __img_via_file__ (@var{x}, @var{y}, @var{im}, @var{zoom}, @var{command}) |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
23 ## Undocumented internal function. |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
24 ## @end deftypefn |
7d48766c21a5
use consistent format for doc strings of internal functions
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
25 |
6164 | 26 ## Display an image by saving it to a file in PPM format and launching |
27 ## @var{command}. | |
28 ## | |
29 ## The @var{command} must be a format string containing @code{%s} and | |
30 ## possibly @code{%f}. The @code{%s} will be replaced by the filename | |
31 ## of the image, and the @code{%f} will be replaced by @var{zoom}. The | |
32 ## @var{x} and @var{y} arguments are ignored. | |
33 | |
34 function __img_via_file__ (x, y, im, zoom, command) | |
35 | |
36 ppm_name = tmpnam (); | |
37 saveimage (ppm_name, im, "ppm"); | |
38 | |
39 rm = sprintf ("rm -f \"%s\"", ppm_name); | |
40 | |
41 if (isempty (command)) | |
42 ## Different image viewer commands. | |
43 xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name); | |
44 xloadimage = sprintf ("xloadimage -zoom %f \"%s\"", zoom*100, ppm_name); | |
6257 | 45 im_display = sprintf ("display -resize %f%% \"%s\"", zoom*100, ppm_name); |
6164 | 46 |
47 ## Need to let the shell clean up the tmp file because we are putting | |
48 ## the viewer in the background. | |
49 status = system (sprintf ("( %s || %s || %s && %s ) > /dev/null 2>&1 &", | |
50 im_display, xv, xloadimage, rm)); | |
51 else | |
52 ## Does the command support zooming? | |
53 if (findstr (command, "%f")) | |
54 command = sprintf (command, zoom, ppm_name); | |
55 else | |
56 command = sprintf (command, ppm_name); | |
57 endif | |
6967 | 58 status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm)); |
6164 | 59 endif |
60 | |
61 ## Did the system call fail? | |
62 if (status != 0) | |
63 error ("the image viewing command failed"); | |
64 endif | |
65 | |
66 endfunction |