rem SmoothX ... Rev 4.1 rem Assembly Language version rem====================================================== rem This program smooths the image in a .bmp or .jpg file rem====================================================== rem ========================================= on error if (err=17) then quit *FLOAT 64 himem=lomem + 100000000 install @lib$+"MyUtils.bbc" install @lib$+"BMP_Utils.bbc" rem ========================================= rem Setup proc_setup rem Select the picture for smoothing proc_pichoose(Name$, FulName$, Pre$, wdth%, hght%, lgth%, pf%) rem Set scaling proc_scale(xscreen%,yscreen%,wdth%,hght%,xb%,yb%,xc%,yc%) rem Display the picture initially proc_BMP_Disp(xc%,yc%,pf%,xb%,yb%) rem 2nd setup proc_setup2 rem Select Smoothing System proc_select rem Smooth the Picture call smooth% rem Display Picture proc_BMP_Disp(xc%,yc%,pfmir%,xb%,yb%) rem Save pictures to disc, at path destination same as source picture proc_picsave proc_event(a$,b&) : quit rem End of Program +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Setup def proc_setup rem Maximise the screen size proc_fullscreen(xscreen%,yscreen%) colour 132,0,0,50 : colour 4,0,0,50 : colour 132 : cls endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem 2nd setup def proc_setup2 local pass& rem Set up a mirror bitmap proc_BMP_Set(wdth%,hght%, pfmir%, Wlim%, lgth%) rem Various Variables dim exab% 9, smooth% 2000, bsave% 500 rem Dual-pass assembly, in case of labels for pass&=0 to 2 step 2 proc_smooth(pass&) proc_bsave(pass&) next pass& endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Choose Smoothing System def proc_select print tab(5,10);"Choose the relative weights of the central and surrounding pixels." print tab(5,12);"The central pixel can have a value anywhere between 0 and 5." print tab(5,14);"The surrounding pixels can have a weight between 1 and 5." repeat input tab(10,16);"Enter the weight for the Central Pixel (1)",Wc% until (Wc%>=0 and Wc%<1001) repeat input tab(10,18);"Enter the weight for the Surrounding Pixels (1)",Ws% if Ws%=0 then Ws%=1 until (Ws%>0 and Ws%<101) Sm%=8*Ws% + Wc% : rem Sum of Weights to Calculate Average a$=inkey$(10) endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Smoothing Utility - Assembly Routine def proc_smooth(opt&) P%=smooth% [opt opt& mov edx,0 mov [^j%],edx .ocirc inc dword [^j%] mov eax,0 mov [^k%],eax ;Initialise loop control .circ inc dword [^k%] mov eax,[^Wlim%] ;Calc pr% mov ebx,[^j%] dec ebx imul eax,ebx mov ebx,[^k%] dec ebx add eax,ebx add eax,ebx add eax,ebx add eax,54 mov [^pr%],eax ;Calc pr% mov al,0 mov [^d&],al .rep mov eax,[^pr%] ;Calculate dfault reference, df% mov bl,[^d&] cmp bl,2 jl ninc2 inc eax .ninc2 cmp bl,1 jl ninc1 inc eax .ninc1 mov [^df%],eax ;df%=pr%+d% mov [^rf%],eax ;Dfault vlue 0f rf% also pr%+d% mov cl,pf%[eax] ;eax=rf% at this point mov edx,0 .again mov exab%[edx],cl ;Load up exab%n, (n=0 t0 8) with vlue 0f current pixel inc edx cmp edx,8 jle again mov eax,[^k%] ;If k%1 do flwng cmp eax,1 jng nowj mov ebx,[^rf%] sub ebx,3 mov cl,pf%[ebx] mov edx,3 mov exab%[edx],cl ;Update exab%3 .nowj mov eax,[^j%] ;If j%>1, do following cmp eax,1 jng conta mov ebx,[^df%] sub ebx,[^jr%] mov [^rf%],ebx mov cl,pf%[ebx] mov edx,1 mov exab%[edx],cl ;Update exab%1 mov eax,[^k%] ;If also k%1 do flwng cmp eax,1 jng conta mov ebx,[^rf%] sub ebx,3 mov cl,pf%[ebx] mov edx,0 mov exab%[edx],cl ;Update exab%0 .conta mov eax,[^j%] ;If j%1 do flwng cmp eax,1 jng contb mov ebx,[^rf%] sub ebx,3 mov cl,pf%[ebx] mov edx,6 mov exab%[edx],cl ;Update exab%6 .contb mov eax,0 ;Adds surrounding 8 pixels mov ecx,0 mov ebx,0 .bgain mov cl,exab%[ebx] add eax,ecx inc ebx cmp ebx,8 jbe bgain mov ebx,4 ;Take 0ff the central pixel Value mov ecx,0 mov cl,exab%[ebx] sub eax,ecx mov ebx,[^Ws%] ;Multiply bi Ws% imul ebx mov ebx,eax mov eax,0 ;Smooth mov ecx,[^Wc%] mov edx,4 mov al,exab%[edx] imul ecx add eax,ebx mov edx,0 mov ecx,[^Sm%] idiv ecx mov ecx,eax mov eax,4 ;Adjust Colour accordingly mov exab%[eax],cl mov ebx,[^pr%] mov ecx,0 mov cl,[^d&] add ebx,ecx mov cl,exab%[eax] mov pfmir%[ebx],cl ;Adjust Colours accordingly inc byte [^d&] mov al,[^d&] cmp al,3 jb near rep mov eax,[^k%] cmp eax,[^wdth%] jl near circ mov edx,[^j%] cmp edx,[^hght%] jl near ocirc ret ] endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Save pictures to disc, at path destination same as source picture def proc_picsave colour 132:colour 3:print tab(0,0);"Saving Picture" Adn$="S.bmp" ps%=instr(Name$,".") Newpic$=left$(Name$,(ps%-1))+Adn$ Dpath$=Pre$+Newpic$ print tab(0,1);"File located at: ";Dpath$ g&=openout Dpath$ call bsave% : rem Byte Save Routine close#g& colour 132:colour 3:print tab(0,3);"DONE" endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rem Byte Save - Assembly Routine def proc_bsave(opt&) P%=bsave% [opt opt& mov ebx,0 mov bl,[^g&] ;Puts channel ref t0 ebx mov edx,0 mov [^w%],edx ;Initialise loop counter .loop mov al,pfmir%[edx] call "osbput" ;Puts al t0 channel ebx inc dword [^w%] mov edx,[^w%] cmp edx,[^lgth%] jle loop ret ] endproc rem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++