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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8812
diff changeset
1 ## Copyright (C) 2006, 2007, 2009 S�ren Hauberg
6164
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 -*-
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
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
26 ## 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
27 ## @var{command}.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
28 ##
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
29 ## 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
30 ## 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
31 ## 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
32 ## @var{x} and @var{y} arguments are ignored.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
33
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
34 function __img_via_file__ (x, y, im, zoom, command)
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
35
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
36 ppm_name = tmpnam ();
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
37 saveimage (ppm_name, im, "ppm");
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
38
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
39 rm = sprintf ("rm -f \"%s\"", ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
40
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
41 if (isempty (command))
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
42 ## Different image viewer commands.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
43 xv = sprintf ("xv -raw -expand %f \"%s\"", zoom, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
44 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
45 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
46
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
47 ## 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
48 ## the viewer in the background.
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
49 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
50 im_display, xv, xloadimage, rm));
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
51 else
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
52 ## Does the command support zooming?
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
53 if (findstr (command, "%f"))
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
54 command = sprintf (command, zoom, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
55 else
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
56 command = sprintf (command, ppm_name);
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
57 endif
6967
65a28e9de0a5 [project @ 2007-10-06 12:47:11 by jwe]
jwe
parents: 6945
diff changeset
58 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
59 endif
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
60
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
61 ## Did the system call fail?
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
62 if (status != 0)
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
63 error ("the image viewing command failed");
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
64 endif
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
65
d90b16110095 [project @ 2006-11-14 21:08:00 by jwe]
jwe
parents:
diff changeset
66 endfunction