{ PBMplus import macro. This macro will import the 8-bit RAW versions of PBMplus bitmaps, greymaps or picmaps. This macro will not import the ASCII versions of these files. Timing of this is slow for Bitmaps and Picmaps. A 128x128 bitmap or picmap will read in 43 seconds or 10 seconds respectively on a Centris 650. Your milage may vary. v1.0 - March 25, 1994 Doug Morris - Univ. of Illinois- Biomedical Magnetic Resonance Lab dmorris@bmrl.med.uiuc.edu } var tstatus,dtime:integer; procedure Timeit; var year, month,day,hour, minute,second,dayofweek:integer begin if tstatus=1 then begin GetTime(year,month,day,hour,minute,second,dayofweek); dtime := (hour*3600 + 60*minute + second) - dtime; SelectWindow(txtstr); Writeln('Elapsed Time = ',dtime:10:0,' s'); tstatus := 0; dtime :=0; end; if tstatus=0 then begin GetTime(year,month,day,hour,minute,second,dayofweek); dtime := (hour*3600 + 60*minute + second) - dtime; tstatus :=1; end; end; macro 'Import PBMplus files' var pix,ndim,slices,width,height,itype,offset,i,j,n:integer; bit8,bit7,bit6,bit5,bit4,bit3,bit2,bit1,nconpbm,ntitle:integer; count, offset,maxval,pix1,pix2,pix3,pix4,spix:integer; titlestr,conpbm,str,txtstr:string; dtime,year, month,day,hour, minute,second,dayofweek:integer begin width:=100; height:=1; offset:=0; slices:=1; count :=0; dtime:=0; tstatus:=0; {SetPalette('GrayScale'); } SetImport('8-bit'); SetCustom(width,height,offset,slices); Import(''); {Read in header as an image, prompting for file name.} titlestr := Windowtitle; txtstr := concat(titlestr,' Image Info'); if (GetPixel(0,0) <> 80 ) then begin Dispose; PutMessage(' Not a PBMplus file.'); Exit; end; NewTextWindow(txtstr,300,300); pix := GetPixel(1,0); if pix = 49 then begin Writeln('PBM file ASCII Format'); itype:= 1; end; if pix=50 then begin Writeln('PGM file ASCII Format'); itype:= 2; end; if pix=51 then begin Writeln('PPM file ASCII Format'); itype:= 3; end; if pix=52 then begin Writeln('PBM file RAW Format'); itype:= 4; end; if pix=53 then begin Writeln('PGM file RAW Format'); itype:= 5; end; if pix=54 then begin Writeln('PPM file RAW Format'); itype:= 6; end; if ((pix>54) OR (pix<49)) then begin PutMessage('Unknown PBMPlus File Format'); Exit; end; offset:=3; if (Getpixel(offset,0) = 35) then begin Writeln('File has a comment'); while Getpixel(offset,0) = 35 do begin while Getpixel(count+offset,0) <> 10 do begin spix := Getpixel(count+offset,0); str := chr(spix); Write(str); count := count+1; if count > width then begin PutMessage('End of comment not found. Increase Import Width'); Exit; end; end; Writeln(''); count := count +1; offset := offset + count; count :=0; end; Writeln('end of comment'); end; while Getpixel(count+offset,0) <> 32 do begin count := count+1; end; width :=0; for i := offset to offset+count-1 do begin pix := GetPixel(i,0); width := width + (pix - 48)*exp(2.303*(count+offset - i-1)); end; width := trunc(width); Writeln('Image Width= ',width:10:0); offset:=offset+count+1; count :=0; while Getpixel(count+offset,0) <> 10 do begin count := count+1; end; height :=0; for i := offset to offset+count-1 do begin pix := GetPixel(i,0); height := height + (pix - 48)*exp(2.303*(count+offset - i-1)); end; height := trunc(height); Writeln('Image Height = ',height:10:0); offset:=offset+count+1; count :=0; if ((itype <> 1) AND (itype <> 4)) then begin while Getpixel(count+offset,0) <> 10 do begin count := count+1; end; for i := offset to offset+count-1 do begin pix := GetPixel(i,0); maxval := maxval + (pix - 48)*exp(2.303*(count+offset - i-1)); end; maxval := trunc(maxval); Writeln('Maximum bit value ',maxval:10:0); end; if ((itype >= 1) AND (itype <=3)) then begin SelectWindow(titlestr); Dispose; PutMessage('Only RAWBIT PBMplus formats are handled'); Exit; end; offset := offset+count+1; Writeln('Final 8-bit Import Offset ',offset:8:0); Timeit; if (itype =5 ) then begin SelectWindow(titlestr); Dispose; SetCustom(width,height,offset,slices); Import(''); Timeit; end; if (itype =6 ) then begin SelectWindow(titlestr); Dispose; slices :=1; SetCustom(width*3,height,offset,slices); Import(''); Invert; ApplyLUT; titlestr := WindowTitle; ntitle := PicNumber; conpbm := concat(titlestr,'.convert'); SetNewSize(width,height); MakeNewStack(conpbm); nconpbm := PicNumber; AddSlice; AddSlice; MoveWindow(320,240); for slices := 1 to 3 do begin SetNewSize(width,height); for i := 1 to width do begin ChoosePic(ntitle); n := ((i-1)*3)+slices; MakeLineROI(n-1,0,n-1,height); Copy; ChoosePic(nconpbm); ChooseSlice(slices); MakeLineROI(i-1,0,i-1,height); Paste; end; end; SelectWindow(titlestr); Dispose; SelectWindow(conpbm); SetPicName(titlestr); SelectSlice(1); RGBToIndexed('Custom LUT'); Timeit; end; if (itype = 4) then begin offset := offset - 1; SelectWindow(titlestr); Dispose; SetCustom(width/8,height,offset,slices); Import(''); titlestr := Windowtitle; ntitle := PicNumber; conpbm := concat(titlestr,'.convert'); SetNewSize(width,height); MakeNewWindow(conpbm); nconpbm := PicNumber; for i:= 0 to (width/8-1) do begin for j:= 0 to height do begin ChoosePic(ntitle); pix := GetPixel(i,j); bit8 := trunc(pix/128); bit7 := trunc((pix - bit8*128)/64); bit6 := trunc((pix - bit8*128 - bit7*64)/32); bit5 := trunc((pix - bit8*128 - bit7*64 - bit6*32)/16); bit4 := trunc((pix - bit8*128 - bit7*64 - bit6*32 - bit5*16)/8); bit3 := trunc((pix - bit8*128 - bit7*64 - bit6*32 - bit5*16 - bit4*8)/4); bit2 := trunc((pix - bit8*128 - bit7*64 - bit6*32 - bit5*16 - bit4*8 - bit3*4)/2); bit1 := pix- bit8*128 - bit7*64 - bit6*32 - bit5*16 - bit4*8 - bit3*4 - bit2*2; ChoosePic(nconpbm); PutPixel(8*i,j,bit8*255); PutPixel(8*i+1,j,bit7*255); PutPixel(8*i+2,j,bit6*255); PutPixel(8*i+3,j,bit5*255); PutPixel(8*i+4,j,bit4*255); PutPixel(8*i+5,j,bit3*255); PutPixel(8*i+6,j,bit2*255); PutPixel(8*i+7,j,bit1*255); end; end; SelectWindow(titlestr); Dispose; SelectWindow(conpbm); SetPicName(titlestr); Timeit; end; end; end;