Advertisement
Mysoft

Untitled

Oct 5th, 2016
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sub rotozoom8( dst as FB.IMAGE ptr = 0, src as FB.IMAGE ptr, positx as integer, posity as integer, angle as integer, zoomx as single, zoomy as single )
  2.  
  3.   #define ToFix(_ni) ((_ni)*65536)
  4.   #define ToInt(_nf) ((_nf) shr 16)
  5.   const PI_180 = -3.141592/180, TransColor = 0
  6.   type pixel as ubyte
  7.  
  8.   ' declare all required variables (without assigning values)
  9.   dim as integer px=any, py=any, mx=any, my=any, col=any
  10.   dim as integer dstpit=any,srcwid=any,srchei=any,srcpit=any
  11.   dim as integer nxtc=any, nxts=any, nytc=any, nyts=any
  12.   dim as integer sw2=any, sh2=any, nsw2=any, nsh2=any, dw=any, dh=any
  13.   dim as integer ntcx=any,ntsx=any,ntcy=any,ntsy=any  
  14.   dim as pixel ptr dstptr=any, dstline=any, srcptr=any
  15.   dim as integer xput=any, yput=any
  16.   dim as integer startx=any, endx=any, starty=any, endy=any
  17.  
  18.   ' the target is onscreen or offscreen?
  19.   if dst = 0 then
  20.     dstptr = screenptr : screeninfo dw,dh
  21.     dstpit = dw
  22.   else
  23.     dstptr = cast( pixel ptr, dst+1)
  24.     dw = dst->width : dh = dst->height
  25.     dstpit = dst->pitch
  26.   end if    
  27.  
  28.   ' setup rotation parameters
  29.   srcptr = cast( pixel ptr, src+1): srcpit = src->pitch
  30.   srcwid = src->width: srchei = src->height  
  31.   sw2 = srcwid\2: positx -= sw2: nsw2 = ToFix(sw2)
  32.   sh2 = srchei\2: posity -= sh2: nsh2 = ToFix(sh2)
  33.   var dtcx = cos( angle * pi_180 ), dtsx = sin( angle * pi_180 )  
  34.   ntcy = ToFix(dtcx/ZoomY) : ntsy = ToFix(dtsx/ZoomY)
  35.   ntcx = ToFix(dtcx/ZoomX) : ntsx = ToFix(dtsx/ZoomY)
  36.   var zoom = iif(zoomx>zoomy,zoomx,zoomy)
  37.   xput = abs(dtsx*srcwid)*(zoom/2) + abs(dtcx*srchei)*(zoom/2)
  38.   yput = abs(dtcx*srcwid)*(zoom/2) + abs(dtsx*srchei)*(zoom/2)
  39.   startx = (srcwid/2)-xput : endx = (srcwid/2) + xput
  40.   starty = (srchei/2)-yput : endy = (srchei/2) + yput    
  41.  
  42.   'setup vertical parameters
  43.   py = (starty)-sh2  
  44.   var iT = starty+posity: if iT < 0 then py -= iT: iT = 0
  45.   var iB = endy+posity: if iB >= dH then iB = dH-1  
  46.   dstptr += (iT*dstpit)+startx+positx  
  47.   nytc = (py * ntcy) : nyts = (py * ntsy)
  48.  
  49.   var nsrcwid = ToFix(srcwid), nsrchei = ToFix(srchei)
  50.   for y as integer = iT to iB    
  51.    
  52.     'setup horizontal parameters
  53.     px = (startx)-sw2: dstline = dstptr
  54.     var iL = startx+positx: if iL < 0 then dstline -= iL: px -= iL: iL = 0
  55.     var iR = endx+positx: if iR >= dW then iR = dW-1
  56.     nxtc = (px*ntcx)+nsw2-nyts : nxts = (px*ntsx)+nsh2+nytc
  57.    
  58.     for xput as integer = iL to iR      
  59.       if cuint(nxtc)<nsrcwid and cuint(nxts)<nsrcwid then
  60.         mx = ToInt(nxtc) : my = ToInt(nxts)        
  61.         col = *cast(pixel ptr, cast(ubyte ptr, srcptr) + my * srcpit + mx )
  62.         if col then *dstline = col '<>TransColor
  63.       end if        
  64.       nxtc += ntcx: nxts += ntsx
  65.       dstline += 1
  66.     next xput
  67.    
  68.     nytc += ntcy: nyts += ntsy
  69.     dstptr += dstpit    
  70.    
  71.   next
  72.  
  73. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement