[Index for tmp_for_tar/vrml.doc] [Return to Master Index]

ims_save

(tmp_for_tar/vrml.doc/ims_save.m)


Function Synopsis

ok = ims_save (ims, file, fmt)

Help text

       ok = ims_save (ims, file [, fmt])

 Attempts to save image structure ims.

 Last modified: December 2000



Listing of function file tmp_for_tar/vrml.doc/ims_save.m

##       ok = ims_save (ims, file [, fmt])
## 
## Attempts to save image structure ims.

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: December 2000

function ok = ims_save (ims, file, fmt)

ok = 1 ;

if nargin < 1,
  printf ("usage : ims_save (ims [,file] )");
  ok = 0 ;
  return
end

if nargin < 2,			# Guess file name
  if struct_contains (ims, "file"),
    file = ims.file ;
  else
    printf ("ims_save can't determine file name\n");
    ok = 0 ;
    keyboard
  end
end

if nargin < 3,			# Guess file format
  if struct_contains(ims, "fmt"), 
    fmt = ims.fmt ;
  else
    fmt = filename_ext (file);
    if ! length (fmt),
				# Default is ppm / pgm
      if ims.rgb, fmt = "ppm";
      else        fmt = "pgm";
      end
      file = [file, ".", fmt];
      ## printf ("ims_save can't determine file format\n");
      ## keyboard
    end
  end
end
				# Now, fmt and file are set

scale =  ims.maxval != 255 ;

if strcmp(fmt,"ppm") || (strcmp(fmt,"pnm") && ims.rgb) ,
  
  if !ims.rgb,
    tmp = gray2rgb ( ims.im );
    writeppm (file, tmp, scale);
  else
    writeppm (file, ims.im, scale);
  end

elseif strcmp(fmt,"pgm") || strcmp(fmt,"pnm"),

  if ims.rgb, 
    tmp = rgb2gray ( ims.im );
    writepgm (file, tmp, scale);
  else
    writepgm (file, ims.im, scale);
  end

elseif strcmp(fmt,"gif"),

  if ims.rgb, writegif (file, ims.im, scale);
  else        writegraygif (file, ims.im, scale);
  end

elseif strcmp(fmt,"jpg"),

  if ims.rgb, writejpg (file, ims.im, scale);
  else        writegrayjpg (file, ims.im, scale);
  end

elseif strcmp(fmt,"fi"),

  if ims.rgb,   warning ("ims_save a color image to gray file (fi)\n"); end
  writefi (file, ims.im);

elseif findstr([" ",fmt," "]," img ps "),

  if ims.rgb, map = [0,0.5,1] ; else map = [0,0,0]; end
  saveimage (file, ims.im, fmt, map);

else
  printf ("ims_save doesn't what to do with format '%s'\n",fmt);
  ok = 0 ;
  keyboard
end

Produced by oct2html on Sat Dec 2 19:08:39 2000
Cross-Directory links are: ON