Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 )
- #define ToFix(_ni) ((_ni)*65536)
- #define ToInt(_nf) ((_nf) shr 16)
- const PI_180 = -3.141592/180, TransColor = 0
- type pixel as ubyte
- ' declare all required variables (without assigning values)
- dim as integer px=any, py=any, mx=any, my=any, col=any
- dim as integer dstpit=any,srcwid=any,srchei=any,srcpit=any
- dim as integer nxtc=any, nxts=any, nytc=any, nyts=any
- dim as integer sw2=any, sh2=any, nsw2=any, nsh2=any, dw=any, dh=any
- dim as integer ntcx=any,ntsx=any,ntcy=any,ntsy=any
- dim as pixel ptr dstptr=any, dstline=any, srcptr=any
- dim as integer xput=any, yput=any
- dim as integer startx=any, endx=any, starty=any, endy=any
- ' the target is onscreen or offscreen?
- if dst = 0 then
- dstptr = screenptr : screeninfo dw,dh
- dstpit = dw
- else
- dstptr = cast( pixel ptr, dst+1)
- dw = dst->width : dh = dst->height
- dstpit = dst->pitch
- end if
- ' setup rotation parameters
- srcptr = cast( pixel ptr, src+1): srcpit = src->pitch
- srcwid = src->width: srchei = src->height
- sw2 = srcwid\2: positx -= sw2: nsw2 = ToFix(sw2)
- sh2 = srchei\2: posity -= sh2: nsh2 = ToFix(sh2)
- var dtcx = cos( angle * pi_180 ), dtsx = sin( angle * pi_180 )
- ntcy = ToFix(dtcx/ZoomY) : ntsy = ToFix(dtsx/ZoomY)
- ntcx = ToFix(dtcx/ZoomX) : ntsx = ToFix(dtsx/ZoomY)
- var zoom = iif(zoomx>zoomy,zoomx,zoomy)
- xput = abs(dtsx*srcwid)*(zoom/2) + abs(dtcx*srchei)*(zoom/2)
- yput = abs(dtcx*srcwid)*(zoom/2) + abs(dtsx*srchei)*(zoom/2)
- startx = (srcwid/2)-xput : endx = (srcwid/2) + xput
- starty = (srchei/2)-yput : endy = (srchei/2) + yput
- 'setup vertical parameters
- py = (starty)-sh2
- var iT = starty+posity: if iT < 0 then py -= iT: iT = 0
- var iB = endy+posity: if iB >= dH then iB = dH-1
- dstptr += (iT*dstpit)+startx+positx
- nytc = (py * ntcy) : nyts = (py * ntsy)
- var nsrcwid = ToFix(srcwid), nsrchei = ToFix(srchei)
- for y as integer = iT to iB
- 'setup horizontal parameters
- px = (startx)-sw2: dstline = dstptr
- var iL = startx+positx: if iL < 0 then dstline -= iL: px -= iL: iL = 0
- var iR = endx+positx: if iR >= dW then iR = dW-1
- nxtc = (px*ntcx)+nsw2-nyts : nxts = (px*ntsx)+nsh2+nytc
- for xput as integer = iL to iR
- if cuint(nxtc)<nsrcwid and cuint(nxts)<nsrcwid then
- mx = ToInt(nxtc) : my = ToInt(nxts)
- col = *cast(pixel ptr, cast(ubyte ptr, srcptr) + my * srcpit + mx )
- if col then *dstline = col '<>TransColor
- end if
- nxtc += ntcx: nxts += ntsx
- dstline += 1
- next xput
- nytc += ntcy: nyts += ntsy
- dstptr += dstpit
- next
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement