home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Fast_image47320182002.psc / Module1.bas < prev   
Encoding:
BASIC Source File  |  2002-01-09  |  5.8 KB  |  149 lines

  1. Attribute VB_Name = "Module1"
  2. 'Sample function Exported by the Filter.dll
  3.  
  4.  
  5. 'See the C++ code for more details
  6.  Declare Function Draw Lib "Filter.dll" (ByVal DC As Long, ByVal WI As Integer, ByVal HI As Integer, lpCallback As Any) As Long
  7.  Declare Sub InvertRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer) ', lpCallback As Any)
  8.  Declare Sub GrayIntensityRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer) ', lpCallback As Any)
  9.  Declare Sub DarKenRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer, ByVal level As Long) ', lpCallback As Any)
  10.  Declare Sub LightenRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer, ByVal level As Long) ', lpCallback As Any)
  11.  Declare Sub BlurRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer, ByVal BlurRadius As Long, lpCallback As Any)
  12.  Declare Sub MorphFishEyeRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer, ByVal CurvingLevel As Single, lpCallback As Any)
  13.  
  14. 'the most important
  15.  Declare Sub ApplyKernelToRVB Lib "Filter.dll" (ByRef myRVBarray As RVB, ByVal Width As Integer, ByVal Height As Integer, ByRef KernelArray As Single, ByVal DevideColor As Single, ByVal AddColor As Single, lpCallback As Any)
  16.  
  17.  
  18.  
  19.  
  20.  
  21. 'API'z for getting all Pixel Data
  22.  Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  23.  Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, ByVal lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
  24.  Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  25.  Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
  26.  Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal HBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
  27.  Declare Function SetDIBitsToDevice Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal SrcX As Long, ByVal SrcY As Long, ByVal Scan As Long, ByVal NumScans As Long, Bits As Any, BitsInfo As BITMAPINFO, ByVal wUsage As Long) As Long
  28.  
  29.  Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  30.  Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  31.  
  32.  
  33.  
  34. Public Const BI_RGB = 0&
  35. Public Const DIB_RGB_COLORS = 0 '  color table in RGBs
  36. Public Type BITMAPINFOHEADER '40 bytes
  37.         biSize As Long
  38.         biWidth As Long
  39.         biHeight As Long
  40.         biPlanes As Integer
  41.         biBitCount As Integer
  42.         biCompression As Long
  43.         biSizeImage As Long
  44.         biXPelsPerMeter As Long
  45.         biYPelsPerMeter As Long
  46.         biClrUsed As Long
  47.         biClrImportant As Long
  48. End Type
  49. Public Type RGBQUAD
  50.         rgbBlue As Byte
  51.         rgbGreen As Byte
  52.         rgbRed As Byte
  53.         rgbReserved As Byte
  54. End Type
  55. Public Type BITMAPINFO
  56.         bmiHeader As BITMAPINFOHEADER
  57.         bmiColors As RGBQUAD
  58. End Type
  59.  
  60.  
  61.  
  62.  
  63.  
  64. 'for holding Pixel color
  65. Public Type RVB
  66.     Rouge As Byte
  67.     Vert As Byte
  68.     Bleu As Byte
  69.     Reserved As Byte
  70. End Type
  71.  
  72. Public RVBarray() As RVB
  73.  
  74.  
  75. 'For the GetBit procedure
  76. Public iBitmap As Long
  77. Public bi24BitInfo As BITMAPINFO
  78. Public TempDC As Long
  79.  
  80.  
  81.  
  82.  
  83.  
  84. '=========================================================
  85. '
  86. '  CallBack Function
  87. '  The C++ Dll call that function for update the progression level
  88. '   this function must be declared at a module section
  89. '========================================================
  90. Function Progress(ByVal percent As Integer) As Boolean
  91.   
  92.   
  93.   'Form1.Caption = CStr(percent) + "%"
  94.   Form1.ProgressBar1.Value = percent
  95.   Progress = True
  96.   
  97. End Function
  98.  
  99.  
  100.  
  101.  
  102. Public Sub GetPixelData()
  103.  
  104.   'fill the bitmapinfoheader structure
  105.     
  106.   With bi24BitInfo.bmiHeader
  107.         .biBitCount = 32  'we use 32 bit alignement for RGB and the unused 8 bytes
  108.         .biCompression = BI_RGB
  109.         .biPlanes = 1
  110.         .biSize = Len(bi24BitInfo.bmiHeader)
  111.         .biWidth = Form1.Picture1.ScaleWidth
  112.         .biHeight = Form1.Picture1.ScaleHeight
  113.     End With
  114.     ReDim RVBarray(0 To bi24BitInfo.bmiHeader.biWidth - 1, 0 To bi24BitInfo.bmiHeader.biHeight - 1)
  115.     
  116.     TempDC = CreateCompatibleDC(0)
  117.     iBitmap = CreateDIBSection(TempDC, bi24BitInfo, DIB_RGB_COLORS, ByVal 0&, ByVal 0&, ByVal 0&)
  118.     SelectObject TempDC, iBitmap
  119.     BitBlt TempDC, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, Form1.Picture1.hdc, 0, 0, vbSrcCopy
  120.     
  121.     'Finaly get All the pixels color
  122.     GetDIBits TempDC, iBitmap, 0, bi24BitInfo.bmiHeader.biHeight, RVBarray(0, 0), bi24BitInfo, DIB_RGB_COLORS
  123.    
  124.    'IMPORTANT if someone knows how to Get all pixels in a RVB structure send allmodified
  125.    'to the device  in C++
  126.     'let me know cauz it would be possible to pass only a
  127.     'Device context and a addressof a callback function
  128. End Sub
  129.  
  130.  
  131. Sub Blit()
  132.     'Send the pixeldata to the device
  133.     'it would be great to do it in C++ unfortunately all my tries failed
  134.     SetDIBitsToDevice Form1.Picture1.hdc, 0, 0, bi24BitInfo.bmiHeader.biWidth, bi24BitInfo.bmiHeader.biHeight, 0, 0, 0, bi24BitInfo.bmiHeader.biHeight, RVBarray(0, 0), bi24BitInfo, DIB_RGB_COLORS
  135.     Form1.ProgressBar1.Value = 0
  136. End Sub
  137.  
  138.  
  139. Sub FreeMemomy()
  140.   'free the temp device and his attached bitmap
  141.     If TempDC > 0 Then
  142.      DeleteDC TempDC
  143.      DeleteObject iBitmap
  144.      Erase RVBarray
  145.     
  146.     End If
  147.  
  148. End Sub
  149.