From octave-sources-request at bevo dot che dot wisc dot edu Fri Jan 10 17:59:01 2003 Subject: image.m that reuses window From: "Joshua L. Cherry" To: Date: Fri, 10 Jan 2003 18:50:56 -0500 (EST) The image command in octave brings up a new window each time it's called, so image windows accumulate. Usually it would be preferable for a single window to be reused. I've modified the image code to launch xv once and use the same instance repeatedly. The trick is that sending xv the QUIT signal makes it reread its file. Josh Cherry -------------------begin image.m--------------- ## Copyright (C) 1996, 1997 John W. Eaton ## ## This file is part of Octave. ## ## Octave is free software; you can redistribute it and/or modify it ## under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## Octave is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with Octave; see the file COPYING. If not, write to the Free ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA ## 02111-1307, USA. ## -*- texinfo -*- ## at deftypefn {Function File} {} image (@var{x}, @var{zoom}) ## at deftypefnx {Function File} {} image (@var{x}, @var{y}, @var{A}, @var{zoom}) ## Display a matrix as a color image. The elements of at var{x} are indices ## into the current colormap and should have values between 1 and the ## length of the colormap. If at var{zoom} is omitted, the image will be ## scaled to fit within 600x350 (to a max of 4). ## ## The axis values corresponding to the matrix elements are specified in ## at var{x} and @var{y}. At present they are ignored. ## at end deftypefn ## at seealso{imshow, imagesc, and colormap} ## Author: Tony Richardson ## Created: July 1994 ## Adapted-By: jwe ## Modified by Josh Cherry ## to use xv's reload feature (upon signal -QUIT) ## so that the same window is reused ## January 2003 function image (x, y, A, zoom) if (nargin == 0) ## Load Bobbie Jo Richardson (Born 3/16/94) x = loadimage ("default.img"); zoom = 2; elseif (nargin == 1) A = x; zoom = []; x=y=[]; elseif (nargin == 2) A = x; zoom = y; x=y=[]; elseif (nargin == 3) zoom = []; elseif (nargin > 4) usage ("image (matrix, [zoom]) or image (x, y, matrix, [zoom])"); endif if isempty(zoom) ## Find an integer scale factor which sets the image to ## approximately the size of the screen. zoom = min([350/rows(A), 600/columns(A), 4]); if zoom>=1 zoom=floor(zoom); else zoom=1/ceil(1/zoom); endif endif # use old temp file name if it exists global __image_ppm_name__; if (!exist("__image_ppm_name__")) __image_ppm_name__ = tmpnam (); end saveimage (__image_ppm_name__, A, "ppm"); [output, status] = system("which xv", 1); # is xv available? if (status) # no xv; fall back on xloadimage xloadimage = sprintf ("xloadimage -zoom %f %s", zoom*100, __image_ppm_name__); system(xloadimage, 1, "async"); else # use xv # determine whether xv is already running global __image_xv_pid__; if (!exist("__image_xv_pid__")) running = 0; # first time image called else if (waitpid(__image_xv_pid__, 1)) # process defunct or no longer running running = 0; else running = 1; end end if (!running) # xv not running; start it xv = sprintf ("xv -expand %f -raw %s", zoom, __image_ppm_name__); __image_xv_pid__ = system (xv, 1, "async"); else # xv already started; send QUIT signal kill = sprintf("kill -QUIT %d", __image_xv_pid__); system(kill); end end # this version does not remove the temp file __image_ppm_name__ endfunction