rem BMP Utils ....... Rev 2.1 rem A J Tooth // July 2007 rem Set up a bitmap according to parameters provided def proc_BMP_Set(Ww%,Hh%,return pc%,return Wlim%,return lgth%) Wlim%=((Ww%*3+3)and-4) lgth% = 54+Hh%*Wlim% dim pc% lgth% P% = pc% [OPT 0 DB "BM" ; Signature DD lgth% ; Total file bytes DD 0 ; Set t0 zero DD 54 ; Header bytes DD 40 ; Offset t0 Data DD Ww% ; Image Width DD Hh% ; Image Height DW 1 ; Bit planes DW 24 ; Colour depth in bits DD 0 ; Compression type=0=none DD lgth%-54 ; Image size net 0f header DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero ] endproc rem ======================================================================= rem Provide a bitmap with a header def proc_bmpheader(Ww%,Hh%,pc%,return Wlim%,return lgth%) Wlim%=((Ww%*3+3)and-4) lgth% = 54+Hh%*Wlim% P% = pc% [OPT 0 DB "BM" ; Signature DD lgth% ; Total file bytes DD 0 ; Set t0 zero DD 54 ; Header bytes DD 40 ; Offset t0 Data DD Ww% ; Image Width DD Hh% ; Image Height DW 1 ; Bit planes DW 24 ; Colour depth in bits DD 0 ; Compression type=0=none DD lgth%-54 ; Image size net 0f header DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero ] endproc rem ======================================================================= rem Reads a picture as a BMP def proc_read_as_bmp(fil$, return Ww%, return Hh%, return lgth%, return pic%) local bm%, G% dim temp% 255, bm% 86 bm% = (bm% + 3) and -4 : rem Ensures bm% is a multiple of FOUR sys "MultiByteToWideChar", 0, 0, fil$, len(fil$), temp%, 256 sys "LoadLibrary", "OLEAUT32.DLL" to oleaut32% sys "GetProcAddress", oleaut32%, "OleLoadPicturePath" to olpp% I% = &7BF80980 : rem. 128-bit iid J% = &101ABF32 K% = &AA00BB8B L% = &AB0C3000 sys olpp%, temp%, 0, 0, 0, ^I%, ^G% : rem. OleLoadPicturePath if G% = 0 error 0, "Cannot load file """+fil$+"""" sys !(!G%+12), G%, ^hbm% : rem. IPicture::get_Handle sys "GetObject", hbm%, 84, bm% Ww% = bm%!4 Hh% = bm%!8 lgth% = 54+Hh%*((Ww%*3+3)and-4) dim pic% lgth% P% = pic% [OPT 0 DB "BM" ; Signature DD lgth% ; Total file bytes DD 0 ; Set t0 zero DD 54 ; Header bytes DD 40 ; Offset t0 Data DD Ww% ; Image Width DD Hh% ; Image Height DW 1 ; Bit planes DW 24 ; Colour depth in bits DD 0 ; Compression type=0=none DD lgth%-54 ; Image size net 0f header DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero DD 0 ; Set t0 zero ] sys "GetDIBits", @memhdc%, hbm%, 0, Hh%, pic%+54, pic%+14, 0 sys !(!G%+8), G% : rem. IPicture::Release endproc rem =============================================================== rem Display BMP def proc_BMP_DispB(wdth%,hght%,pic%) : local xst%,yst% : xst%=0 : yst%=0 def proc_BMP_Disp(wdth%,hght%,pic%,xst%,yst%) sys "SetStretchBltMode", @memhdc%, 3 command$="MDISPLAY "+str$~pic%+" "+str$(2*xst%)+","+str$(2*yst%)+","+str$(2*wdth%)+","+str$(2*hght%) oscli command$ endproc rem =============================================================== rem Choose a picture def proc_pichoose(return Name$, return FulName$, return Pre$, return wdth%, return hght%, return lgth%, return pic%) local g%,rn%,n$,Flg&,pic$,fullname$,command$,m& dim pq% 75, ff% 30, fm% 255 !pq%=76 pq%!4=@hwnd% pq%!12=ff% pq%!28=fm% pq%!32=256 pq%!52=6 $ff% ="Images"+chr$0+"*.bmp;*.gif;*.jpg"+chr$0+chr$0 sys "GetOpenFileName", pq% to result% if result%<>0 then fullname$ = $$fm% else quit rn%=len(fullname$) g%=0 : pic$="" repeat n$=mid$(fullname$,rn%-g%,1) if n$<>"\" then pic$=n$+pic$ : g%+=1 until n$="\" Pre$=left$(fullname$,rn%-g%) rem Change the current Directory command$="CD "+chr$(34)+Pre$+chr$(34) oscli command$ Name$=pic$ : FulName$=Pre$+Name$ rem Read in a picture as a bitmap proc_read_as_bmp(FulName$,wdth%,hght%,lgth%,pic%) endproc rem--------------------------------------------------------------------- rem Choose a picture def proc_pichoose24(return Name$, return FulName$, return Pre$, return wdth%, return hght%, return lgth%) local g%,rn%,n$,Flg&,pic$,fullname$,command$,m& dim pq% 75, ff% 30, fm% 255 !pq%=76 pq%!4=@hwnd% pq%!12=ff% pq%!28=fm% pq%!32=256 pq%!52=6 $ff% ="Images"+chr$0+"*.bmp;*.gif;*.jpg"+chr$0+chr$0 sys "GetOpenFileName", pq% to result% if result%<>0 then fullname$ = $$fm% else quit rn%=len(fullname$) g%=0 : pic$="" repeat n$=mid$(fullname$,rn%-g%,1) if n$<>"\" then pic$=n$+pic$ : g%+=1 until n$="\" Pre$=left$(fullname$,rn%-g%) rem Change the current Directory command$="CD "+chr$(34)+Pre$+chr$(34) oscli command$ Name$=pic$ : FulName$=Pre$+Name$ wdth%=1024 hght%=768 lgth%=2359350 endproc rem--------------------------------------------------------------------- rem Choose a picture def proc_pichooseSZ(return Name$, return FulName$, return Pre$, return wdth%, return hght%, return lgth%) local g%,rn%,n$,Flg&,pic$,fullname$,command$,m& dim pq% 75, ff% 30, fm% 255 !pq%=76 pq%!4=@hwnd% pq%!12=ff% pq%!28=fm% pq%!32=256 pq%!52=6 $ff% ="Images"+chr$0+"*.bmp;*.gif;*.jpg"+chr$0+chr$0 sys "GetOpenFileName", pq% to result% if result%<>0 then fullname$ = $$fm% else quit rn%=len(fullname$) g%=0 : pic$="" repeat n$=mid$(fullname$,rn%-g%,1) if n$<>"\" then pic$=n$+pic$ : g%+=1 until n$="\" Pre$=left$(fullname$,rn%-g%) rem Change the current Directory command$="CD "+chr$(34)+Pre$+chr$(34) oscli command$ Name$=pic$ : FulName$=Pre$+Name$ wdth%=xscreen% hght%=yscreen% Wlim%=((wdth%*3+3)and-4) lgth%=yscreen%*Wlim% + 54 endproc rem--------------------------------------------------------------------- rem Display a Picture def proc_gendisp(Ctr&,picture$,xpos%,ypos%,xsize%,ysize%,return pic%,return lgth%) local lon%,olpp%,ry% sys "LoadLibrary", "OLEAUT32.DLL" sys "GetModuleHandle", "OLEAUT32.DLL" to oleaut32% sys "GetProcAddress", oleaut32%, "OleLoadPicturePath" to olpp% if olpp%=0 error 0, "Could not get address of OleLoadPicturePath" dim iid% 15, gpp% 3, hmw% 3, hmh% 3, picture% 513 sys "MultiByteToWideChar", 0, 0, picture$, len(picture$), picture%, 256 to lon% picture%!(2*lon%) = 0 iid%!0 = &7BF80980 iid%!4 = &101ABF32 iid%!8 = &AA00BB8B iid%!12 = &AB0C3000 sys olpp%, picture%, 0, 0, 0, iid%, gpp% if !gpp% = 0 error 0, "OleLoadPicturePath failed" sys !(!!gpp%+24), !gpp%, hmw% : rem. IPicture::get_Width sys !(!!gpp%+28), !gpp%, hmh% : rem. IPicture::get_Height sys !(!!gpp%+32), !gpp%, @memhdc%, xpos%, ypos%, xsize%, ysize%, 0, !hmh%, !hmw%, -!hmh%, 0 to res% if res% error 0, "IPicture::Render failed" sys !(!!gpp%+8), !gpp% : rem. IPicture::Release sys "InvalidateRect", @hwnd%, 0, 0 sys "UpdateWindow", @hwnd% if Ctr&=1 then lgth% = 54+ysize%*((xsize%*3+3)and-4) dim pic% lgth% ry%=2*yscreen%-2*ysize% : if ry%<0 then ry%=0 command$=" SCREENSAVE "+"temp.bmp"+" 0,"+str$(ry%)+","+str$(2*xsize%)+","+str$(2*ysize%) oscli command$ command$=" LOAD "+"temp.bmp "+str$~pic% oscli command$ else pic%=0 : lgth%=0 endif endproc rem ==================================================================== rem Display a backdrop picture def proc_BackPic(Name$,xsc%,ysc%) local BPic$,nt% BPic$=@dir$ + Name$ rem Display a background picture proc_gendisp(0,BPic$,10,10,xsc%-20,ysc%-70,nt%,nt%) endproc rem ==================================================================== rem Save picture to disc def proc_save(Name$,xt$,pic%,lgth%,return Newpic$) local ps& ps&=instr(Name$,".") Newpic$=left$(Name$,(ps&-1))+xt$+".bmp" command$=" SAVE "+chr$(34) + Newpic$ +chr$(34) +str$~pic%+" +"+str$~(lgth%) oscli command$ endproc rem ======================================================================== rem Set scaling for displaying pictures centrally def proc_scale(xscreen%,yscreen%,wdth%,hght%,return xb%, return yb%, return xc%, return yc%) if hght%<0.75*wdth% then yc%=int(xscreen%*hght%/wdth%) : yb%=int((yscreen%-yc%)/2) xc%=xscreen% : xb%=0 else yc%=yscreen% : yb%=0 xc%=int(yscreen%*wdth%/hght%) : xb%=int((xscreen%-xc%)/2) endif endproc rem =======================================================================