Mercurial > hg > octave-image
changeset 9:00efc2699da9
unfortunately using popen seems to create problems, mostly
on win32, but also on linux, so we need to move to a tmpfile approach
author | aadler |
---|---|
date | Tue, 19 Mar 2002 18:14:13 +0000 |
parents | f2a0a6e5dd60 |
children | 7b475987b12c |
files | imread.m imwrite.m |
diffstat | 2 files changed, 41 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/imread.m +++ b/imread.m @@ -159,18 +159,25 @@ outputtype="pgm"; end - pname= sprintf("convert %s '%s' %s:- 2>/dev/null", - option_str, fname, outputtype); - fid= popen(pname ,'r'); +# pname= sprintf("convert %s '%s' %s:- 2>/dev/null", +# pname= sprintf("convert %s '%s' %s:- ", +# option_str, fname, outputtype); +# fid= popen(pname ,'r'); # disp(pname); disp(fid); + + tnam= tmpnam(); + cmd= sprintf("convert %s '%s' %s:%s 2>/dev/null ", + option_str, fname, outputtype, tnam); + system(cmd); + fid= fopen(tnam,"rb"); # # can we open the pipe? # if not 1) The file format is wrong and the conver program has bailed out # 2) The apropriate converter program hasn't been installed # if fid<0; - fclose(fid); - error(['could not popen ' pname '. Is imagemagick installed?']); + unlink(tnam); + error(['could not read file: ' tnam]); end # get file type @@ -182,8 +189,9 @@ elseif strcmp(line, 'P3'); bpp=8; spp=3; bindata=0; elseif strcmp(line, 'P6'); bpp=8; spp=3; bindata=1; else - fclose(fid); - error(['Image format error for ' fname ]); +# pclose(fid); + fclose(fid); unlink(tnam); + error(['Image format error for ',fname,':line=', setstr(line)]); end # ignore comments @@ -223,7 +231,8 @@ end # feof end #if bindata - fclose( fid ); +# pclose(fid); + fclose(fid); unlink(tnam); if spp==1 greyimg= reshape( data(:), wid, hig )'; @@ -310,6 +319,10 @@ # # $Log$ +# Revision 1.3 2002/03/19 18:14:13 aadler +# unfortunately using popen seems to create problems, mostly +# on win32, but also on linux, so we need to move to a tmpfile approach +# # Revision 1.2 2002/03/17 05:26:14 aadler # now accept filenames with spaces #
--- a/imwrite.m +++ b/imwrite.m @@ -179,23 +179,33 @@ error("imwrite: too many data matrices specified"); end - pname= sprintf("convert %s %s:- '%s' 2>/dev/null", - option_str, outputtype, fname); - fid= popen(pname ,'w'); +# pname= sprintf("convert %s %s:- '%s' 2>/dev/null", +# option_str, outputtype, fname); +# fid= popen(pname ,'w'); + + tnam= tmpnam(); + cmd= sprintf("convert %s %s:%s '%s' 2>/dev/null", + option_str, outputtype, tnam, fname); + fid= fopen(tnam, "wb"); + # disp(pname); disp(fid); if fid<0; - fclose(fid); - error(['could not popen ',pname,'. Is imagemagick installed?']); + error(['could not create file: ',tnam]); end fprintf(fid,"%s\n%d %d\n255\n",pnm_sig,wid,hig); write_count= fwrite(fid,data(:)); if write_count != prod(size(data)) - fclose(fid); + fclose(fid); unlink(tnam); error(['Unable to write image: ', fname ]); end fclose(fid); + [jnk,retcode] = system(cmd); + if retcode !=0 + error('could not call imagemagick convert'); + end + unlink( tnam ); unwind_protect_cleanup empty_list_elements_ok= save_empty_list_elements_ok; @@ -203,6 +213,10 @@ # # $Log$ +# Revision 1.3 2002/03/19 18:14:13 aadler +# unfortunately using popen seems to create problems, mostly +# on win32, but also on linux, so we need to move to a tmpfile approach +# # Revision 1.2 2002/03/17 05:26:14 aadler # now accept filenames with spaces #