annotate scripts/image/__img_via_file__.m @ 7016:93c65f2a5668

[project @ 2007-10-12 06:40:56 by jwe]
author jwe
date Fri, 12 Oct 2007 06:41:26 +0000
parents 65a28e9de0a5
children a1dbe9d80eee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
1 ## Copyright (C) 2006 S�ren Hauberg
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
2 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
3 ## This file is part of Octave.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
4 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
6 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
8 ## your option) any later version.
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
9 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
13 ## General Public License for more details.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
14 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6967
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
18
6945
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6257
diff changeset
19 ## Undocumented internal function.
6bbf56a9718a [project @ 2007-10-02 20:47:22 by jwe]
jwe
parents: 6257
diff changeset
20
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
21 ## -*- texinfo -*-
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
22 ## @deftypefn {Function File} {} __img_via_file__(@var{x}, @var{y}, @var{im}, @var{zoom}, @var{command})
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
23 ## Display an image by saving it to a file in PPM format and launching
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
24 ## @var{command}.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
25 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
26 ## The @var{command} must be a format string containing @code{%s} and
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
27 ## possibly @code{%f}. The @code{%s} will be replaced by the filename
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
28 ## of the image, and the @code{%f} will be replaced by @var{zoom}. The
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
29 ## @var{x} and @var{y} arguments are ignored.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
30 ## @seealso{image, imshow, __img__, __img_via_file__, image_viewer}
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
31 ## @end deftypefn
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
32
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
33 function __img_via_file__ (x, y, im, zoom, command)
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
34
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
35 ppm_name = tmpnam ();
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
36 saveimage (ppm_name, im, "ppm");
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
37
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
38 rm = sprintf ("rm -f \"%s\"", ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
39
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
40 if (isempty (command))
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
41 ## Different image viewer commands.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
42 xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
43 xloadimage = sprintf ("xloadimage -zoom %f \"%s\"", zoom*100, ppm_name);
6257
44c91c5dfe1d [project @ 2007-01-30 19:16:52 by jwe]
jwe
parents: 6164
diff changeset
44 im_display = sprintf ("display -resize %f%% \"%s\"", zoom*100, ppm_name);
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
45
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
46 ## Need to let the shell clean up the tmp file because we are putting
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
47 ## the viewer in the background.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
48 status = system (sprintf ("( %s || %s || %s && %s ) > /dev/null 2>&1 &",
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
49 im_display, xv, xloadimage, rm));
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
50 else
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
51 ## Does the command support zooming?
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
52 if (findstr (command, "%f"))
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
53 command = sprintf (command, zoom, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
54 else
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
55 command = sprintf (command, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
56 endif
6967
65a28e9de0a5 [project @ 2007-10-06 12:47:11 by jwe]
jwe
parents: 6945
diff changeset
57 status = system (sprintf ("( %s && %s) > /dev/null 2>&1 &", command, rm));
6164
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
58 endif
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
59
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
60 ## Did the system call fail?
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
61 if (status != 0)
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
62 error ("the image viewing command failed");
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
63 endif
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
64
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
65 endfunction