home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / A_200_segm204037122007.psc / modRotate8.bas < prev    next >
BASIC Source File  |  2006-12-18  |  5KB  |  97 lines

  1. Attribute VB_Name = "modRotate8"
  2. Option Explicit
  3. Option Base 0
  4.  
  5. 'Email: jason_bullen@yahoo.com
  6. 'Copyright Jason Bullen November 2003. All right reserved.
  7. 'This source code is copyrighted material which may not be published in any form without explicit prior permission from the author.
  8.  
  9.  
  10. Public Sub VB8_ScaleRotate( _
  11.         ByRef dstBits() As Byte, ByVal dstPitch As Integer, _
  12.         ByVal dstX As Integer, ByVal dstY As Integer, _
  13.         ByVal dstCenX As Integer, ByVal dstCenY As Integer, _
  14.         ByVal dstWidth As Integer, ByVal dstHeight As Integer, _
  15.         ByRef srcBits() As Byte, ByVal srcPitch As Integer, _
  16.         ByVal srcX As Integer, ByVal srcY As Integer, _
  17.         ByVal srcCenX As Integer, ByVal srcCenY As Integer, _
  18.         ByVal srcWidth As Integer, ByVal srcHeight As Integer, _
  19.         ByVal angle As Single, ByVal zoom As Single, ByVal colorKey As Boolean)
  20.  
  21.     Dim RowAdd As Integer
  22.     Dim x As Integer, y As Integer, irx As Long, iry As Long
  23.     Dim xSrcMax As Integer, ySrcMax As Integer
  24.     Dim cosa As Single, sina As Single
  25.     Dim lcosa As Long, lsina As Long
  26.     Dim issx As Long, issy As Long, iss2x As Long, iss2y As Long
  27.     Dim dIndex As Long, color As Byte
  28.  
  29.     xSrcMax = srcX + srcWidth     ' Set Right and Bottom limits of the source image
  30.     ySrcMax = srcY + srcHeight
  31.  
  32.     cosa = Cos(angle) / zoom    ' Get direction vector and scale it
  33.     sina = Sin(angle) / zoom
  34.     
  35.     lcosa = cosa * 65536#       ' Convert the direction vector to Fixed Point 16.16 bits
  36.     lsina = sina * 65536#
  37.     
  38.     iss2x = (srcX + srcCenX - dstCenX * cosa - dstCenY * sina) * 65536#    ' Find the rotated top left position in source
  39.     iss2y = (srcY + srcCenY - dstCenY * cosa + dstCenX * sina) * 65536#
  40.  
  41.     dIndex = CLng(dstY) * CLng(dstPitch) + CLng(dstX)   ' Get the top left position in destination
  42.  
  43.     RowAdd = dstPitch - dstWidth    ' Get amount to add to destination to move down 1 line
  44.  
  45.     If colorKey Then
  46.         For y = 0 To dstHeight - 1
  47.             issx = iss2x    ' Set the 'X' scan start position
  48.             issy = iss2y
  49.             For x = 0 To dstWidth - 1
  50.                 irx = (issx + 32768) \ 65536              ' Get the rounded integer component of Source Scan X
  51.                 If irx >= srcX And irx < xSrcMax Then       ' Skip if outside source rectangle
  52.                     
  53.                     iry = (issy + 32768) \ 65536           ' Get the rounded integer component of Source Scan Y
  54.                     If iry >= srcY And iry < ySrcMax Then   ' Skip if outside source rectangle
  55.                         
  56.                         color = srcBits(iry * srcPitch + irx)
  57.                         If color Then
  58.                             dstBits(dIndex) = color
  59.                         End If
  60.                     End If
  61.                 End If
  62.                 dIndex = dIndex + 1    ' Move one pixel to the right in destination
  63.                 issx = issx + lcosa        ' Add the direction vectors (scan X)
  64.                 issy = issy - lsina
  65.             Next                  ' Loop X
  66.             dIndex = dIndex + RowAdd  'Move to one pixel down and left edge of destination
  67.             iss2x = iss2x + lsina         'Add direction vector minus 90 degress (scan Y)
  68.             iss2y = iss2y + lcosa
  69.         Next  ' Loop Y
  70.     Else
  71.         For y = 0 To dstHeight - 1
  72.             issx = iss2x    ' Set the 'X' scan start position
  73.             issy = iss2y
  74.             For x = 0 To dstWidth - 1
  75.                 irx = (issx + 32768) \ 65536              ' Get the rounded integer component of Source Scan X
  76.                 If irx >= srcX And irx < xSrcMax Then       ' Skip if outside source rectangle
  77.                     
  78.                     iry = (issy + 32768) \ 65536           ' Get the rounded integer component of Source Scan Y
  79.                     If iry >= srcY And iry < ySrcMax Then   ' Skip if outside source rectangle
  80.                         
  81.                         dstBits(dIndex) = srcBits(iry * srcPitch + irx)
  82.                     End If
  83.                 End If
  84.                 dIndex = dIndex + 1    ' Move one pixel to the right in destination
  85.                 issx = issx + lcosa        ' Add the direction vectors (scan X)
  86.                 issy = issy - lsina
  87.             Next                  ' Loop X
  88.             dIndex = dIndex + RowAdd  'Move to one pixel down and left edge of destination
  89.             iss2x = iss2x + lsina         'Add direction vector minus 90 degress (scan Y)
  90.             iss2y = iss2y + lcosa
  91.         Next  ' Loop Y
  92.     End If
  93. End Sub
  94.  
  95.  
  96.  
  97.