Navigation

Operators and Keywords

Function List:

C++ API

saveimage.m File Reference


Functions

function saveimage (filename, img, img_form, map) if(nargin< 2||nargin > 4) print_usage()
endif if (nargin< 4) if(size(img
 if (map_nc!=3) error("colormap should be an N x 3 matrix")
 elseif (!ischar(img_form)) error("image format specification must be a string")
 elseif (!(strcmp(img_form,"img")||strcmp(img_form,"ppm")||strcmp(img_form,"ps"))) error("unsupported image format specification")
endif if (!ismatrix(img)) warning("image variable is not a matrix")
endif if (!ischar(filename)) error("file name must be a string")
endif if (strcmp(img_form,"img")) save("-text"
 map (map > 1)
 map (map< 0)=0
 img (img > map_nr)
 img (img<=0)
 if (strcmp(img_form,"ppm")) time_string
 if (grey &&bw) if(map(1)!=0) map
 fprintf (fid,"P4\n%s\n%d %d\n", tagline, img_nr, img_nc)
 fwrite (fid, tmp,"uchar")
 fprintf (fid,"\n")
 fclose (fid)
 elseif (grey) fid
 fprintf (fid,"P5\n%s\n%d %d\n255\n", tagline, img_nr, img_nc)
 fwrite (fid, map(img),"uchar")
 tmp (img_idx--)
 fprintf (fid,"P6\n%s\n%d %d\n255\n", tagline, img_nr, img_nc)
endif elseif (strcmp(img_form,"ps")==1) if(!grey) error("must have a greyscale color map for conversion to PostScript")
 if (scols > pagewid *MARGIN||srows > pagehgt *MARGIN) if(scols > pagewid *MARGIN) scale
endif if (srows > pagehgt *MARGIN) scale
endif warning ("image too large for page, rescaling to %g", scale)
 fprintf (fid,"%%!PS-Adobe-2.0 EPSF-2.0\n")
 fprintf (fid,"%%%%Creator: Octave %s (saveimage.m)\n", OCTAVE_VERSION)
 fprintf (fid,"%%%%Title: %s\n", filename)
 fprintf (fid,"%%%%Pages: 1\n")
 fprintf (fid,"%%%%BoundingBox: %d %d %d %d\n", fix(llx), fix(lly), fix(urx), fix(ury))
 fprintf (fid,"%%%%EndComments\n")
 fprintf (fid,"/readstring {\n")
 fprintf (fid," currentfile exch readhexstring pop\n")
 fprintf (fid,"} bind def\n")
 fprintf (fid,"/picstr %d string def\n", fix((img_nr+padright)*bps/8))
 fprintf (fid,"%%%%EndProlog\n")
 fprintf (fid,"%%%%Page: 1 1\n")
 fprintf (fid,"gsave\n")
 fprintf (fid,"%g %g translate\n", llx, lly)
 fprintf (fid,"%g %g scale\n", scols, srows)
 fprintf (fid,"%d %d %d\n", img_nr, img_nc, bps)
 fprintf (fid,"[ %d 0 0 -%d 0 %d ]\n", img_nr, img_nc, img_nc)
 fprintf (fid,"image\n")
 fprintf (fid, fmt, img)
 if (rem(img_sz, 30)!=0) fprintf(fid
endif fprintf (fid,"grestore\n")
 fprintf (fid,"showpage\n")
 fprintf (fid,"%%%%Trailer\n")
else error ("saveimage: what happened to the image type?")

Variables

endif map = rgb2ind(img)
endif endif [map_nr, map_nc] = size (map)
endif filename
endif img = round (img')
 return
endif grey = all (map(:,1) == map(:,2) && map(:,1) == map (:,3))
 pbm = pgm = ppm = 0
 map_sz = map_nr * map_nc
 bw
 img_sz = size (img) img_nr * img_nc
 time_string = time_string (1:length (time_string)-1)
 tagline
endif n_long = rem (img_nc, 8)
 tmp = zeros (ceil (img_nc/8), img_nr)
 k = ceil (img_nr/8)
 bwimg = postpad (reshape (map(img), img_nr, img_nc), k * 8, 0)
 b = kron (pow2 (7:-1:0)', ones (1, img_nc))
for i
endfor fid = fopen (filename, "wb")
else img_idx = ((1:3:3*img_sz)+2)'
 map_idx = ((2*map_nr+1):map_sz)'
 tmap = map(map_idx)
endif bps = 8
 dpi = 300
 pagewid = 612
 pagehgt = 762
 MARGIN = 0.95
 devpix = dpi / 72.0 + 0.5
 pixfac = 72.0 / dpi * devpix
 padright = (((img_nr * bps + 7) / 8) * 8 - img_nr * bps) / bps
 scols = img_nr * pixfac
 srows = img_nc * pixfac
 scale = 1
endif llx = (pagewid - scols) / 2
 lly = (pagehgt - srows) / 2
 urx = llx + fix (scols + 0.5)
 ury = lly + fix (srows + 0.5)
 fmt = "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n"
 n

Function Documentation

endif elseif ( strcmp(img_form,"ps")  = =1  ) 

elseif ( grey   ) 

elseif ( strcmp(img_form,"img")||strcmp(img_form,"ppm")||strcmp(img_form,"ps")  ) 

elseif ( ischarimg_form  ) 

else error ( "saveimage: what happened to the image type?"   ) 

fclose ( fid   ) 

fprintf ( fid  ,
"%%%%Trailer\n"   
)

fprintf ( fid  ,
"showpage\n"   
)

endif fprintf ( fid  ,
"grestore\n"   
)

fprintf ( fid  ,
fmt  ,
img   
)

fprintf ( fid  ,
"image\n"   
)

fprintf ( fid  ,
"\n"  [%d 0 0-%d 0%d],
img_nr  ,
img_nc  ,
img_nc   
)

fprintf ( fid  ,
"%d %d %d\n"  ,
img_nr  ,
img_nc  ,
bps   
)

fprintf ( fid  ,
"%g %g scale\n"  ,
scols  ,
srows   
)

fprintf ( fid  ,
"%g %g translate\n"  ,
llx  ,
lly   
)

fprintf ( fid  ,
"gsave\n"   
)

fprintf ( fid  ,
"%%%%Page: 1 1\n"   
)

fprintf ( fid  ,
"%%%%EndProlog\n"   
)

fprintf ( fid  ,
"/picstr %d string def\n"  ,
fix((img_nr+padright)*bps/8)   
)

fprintf ( fid  ,
"} bind def\n"   
)

fprintf ( fid  ,
" currentfile exch readhexstring pop\n"   
)

fprintf ( fid   ) 

fprintf ( fid  ,
"%%%%EndComments\n"   
)

fprintf ( fid  ,
"%%%%BoundingBox: %d %d %d %d\n"  ,
fix(llx ,
fix(lly ,
fix(urx ,
fix(ury  
)

fprintf ( fid  ,
"%%%%Pages: 1\n"   
)

fprintf ( fid  ,
"%%%%Title: %s\n"  ,
filename   
)

fprintf ( fid  ,
"%%%%Creator: Octave %s (saveimage.m)\n"  ,
OCTAVE_VERSION   
)

fprintf ( fid  ,
"%%!PS-Adobe-2.0 EPSF-2.0\n"   
)

fprintf ( fid  ,
"P6\n%s\n%d %d\n255\n"  ,
tagline  ,
img_nr  ,
img_nc   
)

fprintf ( fid  ,
"P5\n%s\n%d %d\n255\n"  ,
tagline  ,
img_nr  ,
img_nc   
)

fprintf ( fid  ,
"\n"   
)

fprintf ( fid  ,
"P4\n%s\n%d %d\n"  ,
tagline  ,
img_nr  ,
img_nc   
)

fwrite ( fid  ,
map(img)  ,
"uchar"   
)

fwrite ( fid  ,
tmp  ,
"uchar"   
)

if ( rem(img_sz, 30)!  = 0  ) 

endif if ( srows  ,
pagehgt MARGIN 
)

if ( scols  ,
pagewid *MARGIN||  srows,
pagehgt MARGIN 
)

if ( grey &&  bw  )  [pure virtual]

if ( strcmp(img_form,"ppm")   ) 

endif if ( strcmp(img_form,"img")   ) 

endif if ( ischarfilename  ) 

endif if ( ismatriximg  ) 

if ( map_nc!  = 3  ) 

endif if (  ) 

img ( img<=  0  ) 

img ( img  ,
map_nr   
)

map (  )  [pure virtual]

map ( map  ,
 
)

function saveimage ( filename  ,
img  ,
img_form  ,
map   
)

tmp ( img_idx--   ) 

endif warning ( "image too large for   page,
rescaling to%g"  ,
scale   
)


Variable Documentation

b = kron (pow2 (7:-1:0)', ones (1, img_nc))

endif bps = 8

bw

Initial value:

 (map_nr == 2
        && ((map(1,1) == 0 && map(2,1) == 255)
            || (map(1,1) == 255 && map(2,1) == 0)))

bwimg = postpad (reshape (map(img), img_nr, img_nc), k * 8, 0)

devpix = dpi / 72.0 + 0.5

dpi = 300

endif endif[map_nr, map_nc] = size (map)

fid = fopen (filename, "wb")

fmt = "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n"

endif grey = all (map(:,1) == map(:,2) && map(:,1) == map (:,3))

for i

Initial value:

 1:k
        tmp(i,:) = sum (bwimg(8*(i-1)+1:8*i,:) .* b)

img = round (img')

else img_idx = ((1:3:3*img_sz)+2)'

img_sz = size (img) img_nr * img_nc

k = ceil (img_nr/8)

endif llx = (pagewid - scols) / 2

lly = (pagehgt - srows) / 2

else map = rgb2ind(img)

map_idx = ((2*map_nr+1):map_sz)'

map_sz = map_nr * map_nc

MARGIN = 0.95

n

endif n_long = rem (img_nc, 8)

padright = (((img_nr * bps + 7) / 8) * 8 - img_nr * bps) / bps

pagehgt = 762

pagewid = 612

pbm = pgm = ppm = 0

pixfac = 72.0 / dpi * devpix

return

endif scale = 1

scols = img_nr * pixfac

srows = img_nc * pixfac

Initial value:

 sprintf ("# Created by Octave %s, %s",
                       OCTAVE_VERSION, time_string)

tmap = map(map_idx)

tmp = zeros (ceil (img_nc/8), img_nr)

urx = llx + fix (scols + 0.5)

ury = lly + fix (srows + 0.5)